• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

AS400 - SBMJOB with command prompter

I have tried two options.

Option 1. With passing the cmd value as RSTOBJ ?*RSTLIB(ABCLIB).

PGM                                                  
                                                     
 DCL  &CMD          *CHAR  1024                      
 DCL  &CMDLEN       *INT      4   VALUE(1024)        
 DCL  &OPTIONS      *CHAR    20                      
 DCL  &OPTIONSLEN   *INT      4   VALUE(20)          
 DCL  &OPTIONS      *CHAR    20                      
 DCL  &NEWCMD       *CHAR  1024                      
 DCL  &NEWCMDLENA   *INT      4   VALUE(1024)        
 DCL  &NEWCMDLENC   *INT      4   VALUE(1024)        
                                                     
  CHGVAR  %SST(&OPTIONS  1 4) VALUE(X'00000001')      
  CHGVAR  %SST(&OPTIONS  5 1) VALUE('0')              
  CHGVAR  %SST(&OPTIONS  6 1) VALUE('1')              
  CHGVAR  %SST(&OPTIONS  7 1) VALUE('0')              
  CHGVAR  %SST(&OPTIONS 12 4) VALUE(X'00000000')    
CHGVAR  %SST(&OPTIONS 16 5) VALUE(X'0000000000')
 

CHGVAR  &CMD     VALUE('RSTOBJ ?*RSTLIB(ABCLIB)')          
                                                               
                                                               
CALL    QCAPCMD   PARM(&CMD &CMDLEN &OPTIONS &OPTIONSLEN +    
                   'CPOP0100' &NEWCMD &NEWCMDLENA &NEWCMDLENC +
                   X'00000000')                              
 MONMSG  CPF6801  EXEC(RETURN)                                      
            SBMJOB     CMD(CALL PGM(QCMDEXC) PARM(&NEWCMD +          
                         &NEWCMDLENA)) JOB(RSTOBJ#) JOBQ(QBATCH)
                                                                     
 ENDPGM                                                            


After calling above program, below is the prompt, which only displays "restore to library" parameter. All other input parameters are not displayed.

                             Restore Object (RSTOBJ)                  
                                                                     
 Type choices, press Enter.                                          
                                                                     
 Restore to library . . . . . . . > ABCLIB    Name, *SAVLIB      


Option 2. With passing the cmd value will all parameters.

PGM                                                      
                                                         
 DCL  &CMD          *CHAR  1024                          
 DCL  &CMDLEN       *INT      4   VALUE(1024)            
 DCL  &OPTIONS      *CHAR    20                          
 DCL  &OPTIONSLEN   *INT      4   VALUE(20)              
 DCL  &OPTIONS      *CHAR    20                          
 DCL  &NEWCMD       *CHAR  1024                          
 DCL  &NEWCMDLENA   *INT      4   VALUE(1024)            
 DCL  &NEWCMDLENC   *INT      4   VALUE(1024)            
                                                         
  CHGVAR  %SST(&OPTIONS  1 4) VALUE(X'00000001')        
  CHGVAR  %SST(&OPTIONS  5 1) VALUE('0')                
  CHGVAR  %SST(&OPTIONS  6 1) VALUE('1')                
  CHGVAR  %SST(&OPTIONS  7 1) VALUE('0')                
  CHGVAR  %SST(&OPTIONS 12 4) VALUE(X'00000000')        

CHGVAR  %SST(&OPTIONS 16 5) VALUE(X'0000000000')

CHGVAR  &CMD     VALUE('RSTOBJ            +  
                        ??OBJ()               +  
                        ??SAVLIB()            +  
                        ??DEV()               +  
                        ??OBJTYPE(*FILE)      +  
                        ??VOL()               +  
                        ??SEQNBR()            +  
                        ??POSITION()          +
                        ??LABEL()             +    
                        ??ENDOPT()            +    
                        ??SAVF()              +    
                        ??OPTION(*NEW)        +    
                        ??FILEMBR()           +    
                        ??MBROPT(*NEW)        +    
                        ??SPLFDTA()           +    
                        ??SAVDATE()           +    
                        ??SAVTIME()           +    
                        ??ALWOBJDIF(*ALL)     +    
                        ??FRCOBJCVN()         +    
                        ?*RSTLIB(ABCLIB)      +    
                        ??OUTPUT(*PRINT)      +    
                        ??MEDDFN()            +    
                        ??OPTFILE()           +    
                        ??RSTASPDEV()         +    
                        ??RSTASP()            +    
                        ??OUTFILE()           +  
                       ??OUTMBR()            +    
                       ??INFTYPE()           +    
                       ??OMITLIB()           +    
                       ??OMITOBJ()')              
                                                 
 CALL    QCAPCMD   PARM(&CMD &CMDLEN &OPTIONS &OPTIONSLEN +          
                    'CPOP0100' &NEWCMD &NEWCMDLENA &NEWCMDLENC +    
                    X'00000000')                                    
                                                                     
                                                                     
 MONMSG  CPF6801  EXEC(RETURN)                                      
            SBMJOB     CMD(CALL PGM(QCMDEXC) PARM(&NEWCMD +          
                         &NEWCMDLENA)) JOB(RSTOBJ#) JOBQ(QBATCH)
                                                                     
 ENDPGM                                                            


For this option2. we get the prompt for all paramters, however, it fails with below error.

Message . . . . :  -CALL PGM(QCMDEXC) PARM('RSTOBJ ??OBJ(F0001)              
  ??SAVLIB(TESTLIB) ??DEV(TAPLIB1) ??OBJTYPE(*FILE) ??VOL(MA2041) ??SEQNBR(345)
  ??POSITION(*N) ??LABEL(*N) ??ENDOPT(*N) ??SAVF(*N) ??OPTION(*NEW)          
  ??FILEMBR(*N) ??MBROPT(*NEW) ??SPLFDTA(*N) ??SAVDATE(*N) ??SAVTIME(*N)      
  ??ALWOBJDIF(*ALL) ??FRCOBJCVN(*N) ?*RSTLIB(ABCLIB) ??OUTPUT(*PRINT)        
  ??MEDDFN(*N) ??OPTFILE(*N) ??RSTASPDEV(*N) ??RSTASP(*N) ??OUTFILE(*N)      
  ??OUTMBR(*N) ??INFTYPE(*N) ??OMITLIB(*N) ??OMITOBJ(*N)' 1024)              
   02/11/16  04:40:49.603159  QCANPARS     QSYS        094F     QCMD        QSYS
Message . . . . :   String '          ' contains a character that is not      
  valid.
0
Anand K
Asked:
Anand K
1 Solution
 
Gary PattersonVP Technology / Senior Consultant Commented:
Most likely some of the falues you've promted are conditional, and you haven't supplied a value for the parameter that they are based on.

Assuming you want to protect the RSTLIB() parameter, but allow the user to specify any other values, then I suggest you try this:

?RSTOBJ RSTOBJ RSTLIB(ABCLIB)

http://www.ibm.com/support/knowledgecenter/SSAE4W_7.1.0/com.ibm.etools.iseries.pgmgd.doc/evfclmst162.htm
0
 
tliottaCommented:
There are a couple issues with the procedure.

First the QCAPCMD API can have too many possibilities to work through and understand for someone who's not used it before. If generating a command-string by using selective prompting, I recommend using the QCMDCHK API instead (for now). Far simpler and more straightforward. After all the prompting rules are clear, then learning QCAPCMD is a reasonable step for a more experienced developer. Prompting rules are very different from the rules for the QCAPCMD API interface. Learning both sets of rules at the same time only makes things harder. Focus on one set of concepts at a time.

Those both compound also learning how SBMJOB works, and it has a mistake that's not obvious. (Actually, one mistake plus one probably inappropriate usage.)

The mistake is in using the CMD() parameter. In this case, it shouldn't be specified at all. Leave it empty and unspecified. The parameter that should be used instead is RQSDTA(). And the "probably inappropriate usage" is in specifying CALL QCMDEXC. There's no reason to use QCMDEXC at all here. Just use RQSDTA( &NEWCMD ) and no more.

An explanation of how the CMD() and RQSDTA() parameters are related and why there are two parameters that seem to do almost the same thing is tricky. It goes way back to R1.2 (before OS/400 even had "versions", but only "releases" and "mod levels".

I'll only discuss a small part of it.

Originally, the SBMJOB command didn't have a CMD() parameter. Of the two parameters, only RQSDTA() was there. Every use of SBMJOB that submitted a command had to specify the command-string directly as a "request data" string. This caused numerous problems because many CL programmers couldn't seem to grasp the rules of "quoting" in CL variables. It's necessary to construct a "request data" string completely in program code. When the construction logic requires concatenating multiple string parts together, and some parts may contain quoted strings with embedded quotes (i.e., apostrophes), the embedded quotes need to be doubled up.

This 'doubling' logic still gives trouble for many developers in any number of CL cases. But somewhere around version 2 of OS/400, IBM took care of most SBMJOB issues with it by introducing the CMD() parameter. (Unfortunately, most developers are now no longer aware that RQSDTA() is where the real command is processed when SBMJOB does the work. Most don't know the history nor understand its implications.)

The actual command that gets submitted comes from RQSDTA() and not from the CMD() parameter. If you look at the defaults, you'll see RQSDTA( *CMD ), and the help text gives a small hint. When a command is used as input to CMD(), the system's command analyzer processes it to generate a resulting command-string. That result replaces "*CMD" in RQSDTA() at run-time, and it is what finally gets submitted.

When you build a command-string in a CL variable for SBMJOB, it should go straight into RQSDTA(). The processing to build that string is an alternative to using CMD(). It's not intended to be used in conjunction with CMD().

And that's about as far as I should go with this for now. Try using the QCMDCHK API and SBMJOB RQSDTA( &NEWCMD ) and see how far you can get. If errors still show up, it'll be far easier to deal with them. We might need to continue this thread at that time.
0
 
Anand KAuthor Commented:
This is the Best explanation i have seen for my question.  Thanks a ton !!

I used the QCMDCHK, this API solved the problem.

Here is my modified code.

 PGM                                                                
                                                                   
 DCL        VAR(&CMD) TYPE(*CHAR) LEN(4024)                        
 DCL        VAR(&CMDLEN) TYPE(*INT) LEN(4) VALUE(1024)              
 DCL        VAR(&OPTIONS) TYPE(*CHAR) LEN(20)                      
 DCL        VAR(&OPTIONSLEN) TYPE(*INT) LEN(4) VALUE(20)            
 DCL        VAR(&OPTIONS) TYPE(*CHAR) LEN(20)                      
 DCL        VAR(&NEWCMD) TYPE(*CHAR) LEN(4024)                      
 DCL        VAR(&NEWCMDLENA) TYPE(*INT) LEN(4) VALUE(4024)          
 DCL        VAR(&NEWCMDLENC) TYPE(*INT) LEN(4) VALUE(4024)          
                                                                   
 CHGVAR     VAR(%SST(&OPTIONS 1 4)) VALUE(X'00000001')              
 CHGVAR     VAR(%SST(&OPTIONS 5 1)) VALUE('0')                      
 CHGVAR     VAR(%SST(&OPTIONS 6 1)) VALUE('1')                      
 CHGVAR     VAR(%SST(&OPTIONS 7 1)) VALUE('0')                      
  CHGVAR     VAR(%SST(&OPTIONS 12 4)) VALUE(X'00000000')            
  CHGVAR     VAR(%SST(&OPTIONS 16 5)) VALUE(X'0000000000')          
      CHGVAR     VAR(&CMD) VALUE('?RSTOBJ OBJTYPE(*FILE) +          
                    OPTION(*NEW) MBROPT(*NEW) ALWOBJDIF(*ALL) +    
                     ?*RSTLIB(RESTORELIB) OUTPUT(*PRINT)')            
                                                                     
          CALL       PGM(QCMDCHK) PARM(&CMD 2000)                    
         MONMSG     MSGID(CPF6801) EXEC(RETURN)                      
      CALL       PGM(QCAPCMD) PARM(&CMD &CMDLEN &OPTIONS +            
                   &OPTIONSLEN 'CPOP0100' &NEWCMD +                  
                   &NEWCMDLENA &NEWCMDLENC X'00000000')              
         MONMSG     MSGID(CPF6801) EXEC(RETURN)                      
         SBMJOB     JOB(RSTOBJ#) JOBQ(QBATCH) RQSDTA(&NEWCMD)    
         ENDPGM
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now