OUTREC with a searched value?
Moderators: Frank Yaeger, Moderator Group
OUTREC with a searched value?
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
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
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
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.
Before asking for help here, I already checked DFSORT/ICETOOL manuals, but i can't find a simple and optimized solutionStart with the DFSORT Getting Started manual.
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?
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
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".
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".
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
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
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 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).
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).
ok, thank you!
I've tried with PARSE command (my first time that I use it ), but I have some questions...
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...
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?
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?)
output (OK) :
MY OUT IS: AA;
MY OUT IS: BB;
MY OUT IS: 00;
I've tried with PARSE command (my first time that I use it ), but I have some questions...
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';')
..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=(WHEN=(3,20,SS,EQ,C'001'),
PARSE=(%01=(STARTAFT=C'001',FIXLEN=02)),
BUILD=(1:C'MY OUT IS: ',%01,C';'))
..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=(WHEN=(3,20,SS,EQ,C'001'),
PARSE=(%01=(STARTAFT=C'001',FIXLEN=02)),
BUILD=(1:C'MY OUT IS: ',%01,C';')),
IFTHEN=(WHEN=(3,20,SS,NE,C'001'),
BUILD=(1:C'MY OUT IS: ',C'00',C';'))
MY OUT IS: AA;
MY OUT IS: BB;
MY OUT IS: 00;
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
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.
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.
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