Solved

AS400 - SBMJOB with command prompter

Posted on 2016-11-02
3
30 Views
Last Modified: 2016-11-06
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
Comment
Question by:Anand K
3 Comments
 
LVL 34

Expert Comment

by:Gary Patterson
ID: 41871021
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
 
LVL 27

Accepted Solution

by:
tliotta earned 500 total points
ID: 41875057
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
 

Author Closing Comment

by:Anand K
ID: 41876247
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hyena v12.2 is now available for downloading and is available in English, French, German and Spanish versions.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now