Page 1 of 1

IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Tue Jun 16, 2015 1:38 pm
by Martin-1999
Hi,

I am trying to rearrange a file, which includes building a new header from the old header and converting dates, rearranging the data lines and rebuilding a trailer record with a converted date from the original header.

I can get it to work in bits and I can get it all to work in three steps but I'm sure it should work in single step. I'm having trouble combining the BUILD, OVERLAY, PARSE in subsequent IFTHENs, Even with the HIT=NEXT option it is still ignoring certain conditions. The example below is my latest attempt where I combined some of the BUILD, OVERLAY, PARSE statements but I have found out that this is not allowed. As this non-working example is the most concise of my non-working attempts, I will include it as a guide to what I'm trying to do.

The example below gives the input and output of what I'm trying to achieve in a single step.

//STEP10   EXEC PGM=SORT                                               
//*                                                                     
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//SORTIN   DD *                                                         
VOL1JJJJJJ                               333333                         
HDR1NNNNNNN          DDEX  00010001       15162 ZZZZZ 000000           
HDR2NNNNNNNNNNN                                   00                   
UHL1 44444444444    000000004 SULTI  001                               
111111AAAAAAAAXXXXXXXXXXXXXXXXXXXXX00000000011YYYYYYYYYYYYYYYYYYYYYYYYYY
222222BBBBBBBBXXXXXXXXXXXXXXXXXXXXX00000000022YYYYYYYYYYYYYYYYYYYYYYYYYY
333333CCCCCCCCXXXXXXXXXXXXXXXXXXXXX00000000033ZZZZZZZZZZZZZZZZZZZZZZZZZZ
EOF15555555          FFFF  00007777       08888 19999 000000           
EOF2GGGGGGGGGGG                                   00                   
UTL10000000030246000000003024600000020000001        0000000             
//*                                                                     
//SORTOUT  DD DSN=MYSORT.OUT                                           
//*                                                                     
//SYSPRINT DD  SYSOUT=*                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSIN    DD *                                                         
 OPTION COPY                                                         
  OMIT COND=((01,03,CH,EQ,C'VOL'),OR,     -- EXCLUDE THE HEADERS AND 
             (01,04,CH,EQ,C'HDR2'),OR,    -- TRAILERS EXCEPT HDR1     
             (01,03,CH,EQ,C'UHL'),OR,     --                         
             (01,03,CH,EQ,C'EOF'),OR,     --                         
             (01,03,CH,EQ,C'UTL'))        --                         
                                                                     
* REBUILD SINGLE HEADER                                               
  INREC IFTHEN=(WHEN=(01,04,CH,EQ,C'HDR1'),                           
          BUILD=(14C'0',                  -- 14 ZEROS                 
                 DATENS=(4MD),            -- SYSTEM DATE YYYYMMDD     
                 43,05,Y2T,TOGREG=Y4T,    -- CONVERT BULK DATE FROM   
                 C'MORETEXT',             -- Y2T=YYDDD TO Y4T=YYYYMMDD
                 62C' '),                 -- 62 SPACES               
      PARSE=(%01=(ABSPOS=43,FIXLEN=5))),  -- SAVE OFF BULK DATE       
                                                                     
* IDENTIFY THE DATA RECORDS                                           
  IFTHEN=(WHEN=((01,03,CH,NE,C'VOL'),AND, -- IDENTIFY DATA RECS       
                (01,03,CH,NE,C'HDR'),AND, --                         
                (01,03,CH,NE,C'UHL'),AND, --                         
                (01,03,CH,NE,C'EOF'),AND, --             
                (01,03,CH,NE,C'UTL')),    --             
          BUILD=(01,06,                                 
                 07,08,                                 
                 36,11,                                 
                 75C' '),                               
         OVERLAY=(101:36,11))                           
                                                         
* BUILD NEW TRAILER WITH CONVERTED BULK DATE AND TOTALS 
  OUTFIL REMOVECC,                                       
  TRAILER1=(14C'0',                                     
            DATENS=(4MD),                               
            %01,Y2T,TOGREG=Y4T,                         
            'MORETEXT',                                 
            '  ',                                       
            TOT=(101,11,ZD,M11,LENGTH=15),               
            41C' ')                                     
//*                                                                                   


