Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Using Quotes in CL

Using Quotes in CL.

Using Quotes in CL Quote, quote variable, embedded quote, character, double quote, as400 and sql tricks, as400, ibm i, sql
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

  • If a character string contains single quotation mark then two single quotation mark must be entered consecutively to indicate that it is a single quotation mark.
  • Program for using quotes (embedded quotes) and quote variable

                  PGM                                                                    
                  DCL        VAR(&QUOTE) 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 &quote +                          
                             *CAT 'i' *CAT &quote)                                      
                  SNDPGMMSG  MSG(&MSG)                                                   
                                                                                         
                                                                                         
                  ENDPGM                                                                 
    

    Explanation

  • Embedding Quotation mark in CL string.
  •  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'.

  • Using Quote variable with CL string during concatenation.
  •               DCL        VAR(&QUOTE) 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 &quote +                          
                             *CAT 'i' *CAT &quote)            

    Here, we are doing concat with QUOTE variable and the final value in &MSG variable would be Hi 'i'.

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain