ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Passing parms to a program expecting parms, can I pass as a DS instead?

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

  • Passing parms to a program expecting parms, can I pass as a DS instead?

    Hello,

    I've got a program (prog1) with 10 input parms, all 1a, defined as a *entry plist.

    Calling prog1 from elsewhere; is there a way of bunching the parms together (like in a ds) and calling it with the DS, rather than all 10 individual parms? Without changing prog1 (or at least, changing it in a way that will affect the other programs that call it).

    Example;


    Code:
    (Prog1);
    C *ENTRY PLIST
    C PARM FLAG01 1
    C PARM FLAG02 1
    C PARM FLAG03 1
    C PARM FLAG04 1
    C PARM FLAG05 1
    C PARM FLAG06 1
    C PARM FLAG07 1
    C PARM FLAG08 1
    C PARM FLAG09 1
    C PARM FLAG10 1
    
    (Calling from elsewhere);
    d prog1 pr extpgm('prog1')
    d flag1 1a
    d flag2 1a
    d flag3 1a
    d flag4 1a
    d flag5 1a
    d flag6 1a
    d flag7 1a
    d flag8 1a
    d flag9 1a
    d flag10 1a
    
    d flag1 s 1a
    d flag2 s 1a
    d flag3 s 1a
    d flag4 s 1a
    d flag5 s 1a
    d flag6 s 1a
    d flag7 s 1a
    d flag8 s 1a
    d flag9 s 1a
    d flag10 s 1a
    
    /free
    
    prog1(flag1: flag2: flag3: flag4: flag5:
    flag6: flag7: flag8: flag9: flag10);
    
    *inlr = *on;
    return;
    
    /end-free
    
    (Example of what I'm trying to achieve (this doesn't work);
    
    d prog1 pr extpgm('prog1')
    d prog1Parms likeds(prog1Parms)
    
    d prog1Parms ds
    d flag1 1a
    d flag2 1a
    d flag3 1a
    d flag4 1a
    d flag5 1a
    d flag6 1a
    d flag7 1a
    d flag8 1a
    d flag9 1a
    d flag10 1a
    
    /free
    
    prog1(prog1Parms);
    
    *inlr = *on;
    return;
    
    /end-free
    (for some annoying reason; pasting into the forum's topic box removes excess whitespace making the formatting look stupid)
    Last edited by gcraill; September 26, 2021, 02:41 PM. Reason: title change

  • #2
    Unfortunately the wording I chose for the title sucks, half asleep sorry. Passing parms to a program expecting parms, as a DS instead? would be a bit closer to what I meant.

    Comment


    • #3
      Hello

      Have you considered the possibility of calling a prog2 in between that just redefines the ds as 10 parms and calls prog1 then returns to caller,.

      Else you can play with %parms : when you have 10 parms then work the old way, when 1 parm then use it as a 10 byte long ds. But you have to take care of parms that aren't passed, even if at least they will make prog1 fail. An you have to be sure you just don't corrupt the caller's memory if you touch %subst(ds:2:9) when the caller gives 10 parms.
      Nicolas

      Comment


      • #4
        If I understand you right PROG1 is already in production and referred from many programs using the 10 parameters.
        And you son't want to change the programs in production.

        Thus vazymimils suggestion is the most flexible.
        I would recommend that you define a copysource with a qualified data structure and give it a fixed length from start.
        For example 2000 bytes. If you later need to return a value in a new field FLAG11, you can just implement it in the copysource and don't have
        to compile the existing programs using the datastructure.

        If you used fixed format calls then you could use a PLIST operation code to Identify a Parameter List.
        But after 35 years I have never used this except with *ENTRY

        Comment

        Working...
        X