Using Quotes in CL |
Introduction to Quotation mark in CL
"Quote" means one character (') which is sometimes described as an apostrophe or a tick or a quotation mark. "Double quote" also means one character ("), which is sometimes described as a quotation mark. Do not confuse it with two single quotes ('').
Rule for using Quotation mark in a CL string
Program for using quotes (embedded quotes) and quote variable
PGM DCL VAR("E) TYPE(*CHAR) LEN(1) VALUE('''') DCL VAR(&Msg) TYPE(*CHAR) LEN(20) /* Hello 'i' */ CHGVAR VAR(&MSG) VALUE('Hello ''i''') SNDPGMMSG MSG(&MSG) /* Hi 'i' */ CHGVAR VAR(&MSG) VALUE('Hi' *CAT "e + *CAT 'i' *CAT "e) SNDPGMMSG MSG(&MSG) ENDPGM
Explanation
CHGVAR VAR(&MSG) VALUE('Hello ''i''')
Here, the first quotation mark tells the start of the string and the last quotation mark tell the end of the string. Within that Value we have 4 quotation mark i.e. 2 before "i" letter and 2 after it that means the finl value as per the rule in &MSG variable would be Hello 'i'.
DCL VAR("E) TYPE(*CHAR) LEN(1) VALUE('''')
Here, we are declaring the QUOTE variable of type character and length 1 whose value is single quote (') but as per rule we need to initialize it with 2 single quotes to get one single quote value in the variable.
CHGVAR VAR(&MSG) VALUE('Hi' *CAT "e + *CAT 'i' *CAT "e)
Here, we are doing concat with QUOTE variable and the final value in &MSG variable would be Hi 'i'.