DFSORT OUTREC arithmetic with numeric and constants

DFSORT OUTREC: Editing numeric fields DFSORT OUTREC: Date Operations

OUTREC statement can be used for arithmetic operations on the numeric data in the file.


OUTREC FIELDS=(starting position of field1, length of field1,
		field1 source format, Arithmetic Operator, +n/-n,….. )

Name Description
Starting position of field1Specifies field1 starting position in the input file after sorting.
Length of feild1Field1 physical length in input file.
Field1 Source format Specifies the field1 source format
Arithmetic Operator Specifies the arithmetic operator
+n/-n Specifies the value that used in arithmetic calculation

Arithmetic operation can be performed with numeric fields and decimal constants (+n and -n) using the operators MIN (minimum), MAX (maximum), DIV (division), MUL(Multiplication), MOD (modulus), ADD (addition) and SUB (subtraction).

The order of assessment precedence for the operators specified below.

  1. MIN and MAX
  2. MUL, DIV and MOD
  3. ADD and SUB

The result of an arithmetic operation is a 15-digit ZD value.

The result of an arithmetic operation can beconverted to a different numeric format, or edited using pre-defined edit masks or user-defined edit masks.


Multiply the marks with 10 and store in the same record.

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

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


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      SORT FIELDS=(1,5,CH,A)                                             
002420      OUTREC FIELDS=(1,48,45,3,ZD,MUL,+10)                               
003500 /*                                                                      
****** **************************** Bottom of Data ****************************


********************************* TOP OF DATA **********************************
00001     student1           dept1          560            5600                 
00002     student2           dept3          510            5100                 
00003     student3           dept2          520            5200                 
00004     student4           dept1          540            5400                 
00005     student5           dept2          500            5000                 
******************************** BOTTOM OF DATA ********************************

Explaining Solution:

  1. OUTREC FIELDS=(1,48,..) copies first 48 bytes input file data as it is to output.
  2. OUTREC FIELDS=(..,45,3,ZD,MUL,+10) - data starts from 45th byte of length 3 will be multiplied by +10 and stores it in the same record as a continuation.

DFSORT OUTREC: Editing numeric fields DFSORT OUTREC: Date Operations