Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

To trim spaces in a pipe delimited dataset

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: To trim spaces in a pipe delimited dataset
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: 1715
Location: UK

PostPosted: Mon Oct 10, 2016 2:55 pm    Post subject:
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

Active Member


Joined: 07 Feb 2009
Posts: 984
Location: Oostende, Belgium

PostPosted: Mon Oct 10, 2016 3:29 pm    Post subject: Re: To trim spaces in a pipe delimited dataset
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 10, 2016 3:41 pm    Post subject: Reply to: To trim spaces in a pipe delimited dataset
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    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7234

PostPosted: Mon Oct 10, 2016 4:36 pm    Post subject: Reply to: To trim spaces in a pipe delimited dataset
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 10, 2016 5:17 pm    Post subject: Reply to: To trim spaces in a pipe delimited dataset
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
http://www-01.ibm.com/support/docview.wss?uid=isg3T7000094
Back to top
View user's profile Send private message
prino

Active Member


Joined: 07 Feb 2009
Posts: 984
Location: Oostende, Belgium

PostPosted: Mon Oct 10, 2016 6:58 pm    Post subject:
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 10, 2016 8:26 pm    Post subject: Reply to: To trim spaces in a pipe delimited dataset
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: 1715
Location: UK

PostPosted: Mon Oct 10, 2016 9:51 pm    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Mon Oct 10, 2016 10:38 pm    Post subject:
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    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

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

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

Active User


Joined: 12 Jul 2006
Posts: 153
Location: USA

PostPosted: Sat Nov 19, 2016 6:25 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts FTP - JCL failed while passing FTP co... Suneetha1612 JCL & VSAM 12 Wed Nov 16, 2016 7:33 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Allocate dataset withour BLKSIZE Susanta CLIST & REXX 2 Thu Sep 22, 2016 11:51 am
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us