0

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.

Pls , help me with this issue. And sorry if am not clear

skaffman
  • 398,947
  • 96
  • 818
  • 769

3 Answers3

2

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
0

The best way is to add a "flag" to the shared procedure, and then pass a flag when you need different behavior. You don't want to change the shared procedure so it needs to know what program is calling it.

Tim Kuehn
  • 3,201
  • 1
  • 17
  • 23
0
  • Move all logic of the procedure to a new one that has an input parameter.
  • Call that procedure from the original .p
  • Call the new procedure from the procedure that needs the extra parameter.

Optional

  • Gradually replace all runs of original.p to new.p
  • Remove original.p once you're sure all runs have been changed.

Depending on your OpenEdge version you could move the logic to a class instead of a procedure. In the class you can use overloading

carl verbiest
  • 1,113
  • 1
  • 15
  • 30