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

Regarding Unstring


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

New User


Joined: 21 Jan 2006
Posts: 48
Location: india

PostPosted: Thu Mar 20, 2008 1:32 pm
Reply with quote

I have doubt regarding unstring verb:-

I have a two fields on DB2 table
A value -> Agent Smith
B value -> Community loan and Trust

In code we are formatting this name and it is breaking both values when there is spaces:-
Inspect TV-326-CDD-Fld-Vl-Tx
Converting WS-Lower-Case To WS-Upper-Case -->giving AGENT SMITH

Unstring TV-326-CDD-Fld-Vl-Tx
Delimited By Spaces
Into TV-326-Frst-Nm --- give AGENT
Count In TV-326-Sub-1-Sq
End-Unstring

same for second element B -> Community loan and Trust
Inspect TV-326-CDD-Fld-Vl-1-Tx
Converting WS-Lower-Case To WS-Upper-Case

Unstring TV-326-CDD-Fld-Vl-1-Tx
Delimited By Spaces
Into TV-326-Last-Nm --- give COMMUNITY
Count In TV-326-Sub-2-Sq
End-Unstring

finnally
Move TV-326-Last-Nm
To TV-326-Frmt-Nm (TV-326-Sub-1-Sq:TV-326-Sub-2-Sq)

so getting final o/p as AGENT COMMUNITY

BUT my reqr is to get:- AGENT SMITH COMMUNITY LOAN AND TRUST
so how can i modify on DB2 table to get this o/p?
or is there any code change suggestion to display this string?Thanks.....
Back to top
View user's profile Send private message
shrivatsa
Warnings : 1

Active User


Joined: 17 Mar 2006
Posts: 174
Location: Bangalore

PostPosted: Thu Mar 20, 2008 2:19 pm
Reply with quote

If I understand your problem correctly..
After converting into upper case why you are using UNSTRING
Use STRING to CONCATE the two fileds
Back to top
View user's profile Send private message
jackal
Currently Banned

New User


Joined: 21 Jan 2006
Posts: 48
Location: india

PostPosted: Thu Mar 20, 2008 3:07 pm
Reply with quote

Shrivatsa,
Actual code is in prod i cannot modify with having PM permission...is there any way to get the expected results?Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Mar 20, 2008 3:27 pm
Reply with quote

only reason you would want to unstring and then string is because of the possibility of double spaces between words within a column.


if you don't have any imbedded double spaces between words in each of the two columns, why don't you use trim and concatenate within the sql.

if you have 'adam smite ' in one column, (two spaces between adam and smite) then you will need to unstring to left justify.

If you have variable number of words in each column, you need to clean up your table, (remove all double spaces between words within a column) and use the trim/concatenate sql.

If you can not clean up the table and can have a variable number of words within a column, then the unstring, string logic becomes tedious, even though you could do it with an internal cobol table.-
Back to top
View user's profile Send private message
Thyaga

New User


Joined: 19 Mar 2008
Posts: 2
Location: Chennai

PostPosted: Thu Mar 20, 2008 3:52 pm
Reply with quote

U can use string,instead of unstring.
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Thu Mar 20, 2008 4:42 pm
Reply with quote

Hi jackal,
The below code may help you.

Code:

STRING
   A
  DELIMITED BY SIZE
   '  '
   B
   DELIMITED BY SIZE
INTO
   WS-RESULT

END-STRING

INSPECT WS-RESULT                         
            CONVERTING 'abcdefghijklmnopqrstuvwxyz'
                    TO 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Mar 20, 2008 4:54 pm
Reply with quote

In Rajesh S's example, if A contains more that 1 trailing space, the solution is not applicable for the OP's requirement.


If you can not trim and concatenate with the sql, you will need to unstring and then string the multi-parts generated by the unstring and include a space between.

I believe that the 'DELIMITED BY' phrase is required. thus, Rajesh_mbt's solution will not even compile. If it is an optional phrase, then there must be a default, which must be 'SIZE'.
Back to top
View user's profile Send private message
jackal
Currently Banned

New User


Joined: 21 Jan 2006
Posts: 48
Location: india

PostPosted: Thu Mar 20, 2008 4:54 pm
Reply with quote

Thanks alott!!!!
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Mar 20, 2008 5:43 pm
Reply with quote

Is the UPPER-CASE function in COBOL completely unknown? You can eliminate the costly INSPECT if you use UPPER(columnname) on your SQL or use MOVE UPPER-CASE(TV-326-CDD-Fld-Vl-Tx) to TV-326-CDD-Fld-Vl-Tx
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Mar 20, 2008 6:12 pm
Reply with quote

How about
Code:

SELECT UCASE(TRIM(A) CONCAT ' ' CONCAT TRIM(B))


That would get you the two values already combined and uppercased.
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Thu Mar 20, 2008 6:35 pm
Reply with quote

Hi Dick Brenholtz
I dont understand what is the problem with my code. I've tested the program and worked fine. Why do you assume that there would be a trailing space before A icon_confused.gif ? In jackal query that he had not mentioned anything about trailing space. The sample code has been posted based on what he required for his query icon_cry.gif
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 Handling the numeric data in unstring... COBOL Programming 18
No new posts Unstring COBOL Programming 4
No new posts UNSTRING problem COBOL Programming 3
No new posts UNSTRING a big string COBOL Programming 16
No new posts Unstring list of values into an array. COBOL Programming 8
Search our Forums:

Back to Top