AS/400 QMQRY: How to pass values at runtime

820 pts.
Tags:
AS/400
CL Program
QMQRY
Hi,
I am trying to pass file name to a QMQRY object in a CL program at run time.I was facing some error,which I posted below. I request you to kindly go through the below code & correct me to, if I am wrong.
QMQRY object:
        ************
0001.00 &SELECT     
0002.00 &FIELDS     
0003.00 &FROM       
0004.00 &FILE       
0005.00 &FETCH      
0006.00 &FIRST      
0007.00 &VALUES     
0008.00 &ROWS       
0009.00 &ONLY       
        ************
 
CL program:
 
        *************** Beginning of data ***************************
0001.00              PGM        PARM(&TB_NAME)                       
0002.00              DCL        VAR(&TB_NAME) TYPE(*CHAR) LEN(20)    
0003.00              DCL        VAR(&SELECT_Q) TYPE(*CHAR) +         
0004.00                           LEN(10) VALUE('SELECT')            
0005.00              DCL        VAR(&FIELDS_Q) TYPE(*CHAR) +         
0006.00                           LEN(10) VALUE('*')                 
0007.00              DCL        VAR(&FROM_Q) TYPE(*CHAR) LEN(10) +   
0008.00                           VALUE('FROM')                      
0009.00              DCL        VAR(&FILE_Q) TYPE(*CHAR) LEN(20) +   
0010.00                           VALUE('&TB_NAME')                  
0011.00              DCL        VAR(&FETCH_Q) TYPE(*CHAR) LEN(10) +  
0012.00                           VALUE('FETCH')                     
0013.00              DCL        VAR(&FIRST_Q) TYPE(*CHAR) LEN(10) +  
0014.00                           VALUE('FIRST')                     
0015.00              DCL        VAR(&VALUES_Q) TYPE(*CHAR) +         
0016.00                           LEN(10) VALUE('10')                
0017.00              DCL        VAR(&ROWS_Q) TYPE(*CHAR) LEN(10) +   
0018.00                           VALUE('ROWS')                      
0019.00              DCL        VAR(&ONLY_Q) TYPE(*CHAR) LEN(10) +   
0020.00                           VALUE('ONLY')                     
0021.00              MONMSG     MSGID(CPF0000) EXEC(GOTO +          
0022.00                           CMDLBL(ERROR))                    
0023.00              STRQMQRY   QMQRY(MENTIS1/QMQRY103) +           
0024.00                           SETVAR((SELECT &SELECT_Q) +       
0025.00                           (FIELDS &FIELDS_Q) (FROM +        
0026.00                           &FROM_Q) (FILE &FILE_Q) (FETCH +  
0027.00                           &FETCH_Q) (FIRST &FIRST_Q) +      
0028.00                           (VALUES &VALUES_Q) (ROWS +        
0029.00                           &ROWS_Q) (ONLY &ONLY_Q))          
0030.00              GOTO       CMDLBL(END)                         
0031.00 ERROR:                                                      
0032.00              SNDUSRMSG  MSG('ERROR OCCURED')                
0033.00 END:                                                        
0034.00 ENDPGM                                                      
        ****************** End of data *****************************
 
For this program I am providing the &TB_NAME value at run time.    
 
CALL PGM(FETCHCL) PARM('META_DSNCT')
 
I can find the following error from the DSPJOBLOG as,
CALL PGM(FETCHCL) PARM('META_DSNCT')
  2300 - STRQMQRY QMQRY(MENTIS1/QMQRY103) SETVAR((SELECT 'SELECT') (FIELDS
  '*') (FROM 'FROM') (FILE '&TB_NAME') (FETCH 'FETCH') (FIRST 'FIRST')
   (VALUES '10') (ROWS 'ROWS') (ONLY 'ONLY'))
 Token & was not valid. Valid tokens: ( TABLE LATERAL <IDENTIFIER>.
 RUN QUERY command failed with SQLCODE -104.
 RUN QUERY command ended due to error.
 STRQMQRY command failed.
 
Kindly let me know ,whether to change anything while, passing the value.
 
Thanks
 


Software/Hardware used:
iseries

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • pdraebel
    It looks like the Variables do not get resolved in the QMQRY statement. You should create the command string for the QMQRY command in its entirity and than use QCMDEXC to execute.
    The string would look like 'STRQMQRY ... ' (see line 23 of your Joblog)

    2,895 pointsBadges:
    report
  • pdraebel
    On the other hand, the variables do get resolved, you only used an unsupported value for file where the value starts with &
    2,895 pointsBadges:
    report
  • HABBIE
    No need to go for QCMDEXEC.
    Just replace the 9th line 
    0009.00              DCL        VAR(&FILE_Q) TYPE(*CHAR) LEN(20) +   
    0010.00                           VALUE('&TB_NAME')    
    as
    DCL        VAR(&FILE_Q) TYPE(*CHAR) LEN(20)
    Don't specify the value for the run time acceptance variable.Then It will accept the value at runtime.




    820 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following