Passing an additional packet between programs in the AS400

I have PGMA (RPGLE) which is called from PGMB (CL) and PGMC (CL). PGMB calls PGMA with 2 desks, while PGMC calls PGMA with 3 frames.

How can I handle this at PGMA. I tried the options (* Nopass) for the third parm (which is optional), but this is only for the procedures I am assuming. I cannot put this parameter in PLIST from * entry in PGMA.

+3


source to share


2 answers


Options(*nopass)

works for both programs and procedures. I tend to replace *ENTRY PLIST

with dcl-pi

, but you can make the parameters optional even when using PLIST

.

So the best way is:

ctl-opt Main(MyProgram);

...

dcl-proc MyProgram;
  dcl-pi *n ExtPgm('MYPROGRAM');
    parm1     Char(10);
    parm2     Char(10);
    optparm   Char(10) options(*nopass);
  end-pi;

  ...

  // to process optional parm
  if %parms() >= %parmnum(optparm);
    // do something with optparm;
  endif;

end-proc;

      

Without a linear core specification, you would simply add PI to the main body of the program like this:

dcl-pi MyProgram ExtPgm('MYPROGRAM');
  parm1     Char(10);
  parm2     Char(10);
  optparm   Char(10) options(*nopass);
end-pi;

  ...

// to process optional parm
if %parms() >= %parmnum(optparm);
  // do something with optparm;
endif;

      

Here is the v5 version



 d MyProgram       pr                  ExtPgm('MYPROGRAM')
 d  parm1                        10a        
 d  parm2                        10a   
 d  optparm                      10a   options(*nopass)
 d
 d MyProgram       pi                 
 d  parm1                        10a        
 d  parm2                        10a   
 d  optparm                      10a   options(*nopass)
  *
  /free
   if %parms() >= 3;
     // do something with optparm
   endif;

      

But it even works if you are using PLIST, but in that case you cannot include entries in a factor of 1 or 2. This is only allowed in fixed format programs, and I usually do not write new fixed format code without mitigation, so I would classified this as the last option.

 C     *Entry        PLIST
 C     input1        PARM                    parm1
 C     input2        PARM                    parm2
 C                   PARM                    optparm
 C*
 C                   if        %parms() >= 3
 C*        do something with optparm
 C                   endif

      

Note. I haven't added any prototypes to the freeformat interface examples as they are no longer required. However, if your program can be called by another RPG IV program or procedure, it is best to create a copy of the book with such a prototype and include it in the original program and any calling program. This ensures that the prototype matches the caller.

In all of these cases, it is important to understand that you cannot use a parameter that is not passed. Thus, at the beginning of the program, I will test all the optional parms with the structure if %parms() >= ...

, and if parm was passed, I moved it to a variable defined in the program. If it doesn't exist, I set the value. The above fixed format example works for all RPG IV versions from v3r2 / v3r6. If your RPG version does not have a built-in% parms () module, you can use this field in the program state data structure to determine the number of parameters. This has indeed happened in the past as% parms () was introduced in the second RPG IV release in the mid-1990s.

+3


source


All parameters are automatically optional when using * ENTRY PLIST.



+1


source







All Articles