Page 1 of 2

Insert all records from a file before a line in another file

PostPosted: Fri Jul 19, 2013 5:48 pm
by rookie1
I've two flat files similar similar in properties say file A and file B

File A

12345 6789
78787 6789
AAAAA

File B

77777777777777777777777777
88888888888888888888888888

I want to insert all records from File B to file A when you find character 'A' in coulmn number 1 of file A (before the record AAAA ) and get it in a new file


Output :
12345 6789
78787 6789
77777777777777777777777777
88888888888888888888888888
AAAAA


Inserting before record AAAA is a bit tricky.Is it possible

Re: Insert all records from a file before a line in another

PostPosted: Fri Jul 19, 2013 6:48 pm
by BillyBoyo
Yes, it is possible. A JOINKEYS should do it. What is the RECFM/LRECL of your input files and output file?

Re: Insert all records from a file before a line in another

PostPosted: Fri Jul 19, 2013 6:54 pm
by rookie1
RECFM=FB, LRECL = 80

Re: Insert all records from a file before a line in another

PostPosted: Sat Jul 20, 2013 12:31 pm
by rookie1
Hi Billy or anybody

Can you let me know if this is feasible..

Re: Insert all records from a file before a line in another

PostPosted: Sun Jul 21, 2013 12:02 am
by BillyBoyo
I'd already indicated that it was feasible. When and whether I or anyone else provides code for it is up to us and our available time.

Now you should study this, and explain back to us how it works. If you have difficulties, say what you have done and what problem you have, and someone will assist. When they have time available.


//INSERT EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
  OPTION COPY
  JOINKEYS F1=INA,FIELDS=(81,1,A),SORTED,NOSEQCK
  JOINKEYS F2=INB,FIELDS=(81,1,A),SORTED,NOSEQCK
  JOIN UNPAIRED,F1,F2,ONLY
  REFORMAT FIELDS=(F1:1,80,?,F2:1,80)
                                                 
  INREC IFTHEN=(WHEN=(81,1,CH,EQ,C'1'),
                    BUILD=(1,80)),
               IFTHEN=(WHEN=NONE,
                    BUILD=(82,80))
                                                 
//INA      DD *
1
2
3
A
8
9
//INB      DD *
4
5
6
7
//JNF1CNTL DD *
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'A'),
                PUSH=(81:ID=1))
//JNF2CNTL DD *
 INREC OVERLAY=(81:C'0')


1
2
3
4
5
6
7
A
8
9

Re: Insert all records from a file before a line in another

PostPosted: Mon Jul 29, 2013 1:10 pm
by rookie1
Thanks for your response!

But I'm using SYNCSORT and it doesn't recognise '?' operator.

I'll post the question in SYNCSORT forum and see if it's feasible.

Thanks again for your time and response!

Re: Insert all records from a file before a line in another

PostPosted: Mon Jul 29, 2013 2:24 pm
by NicC
A pity you did not specify your sort product before so that people would not spend time giving a solution that is wrong for you.

Your new topic has been deleted and the original moved.

Re: Insert all records from a file before a line in another

PostPosted: Mon Jul 29, 2013 9:18 pm
by rookie1
yeah thats my mistake..but eager to learn if this can be done by syncsort..

thank you..

Re: Insert all records from a file before a line in another

PostPosted: Mon Jul 29, 2013 10:02 pm
by BillyBoyo
Have a look at examples here using FILL= on the REFORMAT statement. Since you seem to have text everywhere, use FILL=X'FF' or X'00'. Then you can test the, in the RFORMAT record, the first byte of data from F1 and the first byte of data from F2. Takes the place of the ? in DFSORT.

Re: Insert all records from a file before a line in another

PostPosted: Mon Jul 29, 2013 10:37 pm
by rookie1
The contents of file B are dynamic. I only know before which particular record from file A, all dynamic records from file B has to be inserted.


Thank you.