IBM Support

Passing Parameters Longer Than 32 Characters in CL

Troubleshooting


Problem

Passing parameters that are longer that 32 characters between two CL programs requires special handling.

Resolving The Problem


The CL programming manual states:

"For CL character variables larger than 32 characters where trailing blanks are significant, create a variable that is one character larger than needed and substring a non-blank character into the last position. This prevents the significant blanks from being truncated. The called program would ignore the extra character because it is beyond the length expected."

The following code example demonstrates this.

We define a DSPF screen to accept two 40-character variables, &FLD001 and &FLD002.

Example

*************** Beginning of data ************************
     A*%%EC                                                
     A                                      DSPSIZ(24 80 *DS3)
     A          R GETVAR                                      
     A                                 11 22'Var'      
     A                                 11 26'1'        
     A            FLD001        40   B 11 30            
     A                                 12 22'Var'      
     A                                 12 26'2'        
     A            FLD002        40   B 12 30            
****************** End of data ***************************

PGMA a CL program puts up the DSPF and then adds a 41st character to the parameters.


PGM (&HOWTORUN) /* ENTER 'I' FOR INTERACTIVE, 'B' FOR BATCH */
DCLF       FILE(PGMA)                        
DCL        VAR(&HOWTORUN) TYPE(*CHAR) LEN(1)
DCL        VAR(&A) TYPE(*CHAR) LEN(41)      
DCL        VAR(&B) TYPE(*CHAR) LEN(41)      
SNDRCVF    RCDFMT(GETVAR)                    
                                                         
/* POPULATE A VARIABLE THAT IS ONE CHARACTER LONGER THAN NEEDED   */
/* WITH A NON BLANK CHARACTER IN THE LAST POSITION               */
             
CHGVAR     VAR(&A) VALUE(&FLD001)
CHGVAR     VAR(&B) VALUE(&FLD002)
CHGVAR     VAR(%SST(&A 41 1)) VALUE('X')
CHGVAR     VAR(%SST(&B 41 1)) VALUE('X')
                                                                                   
/* YOU CAN RUN THE CALLED PROGRAM INTERACTIVELY BY TYPING IN ANY */
/* PARM OTHER THAN B, WHICH SUMBITS THE CALL TO PGMB TO BATCH    */
                                                                         
IF         COND((&HOWTORUN *EQ 'B') *OR (&HOWTORUN *EQ +
             'b')) THEN(DO)              
SBMJOB     CMD(CALL PGM(PGMB) PARM(&A &B))
ENDDO                                    
ELSE       CMD(DO)                    
CALL PGM(PGMB) PARM(&A &B)            
ENDDO                                  
       
ENDPGM

PGMB accepts the parameters and then displays them in separate messages to show the difference in how they are handled. Because both parameters in this program are defined as 40 characters, the 41st character on the first parameter is stripped off; however, the significant blanks, which were passed, are retained.

/* VARIABLE &ONE, AS PASSED INTO THIS PROGRAM WAS 41 CHARACTERS LONG */
/* WITH THE FINAL CHARACTER NON-BLANK.BY DECLARING IT AS 40 CHAR */
/* IN THIS PROGRAM WE STRIP OFF THAT LAST CHARACTER BUT DO NOT REMOVE */
/* THE SIGNIFICANT BLANKS.                                       */
                                                                             
PGM (&ONE  &TWO)        
DCL        VAR(&ONE) TYPE(*CHAR) LEN(40)
DCL        VAR(&TWO) TYPE(*CHAR) LEN(40)
                                                       
SNDMSG     MSG('the value of the 1st var is' *BCAT +
           &ONE *cat '!') +
           TOUSR(*SYSOPR)                            
                                                       
SNDMSG     MSG('the value of the 2nd var is' *BCAT +
           &TWO *cat '!') +
           TOUSR(*SYSOPR)
                       
ENDPGM


Program A is run with its input parameter set to 'B' to submit PMGB to batch.

Screen shot of record format GETVAR, which is  outputted to the device by PGMA

The results are shown below:

[{"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

427037133

Document Information

Modified date:
18 December 2019

UID

nas8N1014767