0

Is there a way to use the variable of a procedure(.p file) in its internal procedure (.p file)?

skaffman
  • 398,947
  • 96
  • 818
  • 769

3 Answers3

0

Like this?

define variable i as integer no-undo.  /* a variable in the main procedure */

procedure internalProcedure:

  message "Internal Procedure (a):" i.
  i = 13.
  message "Internal Procedure (b):" i.
end.

/* main block
 */

i = 1.
message "Main procedure (a):" i.

run internalProcedure.

message "Main procedure (b):" i.

The more difficult question might be: "Is there anyway to prevent a globally scoped variable from being used in an internal procedure"?

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
  • :Thanks for your kind attention sir. Let me put my whole issue down to you so that you can give me what exactly i need.**_Am working in Progress 4gl and am an novice programmer. I am working on a situation where there are five procedures (.p files) which are not related to each other, sharing a single procedure (.p file). My issue is that i need to modify the shared procedure , that should have its effect on only one calling procedure and not the other four. What are the ways that i can link these two procedures at the same time preventing the effects on other four procedures._** – Vetrivel Sitrarasu Apr 24 '12 at 08:40
  • one more thing is that I was told like passing a flag from 1 .p file to another .p file is not possible . is that so ,sir? If the statement is false, it would solve my issue.!! Thank you. – Vetrivel Sitrarasu Apr 24 '12 at 08:44
  • So your issue actually has nothing to do with internal procedures and is actually about passing parameters between multiple .p files? – Tom Bascom Apr 24 '12 at 10:21
0

The actual problem seems to be: "I have many procedures that call a common procedure. In one special case I need to have the common procedure set a special value in the calling procedure but I cannot modify all of the others."

The simple, but architecturally repugnant, solution is to use a global shared variable.

Many people will tell you that this is a bad coding technique. They are right. But you aren't asking for advice on best practices.

Simply create such a variable in both the caller and the callee. Procedures that don't need it won't miss it.

One of your "normal" programs:

/* p1.p */

message "p1, I'm normal.".
run common.p.

Your "special" program:

/* p2.p */

define new global shared variable special as character no-undo.

message "p2, I'm special!".
run common.p.
message "special = " special.

The common program:

/* common.p */

define new global shared variable special as character no-undo.
message "common stuff...".
if program-name(2) = "p2.p" then special = "special value".
return.

You can define a NEW GLOBAL SHARED variable as many times as you like and you only get one copy of it. The "new" doesn't overwrite any existing variables (if you leave out GLOBAL it behaves differently).

You didn't ask for it and maybe you don't need it but the program-name(2) check peeks at the call stack to see if common.p was called by p2.p.

There are other, more complicated ways to do this but they all boil down to the same problem -- you're creating the basis for some very ugly coupling between your "special" program and the now no longer generic "common" program.

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
  • there are five different screens(5 different .p files) using a piece of code(a 6th .p file) in all of them.I need to change the particular " piece of code " so that it should have its effect only on one screen which i needed and not the other 4. So i thought like using a flag would solve the issue. requesting u to let me know the possible ways to accomplish this. Sorry Am completely new to this niche technology. am just trying to take advantage of whatever is available regarding this. Thanks once again for your help – Vetrivel Sitrarasu Apr 24 '12 at 12:42
  • If the "piece of code" is another procedure (which is what you claim in your question) then the GLOBAL SHARED variable will let you do that. Obviously I have no idea what your code actually looks like -- but you should be able to adapt the concept shown above easily enough. – Tom Bascom Apr 24 '12 at 12:46
  • if I define a globally shared variable , say "flag" in 1 .p file and I use it in another .p file(which i run in the former .p file) without defining, will it work? – Vetrivel Sitrarasu Apr 24 '12 at 12:51
  • You have to define it everywhere that you want to reference it. – Tom Bascom Apr 24 '12 at 19:50
0

Is this what you mean?

Here we have a common .p file called ShowTime.p that the other .p files will run. You want it to behave in a certain way for one of the .p files, and a different way for the others. For this reason we define a parameter. In this example it is a LOGICAL parameter, so the value can be YES or NO. As you can see, the ShowTime procedure will display the TIME if the lShowDate parameter is NO, and it will display the DATE if the lShowDate parameter is YES.

/* ShowTime.p */
DEFINE INPUT PARAMETER lShowDate AS LOGICAL.
IF lShowDate = NO THEN
  MESSAGE STRING(TIME,"HH:MM:SS").
ELSE
  MESSAGE STRING(TODAY,"9999/99/99").

Here is one of your five unrelated .p files. It runs the ShowTime.p procedure, passing it a parameter of NO, so ShowTime will show the TIME.

/* p1.p */
MESSAGE "P File 1".
RUN ShowTime(INPUT NO) NO-ERROR.

Another one, why not?

/* p2.p */
MESSAGE "P File 2".
RUN ShowTime(INPUT NO) NO-ERROR.

This .p file is running ShowTime with the lShowDate parameter as YES, which means that the ShowTime procedure will behave differently for this one, by showing the DATE instead of the TIME.

/* p5.p */
MESSAGE "P File 5".
RUN ShowTime(INPUT YES) NO-ERROR.

So basically what you have is one procedure, ShowTime, that can do one of two things. An unrelated procedure that runs this one procedure can tell it what it wants, by passing it a parameter.

To put it in terms of your question: there are five procedures (p1.p, p2.p ... p5.p) which are not related to each other, sharing a single procedure (ShowTime.p file). The shared procedure is modified with a parameter, so that it can have its effect on only one calling procedure (the one with the YES parameter) and not the other four (the ones with the NO parameter).

But if you cannot change the way five unrelated procedures run the shared procedure, if you can only change the shared procedure, you have to make your decision on something other than a parameter. What about this:

/* DoThing.p */
IF SOURCE-PROCEDURE:NAME = "p5.p" THEN
  MESSAGE "Do one thing".
ELSE
  MESSAGE "Do something else".

This will do one thing for one of the five procedures, and something else for the other four.

RobertT
  • 1,213
  • 10
  • 12
  • Whenever I try "THIS-PROCEDURE:FILE-NAME" to display the current .p file I am working with , the result I always get is a .ped file. I would like to know what a .ped file is and the ways to display the filename that is, the name of the .p file in my program. – Vetrivel Sitrarasu Apr 26 '12 at 12:08
  • When you run your program directly from source code, Progress will compile it in a temp file and run that temp file. THIS-PROCEDURE:FILE-NAME will return the name of the temp file, not the name of the source-code file. But if you run your program as compiled code, you should get the correct file name. If I have a program called app.p open in Procedure Editor, I get "c:\temp\p78104_app.cmp" when I run it. But if I execute "RUN 'app.p'." from procedure editor, it runs the compiled file, so THIS-PROCEDURE:FILE-NAME gives me "C:\MyProgs\app.p". – RobertT Apr 30 '12 at 06:41