OUTREC: arithmetic with numeric and constants
OUTREC: arithmetic with numeric and constants
Summary
- OUTREC statement can be used to perform arithmetic operations on the numeric data in the file.
Syntax -
OUTREC FIELDS=(starting position of field1, length of field1,
field1 source format, Arithmetic Operator, +n/-n,….. )
Starting position of field1 | Specifies field1 starting position in the input file after sorting. |
Length of feild1 | Field1 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 -
- MIN and MAX
- MUL, DIV and MOD
- 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.
Example -
Scenario - Multiply the marks with 10 and store in the same record.
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 *
SORT FIELDS=(1,5,CH,A)
OUTREC FIELDS=(1,48,45,3,ZD,MUL,+10)
/*
**************************** Bottom of Data ****************************
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* 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 Example -
- OUTREC FIELDS=(1,48,..) copies first 48 bytes input file data as it is to output.
- 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.