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
 

 

STRING functionality to fetch the few columns of a record

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: STRING functionality to fetch the few columns of a record
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

Site Director


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

PostPosted: Wed Oct 01, 2008 8:11 pm    Post subject:
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: 205
Location: Bangalore

PostPosted: Wed Oct 01, 2008 8:25 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: STRING functionality
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

Site Director


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

PostPosted: Fri Oct 03, 2008 9:36 am    Post subject:
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    Post subject:
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: 2158
Location: @my desk

PostPosted: Wed Dec 03, 2008 10:08 am    Post subject:
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

Site Director


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

PostPosted: Wed Dec 03, 2008 10:28 am    Post subject: Reply to: STRING functionality
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    Post subject:
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    Post subject:
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: 2158
Location: @my desk

PostPosted: Wed Dec 03, 2008 12:38 pm    Post subject:
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    Post subject:
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: 2158
Location: @my desk

PostPosted: Wed Dec 03, 2008 2:43 pm    Post subject:
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    Post subject:
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: 2158
Location: @my desk

PostPosted: Wed Dec 03, 2008 3:33 pm    Post subject:
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    Post subject:
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    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
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am


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