|
View previous topic :: View next topic
|
| Author |
Message |
prasannahcp
New User
Joined: 16 May 2005 Posts: 17 Location: Bangalore
|
|
|
|
I have requirement of finding a character position and record number in a file
below is the sample file
aaaaaaaa*123455abcdefgh
bbbbbbbbbbbbbbb*12312prprpr
aaaabbbbbbbbbbbbbcccccccccc
rrrrrrrrrrrrreeeeeeeeeeeeeeeeee
cccccc*aaaaaa123131231
From the above sample records i want to find the character '*' in each record
the output should be like below
Rec No | character posn
1 | 9
2 | 16
5 | 7
I want this to be achieved through dfsort.
Please anybody help me to achieve this .
Thanks,
Prasanna |
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
prasannahcp,
What is LRECL and RECFM of the input file?
Thanks, |
|
| Back to top |
|
 |
prasannahcp
New User
Joined: 16 May 2005 Posts: 17 Location: Bangalore
|
|
|
|
Rec length is 300
Rec FM is FB |
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
Sorry forgot to ask you one more question,
Could you possibly have more than one '*' in a single record?
Thanks, |
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
prasannahcp,
Below job assumes you could have only 1 '*' in the record. Even if you have multiple this reports, char. position of first '*'.
FYI, this could be combined in a single ICETOOL job but I don't know if there is any way to achieve the same in single pass.
| Code: |
//SORT01 EXEC PGM=SORT
//SORTIN DD *
AAAAAAAA*123455ABCDEFGH*
BBBBBBBBBBBBBBB*12312PRPRPR
AAAABBBBBBBBBBBBBCCCCCCCCCC
RRRRRRRRRRRRREEEEEEEEEEEEEEEEEE
CCCCCC*AAAAAA123131231
/*
//OUT DD DSN=YOURID.TEST.VB,
// DISP=(,CATLG,DELETE),
// UNIT=SYSDA
//SYSIN DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(09:1,300,1:SEQNUM,8,ZD)),
IFTHEN=(WHEN=INIT,PARSE=(%01=(ENDAT=C'*',FIXLEN=308)),
BUILD=(%01,JFY=(SHIFT=LEFT)))
SORT FIELDS=COPY
OUTFIL FNAMES=OUT,FTOV,VLTRIM=C' '
/*
//SYSOUT DD SYSOUT=*
//*
//SORT02 EXEC PGM=SORT
//SORTIN DD DISP=SHR,DSN=YOURID.TEST.VB
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION VLSCMP
SORT FIELDS=COPY
OUTFIL VTOF,INCLUDE=(1,308,SS,EQ,C'*'),
HEADER1=(1:'REC NO | CHARACTER POSN',80:X),
BUILD=(5,8,ZD,11:C'|',14:1,2,BI,SUB,+12,M11,LENGTH=4,80:X)
/*
//SYSOUT DD SYSOUT=*
//* |
OUTPUT
| Code: |
REC NO | CHARACTER POSN
1 | 0009
2 | 0016
5 | 0007 |
Thanks, |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
prasannahcp,
Sqlcode1 has the right idea and his job needs a little tuning.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=Your input FB 300 file,DISP=SHR
//SORTOUT DD DSN=&&VB,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//SYSIN DD *
SORT FIELDS=COPY
INREC PARSE=(%00=(ENDAT=C'*',FIXLEN=300)),BUILD=(SEQNUM,8,ZD,%00)
OUTFIL INCLUDE=(9,300,SS,EQ,C'*'),FTOV,VLTRIM=C' '
//*
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=&&VB,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL VTOF,BUILD=(5,8,ZD,C'|',1,2,BI,SUB,+12,EDIT=(IIIIT),30:X),
REMOVECC,HEADER1=(1:'REC NO | CHARACTER POSN')
//* |
|
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
Kolusu,
Thanks for the correction. I guess, I am thinking too much in terms of IFTHEN.
Thanks, |
|
| Back to top |
|
 |
prasannahcp
New User
Joined: 16 May 2005 Posts: 17 Location: Bangalore
|
|
|
|
The above code is working fine for single character. But Actually i have a set of character to find like {'*','#',&','^','@',....}.
I need to find any of the characters from the above set present in the record.
Please help me |
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
prasannahcp
huh? Could you give us all the possible special char. that you might have in the input record?
Is it possible to have multiple of them in the same record? If yes, how do you want output for them?
Thanks, |
|
| Back to top |
|
 |
prasannahcp
New User
Joined: 16 May 2005 Posts: 17 Location: Bangalore
|
|
|
|
Yes, it might come more than one character per row.
For now if i get for one character per row also it will be great. We are considering all the possible special character which is there on the keyboard.
AAAAAAAA*123455ABCDEFGH#
BBBBBBBBBBBBBBB*12312PRP&RPR
AAAABBBBBBBBBBBBB$CCCCCCCCCC
RRRRRRRRRRRRREEEEEEEEEEEEEEEEEE
C^CCCAAAAAA123131231
If multiple characters are coming on a single row
then i want the output to be
Rec No | character |character posn
1 | * | 9
1 | # | 24
2 | * | 16
2 | & | 25
3 | $ |18
5 | ^ |2 |
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
How is this information to be used? |
|
| Back to top |
|
 |
prasannahcp
New User
Joined: 16 May 2005 Posts: 17 Location: Bangalore
|
|
|
|
| Information to be used is from a file and special characters are hard coded... |
|
| Back to top |
|
 |
dbzTHEdinosauer
Global Moderator

Joined: 20 Oct 2006 Posts: 6965 Location: porcelain throne
|
|
|
|
well, we could try again with the question:
| dick scherrer wrote: |
How is this information to be used?
|
|
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
| Quote: |
| Information to be used is from a file and special characters are hard coded... |
Huh
How does answer the question of how the data is to be used. . .
Maybe another way to ask is:
How/where will this output file be used once it is created? |
|
| Back to top |
|
 |
prasannahcp
New User
Joined: 16 May 2005 Posts: 17 Location: Bangalore
|
|
|
|
Actually the requrement is to find the invalid characters....So i told i wanted to find special characters.. What i had given was a sample requirement..
I need to find the characters which are not there in the ASCII table.. So those which are not there in the chart are invalid characters...
We need to find out the character positon and records number where the invalid character is there... The output will be used manually...
Please help me.. |
|
| Back to top |
|
 |
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1217 Location: Dublin, Ireland
|
|
|
|
| Quote: |
| Actually the requrement is to find the invalid characters.... |
There are many characters other than the special characters which might be considered invalid. First, define what the valid characters are and then everything else is invalid. For example, X'00' might be considered invalid but it's not a special character.
Garry. |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
prasannahcp,
Sort products do NOT have any built in features to determine the position of a string. You can manipulate for a single string or so, but it is still inefficient as you may have to read the file minimum of 2 times. If all you have is a hammer, everything looks like a nail.
on the other hand a COBOL program is just 10 lines (just the logic to parse apart from the usual setup of reading files) which is quite easy and very efficient.
IMHO write a Cobol program. |
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
I totally second Kolusu's opinion about using Cobol program and that's why I was holding off on posting my solution until I see his reply.
Unless you are totally obsessed with using DFSort use below card. I have used it for only 3 special char (*,#,$). You can add many as possible and make it more complex .
| Code: |
//SORT01 EXEC PGM=SORT
//SORTIN DD *
AAAAAAAA*123455ABCDEFGH#
BBBBBBBBBBBBBBB*12312PRPRPR$
AAAABBBBBBBBBBBBBCCCCCCCCCC
RRRRRRRRRRRRREEEEEEEEEEEEEEEEEE
CCCCCC*AAAAAA123131231
/*
//SORTOUT DD DSN=&&VB,DISP=(,PASS),SPACE=(CYL,(5,5),RLSE)
//SYSIN DD *
INREC PARSE=(%01=(ENDAT=C'*',FIXLEN=300),
%02=(ENDAT=C'#',FIXLEN=300),
%03=(ENDAT=C'$',FIXLEN=300)),
BUILD=(%01,%02,%03)
SORT FIELDS=COPY
OUTFIL BUILD=(SEQNUM,8,ZD,001,300,/,
SEQNUM,8,ZD,301,300,/,
SEQNUM,8,ZD,601,300),FTOV,VLTRIM=C' '
/*
//SYSOUT DD SYSOUT=*
//*
//SORT02 EXEC PGM=SORT
//SORTIN DD DSN=&&VB,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION VLSHRT
INREC IFTHEN=(WHEN=INIT,OVERLAY=(309:1,2,SEQNUM,8,ZD,RESTART=(5,8))),
IFTHEN=(WHEN=GROUP,BEGIN=(311,8,ZD,EQ,1),END=(311,8,ZD,EQ,3),
PUSH=(321:309,2)),
IFTHEN=(WHEN=GROUP,BEGIN=(311,8,ZD,EQ,2),END=(311,8,ZD,EQ,3),
PUSH=(323:309,2)),
IFTHEN=(WHEN=(9,300,SS,EQ,C'*'),OVERLAY=(319:C'*')),
IFTHEN=(WHEN=(9,300,SS,EQ,C'#'),OVERLAY=(319:C'#')),
IFTHEN=(WHEN=(9,300,SS,EQ,C'$'),OVERLAY=(319:C'$'))
SORT FIELDS=COPY
OUTREC IFTHEN=(WHEN=(311,8,ZD,EQ,2,AND,319,1,CH,GT,C' '),
OVERLAY=(309:((309,2,BI,ADD,321,2,BI),SUB,+12),
TO=BI,LENGTH=2)),
IFTHEN=(WHEN=(311,8,ZD,EQ,3,AND,319,1,CH,GT,C' '),
OVERLAY=(309:((309,2,BI,ADD,321,2,BI,ADD,323,2,BI),SUB,+24),
TO=BI,LENGTH=2))
OUTFIL VTOF,INCLUDE=(319,1,CH,GT,C' '),
BUILD=(005,8,C'|',
3X,319,1,5X,C'|',
309,2,BI,SUB,+12,EDIT=(IIIIT),40:X),
REMOVECC,HEADER1=(1:'REC NO |CHARACTER| CHARACTER POSN')
/*
//SYSOUT DD SYSOUT=*
//* |
OUTPUT
| Code: |
REC NO |CHARACTER| CHARACTER POSN
00000001| * | 9
00000001| # | 24
00000002| * | 16
00000002| $ | 28
00000005| * | 7 |
Thanks, |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|