MainframeSupports
tip week 6/2017:

I have written a lot of tips about DFSORT during the years and I can see more and more useful functionality being added. When I find functionality new to me it may be brand new, but sometimes it is just old stuff which has been around for years. I think this is true about the capability of doing math. Sorting and filtering has not changed for many, many years, but formating output is a science in itself. OUTFIL and especially sub function OUTREC should have its own manual.

In this tip I will give you a simple example of how to add two numbers and present the result and the original data:

//TESTING EXEC PGM=SORT
//SORTIN DD *
00001 00002
00006 00003
//SORTOUT  DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
 OPTION COPY
 OUTREC FIELDS=(1,11,X,1,5,ZD,ADD,7,5,ZD,
                     X,1,5,ZD,ADD,7,5,ZD,TO=ZD,LENGTH=5)
/*

Please remark how it is possible to use instream data for SORTIN and SYSOUT=* for SORTOUT. This makes it so much easier to test functionality in SORT. Using OUTREC I copy the first 11 characters from SORTIN. After that I make calculations on each record. The two numbers to add must have their position, length and format specified. Type ZD stands for Zoned Decimal also known as PIC 9. Between the two numbers you specify which operation to use, but using an alphabetic command like in COBOL! ADD stands for addition, MUL for multiplication, SUB for subtraction, DIV for division and last, but not least MOD stands for modulus. You can use parenthesis to specify more complicated expressions. Unfortunately even simple expression is taking up a lot of space. You can do something about that, but I will get back to that another time. As termination of the calculation you can convert the result to another format as shown in the last line of SYSIN. And the output looks like this:

00001 00002               3  00003
00006 00003               9  00009

If you do not specify a format for the result DFSORT uses a predefined format which you might want to get familiar with before using calculations more often. As you can see the result is less space demanding when you specify the format yourself.

Previous tip in english        Forrige danske tip        Tip list