Example: Use character strings and variables

This example shows how several character variables and character strings can be concatenated to produce a message for a work station operator.

The example assumes that the variables &DAYS and &CUSNUM were declared as character variables, not decimal variables.

DCL     VAR(&MSG)TYPE(*CHAR)     LEN(100)
         *
         *
CHGVAR      &MSG   ('Customer' *BCAT &CUSNAMD  +
              *BCAT'Account Number' *BCAT +
              &CUSNUM *BCAT 'is overdue by' +
              *BCAT &DAYS *BCAT 'days.')   

After the appropriate variables have been substituted, the resulting message might be:

Customer ABC COMPANY Account Number 12345
is overdue by 4 days.

If the variables &DAYS and &CUSNUM had been declared as decimal variables, two other CHGVAR commands would have to change the decimal variables to character variables before the concatenation could be performed. If, for example, two character variables named &DAYSALPH and &CUSNUMALPH were also declared in the program, the CHGVAR commands would be:

CHGVAR  &DAYSALPH  &DAYS
 
CHGVAR  &CUSNUMALPH  &CUSNUM

Then instead of &DAYS and &CUSNUM, the new variables &DAYSALPH and &CUSNUMALPH would be specified in the CHGVAR command used to concatenate all the variables and character strings for &MSG.