OUTREC Editing Numeric Fields Example


Scenario - Edit the marks from input file as M12(SII,III,IIT).

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1           dept1     00000560
00003     student3           dept2     00000520
00004     student4           dept1     00000540
00005     student5           dept2     00000500
00002     student2           dept3     00000510

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//MATEPKD  JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01   EXEC PGM=SORT
//SORTIN   DD DSN=MATEPK.SORT.INPUT01,DISP=SHR
//SORTOUT   DD DSN=MATEPK.MERGE.OUTPUT,
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
//            SPACE=(CYL,(1,4),RLSE),
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(1,39,40,8,ZD,EDIT=(SII,III,IIT),SIGNS=(,-))
/*

Output -

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

Explaining Example -

  1. OUTREC FIELDS=(1,39,..) copies first 39 bytes from input file to output as it is.
  2. OUTREC FIELDS=(..,40,8,ZD,EDIT=(SII,III,IIT),SIGNS=(,-)) converts the 8 digit ZD to M12(SII,III,IIT) and displays sign only for negative values.
Note! In the above example, the numeric value was not displayed like 000,000,520 because it has all zeroes before. So the format was ignored and displayed only 520. It also not displaying the sign as the values are positive.