OUTREC with a searched value?

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
sidhe
Member
Posts: 5
Joined: Wed Aug 12, 2015 9:46 pm
Location: Milan (ITALY)

OUTREC with a searched value?

Post by sidhe » Thu Aug 13, 2015 12:47 pm

Hi All,
my INPUT is a fixed lenght file. The records contain a table occurs 4 times:
code pic 9(3)
myvalue pic x(2)

in OUTPUT if the code = 001 i need the text value, when other i need zero. I know the position of the table into the record, but I don't know the position of the 001 code into the table.

Example of input file:
..001AA007BB003DD009AA...
..008CC002CC001BB007DD...
..003DD005AA002CC006BB...

Example of the output that i want:
...AA..
...BB..
...00..

Question1: in your opinion, how can I do it?
Question2: in my sort I already have an OUTREC to format the other part of the output record, may I do all this at once in the same step of my outrec or i must create a new step?

Please, help me, thank you :roll:

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

Post by William Collins » Thu Aug 13, 2015 9:34 pm

You only have four possibilities, so you can use OR on an INCLUDE= on OUTFIL.

INREC/OUTREC and OUTFIL can be extended to multiple statements easily with various flavours of IFTHEN.

Start with the DFSORT Getting Started manual.

sidhe
Member
Posts: 5
Joined: Wed Aug 12, 2015 9:46 pm
Location: Milan (ITALY)

Post by sidhe » Thu Aug 13, 2015 10:44 pm

William Collins wrote:you can use OR on an INCLUDE= on OUTFIL

Thanks for your answer, but I don't think so.
I don't need to filter the input removing unnecessary records, my output must have the same number of record of my input, so I think that OMIT/INCLUDE cannot resolve my problem.
Start with the DFSORT Getting Started manual.
Before asking for help here, I already checked DFSORT/ICETOOL manuals, but i can't find a simple and optimized solution :)

Now I've done with an OUTREC to format the other part of the record, and after it an OUTFIL with multiple IFTHEN to test the code in all the possible position.
It works, but I don't like it...
Adding to my OUTREC the OUTFIL can extend the statement, but does it read again all the file?

I was hoping to find an easiest solution...
any other ideas?

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

Post by William Collins » Thu Aug 13, 2015 11:38 pm

Sorry, I misread your question.

So if a certain position contains 001, you need a certain other position to be left as it is (need the text value)? Else blank? Can there be more than one 001 on the same record?

If you post what you have, it can probably all be done on INREC (unless you have a significant SORT as well).

It'll also make it clearer what you are having problems with.

SORT is not a general-purpose language as such. The aim is optimisation of processing, not short-hand in coding, but we can make it as clear as possible. It has no looping constructs, so you have to code things out if you process something in an "occurs".

sidhe
Member
Posts: 5
Joined: Wed Aug 12, 2015 9:46 pm
Location: Milan (ITALY)

Post by sidhe » Fri Aug 14, 2015 12:53 am

I have to extract from a large file only parts of strings (i've used OUTREC BUILD), changing some values (i've used CHANGE command into the same OUTREC), totalizing some values (i've used ADD command into the same OUTREC), formatting numeric fields (i've used EDIT into the same OUTREC), etc...

My problem is that I'd like to string (with the same OUTREC) the value after the position of the code 001.
I know only the range of position where 001 can be (from xx to yy), but I don't know exactly where the 001 starts, because the 001 doesn't start always in the same position, and in some record the 001 there isn't.
So i need something like this:
- evaluate only from position xx and pos yy of the record
- into this, find the position of the C'001'
- when find it, take out the value that start after the C'001' (need the 2 bytes after the C'001')
- when other (if not find the C'001' from xx to yy) take the default fixed value C'00'

In the first message above, I had written a simplified example of my input and the output I would like to have.

Example of input file:
..001AA007BB003DD009AA...
..008CC002CC001BB007DD...
..003DD005AA002CC006BB...

Example of the output that i want:
...AA..
...BB..
...00..

Thanks for your attention :roll: :)

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

Post by William Collins » Fri Aug 14, 2015 1:11 am

Still no code from you :-)

To find the data, in what looks like four different fixed positions, and if you can guarantee no false hits, you can use PARSE. Tell PARSE where to start and end, and use STARTAFT=C'001' with FIXLEN=2. If the 001 exists in one of the four places on that record (remember, you have to guarantee no false hits) then the PARSEd item will contain the two bytes you want, else it will be two spaces.

You can use PARSE and BUILD on the same statement.

