           # OVERLAY several fields if non-blank

Author Message
autobox

New User

Joined: 19 Aug 2005
Posts: 51 Posted: Fri Jul 10, 2015 12:42 pm Hi All

I want to compute several fields of one record based on the key field, for example the input is:

 Code: ----+----1- 0001  11.11 000202      00033333.33 00044444.44 00040404.04

1~4: the key field
5~6: field 1 with ZD format
7~10: field 2 with free format

If the key field is '0001', then field 1 & 2 divide a number, say 5, respectively, if not blanks.
If the key field is '0002', then field 1 & 2 divide a number, say 6, respectively, if not blanks.
If the key field is '0003', then field 1 & 2 divide a number, say 7, respectively, if not blanks.
If the key field is '0004', then field 1 & 2 divide a number, say 8, respectively, if not blanks.
...
And the output keep the same format as input.

I used IFTHEN and OVERLAY to handle this so far:
 Code: //SYSIN   DD *                                                        OPTION COPY                                                        INREC  IFTHEN=(WHEN=(1,4,CH,EQ,C'0001',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+5,TO=ZD,LENGTH=2)),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0001',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+5,EDIT=(TT.TT),LENGTH=5)),          IFTHEN=(WHEN=(1,4,CH,EQ,C'0002',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+6,TO=ZD,LENGTH=2)),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0002',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+6,EDIT=(TT.TT),LENGTH=5)),          IFTHEN=(WHEN=(1,4,CH,EQ,C'0003',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+7,TO=ZD,LENGTH=2)),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0003',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+7,EDIT=(TT.TT),LENGTH=5)),          IFTHEN=(WHEN=(1,4,CH,EQ,C'0004',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+8,TO=ZD,LENGTH=2)),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0004',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+8,EDIT=(TT.TT),LENGTH=5)) /*

But the output is:
 Code: ----+----1- 0001  02.22 000200      00030433.33 00040544.44 00040004.04

So my questions are that:
1. How to handle several fields of one record at the same time for one, for example field 2 of record 0003 and 2 records 0004 did not overlay?
2. Any better DFSORT keyword to do this for solution and performance? Bill Woodger

Moderator Emeritus

Joined: 09 Mar 2011
Posts: 7312
Location: Inside the Matrix Posted: Fri Jul 10, 2015 1:42 pm What's your expected output? The first IFTHEN=(WHEN=(logicalexpression) which is true stops the remaining IFTHEN=(WHEN=(logicalexpression) processing for that record. You can consider a number of IFTHEN=(WHEN=(logicalexpression) to be equivalent to an EVALUATE if you are familiar with COBOL. To modify this behaviour, your need to use HIT=NEXT. This allows one further IFTHEN=(WHEN=(logicalexpession) to be true for that record (HIT=NEXT can be used multiple times). On the first of your IFTHEN= pairs, you need to code ,HIT=NEXT before the closing bracket of the IFTHEN. autobox

New User

Joined: 19 Aug 2005
Posts: 51 Posted: Fri Jul 10, 2015 2:16 pm Hi Bill, Added HIT=NEXT to each IFTHEN, it works! Thanks so much, I spent 2 days on this already. Bill Woodger

Moderator Emeritus

Joined: 09 Mar 2011
Posts: 7312
Location: Inside the Matrix Posted: Fri Jul 10, 2015 3:31 pm OK, you went a little over-the-top with the HIT=NEXT. You are looking at four different values in the same position, so that can only possibly be true for one of those four on any given record. So no HIT=NEXT needed there. The problem you have is that you have a second test subordinate to a mutually-exclusive value, such that of those pairs there can be none, first only, second only or both true for any given record. It is when both of the pair may logically be true that you have the problem. To allow for that, the first IFTHEN of the pair requires the HIT=NEXT. The second does not, as no subsequent IFTHEN can be true, as the values of the first part of each test are mutually exclusive. In your case putting HIT=NEXT everywhere will work as you intend (because of the mutually-exclusive nature) but unnecessary processing will take place, and the code/data will be harder to understand. magesh23586

Active User Joined: 06 Jul 2009
Posts: 213
Location: Chennai Posted: Fri Jul 10, 2015 4:37 pm Here is the code for you.
 Code: //SYSIN   DD *                                                        OPTION COPY                                                        INREC  IFTHEN=(WHEN=(1,4,CH,EQ,C'0001',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+5,TO=ZD,LENGTH=2),HIT=NEXT),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0001',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+5,EDIT=(TT.TT),LENGTH=5)),          IFTHEN=(WHEN=(1,4,CH,EQ,C'0002',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+6,TO=ZD,LENGTH=2),HIT=NEXT),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0002',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+6,EDIT=(TT.TT),LENGTH=5)),          IFTHEN=(WHEN=(1,4,CH,EQ,C'0003',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+7,TO=ZD,LENGTH=2),HIT=NEXT),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0003',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+7,EDIT=(TT.TT),LENGTH=5)),          IFTHEN=(WHEN=(1,4,CH,EQ,C'0004',AND,5,2,CH,NE,C'  '),                       OVERLAY=(5:5,2,ZD,DIV,+8,TO=ZD,LENGTH=2),HIT=NEXT),                 IFTHEN=(WHEN=(1,4,CH,EQ,C'0004',AND,7,5,CH,NE,C'     '),                   OVERLAY=(7:7,5,SFF,DIV,+8,EDIT=(TT.TT),LENGTH=5)) /* autobox

New User

Joined: 19 Aug 2005
Posts: 51 Posted: Mon Jul 13, 2015 11:20 am Thanks Bill and Magesh! Search our Forum:

 Topic Forum Replies Similar Topics Break a record into fields, each fiel... SYNCSORT 2 FIELDS OVERLAPPING WITH MODE = IN OR ... CICS 3 Sort on different fields, removing du... SYNCSORT 8 Please help - SORT with SUM fields an... DFSORT/ICETOOL 6 Eliminating blank space in XML parsed... COBOL Programming 0 