ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SAVOBJ list of files in CL parameter to SAVF failing

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

  • SAVOBJ list of files in CL parameter to SAVF failing

    I am working on a CL program to move source code around from DEV to PROD. I want to create a backup of current stuff 'just in case'
    So I wrote a cl program to put the names of the programs I want to save into a parm. When I run the SAVOBJ command, it puts a single quote at the start which causes it to fail.
    SAVOBJ OBJ(&PGMLIST) LIB(&FROMLIB) DEV(*SAVF) +
    SAVF(&SAVEFILE)

    here is the job log. First SAVOBJ is if I write the list out manually and it works as expected. Second SAVOBJ uses the cl parm (as listed above) and fails. It seems to be trying to chunk it into 10 character parms.
    I am not sure how the quotes are getting in there, let alone how to remove them.




    7800 - SAVOBJ OBJ(LOB20CP LOB20M1 LOB20M2 LOB20V1 LOB20V2 LOB20V3
    LOB20V4 LOB20FM VERSION) LIB(LSILIB) DEV(*SAVF) SAVF(SLIT122320)
    9 objects saved from library LSILIB.
    8200 - SAVOBJ OBJ('LOB20CP LOB20M1 LOB20M2 LOB20V1 LOB20V2 LOB20V3
    LOB20V4 LOB20FM VERSION') LIB(LSILIB) DEV(*SAVF) SAVF(SLIT122320)
    Value 'LOB20CP LO' for OBJ not a name or generic name.

    I am using %trim to remove a leading blank, but it failed either with or without the leading blank.

    oh yeah, here is the parm DCL &PGMLIST *CHAR 500

  • #2
    SAVOBJ's OBJ parameter is a parameter that accepts multiple values.

    E.g. SAVOBJ OBJ(LOB20CP LOB20M1 LOB20M2 LOB20V1 LOB20V2 LOB20V3 LOB20V4 LOB20FM VERSION) as per your first example.

    But inside a CL program, where you are using variables to set parameter values, each variable is always ONE value, no matter what it contains.

    So if you run this:
    SAVOBJ OBJ(&PGMLIST)

    And &PGMLIST contains this string:
    LOB20CP LOB20M1 LOB20M2 LOB20V1 LOB20V2 LOB20V3 LOB20V4 LOB20FM VERSION

    It does not interpret &PGMLIST as a list of nine object names. It interprets it as one object name, so it means save the one object with the name 'LOB20CP LOB20M1 LOB20M2 LOB20V1 LOB20V2 LOB20V3 LOB20V4 LOB20FM VERSION'. Which of course is not a valid object name, so you get an error.

    What you are trying to do, use one variable to specify multiple values for one CL command parameter, is unfortunately not supported. The only way is to build the command itself as a string, and then execute that string as a command QCMDEXC API (or the . You can do this in CL, but personally I find it easier in RPGLE:

    Code:
    dcl-pr QCMDEXC extpgm;
      cmd         char(1000) const;
      len         packed(15:5) const;
    end-pr;
    
    dcl-s pgmList varchar(500);
    dcl-s cmd     varchar(1000);
    
    
    pgmList= 'LOB20CP LOB20M1 LOB20M2 LOB20V1 LOB20V2 LOB20V3 LOB20V4 LOB20FM VERSION';
    
    cmd = 'SAVOBJ OBJ(' + pgmList+ ') LIB(LSILIB) DEV(*SAVF) SAVF(SLIT122320)';
    
    QCMDEXC(cmd, %len(%trimr(cmd)));

    Comment


    • Vectorspace
      Vectorspace commented
      Editing a comment
      typo: execute that string as a command *using the* QCMDEXC API

  • #3
    thanks for the explanation. I am going to play around some more in cl before I try your solution. Only because that is currently how I am getting my program names. I want to avoid passing a string of program name parms from cl to rpg and then return to cl for more processing. but that may be how it ends up. we'll see .
    thanks again.

    Comment

    Working...
    X