Sunday, December 15, 2013

Day-26.

 CL Programming:

 Overview:

This module enables the student to understand the concept of Control Language.

Outline:
Topics covered,
a.     Built -in functions
b.     Operators in CL
Objective:
By the end of this module, the student should be able to:
  1. CAT, BCAT, TCAT, SST
  2. Arithmetic operators, Logical operators and    relational operators
 Built In Functions:

With the help of operators and functions , CL also provides programmers the ability to manipulate string variables and constants.

·       *CAT: The *CAT operator concatenates two strings, with the resulting string containing the complete contents of both strings

·       *BCAT: The *BCAT operator concatenates two strings, placing a space between two strings.
If First string has trailing spaces then *BCAT will truncate all training spaces and add one space between two strings.

·       *TCAT: The *TCAT operator concatenates two strings and trims the trailing blanks from the first string, with no space between the strings.

·         %SST: This built in function extracts a Substring from a character variable. This function may also be abbreviated as % SST. The syntax for this function is: %SST (Char_var, start_pos length) where char_var is the character variable from which the Substring will be extracted, start_pos is the starting position in the character to begin the extraction, and length is the number of characters to be extracted. The result of a %SST operation may be placed into a different character variable.

Following example shows the difference between *CAT, *BCAT, *TCAT

Step 1: *CAT example,

In this step we use ‘DCL’ and ‘RTVSYSVAL’ to declare variable and system value respectively.

Columns . . . :    1  71            Edit                         SHLIB/QCLPSRC
 SEU==>                                                                      C1
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0000.01 /* PROGRAM : EXAMPLE OF *CAT,*BCAT,*TCAT*/                             
0001.00 PGM                                                                    
0001.01 /* DECLARE THE VERIABLE 'DT' AS GIVEN BELOW */                         
0002.00              DCL                            
'''''''                                                                         
        ****************** End of data ****************************************
                                                                                                                                                    
                                                                               
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
 
Press F4 and fill the attributes like Variable name, type, length.



                                                                           Declare CL Variable (DCL)                          
                                                                               
 Type choices, press Enter.                                                    
                                                                                
 Label  . . . . . . . . . . . . .                                              
 CL variable name . . . . . . . . > &DT           Variable name                
 Type . . . . . . . . . . . . . . > *CHAR         *DEC, *CHAR, *LGL            
 Length of variable:                                                           
   Length . . . . . . . . . . . . > 6             Number                       
   Decimal positions  . . . . . .                 Number                        
 Initial value  . . . . . . . . .                                              
                                                                                                                                                  
                                                                               
                                                                                
                                                                        More...
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display   
 F24=More keys                                                                  
                                                                                                                                                             

Hit enter,
Columns . . . :    1  71            Edit                         SHLIB/QCLPSRC
 SEU==>                                                                      C1
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0000.01 /* PROGRAM : EXAMPLE OF *CAT,*BCAT,*TCAT*/                             
0001.00 PGM                                                                    
0001.01 /* DECLARE THE VERIABLE 'DT' AS GIVEN BELOW */                          
0002.00              DCL        VAR(&DT) TYPE(*CHAR) LEN(6)                    
0003.00 /* RETRIVE SYSTEM VALUE */                                             
0004.00              RTVSYSVAL                                                 
'''''''                                                                        
        ****************** End of data ****************************************
                                                                               
                                                                                                                   
                                                                               
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                                                               
PRESS F4 and fill parameter like system value and CL variable for returned value (i.e. we are moving the system value QDATE in the variable DT as given below.



                                                               Retrieve System Value (RTVSYSVAL)                      
                                                                               
 Type choices, press Enter.                                                    
                                                                               
 Label  . . . . . . . . . . . . .                                              
 System value . . . . . . . . . .   QDATE         QABNORMSW, QACGLVL...        
 CL variable for returned value     &DT           Character value              
 Comment  . . . . . . . . . . . .                                              
                                                                               
                                                                                                                                            
                                                                               
                                                                         Bottom
 F3=Exit   F4=Prompt   F5=Refresh   F12=Cancel   F13=How to use this display    
 F24=More keys                                                                 
                                                                               

HIT ENTER and display date using command SNDSRMSG as shown below:

Columns . . . :    1  71            Edit                         SHLIB/QCLPSRC
 SEU==>                                                                      C1
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0000.01 /* PROGRAM : EXAMPLE OF *CAT,*BCAT,*TCAT*/                             
0001.00 PGM                                                                    
0001.01 /* DECLARE THE VERIABLE 'DT' AS GIVEN BELOW */                         
0002.00              DCL        VAR(&DT) TYPE(*CHAR) LEN(6)                    
0003.00 /* RETRIVE SYSTEM VALUE */                                             
0004.00              RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&DT)                       
0005.00 /*DISPLAY SYSTEM DATE USING *CAT */                                    
0006.00              SNDUSRMSG                                                 
'''''''                                                                         
        ****************** End of data ****************************************
                                                                               
                                                                                                                
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
Either MSG or MSGID must be specified.                                         




                          Send User Message (SNDUSRMSG)                        
                                                                                
 Type choices, press Enter.                                                    
                                                                               
 Label  . . . . . . . . . . . . .                                               
 Message text, or . . . . . . . .   'TODAYS DATE IS: ' *CAT &DT                
                                                                               
                                                                                
                                                                                                                                            
                                                                               
 Message identifier . . . . . . .                 Name                         
 Message file . . . . . . . . . .                 Name                         
   Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB         
                                                                                                                                                         
                                                                               
                                                                        More...
 F3=Exit   F4=Prompt   F5=Refresh   F10=Additional parameters   F12=Cancel     
 F13=How to use this display        F24=More keys                              
                                                                                


