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.
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?
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
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.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
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.