View previous topic :: View next topic
|
Author |
Message |
Nish84
New User
Joined: 03 Oct 2016 Posts: 6 Location: India
|
|
|
|
Hi.. My requirement is to generate a pipe delimited dataset by reformatting a normal fixed-length input file. The output dataset has around 60 fields, as below.
Code: |
|ABC|12.99|DEF GHI JKLMN|34569999000|.......... |
If one of the input fields have trailing spaces, I am supposed to trim them. If an input field does not contain any value, I am supposed to represent the field as ||, without any spaces in between.
I understand that checking each input field and moving only the bytes with actual data using reference modification is an option. However, since there are 60 such fields, checking each field individually and moving the data to the output makes my code a bit too long.
Is there any other way to go about it? Any pointer will be of great help. Thanks!
Code'd |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
What does the input look like for that output record? Use the code tags so that we can see the actual spaces which the forum software would otherwise strip out. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Nish84 wrote: |
However, since there are 60 such fields, checking each field individually and moving the data to the output makes my code a bit too long. |
And does the compiler complain about long code? Or are you just too lazy to copy the code 59 times and change the field names?
Ever thought about writing a subroutine? Or maybe your organisation already has one? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
where are You facing problems, the logic or the coding ? |
|
Back to top |
|
|
Nish84
New User
Joined: 03 Oct 2016 Posts: 6 Location: India
|
|
|
|
Thank you for the quick response!
The input record would be something like this, where only a subset of the input fields are to be populated into the output. In addition, some of the input fields would contain trailing spaces and some would contain only blank values:
Code: |
HIJLK 12.99 ABC 18908.6770 DEF GHI JKLMN 234 34569999000 ......... |
I do not mind copy pasting, but for the fact that it would affect code readability Writing a sub-routine is also fine (moving each field into the output record using reference modification and calling the routine to remove unwanted spaces). However, there would be 60 calls to the sub-routine, one after each MOVE statement. This is what I plan on doing if there isn't an alternative.
My query was to check if the coding can be done in a simpler way, using something like the INSPECT statement. Please let me know if you need further details. Thanks! |
|
Back to top |
|
|
Nish84
New User
Joined: 03 Oct 2016 Posts: 6 Location: India
|
|
|
|
Apologies, I missed to add a detail.
As an alternative to using reference modification, I was trying to check if the fields could be moved AS IS from the input dataset to the output and later have the unwanted spaces removed in one go, using a COBOL command or via a SORT step. Any occurrence of more than one space consecutively is to be removed. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
What about leading spaces and embedded spaces? |
|
Back to top |
|
|
Nish84
New User
Joined: 03 Oct 2016 Posts: 6 Location: India
|
|
|
|
The chances of having leading spaces is low. However, if present, the requirement is that any occurrence of more than one consecutive spaces are to be removed. In case of a non-populated field, the delimiters should appear one after the other, without a single space.
Thanks! |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Nish84 wrote: |
However, there would be 60 calls to the sub-routine, one after each MOVE statement. This is what I plan on doing if there isn't an alternative. |
Sheesh, 60 calls...
In a real language, like PL/I:
Code: |
outrec = trim(field1) || '|';
.
.
.
outrec = outrec || trim(field60);
|
Perfectly readable... |
|
Back to top |
|
|
Nish84
New User
Joined: 03 Oct 2016 Posts: 6 Location: India
|
|
|
|
@ enrico - Thank you, I will try this out..
@ prino - I wish it were that simple too. However, that doesn't seem to be the case |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
if instead of complaining about the 60 moves, and waiting for a forum reply
You had started coding, by now You' d have completed the task |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
If the input data is in fixed positions then it is very simple in DFSort - parse out each field based on position, squeeze and combine each required field with pipe symbol in between to create your output record. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
1.
Quote: |
My query was to check if the coding can be done in a simpler way, using something like the INSPECT statement. |
of course, read yourself
Code: |
MOVE FUNCTION REVERSE(INPUT) TO INPUT-R.
INSPECT INPUT-R TALLYING CNTR FOR LEADING SPACES.
COMPUTE INP-LEN = LENGTH OF INPUT-R - CNTR.
INPUT-TRIM = MOVE INPUT(1:INP-LEN) |
2. Tell us the source of the data under the pipes?
3.Answer to 2 is DB2 then you can do in the select itself else let us know if you can make this cobol-db2 program as in one select from sysibm.sysdummy1 you can make all 60 in good shape.
4.use SORT SQZ/PARSE as told by Enrico.
In short there are many simple ways, so that beg me to only question; How far you willing to move your legs? |
|
Back to top |
|
|
Nish84
New User
Joined: 03 Oct 2016 Posts: 6 Location: India
|
|
|
|
Thank you all for your responses! Sorry for the late reply, I was off sick and had quite a bit of work to catch up on when I got back
The destination system receiving the feed from us mentioned later that they would require one space between pipes if a field is empty. So what I finally did was to move the input data to into fixed positions in the output record using a program (used a program instead of a PARSE as there were a few manipulations to be done on some of the fields) and then a SORT SQZ to remove consecutive spaces.
Code: |
OPTION COPY
INREC BUILD=(1,3000,SQZ=(SHIFT=LEFT,MID=C' '))
|
And for the record, I wasn't sitting idle waiting for the forum reply. There were n number of other things being worked upon in parallel
As I have been out of touch with mainframe for a while, I was only checking if there were methods more efficient than mine to achieve my requirement.
Thank you once again! |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Great!! thanks. |
|
Back to top |
|
|
jasorn Warnings : 1 Active User
Joined: 12 Jul 2006 Posts: 191 Location: USA
|
|
|
|
This is how I do this, too.
Rohit Umarjikar wrote: |
1.
Quote: |
My query was to check if the coding can be done in a simpler way, using something like the INSPECT statement. |
of course, read yourself
Code: |
MOVE FUNCTION REVERSE(INPUT) TO INPUT-R.
INSPECT INPUT-R TALLYING CNTR FOR LEADING SPACES.
COMPUTE INP-LEN = LENGTH OF INPUT-R - CNTR.
INPUT-TRIM = MOVE INPUT(1:INP-LEN) |
2. Tell us the source of the data under the pipes?
3.Answer to 2 is DB2 then you can do in the select itself else let us know if you can make this cobol-db2 program as in one select from sysibm.sysdummy1 you can make all 60 in good shape.
4.use SORT SQZ/PARSE as told by Enrico.
In short there are many simple ways, so that beg me to only question; How far you willing to move your legs? |
|
|
Back to top |
|
|
|