Need help in JCL string search

In this Mainframe Forum - You can post your queries on JCL, OS/390 JCL, MVS JCL, z/OS JCL, JES2 & JES3

Moderators: Frank Yaeger, DikDude, Moderator Group

Post Reply
varad.raikar
Member
Posts: 6
Joined: Tue Oct 06, 2015 12:13 pm

Need help in JCL string search

Post by varad.raikar » Thu Nov 26, 2015 1:44 pm

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

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Thu Nov 26, 2015 7:03 pm

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)) 

varad.raikar
Member
Posts: 6
Joined: Tue Oct 06, 2015 12:13 pm

Post by varad.raikar » Thu Nov 26, 2015 11:29 pm

That worked!!. Thanks william.

Wat if the scenario is
Input
Key1 | capgemini 02013-7654 india01
Key2 | morgan stanley 02156-8954 ny01

how do i get the output as
Key1 | 02013-7654
Key2 | 02156-8954

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Fri Nov 27, 2015 7:41 pm

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.

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?

varad.raikar
Member
Posts: 6
Joined: Tue Oct 06, 2015 12:13 pm

Post by varad.raikar » Fri Nov 27, 2015 10:45 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).

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Mon Nov 30, 2015 5:34 pm

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".

academyindia4

Topic deleted by Admin

Post by academyindia4 » Tue Jan 19, 2016 7:15 pm

<< Content deleted By Admin >>

Post Reply

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



Other References
Mainframe Tools and others