IBM Support

OPNQRYF Using Received Variables within WLDCRD

Troubleshooting


Problem

This document provides information about using a variable from a CL program as a variable search string in a %WLDCRD in the OPNQRYF statement.

Resolving The Problem

Question: How can I use a variable from a CL program as a variable search string in a %WLDCRD in the OPNQRYF statement?

Answer: The CL program below is an example of using a variable as a search string within the %WLDCRD statement. The variable can contain from 1 to 20 characters. The *TCAT function is used to concatenate an '*' before the contents of the parameter and to concatenate an '*' after the contents of the parameter and to remove any trailing blanks from the variable. For example, the contents of the variable contains the following characters 'RECORD '. Trailing blanks will fill the variable because it was defined with a length of 20 characters. After the *TCAT operation, the WLDCRD will contain ' *RECORD* '. The trailing blanks were removed, and an '*' was added before and after the variable. The OPNQRYF will return any occurrence of 'RECORD' in any position within the field.

PGM        PARM(&SRCHSTRG)                            
  DCL        VAR(&SRCHSTRG) TYPE(*CHAR) LEN(20)        
  DCL        VAR(&ASTR) TYPE(*CHAR) LEN(1)              
  CHGVAR     VAR(&ASTR) VALUE('*')                      
                                                       
  OPNQRYF     FILE(UPCHURCH/TESTPF)     +              
              QRYSLT(          +                        
  'TESTPF *EQ %WLDCRD("' *TCAT  &ASTR  *TCAT  +      
    &SRCHSTRG   *TCAT &ASTR *TCAT '")')            
                                                       
  CPYFRMQRYF FROMOPNID(TESTPF) TOFILE(*PRINT)          
                                                       
  CLOF   TESTPF                                        
                                                       
  ENDPGM  

Note: Specific coding examples are beyond the scope of a Software Maintenance Agreement.

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"6.1.0"}]

Historical Number

25153005

Document Information

Modified date:
18 December 2019

UID

nas8N1017179