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

STRING functionality to fetch the few columns of a record


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

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Wed Oct 01, 2008 4:22 pm
Reply with quote

Hi,

I have to fetch the few columns of a record from a table and write it to a file seperating each field by commas.
For e.g. I have a table as follows,

EmpNo ACC Role Amount Description
------------------------------------------------------------------
0123 00234 SE 00100.00 Software
0456 00456 WC 00200.00 worker

I want to write the data to a file as follows,

123,234,SE,100.00,Software
456,456,WC,200.00,worker

Some fields are packed decimals so I have moved those fields to numeric and then to alphanumeric and I have used STRING function to create these records, but I'm not able to remove the zeroes before the fields.

Please let me know is there any way that I could trim the leading zeroes after using STRING function and before writing to the file?

Thanks,
Gomathi.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Oct 01, 2008 8:11 pm
Reply with quote

Hello,

Quote:
Please let me know is there any way that I could trim the leading zeroes after using STRING function and before writing to the file?
You will probably need to do the modificatons before issuing the string. Once you have the comma-delimited string, it will be more tedious and use much more system resources to then remove the leading zeroes.

If there is a need to remove the leading zeros (they shouldn't hurt anything, so you might just leave them), you would be better served doing this before the STRING.
Back to top
View user's profile Send private message
Ajay Baghel

Active User


Joined: 25 Apr 2007
Posts: 206
Location: Bangalore

PostPosted: Wed Oct 01, 2008 8:25 pm
Reply with quote

Quote:
Please let me know is there any way that I could trim the leading zeroes after using STRING function and before writing to the file?


I think you can move your fields to numeric edited fields with edit mask of Z (suppresses leading Zeros.)
and then use these fields for writing to file.

-Ajay
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Oct 01, 2008 9:21 pm
Reply with quote

Quote:

I think you can move your fields to numeric edited fields with edit mask of Z (suppresses leading Zeros.)
and then use these fields for writing to file.


and when the OP wants to trim the spaces?
Back to top
View user's profile Send private message
gomu_mm

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Fri Oct 03, 2008 9:27 am
Reply with quote

Hi,

thanks for the suggestions.

as for as i know, Z is used only for displaying purpose and it does not remove the leading zeroes. in this case i wil not display the values straight away but move to alphanumeric to perform STRING function.

i just thout of picking the values as soon as i pick it from table and trim them before moving to the alphanumeric field.

thanks,
gomathi.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Oct 03, 2008 9:36 am
Reply with quote

Hello,

Quote:
as for as i know, Z is used only for displaying purpose and it does not remove the leading zeroes.
What you know is incomplete/incorrect. . . The purpose of Z is to remove leading zeros - the move to a "Z" field does not know anything about how the result will be used.

Quote:
trim them before moving to the alphanumeric field.
As i mentioned, you needed to remove the leading zeros before the STRING is done.

Have you been able to get the result you want?
Back to top
View user's profile Send private message
gomu_mm

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Wed Dec 03, 2008 9:56 am
Reply with quote

Hi,

I was able to remove the leading zeroes but not the spaces,which was not accepatable in the CSV file. Hence I used the following technique,

V1 - PIC 9(5) ------> Actual variable
V2 - PIC ++++9
V3 - PIC x(5)
V4 - PIC x(5)
V5 - PIC x(5)


MOVE V1 TO V2 -----> 00200 TO ( +200)
MOVE V2 TO V3 -----> ( +200) TO ( +200)
STRING V3 DELIMITED BY '+'
INTO V4, V5 -----> ( +200) TO ( +), (200)

Then I used the variable V5 in my STRING function to create the file. This worked fine.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 03, 2008 10:08 am
Reply with quote

gomu_mm,

Your initial variable was unsigned. Then what's the point in inserting a + sign while editing and then removing the + sign later.
Quote:
STRING V3 DELIMITED BY '+'
Should n't this be an UNSTRING?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Dec 03, 2008 10:28 am
Reply with quote

Hello gomathi,

Good to hear you have it working the way you need icon_smile.gif

As Arun mentioned, unstring seems more likely - i suspect a typo.

Thanks for letting us know,

d
Back to top
View user's profile Send private message
gomu_mm

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Wed Dec 03, 2008 12:20 pm
Reply with quote

Hi,

The only point in inserting the + sign is to use the STRING function to seperate the spaces before the actual value. I have only come across declaration +++9 and ---9 and hence used one of them.

When we move a value 00200 variable to ++++9 variable, there would be one space and +200. Then we use STRING function to split the space and + (delimiting by +) into one variable and the actual value into another variable.

When I use the actual value in the CSV file convertion, I give delimited by space.

Thanks,
Gomathi.
Back to top
View user's profile Send private message
gomu_mm

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Wed Dec 03, 2008 12:21 pm
Reply with quote

Hi dick,

Yes its s typo. It should be UNSTRING.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 03, 2008 12:38 pm
Reply with quote

gomu_mm,

I still believe you could have done the same without an UNSTRING.
Code:
05  NUM-1   PIC  9(05) VALUE   200.
05  NUM-E   PIC  Z(05).
05  NUM-X REDEFINES NUM-E  PIC  X(05).

MOVE NUM-1 TO NUM-E

DISPLAY 'NUM-1    :' NUM-1
DISPLAY 'NUM-E    :' NUM-E
DISPLAY 'NUM-X    :' NUM-X

Code:
NUM-1    :00200
NUM-E    :  200
NUM-X    :  200
Back to top
View user's profile Send private message
gomu_mm

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Wed Dec 03, 2008 2:33 pm
Reply with quote

Yes Arun. I accept Z replaces the zeroes with spaces. But that was not the task. I should create a CSV file with the data. when I attempted to create a CSV file, the value was prefixed with spaces,

0123 00234 SE 00100.00 Software

would look like (prefixed with spaces)

123, 234,SE, 100.00,Software

So I had to edit the number(remove the spaces) before preparing the record as comma seperated.

Thanks,
Gomathi.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 03, 2008 2:43 pm
Reply with quote

gomu_mm,

I am not saying that moving to edited field will solve all your problems. What I tried to point out was that, moving to ++++9 , doing an UNSTRING and then finally getting the output(with leading spaces) in X(5) could be just achieved by moving into a Z(5). Why unnecessary overhead of doing an UNSTRING?
Back to top
View user's profile Send private message
gomu_mm

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Wed Dec 03, 2008 3:21 pm
Reply with quote

Ok but how will you remove the space in STRING function?
If it is at last then we could give DELIMITED BY SPACES.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Dec 03, 2008 3:33 pm
Reply with quote

gomu_mm,

How about counting the leading ZEROS using an INSPECT and then using reference modification to do a MOVE from the first non-zero digit?
Back to top
View user's profile Send private message
gomu_mm

New User


Joined: 05 Dec 2006
Posts: 19
Location: Chennai

PostPosted: Wed Dec 03, 2008 3:47 pm
Reply with quote

I thought about this before but it was becoming very complex and hence found this way the easier one.
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top