|
View previous topic :: View next topic
|
| Author |
Message |
ramas.kamal
New User

Joined: 03 Mar 2014 Posts: 22 Location: India
|
|
|
|
Hi, in the below input file (LRECL=49,RECFM=FB) there are few records with value "2651" appearing twice in the same line. The 6 byte key starts at 4th column and is followed by 4 digit numbers till 49th column. So, I need to search for value "2651" in between 10th and 49th column and if any record has two of "2651" appearing then write such ones to output.
| Code: |
----+----1----+----2----+----3----+----4----+----5
@1 GTL0@192009106265149002651
@8 BAS9@878903434789326510300
@4 TULI@4901226513564090045092651
@3 KJML@3090108430651654088453379265100012651
@6 FINA@62651404023405430203419083920
@2 LON0@23901266143500120387002310241029125612661
|
How to pick only those into output file? I thought of using PARSE function but do not know how to collect or not collect them !!
Expecte Output:
| Code: |
@1 GTL0@192009106265149002651
@4 TULI@4901226513564090045092651
@3 KJML@3090108430651654088453379265100012651
|
Please help. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
What if there are more that two occurrences?
For two, or for the size of your record, PARSE is going to be the correct way.
Have a look at STARTAT in PARSE, and ensure you know how PARSE works. Experiment if necessary.
If the field from the second STARTAT is non-blank, then you have two (or more) of that particular value. You have fixed-length records, so extend at the end of each record. You only need one byte from the PARSEd field, as it will be just blank or non-blank.
If you arrive at an answer, please post it.
If you have difficulties, please show what you have tried, what went wrong, and what you expected to happen. |
|
| Back to top |
|
 |
ramas.kamal
New User

Joined: 03 Mar 2014 Posts: 22 Location: India
|
|
|
|
| Quote: |
What if there are more that two occurrences?
|
there are few records with value "2651" appearing twice in the same line.
Can you please explain your idea more clearly? |
|
| Back to top |
|
 |
ramas.kamal
New User

Joined: 03 Mar 2014 Posts: 22 Location: India
|
|
|
|
This is what I tried but it written all to output !
Sort Job:
| Code: |
//STEP0001 EXEC PGM=SORT
//SORTIN DD *
@1 GTL0@192009106265149002651
@8 BAS9@878903434789326510300
@4 TULI@4901226513564090045092651
@3 KJML@3090108430651654088453379265100012651
@6 FINA@62651404023405430203419083920
@2 LON0@23901266143500120387002310241029125612661
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC PARSE=(%01=(STARTAT=C'2651',FIXLEN=4),
%02=(STARTAT=C'2651',FIXLEN=4)),
BUILD=(4,6,X,%01,X,%02)
|
Output I got:
| Code: |
GTL0@1 2651 2651
BAS9@8 2651
TULI@4 2651 2651
KJML@3 2651 2651
FINA@6 2651
LON0@2
|
Thanks. |
|
| Back to top |
|
 |
ramas.kamal
New User

Joined: 03 Mar 2014 Posts: 22 Location: India
|
|
|
|
well.....well.......experimented it more and got results with below sort card.
| Code: |
//SYSIN DD *
SORT FIELDS=COPY
INREC PARSE=(%01=(STARTAT=C'2651',FIXLEN=4),
%02=(STARTAT=C'2651',FIXLEN=4)),
BUILD=(1,49,2X,%01,%02)
OUTFIL INCLUDE=(56,4,CH,EQ,C'2651'),BUILD=(1,49)
|
Thanks. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Good you got there. Without INCLUDE= or OMIT= everything will appear on OUTFIL, so you need one of those.
Now we can tidy things a little:
| Code: |
SORT FIELDS=COPY
INREC PARSE=(%=(STARTAT=C'2651',FIXLEN=4),
%01=(STARTAT=C'2651',FIXLEN=1)),
BUILD=(1,49,%01)
OUTFIL OMIT=(50,1,CH,EQ,C' '),BUILD=(1,49) |
You shouldn't need two PARSEd fields. If you are going to use a field, give it a %nn, if you are just using it for positioning, give it a simple %.
From the second PARSE, all you are interested in is when a value was found. If a value was not found, then the PARSEd result with a length of 1 will be space. If a value was found (that value being 2651) then the length of 1 will give "2", which is non-blank.
The first part of the PARSE locates 2651 if present, and advances the parse pointer by four bytes.
The second part of the PARSE locates a second 2651 if present, and allows you to reference the first byte found, by name (%01 here).
Ensure that you test with consecutive "2651"s and more than two on the same record. |
|
| Back to top |
|
 |
ramas.kamal
New User

Joined: 03 Mar 2014 Posts: 22 Location: India
|
|
|
|
| Bill, thanks for explaining the concept. Very useful. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|