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

Using INSPECT logic in COBOL using DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ajeshrn

New User


Joined: 25 Mar 2009
Posts: 78
Location: India

PostPosted: Tue Dec 06, 2011 7:17 pm
Reply with quote

Hi,

We have a scenario where we need to check the value of a column in db2 table and replace the first occurence of the space between words with a comma(,). Can someone suggest on how to achieve this. We are planning to use this query for a one time update on the table.

For example,
Current data in table
Test Name
Test


It should be replaced as below:
Test,Name
Test,
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: Tue Dec 06, 2011 7:33 pm
Reply with quote

INSPECT nice-descriptive-data-name REPLACING FIRST SPACE BY COMMA.
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: Tue Dec 06, 2011 7:56 pm
Reply with quote

Ahh...

You mean you want to have some SQL which behaves in the same way as the above?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Dec 06, 2011 8:46 pm
Reply with quote

Code:
update tab1
set col1 =
case when (posstr(strip(col1),' ') > 0 ) then
     substr(col1,1,posstr(remarks,' ') - 1) || ',' ||
     substr(col1,posstr(remarks,' ') + 1)
else col1
end
Back to top
View user's profile Send private message
ajeshrn

New User


Joined: 25 Mar 2009
Posts: 78
Location: India

PostPosted: Thu Dec 08, 2011 4:42 pm
Reply with quote

Thanks a lot...It works and we were able to successfully update the table value with , for the first occurance of space... icon_smile.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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top