Search code examples
ibm-midrangerpglerpg

How do you define a global variable in a rpg Program that can be accessed in calling functions


RPG on the AS400

Is their a way to define a Global variable that can be accessed by functions inside my main function?

For example I have my main rpg program (Lets call it "MAIN_PROGRAM", inside it I call another RPG program(Lets call it SUB_PROGRAM). Now I want to define a string variable "ABC" in my MAIN_PROGRAM and then when calling my SUB_PROGRAM use the variable inside my SUB_PROGRAM.

The reason I don't want to send it into SUB_PROGRAM as a input parameter is that my MAIN_PROGRAM is compiled with a generator (CA-PLEX)... and this gives me a limmit to a string size of 60 000. I did get a way of going around this but cant pass it to the SUB_PROGRAM because PLEX will cut it off at 60 000 characters.

What I would like to do is to create a Global varying variable that can be referenced by the SUB_PROGRAM.

I am new to RPG programming. I am able to edit the source of the programs but I just don't know if one can create a global variable or something similar.


Solution

  • Between two programs? No.

    Between two modules bound into the same *PGM (or *SRVPGM) object, you can use the EXPORT and IMPORT keywords on the variable d-spec.

    If you must leave them as programs, passing the data as an external data area may be your best choice.

    What version of Plex are you using? I haven't used it since 6.1...I'd be somewhat surprised if the current version hasn't kept pace with RPGLE.

    If you haven't already, the CA Plex / 2E community is a great resource for help.