I have a file with following data. Lrecl -50
Key1 | capgemini 02013-7654
Key2 | morgan stanley 02156-8954
I need output as
Key1 | 02013-7654
Key2 | 02156-8954
Please help me out
Need help in JCL string search
Moderators: Frank Yaeger, DikDude, Moderator Group
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
The first part of your data is in a fixed position, the thing is to get the final part also in a fixed position. You can use JFY with SHIFT=RIGHT to do that. Once you've got all the data you want in fixed positions, it is simple with BUILD.
Code: Select all
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(51:7,44,JFY=(SHIFT=RIGHT))),
IFTHEN=(WHEN=INIT,
BUILD=(1,7,86,9))
-
- Member
- Posts: 6
- Joined: Tue Oct 06, 2015 12:13 pm
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
The you use PARSE, to find the "-" and pick up that and the four characters after it, and then set the parse-pointer back 10 and pick up the first five characters.
This assumes that you don't have a "-" anywhere else prior to that. Not always true for a name.
Is there anything common in that last item? Always ending in 01?
This assumes that you don't have a "-" anywhere else prior to that. Not always true for a name.
Code: Select all
OPTION COPY
INREC PARSE=(%01=(STARTAT=C'-',FIXLEN=5),
%02=(SUBPOS=10,FIXLEN=5)),
BUILD=(1,7,%02,%01)
Is there anything common in that last item? Always ending in 01?
-
- Member
- Posts: 6
- Joined: Tue Oct 06, 2015 12:13 pm
No. It doesn't always end with 01. And key1 and key2 that i have mentioned is actually time stamp. so there are "-" elsewhere too.Only thing that is common in all the records is that the output i need contains "00000-0000" i.e, first five bytes and last four bytes are always numbers. So is there anything that could trace this pattern and get me output along with key1(timestamp).
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
With a variable number of variable-length data items (you could have A E I O U Incorporated, you could have dashes, numbers) and with variable-length data following what you want to extract, it is not going to be convenient.
SORT has no loop-constructs. Although your field is second-from-the-end, that, as a PARSEd field, could be number 10, or number 81.
What is the maximum length of that final field, and how many fields may precede the data you want to extract such that the minimum data-lengths would add up to that length? Then you JFY right, chop off enough to guarantee having your data, and "manually" (coded-out) PARSE to find which field is second-from-last (field after last would be blank).
It's the penalty of not having delimiters, or fixed-length fields or a fixed number of items. Basically a design fault. Although "languages" can find the second-to-last in this case, in others you'd have trouble if the final field contained "words".
SORT has no loop-constructs. Although your field is second-from-the-end, that, as a PARSEd field, could be number 10, or number 81.
What is the maximum length of that final field, and how many fields may precede the data you want to extract such that the minimum data-lengths would add up to that length? Then you JFY right, chop off enough to guarantee having your data, and "manually" (coded-out) PARSE to find which field is second-from-last (field after last would be blank).
It's the penalty of not having delimiters, or fixed-length fields or a fixed number of items. Basically a design fault. Although "languages" can find the second-to-last in this case, in others you'd have trouble if the final field contained "words".
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page