Include only part of input in output.
-
Seema Jain
- New Member
- Posts: 6
- Joined: Sun Dec 20, 2015 11:58 pm
Include only part of input in output.
If I have an input file containing data like 12345578, and I want the output to include only 5578, what would the logic for this be in COBOL?
Re: Include only part of input in output.
Hello.
There are a couple of ways of doing it, assuming that everything is working on fixed positions.
The first is that you can split the input field into two parts, for example:
You then move WA-INPUT-FIELD-END to the output record.
The alternative is to substring the field in a MOVE statement:
which will copy four characters from WA-INPUT-FIELD starting at position five to WA-OUTPUT-FIELD.
There are a couple of ways of doing it, assuming that everything is working on fixed positions.
The first is that you can split the input field into two parts, for example:
Code: Select all
01 WA-INPUT-RECORD.
03 WA-INPUT-FIELD.
05 WA-INPUT-FIELD-START PIC X(4).
05 WA-INPUT-FIELD-END PIC X(4).
03 FILLER PIC X(72).The alternative is to substring the field in a MOVE statement:
Code: Select all
MOVE WA-INPUT-FIELD (5:4) TO WA-OUTPUT-FIELD-
Seema Jain
- New Member
- Posts: 6
- Joined: Sun Dec 20, 2015 11:58 pm
Re: Include only part of input in output.
zum13
The alternative is to substring the field in a MOVE statement:
which will copy four characters from WA-INPUT-FIELD starting at position five to WA-OUTPUT-FIELD.Code: Select all
MOVE WA-INPUT-FIELD (5:4) TO WA-OUTPUT-FIELD
Thank you zum13. I've used this, will this work for Variable records also?
Re: Include only part of input in output.
Yes, it will work, although it is incumbent upon you to make sure that the thing you are substringing is within the length of the current record otherwise you may well get some odd results!
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute