ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Problem with calling the program and passing parameters

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with calling the program and passing parameters

    I have this programme in RPGLE (a summary)

    d WkCd0001 s 3a
    d WkCd0002 s 3a
    d WkDe0001 s 50a
    D STARTPGM1 PR
    D P_PARM LIKE (P_PARM)
    *
    D STARTPGM1 PI
    D P_PARM 5000
    *
    D DsQuery1 DS
    D Field_1 1 10 Inz(*Blanks)
    D Field_2 11 50 Inz(*Blanks)
    D Field_3 51 101 Inz(*Blanks)
    c ExSr SrRout01
    c ExSr SrStart
    /free
    BegSr SrRout01;

    EVAL DsQuery1 = P_PARM;
    Eval WkCd0001 = %Trim(Field_1);
    Eval WkCd0002 = %Trim(Field_2);
    Eval WkDe0001 = %Trim(Field_3);

    with a simple interactive call, passing these 3 parameters:
    CALL PGM(MYLIBL/STARTPGM1) PARM(“TXT” '$$$“ 'NOT FOUND”) and when debugging

    the third parameter (WKDEELEM) gives me this result

    WKDEELEM = “NOT FOUND ?? ”

    that is, it also returns these two characters (??) in addition to ‘NOT FOUND’.

    I would like to obtain only the following result:
    WkCd0001 = “TXT”
    WKCd0002 = '$$$'
    WkDe0001 = “NOT FOUND ”

    How can I correct the code?

  • #2
    The cause is the well known 32 byte problem.

    Take a look at this explanation:
    Call Program (CALL) - IBM Documentation​

    Scroll down to:
    • Character string constants of 32 bytes or less are always passed with a length of 32 bytes (padded on the right with blanks). If a character constant is longer than 32 bytes, the whole length of the constant is passed. If the parameter is defined to contain more than 32 bytes, the calling program must pass a constant that contains exactly that number of bytes. Constants longer than 32 characters are not padded to the length expected by the receiving program.

      The receiving program can receive less than the number of bytes passed (in this case, no message is sent). For example, if a program specifies that 4 characters are to be received and ABCDEF is passed (padded with blanks in 26 positions), only ABCD is accepted and used by the program. Quoted character strings can also be passed.
    ​

    Comment


    • #3
      If you are on OS release 7.4 (with PTF SI82606 applied) or above, you can specify the data type and length of parameters on the CALL command (if not specified, the default is still 32):

      CALL PGM(MYLIBL/STARTPGM1) PARM(('TXT') ('???') ('NOT FOUND' (*CHAR 50)))

      Comment

      Working...
      X