DFSORT OUTREC Inserting sequence numbers

DFSORT OUTREC: Reformatting with FINDREP DFSORT OUTREC: Inserting sequence numbers

Advertisements


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 itemsto all input records.

WHEN=INIT clauseis 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 clauseis 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: -

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 ********************************

Job:

000100 //Jobcard 
000400 //*                                                                     
000500 //**********************************************************************
000600 //*                                                                     
000700 //* SORT FOR OUTREC STATEMENT                                           
000800 //*                                                                     
000900 //**********************************************************************
001100 //STEP01   EXEC PGM=SORT                                                
001300 //SORTIN   DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR                    
001800 //SORTOUT  DD SYSOUT=*                                                  
001900 //SYSOUT   DD SYSOUT=*                                                  
002400 //SYSIN    DD *                                                         
002411      OPTION COPY                                                        
002420      OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,80)),                          
002430           IFTHEN=(WHEN=(30,5,CH,EQ,C'dept1'),OVERLAY=(45:C'***')),      
002440           IFTHEN=(WHEN=NONE,BUILD=(1:1,80))                             
003500 /*                                                                      
****** **************************** 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 Solution:

  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.

DFSORT OUTREC: Reformatting with FINDREP DFSORT OUTREC: Inserting sequence numbers

Advertisements