IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To trim spaces in a pipe delimited dataset


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Nish84

New User


Joined: 03 Oct 2016
Posts: 6
Location: India

PostPosted: Mon Oct 10, 2016 1:54 pm
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Mon Oct 10, 2016 2:55 pm
Reply with quote

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
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Mon Oct 10, 2016 3:29 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 10, 2016 3:41 pm
Reply with quote

where are You facing problems, the logic or the coding ?
Back to top
View user's profile Send private message
Nish84

New User


Joined: 03 Oct 2016
Posts: 6
Location: India

PostPosted: Mon Oct 10, 2016 4:25 pm
Reply with quote

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 icon_smile.gif 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
View user's profile Send private message
Nish84

New User


Joined: 03 Oct 2016
Posts: 6
Location: India

PostPosted: Mon Oct 10, 2016 4:35 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Oct 10, 2016 4:36 pm
Reply with quote

What about leading spaces and embedded spaces?
Back to top
View user's profile Send private message
Nish84

New User


Joined: 03 Oct 2016
Posts: 6
Location: India

PostPosted: Mon Oct 10, 2016 4:51 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 10, 2016 5:17 pm
Reply with quote

why not consider a sort with a <mass> build and squeeze on the full record ?

see here on how to construct and deconstruct CSV records
www-01.ibm.com/support/docview.wss?uid=isg3T7000094
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Mon Oct 10, 2016 6:58 pm
Reply with quote

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
View user's profile Send private message
Nish84

New User


Joined: 03 Oct 2016
Posts: 6
Location: India

PostPosted: Mon Oct 10, 2016 8:21 pm
Reply with quote

@ 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 icon_sad.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 10, 2016 8:26 pm
Reply with quote

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 icon_evil.gif
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Mon Oct 10, 2016 9:51 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Mon Oct 10, 2016 10:38 pm
Reply with quote

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
View user's profile Send private message
Nish84

New User


Joined: 03 Oct 2016
Posts: 6
Location: India

PostPosted: Fri Oct 21, 2016 1:00 am
Reply with quote

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 icon_smile.gif

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 icon_biggrin.gif
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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Sat Oct 22, 2016 1:07 am
Reply with quote

Great!! thanks.
Back to top
View user's profile Send private message
jasorn
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Sat Nov 19, 2016 6:25 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Allocated cylinders of a dataset DB2 12
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
Search our Forums:

Back to Top