Input

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
VOL1JJJJJJ                               333333                         
HDR1NNNNNNN          DDEX  00010001       15162 ZZZZZ 000000           
HDR2NNNNNNNNNNN                                   00                   
UHL1 44444444444    000000004 SULTI  001                               
111111AAAAAAAAXXXXXXXXXXXXXXXXXXXXX00000000011YYYYYYYYYYYYYYYYYYYYYYYYYY
222222BBBBBBBBXXXXXXXXXXXXXXXXXXXXX00000000022YYYYYYYYYYYYYYYYYYYYYYYYYY
333333CCCCCCCCXXXXXXXXXXXXXXXXXXXXX00000000033ZZZZZZZZZZZZZZZZZZZZZZZZZZ
EOF15555555          FFFF  00007777       08888 19999 000000           
EOF2GGGGGGGGGGG                                   00                   
UTL10000000030246000000003024600000020000001        0000000       


Output detail:
Header
01-14 14 zeros
15-22 System date YYYYMMDD
23-30 Converted YYDDD date from pos 43 of input HDR1 line converted to YYYYMMDD
31 onwards text.

Trailer

01-14 14 nines
15-22 System date YYYYMMDD
23-30 Converted YYDDD date from pos 43 of input HDR1 line converted to YYYYMMDD
31-40 text
41-58 Sum of amount in detail input lines at pos 36-46

MYSORT.OUT
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
000000000000002015061520150611MORETEXT                                         
111111AAAAAAAA00000000011                                                       
222222BBBBBBBB00000000022                                                       
333333CCCCCCCC00000000033                                                       
999999999999992015061520150611MORETEXT  000000000000000066                     
******************************** Bottom of Data ********************************


Any help much appreciated (I have read several PDF manuals).

I don't know why the Preview has added in blank lines ? .All the code was cut and pasted came from a 72 char wide mainframe screen. Hopefully you can still work what's going on.

Martin.

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Tue Jun 16, 2015 5:18 pm
by BillyBoyo
PARSE values are not going to persist from one stage to another. How could they?

Those are tape labels. You really have those in your data? You've inconveniently hidden the RECFM, LRECL and BLKSIZE on the HDR2, so are we to assume your data is fixed-length 80 byts?

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Tue Jun 16, 2015 6:52 pm
by Martin-1999
Apologies, I forgot the LRECLS, however any LRECL you choose will be fine. The actual input was FB 80 and the output is FB 106. The headers do look like Tape labels, they come from an outside company but the contents are not 'tape related'.

I realise that my last attempt at combining my steps does not work but I thought it would still be useful to see what I was attempting as opposed to trying to describe it all in English. If there is anything else you need please let me know.

Thanks again

Martin.

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Tue Jun 16, 2015 7:12 pm
by BillyBoyo
Once an IFTHEN=(WHEN=(logical expression) is true, no more WHEN=(logical expression) statements are processed. So after identifying the remaining header, you can use WHEN=NONE for the data.

To get data from one record to another you need to use PUSH, which only exits on WHEN=GROUP.

You'll need WHEN=GROUP to identify your header as the starting point of the group and PUSH the date you want to an extension (fixed-length records, so it can be at the "end".

When you have your BUILD for the header/data make sure you don't "lose" the date.

You can then pick it up for the TRAILER1 from the final record (just specify the position on the input record).

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Tue Jun 16, 2015 8:10 pm
by Martin-1999
Hi

Thanks for the tips, I had not used WHEN=GROUP before. WHEN=GROUP and PUSH= are not in my Appl Programmers guide but I found some other examples in this forum to plagiarise.

Here is where I'm at:

//SYSIN    DD *                                                         
 OPTION COPY                                                           
  OMIT COND=((01,03,CH,EQ,C'VOL'),OR,     -- EXCLUDE THE HEADERS AND   
             (01,04,CH,EQ,C'HDR2'),OR,    -- TRAILERS EXCEPT HDR1 WHICH
             (01,03,CH,EQ,C'UHL'),OR,     --                           
             (01,03,CH,EQ,C'EOF'),OR,     --                           
             (01,03,CH,EQ,C'UTL'))        --                           
                                                                       
* IDENTIFY THE HEADER THAT WE WILL REARRANGE.                           
  INREC IFTHEN=(WHEN=(01,04,CH,EQ,C'HDR1'),                             
          BUILD=(14C'0',                  --  14 ZEROS                 
                 DATENS=(4MD),            --  SYSTEM DATE YYYYMMDD     
                 43,05,Y2T,TOGREG=Y4T,    --* CONVERT BULK DATE FROM   
                 C'DDETRANS',             --* Y2T=YYDDD TO Y4T=YYYYMMDD
                 62C' '),HIT=NEXT),       --  62 SPACES                 
        IFTHEN=(WHEN=GROUP,BEGIN=(01,04,CH,EQ,C'HDR1'),                 
        PUSH=(107:23,05)),                                             
                                                                       
* IDENTIFY THE DATA RECORDS                                             
  IFTHEN=(WHEN=ANY),                                                   
          BUILD=(01,06,                   --                           
                 07,08,                   --                       
                 36,11,                   -- AMOUNT FROM P36       
                 75C' '))                 -- 75 SPACES             
                                                                   
  OUTFIL REMOVECC,                                                 
  TRAILER1=(14C'0',                  --  14 ZEROS                   
            DATENS=(4MD),            --  SYSTEM DATE YYYYMMDD       
            107,05,Y2T,TOGREG=Y4T,   --                             
            'DDETRAIL',                                             
            '  ',                                                   
            TOT=(115,11,ZD,M11,LENGTH=15),                         
            41C' ')                  -- 75 SPACES                   
