ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SAVOBJ with object list in variable

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

  • SAVOBJ with object list in variable

    Hello,

    I have problem in my program.
    It will used to backup objects that I get from PF.

    This is my RPGLE Code to get object list from PF.
    Code:
    D prFILE          S           6000
    C*------------------------------------------------------------------------*
    C* Sub Routine : #BackUp                                                  *
    C*------------------------------------------------------------------------*
    C     #BackUp       BegSr                                                  
    C                   Movel     *Blanks       prFILE                         
    C*          Get the object list                   
    C     *Loval        SetLL     CTLSFLL1                                     
    C                   Read      CTLSFLL1                               99    
    C                   Dow       *In99 = *Off                                 
    C                   Cat       LSFILE:1      prFILE                         
    C                   Read      CTLSFLL1                               99    
    C                   EndDo                                                  
    C*          Call the backup program                                
    C                   Call      'CTD09C1'                                    
    C                   Parm                    prFILE                         
    C     $BackUp       EndSr
    And This is my CLLE code
    Code:
                 PGM        PARM(&FILE)                      
                 DCL        VAR(&FILE) TYPE(*CHAR) LEN(6000) 
                                                             
     SAV:        SAVOBJ     OBJ(&FILE) LIB(LIBNAME) +        
                              DEV(*SAVF) SAVF(LIBNAME/SAVFNAME)
                 MONMSG     MSGID(CPF0000)                   
                                                             
    END:         ENDPGM
    What's the problem in my code?

    Thanks before

  • #2
    Re: SAVOBJ with object list in variable

    The problem is that the SAVOBJ command is compiled and that the SAVOBJ OBJ() parameter expects a list but you are only sending in a single variable. If you want to save multiple objects with a single command, there are two general approaches.

    First, for a compiled command, you can have one variable to save one object, two variables for two objects, three variables for three objects, etc. It should be obvious that that can be a difficult way to go because you don't know how many variables you need and the command allows 300 of them. For example for four objects:
    Code:
    SAVOBJ  OBJ(&FILE1 &FILE2 &FILE3 &FILE4) LIB(LIBNAME)...
    Second, you can create the SAVOBJ command in a long character variable and concatenate your &FILE variable into the middle of the string. Then execute the command variable by passing it into the QCMDEXC API. This is usually much easier. In your case, it can be done all inside your RPG program; and there is no need for a CL program. Example RPG code:
    Code:
         D prFILE          S           3300
         D prCmd           S           3400
         D prCmdLen        S             15p 5
    
         C                   eval      prCmd = 'SAVOBJ OBJ('
         C                                   + %trim( prFILE )
         C                                   + ') LIB(LIBNAME) DEV(*SAVF) +
         C                                      SAVF(LIBNAME/SAVFNAME)'
    
         C                   eval      prCmdLen = %len(%trim( prCmd ))
    
         C                   call (E)  'QCMDEXC'
         C                   parm                    prCmd
         C                   parm                    prCmdLen
    The prFILE variable doesn't need to be more then 3300 bytes in length because it can't be used for more than 300 objects. Each object name can't be more than ten characters, so that makes a maximum of 3000 characters. And there must be at least one blank between each object name, so that can essentially add another 300 characters.

    The variable for your SAVOBJ command needs to be big enough to hold the prFILE variable plus all the characters in the constant literals. A maximum length of 3400 should be plenty until you add more parms.

    Tom
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      Re: SAVOBJ with object list in variable

      Thanks tom, it works

      Comment


      • #4
        Re: SAVOBJ with object list in variable

        I'm glad it worked for you. It might not be the very best way to do it, but it seemed closest to the code that you showed. It should make clear sense to you. When you feel comfortable with /free formatting and with more APIs, you might want to look at it again.
        Tom

        There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

        Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

        Comment

        Working...
        X