Page 1 of 1

Altering the RECORDs in a GROUP

PostPosted: Wed Oct 12, 2011 5:36 pm
by RajeshT
Hi Good Day !!

I'm trying find a way to alter the records in a GROUP. I wanted to bring in the THIRD record in a group as FRIST record, would it be possible to make it that way ? Can someone help. Mentioned below is an example that i'm looking at. RECFM=FB and LRECL=200.

INREC  IFTHEN=(WHEN=GROUP,   
       BEGIN=(5,5,CH,EQ,C'ABCDE'),
       END=(5,3,CH,EQ,C'IEA'), 
       PUSH=(205:ID=5,SEQ=5))
SORT FIELDS=COPY           


Once the group is identified with the above criteria, i'm want to know to how to push the THIRD record as FIRST one in the GROUP.

INPUT
ISA*ABCDE*00**00**00*
GK*PR*KROGER*1*006990
GS*PR*123456789121212
N3*7171 GOODLETT FAR
N4*CORDOVA*TN*380160*
IEA*77368*20110930~ 

OUTPUT
GS*PR*123456789121212
ISA*ABCDE*00**00**00*
GK*PR*KROGER*1*006990
N3*7171 GOODLETT FAR
N4*CORDOVA*TN*380160*
IEA*77368*20110930~


Appreciate the response.

Thank You.
Rajesh.

Re: Altering the RECORDs in a GROUP

PostPosted: Wed Oct 12, 2011 8:17 pm
by BillyBoyo
If you identify sequence-within-the-group as being three, then you can set it to, say, zero. Sort the file with the sequence number of the type you have just adjusted after the rest of the group stuff.

Re: Altering the RECORDs in a GROUP

PostPosted: Wed Oct 12, 2011 8:47 pm
by RajeshT
Hi Billy,

Can you please be more elaborate ? how do i set the sequence number as ZERO after initially identifying it as THREE.

Thank You.
Rajesh.

Re: Altering the RECORDs in a GROUP

PostPosted: Wed Oct 12, 2011 8:52 pm
by BillyBoyo
In the position where you have the sequence for the group, and you have identified it as number three, simply put zero there (a zero of the same size and type as the sequence number).

so

000001
000002
000003
000004
000005

becomes

000001
000002
000000
000004
000005

which you then sort (logically or exactly within the group)

000000
000001
000002
000004
000005


Then you can drop all the extra stuff as no longer needed.

The original third record in the group should now be the first.

Re: Altering the RECORDs in a GROUP

PostPosted: Wed Oct 12, 2011 10:16 pm
by RajeshT
:)

Understood. And it worked.
STEP-1
INREC  IFTHEN=(WHEN=GROUP,       
       BEGIN=(1,4,CH,EQ,C'ISA*'),
       END=(1,3,CH,EQ,C'IEA'),   
       PUSH=(81:ID=5,SEQ=5))     
SORT FIELDS=COPY                 
OUTFIL BUILD=(1,90)             

STEP-2
SORT FIELDS=COPY                                             
OUTREC IFTHEN=(WHEN(86,5,CH,EQ,C'00003'),OVERLAY(86:C'00000'))

STEP-3
SORT FIELDS=(81,10,CH,A)


Thank You Billy.
Rajesh.

Re: Altering the RECORDs in a GROUP

PostPosted: Wed Oct 12, 2011 10:51 pm
by BillyBoyo
Good for you. I think you can streamline things a little, perhaps to one step. For instance, can the final sort could be in step-2 with INREC instead of OUTREC? You have a working solution you got to yourself, so if that leaves you with time, see if you can smarten it up a bit. It is a useful exercise, as you will end up knowing what you can do where in the sort process. Check your manual.

Re: Altering the RECORDs in a GROUP

PostPosted: Wed Oct 12, 2011 11:57 pm
by BillyBoyo
Just as an afterthought, what if there is no third record? Which should appear as the first? As an exercise, even if not possible with your actual data, how about trying 2nd record first, if only two records?