OUTREC: Reformatting records with IFTHEN


IFTHEN clauses for the OUTREC statement can be used to select subsets of the output records and apply different BUILD, FINDREP or OVERLAY items to them.

Five types of IFTHEN clauses as follows -

WHEN=INIT -


Use one or more WHEN=INIT clauses to apply BUILD, FINDREP or OVERLAY items to all input records. WHEN=INIT clause is processed before any of the other IFTHEN clauses.

WHEN=GROUP -


Use one or more WHEN=GROUP clauses to spread fields, identifiers and sequence numbers within groups of records.

The records can define that belong to a group using an suitable combination of BEGIN=(logexp), END=(logexp), KEYBEGIN=(field) and RECORDS=n parameters.

A KEYBEGIN=(field) parameter is satisfied when the field value changes. WHEN=GROUP clause is processed before any of the other IFTHEN clauses.

WHEN=(logexp) -


Use one or more WHEN=(logexp) clauses to apply BUILD, FINDREP or OVERLAY items to the subset of records that satisfy a specified logical expression.

WHEN=ANY -


Use a WHEN=ANY clause after multiple WHEN=(logexp) clauses to apply additional BUILD, FINDREP or OVERLAY items to records if they satisfied the criteria for any of the preceding WHEN=(logexp) clauses.

WHEN=NONE -


Use one or more WHEN=NONE clauses to apply BUILD, FINDREP or OVERLAY items to records that did not meet the criteria for any of the WHEN=(logexp) clauses.

WHEN=NONE clauses are processed after any of the other IFTHEN clauses.

Example -


Scenario - Reformatting records to hide the marks of student of the dept1 using IFTHEN.

Input File - MTHUSER.SORT.INPUT01 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00001     student1           dept1          560                                 
00003     student3           dept2          520                                 
00004     student4           dept1          540                                 
00005     student5           dept2          500                                 
00002     student2           dept3          510                                 
******************************** Bottom of Data ********************************

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card 
//*                                                                     
//**********************************************************************
//*                                                                     
//* SORT FOR OUTREC STATEMENT                                           
//*                                                                     
//**********************************************************************
//STEP01   EXEC PGM=SORT                                                
//SORTIN   DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR                    
//SORTOUT  DD SYSOUT=*                                                  
//SYSOUT   DD SYSOUT=*                                                  
//SYSIN    DD *                                                         
     OPTION COPY                                                        
     OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,80)),                          
          IFTHEN=(WHEN=(30,5,CH,EQ,C'dept1'),OVERLAY=(45:C'***')),      
          IFTHEN=(WHEN=NONE,BUILD=(1:1,80))                             
/*                                                                      
**************************** Bottom of Data ****************************

Output -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
00001     student1           dept1          ***                                 
00003     student3           dept2          520                                 
00004     student4           dept1          ***                                 
00005     student5           dept2          500                                 
00002     student2           dept3          510                                 
******************************** BOTTOM OF DATA ********************************

Explaining Example -

  1. OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,80)),..) - Copies the 80 bytes data from input file to output as it is.
  2. IFTHEN=(WHEN=(30,5,CH,EQ,C'dept1'),OVERLAY=(45:C'***')) - overlays the marks of the student with ‘***’ who are belong to dept1.
  3. IFTHEN=(WHEN=NONE,BUILD=(1:1,80)) - If no matches to conditions specified in WHEN, copy the 80 bytes data from input file to output as it is.