In message text we add text ‘Today’s date is’  with the variable value &DT which contain system value using *CAT keyword. Press enter-

Columns . . . :    1  71            Edit                         SHLIB/QCLPSRC
 SEU==>                                                                      C1
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0000.01 /* PROGRAM: EXAMPLE OF *CAT, *BCAT,*TCAT*/                             
0001.00 PGM                                                                    
0001.01 /* DECLARE THE VERIABLE 'DT' AS GIVEN BELOW */                         
0002.00              DCL        VAR(&DT) TYPE(*CHAR) LEN(6)                    
0003.00 /* RETRIVE SYSTEM VALUE */                                             
0004.00              RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&DT)                      
0005.00 /*DISPLAY SYSTEM DATE USING *CAT */                                     
0006.00              SNDUSRMSG  MSG('TODAYS DATE IS: ' *CAT &DT)               
        ****************** End of data ****************************************
                                                                                                                                                          
                                                                                
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                
                                                                                
In above statement we cat text with variable value.

Like *CAT use *BCAT and *TCAT as given below-


Columns . . . :    1  71            Edit                         SHLIB/QCLPSRC
 SEU==>                                                                    CLP1
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0000.01 /* PROGRAM : EXAMPLE OF *CAT,*BCAT,*TCAT*/                             
0001.00 PGM                                                                    
0001.01 /* DECLARE THE VERIABLE 'DT' AS GIVEN BELOW */                         
0002.00              DCL        VAR(&DT) TYPE(*CHAR) LEN(6)                    
0002.01 /*RETRIVE SYSTEM DATE */                                               
0003.00              RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&DT)                      
0003.01 /*DISPLAY SYSTEM DATE USING *CAT */                                     
0004.00              SNDUSRMSG  MSG('TODAYS DATE IS : ' *CAT &DT)              
0004.01 /*DISPLAY SYSTEM DATE USING *BCAT */                                   
0004.02              SNDUSRMSG  MSG('TODAYS DATE IS : ' *BCAT &DT)             
0004.03 /*DISPLAY SYSTEM DATE USING *TCAT */                                   
0004.04              SNDUSRMSG  MSG('TODAYS DATE IS : ' *TCAT &DT)             
0005.00 ENDPGM                                                                  
        ****************** End of data ****************************************
                                                                               
                                                                               
                                                                                
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                

The output of above program is:

                                              Display Program Messages                            
                                                                               
 Job 089834/PB01U04/HBJH started on 04/04/05 at 10:25:52 in subsystem QINTER   
 TODAYS DATE IS : 040405                                                       
 *N                                                                            
 TODAYS DATE IS : 040405                                                       
 *N                                                                             
 TODAYS DATE IS :040405                                                        
                                                                               
                                                                                                                                                        
                                                                               
 Type reply, press Enter.                                                       
   Reply . . .                                                                 
                                                                               
                                                                                
 F3=Exit   F12=Cancel                                                          
                                                                              


Above program shows simple output 040405 is in the format mm, dd and yy without any separator if you want to insert separator use function %SST



Columns . . . :    1  71            Edit                         SHLIB/QCLPSRC
 SEU==>                                                                    CLP1
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0000.01 /* PROGRAM : EXAMPLE OF *CAT,*BCAT,*TCAT*/                             
0001.00 PGM                                                                     
0001.01 /* DECLARE THE VERIABLE 'DT' AS GIVEN BELOW */                         
0002.00              DCL        VAR(&DT) TYPE(*CHAR) LEN(6)                    
0002.01 /*RETRIVE SYSTEM DATE */                                                
0003.00              RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&DT)                      
0003.01 /*DISPLAY SYSTEM DATE USING *CAT */                                    
0004.00              SNDUSRMSG  MSG('TODAYS DATE IS : ' *CAT &DT)               
0004.01 /*DISPLAY SYSTEM DATE USING *BCAT */                                   
0004.02              SNDUSRMSG  MSG('TODAYS DATE IS : ' *BCAT &DT)             
0004.03 /*DISPLAY SYSTEM DATE USING *TCAT */                                   
0004.04              SNDUSRMSG  MSG('TODAYS DATE IS : ' *TCAT &DT)
0004.05 /*DISPLAY SYSTEM DATE USING %SST */                                   
0005.00              SNDUSRMSG  MSG('TODAYS DATE IS:' *CAT (%SST(&DT 1 2)) +      
0006.00                          *CAT '/' *CAT (%SST(&DT 3 2)) +               
0007.00                       *CAT '/' *CAT (%SST(&DT 5 2)))                                
0008.00 ENDPGM                                                                 
        ****************** End of data ****************************************
                                                                               
                                                                               
                                                                                
 F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle      
 F16=Repeat find       F17=Repeat change          F24=More keys                

Above %SST helps you to show the date including separators. In this way we used built in functions.


No comments:

Post a Comment