Page 1 of 1

convert cobol logic to joinkey sort.

PostPosted: Wed Mar 25, 2015 9:42 am
by arpitpatel01
I have to convert below cobol code logic to sort. Kindly help

IF WS-PREV-KEY   = WS-CURR-KEY
   IF I-PREV-SEG = I-CURR-SEG 
       PERFORM 2100-READ-PREV
       PERFORM 2100-READ-CURR
   ELSE                               
   MOVE I-CURR-REC(1:10) TO WS-OUTA
   PERFORM 2300-WRITE-DELTA
   PERFORM 2100-READ-PREV 
   PERFORM 2100-READ-CURR 
ELSE                                   
   IF WS-PREV-KEY  <  WS-CURR-KEY     
      MOVE I-PREV-REC(1:10) TO WS-OUTA
      PERFORM 2300-WRITE-DELTA
      PERFORM 2100-READ-PREV 
   ELSE
      MOVE I-CURR-REC(1:10) TO WS-OUTA
      PERFORM 2300-WRITE-DELTA
      PERFORM 2100-READ-CURR 
   END-IF
END-IF.

FYI:
01  I-PREV-REC.                               
    05  I-PREV-KEY                 PIC X(10).
    05  I-PREV-DUMMY-KEY     PIC X(03).
    05  I-PREV-SEG-KEY          PIC X(09).
    05  I-PREV-SEG                 PIC X(067).

01  I-CURR-REC.                               
    05  I-CURR-KEY                 PIC X(10).
    05  I-CURR-DUMMY-KEY     PIC X(03).
    05  I-CURR-SEG-KEY          PIC X(09).
    05  I-CURR-SEG                 PIC X(067).


Coded'd

Re: convert cobol logic to joinkey sort.

PostPosted: Wed Mar 25, 2015 1:24 pm
by BillyBoyo
Where are you having a problem? You read the documentation for JOINKEYS and experiment. Look for examples. Read. Experiment.

If you get to something you can't understand, show us what you have, and what you've done.

Re: convert cobol logic to joinkey sort.

PostPosted: Wed Mar 25, 2015 2:50 pm
by arpitpatel01
@ BillyBoyo: If first IF clause fails, then how the condtion in the ELSE clause (IF WS-PREV-KEY < WS-CURR-KEY ) be handled thru sort?

Re: convert cobol logic to joinkey sort.

PostPosted: Wed Mar 25, 2015 2:50 pm
by arpitpatel01
If first IF clause fails, then how the condtion in the ELSE clause (IF WS-PREV-KEY < WS-CURR-KEY ) be handled thru sort?

Re: convert cobol logic to joinkey sort.

PostPosted: Wed Mar 25, 2015 3:45 pm
by BillyBoyo
Differently. You never see those IFs, just the results:

 JOIN UNMATCHED,F1,F2


That gives you matched records, and unmatched F1 and unmatched F2.

Then you need some OUTFILs with INCLUDE=/OMIT= which do the comparison work.

Re: convert cobol logic to joinkey sort.

PostPosted: Wed Mar 25, 2015 6:05 pm
by arpitpatel01
Input 1:
1234567890ABC
5678971554FYU

Input 2:
123456789OMG
849798979HOL

OUTPUT
1234567890ABC1234567890OMG
5678971554FYU
849798979HOL


For this output how will i compare (1,10) of 2nd record with (11,10) of 3rd record thru sort???? is it possible?

Kindly refer to the query again!

Re: convert cobol logic to joinkey sort.

PostPosted: Wed Mar 25, 2015 7:11 pm
by BillyBoyo
Find an example, preferably with the JOIN statement I showed previously.

You seem to want one OUTFIL only. So you'll need an INCLUDE=/OMIT= which covers your requirements. OMIT=(prevseg,EQ,currseg) would seem to do you. Then you just need to BUILD the key, and you have one IFTHEN=(WHEN=(logical expression) to BUILD from a different source position when you have the unmatched F2 (all the F1 data on the REFORMAT statement will be blank).