//*                                                                 


This results in:
********************************* TOP OF DATA **********************************
ICE805I 1 JOBNAME: SORTDT4  , STEPNAME: STEP10                                 
ICE802I 0 BLOCKSET     TECHNIQUE IN CONTROL                                     
ICE143I 0 BLOCKSET     COPY  TECHNIQUE SELECTED                                 
ICE250I 0 VISIT http://www.ibm.com/storage/dfsort FOR DFSORT PAPERS, EXAMPLES AN
ICE000I 1 - CONTROL STATEMENTS FOR 5650-ZOS, Z/OS DFSORT V2R1  - 15:36 ON TUE JU
           OPTION COPY                                                         
            OMIT COND=((01,03,CH,EQ,C'VOL'),OR,     -- EXCLUDE THE HEADERS AND 
                       (01,04,CH,EQ,C'HDR2'),OR,    -- TRAILERS EXCEPT HDR1 WHIC
                       (01,03,CH,EQ,C'UHL'),OR,     --                         
                       (01,03,CH,EQ,C'EOF'),OR,     --                         
                       (01,03,CH,EQ,C'UTL'))        --                         
                                                                               
          * IDENTIFY THE HEADER THAT WE WILL REARRANGE.                         
            INREC IFTHEN=(WHEN=(01,04,CH,EQ,C'HDR1'),                           
                    BUILD=(14C'0',                  --  14 ZEROS               
                           DATENS=(4MD),            --  SYSTEM DATE YYYYMMDD   
                           43,05,Y2T,TOGREG=Y4T,    --* CONVERT BULK DATE FROM 
                           C'DDETRANS',             --* Y2T=YYDDD TO Y4T=YYYYMMD
                           62C' '),HIT=NEXT),       --  62 SPACES               
                  IFTHEN=(WHEN=GROUP,BEGIN=(01,04,CH,EQ,C'HDR1'),               
                               £                                               
ICE107A F DUPLICATE, CONFLICTING, OR MISSING INREC OR OUTREC STATEMENT OPERANDS
                  PUSH=(107:23,05)),                                           
                  £                                                             
ICE005A 0 BLANK NEEDED IN COLUMN 1 OR OPERATION NOT DEFINED CORRECTLY           
                                                                               
          * IDENTIFY THE DATA RECORDS                                           
            IFTHEN=(WHEN=ANY),                                                 
            £                                                                   
