*CAT, *BCAT, *TCAT in CL

*CAT, *BCAT, *TCAT in CL
*CAT, *BCAT, *TCAT in CL
*CAT, *BCAT, *TCAT in CL

*CAT (concatenation, symbol ||) operator

The *CAT operator concatenates two character strings. Blanks are also included in the concatenation of two character strings. Take an example to understand this:

For Example:
  • 'HELLO' *CAT 'SIR' becomes 'HELLOSIR'.
  • 'HELLO ' *CAT 'SIR ' becomes 'HELLO SIR '.
  • 'HELLO ' *CAT ' SIR ' becomes 'HELLO SIR '.
  • *BCAT (concatenation with blank insertion, symbol |>) operator

    The *BCAT operator truncates all trailing blanks in the first character string then one blank is inserted and then the two character strings are concatenated. Leading blanks on the second character strings are not truncated. Take an example to understand this:

    For Example:
  • 'HELLO' *BCAT 'SIR' becomes 'HELLO SIR'.
  • 'HELLO ' *BCAT 'SIR' becomes 'HELLO SIR'.
  • 'HELLO ' *BCAT ' SIR ' becomes 'HELLO SIR '.
  • *TCAT (concatenation with trailing blank truncation, symbol |<) operator

    The *TCAT operator truncates all trailing blanks in the first character string and then the two character strings are concatenated. All leading blanks on the second character strings are not truncated. Take an example to understand this:

    For Example:
  • 'HELLO' *TCAT 'SIR' becomes 'HELLOSIR'.
  • 'HELLO ' *TCAT 'SIR' becomes 'HELLOSIR'.
  • 'HELLO ' *TCAT ' SIR' becomes 'HELLO SIR'.
  • CL program showing the above examples

                 PGM                                                      
                 /*CAT variables */                                       
                 DCL        VAR(&VAR1) TYPE(*CHAR) LEN(5) VALUE('HELLO')  
                 DCL        VAR(&VAR2) TYPE(*CHAR) LEN(3) VALUE('SIR')    
                 DCL        VAR(&OUT1) TYPE(*CHAR) LEN(8)                 
                                                                          
                 DCL        VAR(&VAR3) TYPE(*CHAR) LEN(6) VALUE('HELLO ') 
                 DCL        VAR(&VAR4) TYPE(*CHAR) LEN(4) VALUE('SIR ')   
                 DCL        VAR(&OUT2) TYPE(*CHAR) LEN(10)                
                                                                          
                 DCL        VAR(&VAR5) TYPE(*CHAR) LEN(6) VALUE('HELLO ') 
                 DCL        VAR(&VAR6) TYPE(*CHAR) LEN(5) VALUE(' SIR ')  
                 DCL        VAR(&OUT3) TYPE(*CHAR) LEN(11)                
                                                                          
                 /*BCAT variables */                                      
                 DCL        VAR(&VARA) TYPE(*CHAR) LEN(5) VALUE('HELLO')  
                 DCL        VAR(&VARB) TYPE(*CHAR) LEN(3) VALUE('SIR')    
                 DCL        VAR(&OUTA) TYPE(*CHAR) LEN(9)                 
    
                 DCL        VAR(&VARC) TYPE(*CHAR) LEN(6) VALUE('HELLO ')   
                 DCL        VAR(&VARD) TYPE(*CHAR) LEN(3) VALUE('SIR')      
                 DCL        VAR(&OUTB) TYPE(*CHAR) LEN(9)                   
                                                                            
                 DCL        VAR(&VARE) TYPE(*CHAR) LEN(6) VALUE('HELLO ')   
                 DCL        VAR(&VARF) TYPE(*CHAR) LEN(5) VALUE(' SIR ')    
                 DCL        VAR(&OUTC) TYPE(*CHAR) LEN(11)                  
                                                                            
                 /*TCAT variables */                                        
                 DCL        VAR(&VART1) TYPE(*CHAR) LEN(5) VALUE('HELLO')   
                 DCL        VAR(&VART2) TYPE(*CHAR) LEN(3) VALUE('SIR')     
                 DCL        VAR(&OUTT1) TYPE(*CHAR) LEN(8)                  
                                                                           
                 DCL        VAR(&VART3) TYPE(*CHAR) LEN(6) VALUE('HELLO ')  
                 DCL        VAR(&VART4) TYPE(*CHAR) LEN(3) VALUE('SIR')     
                 DCL        VAR(&OUTT2) TYPE(*CHAR) LEN(8)                  
                                                                           
                 DCL        VAR(&VART5) TYPE(*CHAR) LEN(6) VALUE('HELLO ')  
                 DCL        VAR(&VART6) TYPE(*CHAR) LEN(4) VALUE(' SIR')    
                 DCL        VAR(&OUTT3) TYPE(*CHAR) LEN(9)                  
                                                                     
                 /*CAT */                                            
                 CHGVAR     VAR(&OUT1) VALUE(&VAR1 *CAT &VAR2)       
                 CHGVAR     VAR(&OUT2) VALUE(&VAR3 *CAT &VAR4)       
                 CHGVAR     VAR(&OUT3) VALUE(&VAR5 *CAT &VAR6)       
                                                                     
                 /*BCAT */                                           
                 CHGVAR     VAR(&OUTA) VALUE(&VARA *BCAT &VARB)      
                 CHGVAR     VAR(&OUTB) VALUE(&VARC *BCAT &VARD)      
                 CHGVAR     VAR(&OUTC) VALUE(&VARE *BCAT &VARF)      
                                                                     
                 /*TCAT */                                           
                 CHGVAR     VAR(&OUTT1) VALUE(&VART1 *TCAT &VART2)   
                 CHGVAR     VAR(&OUTT2) VALUE(&VART3 *TCAT &VART4)   
                 CHGVAR     VAR(&OUTT3) VALUE(&VART5 *TCAT &VART6)   
    
                 /*CAT (||) */                                 
                 CHGVAR     VAR(&OUT1) VALUE(&VAR1 || &VAR2)   
                 CHGVAR     VAR(&OUT2) VALUE(&VAR3 || &VAR4)   
                 CHGVAR     VAR(&OUT3) VALUE(&VAR5 || &VAR6)   
                                                               
                 /*BCAT (|>) */                                
                 CHGVAR     VAR(&OUTA) VALUE(&VARA |> &VARB)   
                 CHGVAR     VAR(&OUTB) VALUE(&VARC |> &VARD)   
                 CHGVAR     VAR(&OUTC) VALUE(&VARE |> &VARF)   
                                                               
                 /*TCAT (|<) */                                      
                 CHGVAR     VAR(&OUTT1) VALUE(&VART1 |< &VART2)
                 CHGVAR     VAR(&OUTT2) VALUE(&VART3 |< &VART4)
                 CHGVAR     VAR(&OUTT3) VALUE(&VART5 |< &VART6)
                                                               
    
                 RETURN                                              
                 ENDPGM 

    Take option 14 on clle source member to trigger CRTBNDCL command and create the program object and then execute the program using CALL command. One can also debug using STRDBG command to debug this program and see the output in the out variables in the program.

    Post a Comment

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