View previous topic :: View next topic
Author
Message
kaushik8205 New User Joined: 10 Nov 2006Posts: 49 Location: Canada
Hi,
I want to edit 1st and Last record of a file. All records are similar and we cannot differentiate between them.
eg:- Input File :-
'111111',
'222222',
'333333',
'444444',
Desired output file:-
('111111',
'222222',
'333333',
'444444');
The 1st record should be prefixed with OPEN BRACKET ( and for the LAST record COMMA should be removed and suffixed with CLOSE BRACKET ) and SEMI COLON ;
Can anybody please suggest the most appropiate way.
Thanks
Back to top
saiprasadh Active User Joined: 20 Sep 2006Posts: 154 Location: US
Hi,
Why can't you use REXX to do that.
Sai
Back to top
William Thompson Global Moderator Joined: 18 Nov 2006Posts: 3156 Location: Tucson AZ
Using a programming language this would be easy, you know when it's the first record, and at EOF, you know when it's the last record.
With sort, the trick is figuring out when you have the last record, but as shown several times in this forum and in DFSORT's Smart Tricks manual.
Back to top
Prajesh_v_p Active User Joined: 24 May 2006Posts: 133 Location: India
If you are looking for attaching this to a query..I think we could do this by single sort with sort card as:
Code:
INREC IFTHEN=(WHEN=INIT,
BUILD=(1,70,71:SEQNUM,4,ZD)),
IFTHEN=(WHEN=(71,4,ZD,EQ,1),
BUILD=(1:1,8,9:C') ',11:11,70)),
IFTHEN=(WHEN=(71,4,ZD,EQ,2),
BUILD=(1:C'(',2:1,9,11:11,60,71:C'9999')),
IFOUTLEN=80
SORT FIELDS=(71,4,ZD,D)
OUTREC FIELDS=(1,70,10X)
Code:
'111111',
'222222',
'333333',
'444444',
will be formatted to
Code:
('222222',
'444444',
'333333',
'111111')
I presume that order will not be a problem if you are attaching this to a query...
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
kaushik8205,
Here's a DFSORT job that will produce the output in the order you asked for:
Code:
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//S1 DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN DD *
OPTION COPY
INREC OVERLAY=(81:SEQNUM,8,ZD)
OUTFIL FNAMES=T1
OUTFIL FNAMES=S1,REMOVECC,NODETAIL,
BUILD=(80X),
TRAILER1=('LASTREC,+',COUNT=(M11,LENGTH=8))
/*
//S2 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//SORTIN DD DSN=&&T1,DISP=(OLD,PASS)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
OPTION COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(81,8,ZD,EQ,+1),
BUILD=(C'(',1,9)),
IFTHEN=(WHEN=(81,8,ZD,EQ,LASTREC),
BUILD=(1,8,C');'))
/*
SORTOUT will have:
Code:
('111111',
'222222',
'333333',
'444444');
Back to top
Please enable JavaScript!