ICE005A 0 BLANK NEEDED IN COLUMN 1 OR OPERATION NOT DEFINED CORRECTLY           
                    BUILD=(01,06,                   --                         
                    £                                                           
ICE005A 0 BLANK NEEDED IN COLUMN 1 OR OPERATION NOT DEFINED CORRECTLY           
                           07,08,                   --                         
                           £                                                   
ICE007A 0 SYNTAX ERROR                                                         
                           36,11,                   -- AMOUNT FROM P36         

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Tue Jun 16, 2015 9:20 pm
by BillyBoyo
Well, WHEN=GROUP is definitely for sure in the Application Programming Guide. You have Version 2.1 so you are up-to-date.

The problem you're having in using it is that it must come before any IFTHEN=(WHEN=(logicalexpression).

So you need the GROUP to do the PUSH before you otherwise identify the record and rearrange. Which means in the rearrangement, don't trash what you PUSHed.

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Wed Jun 17, 2015 1:19 pm
by Martin-1999
I still have two main stumbling blocks:
1. Finding a combination of IFTHEN=(WHEN= that are allowed. From the latest attempt I cannot see why I’m failing based on the explanations in ICE107A message.
2. I need to perform a BUILD and an OVERLAY on my data records and that is not allowed.

Latest SORT cards (with no OVERLAY for the data records)

//SYSIN    DD *                                                         
 OPTION COPY                                                           
  OMIT COND=((01,03,CH,EQ,C'VOL'),OR,     -- EXCLUDE THE HEADERS AND   
             (01,04,CH,EQ,C'HDR2'),OR,    -- TRAILERS EXCEPT HDR1       
             (01,03,CH,EQ,C'UHL'),OR,     --                           
             (01,03,CH,EQ,C'EOF'),OR,     --                           
             (01,03,CH,EQ,C'UTL'))        --                           
                                                                       
* IDENTIFY THE HEADER THAT WE WILL REARRANGE.                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(01,04,CH,EQ,C'HDR1'),                 
        PUSH=(107:23,05)),                                             
                                                                       
        IFTHEN=(WHEN=(01,04,CH,EQ,C'HDR1'),                             
          BUILD=(14C'0',                  --  14 ZEROS                 
                 DATENS=(4MD),            --  SYSTEM DATE YYYYMMDD     
                 43,05,Y2T,TOGREG=Y4T,    --* CONVERT BULK DATE FROM   
                 C'DDETRANS',             --* Y2T=YYDDD TO Y4T=YYYYMMDD
                 62C' ')),                --  62 SPACES                 
                                                                       
* IDENTIFY THE DATA RECORDS                                       
  IFTHEN=(WHEN=NONE),                                             
          BUILD=(01,06,                   --                       
                 07,08,                   --                       
                 36,11,                   -- AMOUNT FROM P36       
                 75C' '))                 -- 75 SPACES             
                                                                   
  OUTFIL REMOVECC,                                                 
  TRAILER1=(14C'9',                  --  14 NINES                 
            DATENS=(4MD),            --  SYSTEM DATE YYYYMMDD     
            107,08,                  --                           
            'DDETRAIL',                                           
            '  ',                                                 
            TOT=(115,11,ZD,M11,LENGTH=15),                         
            41C' ')                  -- 75 SPACES                 
//*                                                               


Results in ICE107A

********************************* TOP OF DATA **********************************
ICE805I 1 JOBNAME: SORTDT4  , STEPNAME: STEP10                                 
ICE802I 0 BLOCKSET     TECHNIQUE IN CONTROL                                     
ICE143I 0 BLOCKSET     COPY  TECHNIQUE SELECTED                                 
ICE250I 0 VISIT http://www.ibm.com/storage/dfsort FOR DFSORT PAPERS, EXAMPLES AN
ICE000I 1 - CONTROL STATEMENTS FOR 5650-ZOS, Z/OS DFSORT V2R1  - 08:40 ON WED JU
           OPTION COPY                                                         
            OMIT COND=((01,03,CH,EQ,C'VOL'),OR,     -- EXCLUDE THE HEADERS AND 
                       (01,04,CH,EQ,C'HDR2'),OR,    -- TRAILERS EXCEPT HDR1     
                       (01,03,CH,EQ,C'UHL'),OR,     --                         
                       (01,03,CH,EQ,C'EOF'),OR,     --                         
                       (01,03,CH,EQ,C'UTL'))        --                         
                                                                               
          * IDENTIFY THE HEADER THAT WE WILL REARRANGE.                         
            INREC IFTHEN=(WHEN=GROUP,BEGIN=(01,04,CH,EQ,C'HDR1'),               
                  PUSH=(107:23,05)),                                           
                                                                               
                  IFTHEN=(WHEN=(01,04,CH,EQ,C'HDR1'),                           
                    BUILD=(14C'0',                  --  14 ZEROS               
                           DATENS=(4MD),            --  SYSTEM DATE YYYYMMDD   
                           43,05,Y2T,TOGREG=Y4T,    --* CONVERT BULK DATE FROM 
                           C'DDETRANS',             --* Y2T=YYDDD TO Y4T=YYYYMMD
                           62C' ')),                --  62 SPACES               
                                                                               
          * IDENTIFY THE DATA RECORDS                                           
            IFTHEN=(WHEN=NONE),                                                 
                             £                                                 