If you can't guarantee no false hits, you'll need four IFTHEN=(WHEN=(logicalexpression) to test the four locations and OVERLAY the value you want (or possibly BUILD).

sidhe
Member
Posts: 5
Joined: Wed Aug 12, 2015 9:46 pm
Location: Milan (ITALY)

Post by sidhe » Fri Aug 14, 2015 7:37 pm

ok, thank you!
I've tried with PARSE command (my first time that I use it :D ), but I have some questions... :roll:

Solution 1 - only PARSE: it doesn't work when there is not the C'001' in my range, but there is the same string C'001' in other part of the file
Question 1: with parameter ABSPOS, I can specify the position where start the evaluation, but HOW can I tell him the position where to STOP evaluation? because I haven't a delimiter like point or semicolon or space for the ENDBEFR/ENDAT...

Code: Select all

OUTREC          PARSE=(%01=(STARTAFT=C'001',FIXLEN=02)), 
                BUILD=(1:C'MY OUT IS: ',%01,C';')        
Example of input :
..001AA007BB003DD009AA...other data....0000001XXXX0055001
..008CC002CC001BB007DD...other data....0000022XXXX0063541
..003DD005AA002CC006BB...other data....0000001XXXX0001777
output:
MY OUT IS: AA;
MY OUT IS: BB;
MY OUT IS: XX; <== ko, it takes string out of range to evaluate


Solution 2 - IFTHEN + PARSE : it doesn't work because no action done when there is not the C'001' in my range
Question 2: is it possible to give him a default value (C'00') to use when not found the C'001' in the range?

Code: Select all

OUTREC IFOUTLEN=50,                                      
         IFTHEN=&#40;WHEN=&#40;3,20,SS,EQ,C'001'&#41;,               
                 PARSE=&#40;%01=&#40;STARTAFT=C'001',FIXLEN=02&#41;&#41;,
                 BUILD=&#40;1&#58;C'MY OUT IS&#58; ',%01,C';'&#41;&#41;      
Example of input :
..001AA007BB003DD009AA...other data....0000001XXXX0055001
..008CC002CC001BB007DD...other data....0000022XXXX0063541
..003DD005AA002CC006BB...other data....0000001XXXX0001777
output:
MY OUT IS: AA;
MY OUT IS: BB;
..003DD005AA002CC006BB...other data....0000001XXXX <== ko


Solution 3 - IFTHEN + PARSE+ IFTHEN: it works BUT I repeated 2 times the command BUILD
Question 3: this is a simplified example but my real case is more complicated, and my BUILD actually contains many more parameters.. so: is it possible to write only 1 BUILD instead of 1 for each IFTHEN? (how?)

Code: Select all

OUTREC IFOUTLEN=50,                                       
         IFTHEN=&#40;WHEN=&#40;3,20,SS,EQ,C'001'&#41;,                
                 PARSE=&#40;%01=&#40;STARTAFT=C'001',FIXLEN=02&#41;&#41;, 
                 BUILD=&#40;1&#58;C'MY OUT IS&#58; ',%01,C';'&#41;&#41;,      
         IFTHEN=&#40;WHEN=&#40;3,20,SS,NE,C'001'&#41;,                
                 BUILD=&#40;1&#58;C'MY OUT IS&#58; ',C'00',C';'&#41;&#41;     
output (OK) :
MY OUT IS: AA;
MY OUT IS: BB;
MY OUT IS: 00;

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

Post by William Collins » Fri Aug 14, 2015 8:54 pm

Your data turned out to be longer than I thought, I didn't realise the dots (.) represented other-data-of-some-value.

PARSE is going to stop at the end of the record. You have other data, with different values per record, so you can't ENDBEFR.

You can copy the data to the end of the record (temporarily) and PARSE there. With fixed-position data, PARSE is usually not necessary, but for finding one occurrence amongst eight it may be worth it.

With Solution 2, you have used SS, but again you have to be certain about the possibility or not of false hits. The problem is not the default value for the PARSEd field so much as their has not been a BUILD, so your input record is unchanged.

With Solution 3, WHEN=INIT to establish the other data with BUILD and then OVERLAY in your IFTHEN=(WHEN=(logicalexpression) just for the PARSEd field. In your example you could keep the structure the same, except use WHEN=NONE instead of reversing the condition. Because there are no "procedures" of any type, sometimes there is repetition that you'd prefer there not to be.

Reducing the impact of repetition is one of the uses of SORT symbols/SYMNAMES.

BUILD defaults to starting at the first byte of data, so no need for the column on the BUILD.

sidhe
Member
Posts: 5
Joined: Wed Aug 12, 2015 9:46 pm
Location: Milan (ITALY)

Post by sidhe » Mon Aug 17, 2015 9:20 pm

Thank you very much for your help and tips, I've modified my sort code, and now it works fine :wink:

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Jan 25, 2016 9:29 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