1

I have an RPGLE program that I'm trying to convert from fixed-format to free-format. In general, I know that defining entry variables is done using prototypes like so:

dcl-pr myprogram;
  I#Entry1 char(5);
end-pr;
dcl-pi myprogram;
  InEntry1 char(5);
end-pi;

But what I don't know is how to do this when the field is already defined. We have a standard definitions file that we copy into programs such as the one I am writing, which has the field I'm using as the enter variable already defined and copied in. In fixed-format, this is just

C     *Entry        PList
C                   Parm                    InEntry1

I have already tried just doing the copy before the prototype entry and leaving the specification blank, but that caused errors. I know I could just use the 'LIKE' keyword and change the variable names, but for readability's sake I would prefer to avoid doing that, and I don't know what problems that may cause down the road.

Just in case it's necessary, there are two variables I'm trying to get in: a data structure and a zoned decimal.

How can I use a variable that is already defined as an entry variable in free-format RPGLE, whether using prototypes or some other way that I do not know of?

2 Answers2

1

The "right" way to handle this would be to create a new version of your standard definitions file (StdDefs==>StdDefs2) to declare the variables under a new name (perhaps with a _t suffix) and the TEMPLATE keyword.

Then in your refactored PR/PI, you use LIKE or LIKEDS.

so your original program looks somthing like

 /copy StdDefs
C     *Entry        PList
C                   Parm                    InEntry1

Your refactored one with PR/PI looks like

 /copy StdDefs2
 /copy Mypr
  dcl-pi myprogram;
    InEntry1 like(inEntry_t);
  end-pi;

Note that best practice is to have the PR in a separate member that's /COPY'd into both caller and callee.

Charles
  • 21,637
  • 1
  • 20
  • 44
  • While this is good advice, it's not really feasible at the moment. Many other programs use the standard definition of these variables, and to change them all would take a very, very long time. That's why I was hoping for a way to use the pre-defined variable instead of using LIKE or LIKEDS. – TheLittlePeace Aug 26 '20 at 13:19
  • 1
    @TheLittlePeace that's why I suggested a new version, StdDefs2, of the current StdDefs include file. Change the programs over as you need to. Have modified answer to make that idea clearer. – Charles Aug 26 '20 at 14:11
  • Ah, that makes more sense. Sorry, I read it too fast! Thank you. So can you confirm then that there's no way to actually use the pre-defined variable in the PI? – TheLittlePeace Aug 26 '20 at 14:17
  • Correct, the PI always defines a "local" variable. Though in this case, it's actually global. I can thing of one method that might work...though likely to be a lot more work...let me try it out... – Charles Aug 26 '20 at 14:23
  • My thought was that if you changed your program from a cycle-main to a linear-main one, you might be able to have your copy file variables as global and your PI parms with the same name would be local. Haven't had a chance to try it, I'll update my answer if I get a chance to try it. But likely to cause more work in reality. – Charles Aug 26 '20 at 23:31
-1

Could not find a solution without declaring another variable with like. And assign the new variable to the old at the begenning of the program, and vice versa at the end.

Dam
  • 986
  • 1
  • 14
  • 20
  • I am not really concerned about declaring the same variable twice. I want to know how to use a pre-declared variable as an input within DCL-PI. Or are you saying that I can do that within the DCL-PI and it would work appropriately? – TheLittlePeace Aug 24 '20 at 15:30
  • I read the question too quickly sorry. I encountered the same problem, and could not find a solution without declaring another variable with *like*. And assign the new variable to the old at the begenning of the program, and vice versa at the end... – Dam Aug 24 '20 at 15:41
  • That's what I was afraid of... Would you mind editing your answer to reflect that? Then if no other answers come in that prove it otherwise I can mark it as answered. – TheLittlePeace Aug 24 '20 at 15:46
  • Done. Let's see if someone can find another solution – Dam Aug 26 '20 at 07:32