ICE107A 6 DUPLICATE, CONFLICTING, OR MISSING INREC OR OUTREC STATEMENT OPERANDS
                    BUILD=(01,06,                   --                         
                    £                                                           
ICE005A 0 BLANK NEEDED IN COLUMN 1 OR OPERATION NOT DEFINED CORRECTLY           
                           07,08,                   --                         
                           £                                                   
ICE007A 0 SYNTAX ERROR                                                         
                           36,11,                   -- AMOUNT FROM P36         
                           £                                                   
ICE007A 0 SYNTAX ERROR                                                         
                           75C' '))                 -- 75 SPACES               


I will have to leave it as two steps, thanks for your time, input and encouragement.

Martin.

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Wed Jun 17, 2015 2:54 pm
by BillyBoyo
You've simply "ended" the IFTHEN=(WHEN=NONE by accident, by having a closing ")" after the NONE.

Why do you need a BUILD and an OVERLAY? What is it that you can't do with BUILD that you want to do with OVERLAY (or vice versa)?

BUILD creates a new version of the current record with record-data sourced from the positions of the old current record.

OVERLAY changes the current record, using the data from the current record, meaning be careful not to do something with the same position twice without realising it was changed earlier in the OVERLAY. NB when you extend a record with OVERLAY, a new current record is created, just for completeness.

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Wed Jun 17, 2015 4:08 pm
by Martin-1999
Hi,

I fixed the last issue you pointed out with the early termination of the NONE, it now reads:

IFTHEN=(WHEN=NONE,     
        BUILD=(01,06,   
               07,08,   
               36,11,   
               75C' '))


However the subsequent BUILD of the data records is being ignored, The input data records are unchanged in the output file.

I have a preference for using SORT for this type of data manipulation as it reduces the subsequent testing effort. I am only an occasional user of SORT. For this solution I am finding the cryptic nature of the commands beyond my level of expertise. I have just spent an hour writing an Easytrieve that will do the same task, albeit with more documentation and effort required during testing.

Thanks again for the encouragement.

Re: IFTHEN=(WHEN= combined with BUILD,OVERLAY,PARSE Query

PostPosted: Wed Jun 17, 2015 10:34 pm
by BillyBoyo
Well, you're close. I can't tell why that piece of code you show doesn't do what you think, but I took your earlier INREC and OUTFIL and, apart from some tweaking to the positions of the data to OUTFIL, the code ran.

IFTHEN=(WHEN=(logicalexpression) works like an EVALUATE in COBOL, with WHEN=NONE being the "other".

Once a logicalexpression is satisfied, it drops out of the EVALUATE. If you want to force the use of more than one logicalexpression per record, you need to use HIT=NEXT on an IFTHEN which can be followed by another IFTHEN.

IFTHEN=(WHEN=ANY is a "do this afterwards, whatever has happened) and always requires HIT=NEXT on a prior IFTHEN that has matched.

IFTHEN=(WHEN=INIT is special, it is unconditional processing per record before IFTHEN with logicalexpression.

IFTHEN=(WHEN=GROUP establishes a grouping of records and allows data to be copied from the first of a group to other records in the group.

WHEN=INIT and WHEN=GROUP can be intermingled, and WHEN=GROUP never requires HIT=NEXT.

WHEN=GROUP and WHEN=INIT are processed first, in the order written. Then the WHEN=(logicalexpressions). Then the WHEN=NONE and WHEN=ANY.

To try to make the code clearer, have a look at using SORT symbols/SYMNAMES. This allows you to name fields rather than repeatedly code 1,10,CH or whatever. Very useful.