MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Updating a particular byte of a field in a table

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Tue Nov 08, 2005 2:24 am    Post subject: Updating a particular byte of a field in a table Reply with quote

Hi !!

I want to update the 3rd byte of a character field in a table with character
Back to top
View user's profile Send private message Send e-mail
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Nov 08, 2005 2:59 am    Post subject: Reply with quote

vkphani,

Check this link.
http://www.mvsforums.com/helpboards/viewtopic.php?t=2938&highlight=character+function

Hope it solves your problem,

PS: I am not good in DB2 but I think there is a better solution. Let me see if I can find that for you.

Thanks,
Phantom
Back to top
View user's profile Send private message
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Tue Nov 08, 2005 3:11 am    Post subject: Reply with quote

Yes Phantom,

I too searched for this in the forum. But didn't get any results.
Anyway thanks for the help.
Back to top
View user's profile Send private message Send e-mail
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Nov 08, 2005 3:16 am    Post subject: Reply with quote

vkphani,

I have seen a similar question - long time back. Kolusu had given a solution using column/char functions.

Try if you could do something using the REPLACE function.
http://www.mvsforums.com/helpboards/viewtopic.php?t=4453&highlight=replace

Thanks,
Phantom
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Nov 08, 2005 5:25 am    Post subject: Reply with quote

vkphani,

Try this untested sql

Code:

UPDATE TABLE                         
   SET UPD_COL = SUBSTR(UPD_COL,1,1) CONCAT
                 SUBSTR(UPD_COL,2,1) CONCAT
                 CHAR('A',1)         CONCAT
                 SUBSTR(UPD_COL,4,1) CONCAT
                 SUBSTR(UPD_COL,5,1)       
 ;


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Nov 08, 2005 5:31 am    Post subject: Reply with quote

Kolusu,

I thought (very vaguely remember) I saw some string function to replace a particular position(s) of the string - directly. And you were the one who gave that solution. I don't know where and when I saw that. Isn't there any other way to accomplish this.

Thanks,
Phantom
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Nov 08, 2005 5:35 am    Post subject: Reply with quote

Phantom,

Replace Function works for the entire column and if the string is known. However in this case the 3rd byte is unknown.

I guess you are referring to the solution posted in here

http://www.mvsforums.com/helpboards/viewtopic.php?p=15976#15976


Quote:

I don't know where and when I saw that. Isn't there any other way to accomplish this.


Could be , but at the top of my head right now , I could only think of that

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Tue Nov 08, 2005 5:56 am    Post subject: Reply with quote

Thanks for the help Kolusu.

Kolusu,

Is there any specific reason behind mentioning so many CONCAT statements in the query.

Even the below query works.

Code:
UPDATE TABLE
SET UPD_COL = SUBSTR(UPD_COL,1,2) CONCAT
                      CHAR('A',1) CONCAT
                      SUBSTR(UPD_COL,4,5);
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Nov 08, 2005 6:01 am    Post subject: Reply with quote

Quote:

Is there any specific reason behind mentioning so many CONCAT statements in the query.


Vkphani,

NO reason ! I just got up and was thinking of taking 1 byte at a time and that reflected in my query. Just an early morning blues. Sad

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Tue Nov 08, 2005 6:02 am    Post subject: Reply with quote

Thanks for the help Kolusu.
Back to top
View user's profile Send private message Send e-mail
Rahull
Beginner


Joined: 29 Jan 2004
Posts: 62
Topics: 19

PostPosted: Mon Nov 28, 2005 3:16 pm    Post subject: Reply with quote

How will i do the same(Update any byte) if my column data type is S9(13) COMP-3.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Nov 28, 2005 3:44 pm    Post subject: Reply with quote

Rahull,

If the update column is decimal column , then you need to expand it and then update it.

ex: assume the following data
Code:

Upd_col
-+-----
123456
234567
345678


Now if I want to update the 2 byte of upd_col with a constant 9, then the following sql will give you the desired results.

Code:

UPDATE TABLE                                             
   SET UPD_COL   = DEC(SUBSTR(DIGITS(UPD_COL),1,8)  CONCAT
                       SUBSTR(DIGITS(INT(9)),10,1)  CONCAT   
                       SUBSTR(DIGITS(UPD_COL),10,4))           
 ;                                                     


This will result in

Code:

Upd_col
-+-----
193456.
294567.
395678.


Hope this helps...

Cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group