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 

COMP Data in VARCHAR Field

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


Joined: 14 Feb 2006
Posts: 42
Topics: 22

PostPosted: Thu Oct 13, 2011 7:04 pm    Post subject: COMP Data in VARCHAR Field Reply with quote

Hi

I am in process of doing some data cleanup. And in our shop i found out that a particular table has 2 fields, An INTEGER and a VARCHAR. The data in these fields are quite strange.

The INTEGER field has a 9 digit number and the VARCHAR has the comp representation of the Integer field. For example

Code:
INTEGER              VARCHAR (Hex ON)
37546819             03E4               
                     2CB3


Now some of the rows int he table dont have a entry in the VARCHAR field and my job is to write an update spufi to update the VARCHAR field. How do i write a spufi that satisfies the above criteria.

Upon Further research i found out that the program which does the insert of this data is using a redefines to achieve this result

Code:
05    WS-INTEGER                           PIC 9(09) COMP.
05    WS-VARCHAR      REDEFINES WS-INTEGER PIC X(04).

How can i do this with just a spufi query? Any pointers?
Code:

_________________
Thanks and Regards..
Rajesh
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Oct 13, 2011 8:18 pm    Post subject: Reply with quote

rajeshkoratti,

Try this Untested Sql

Code:

UPDATE TABLE
   SET VARCHAR_COL = 'your update value'
 WHERE INTEGER_COL =  37546819
   ;


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rajeshkoratti
Beginner


Joined: 14 Feb 2006
Posts: 42
Topics: 22

PostPosted: Thu Oct 13, 2011 9:54 pm    Post subject: Reply with quote

Thanks Kolusu

However, I think i wasnt specific enough in my previous post. both the VARCHAR as well as the INTEGER contain the same data. The INTEGER is of 9(9) COMP and the VARCHAR is a redefines of the INETGER.
_________________
Thanks and Regards..
Rajesh
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Thu Oct 13, 2011 11:02 pm    Post subject: Reply with quote

Suggest you write a little bit of code to accomplish this using the samer kind of redefines..

Your organization should want an audit trail of what was changed which would be easy to implement in the code also.
_________________
All the best,

di
Back to top
View user's profile Send private message
GuyC
Supermod


Joined: 27 May 2011
Posts: 35
Topics: 0

PostPosted: Fri Oct 14, 2011 4:32 am    Post subject: Reply with quote

For column i :

Code:
EBCDIC_CHR(mod(i/power(2,24),power(2,8))) ||
EBCDIC_CHR(mod(i/power(2,16),power(2,8))) ||
EBCDIC_CHR(mod(i/power(2, 8),power(2,8))) ||
EBCDIC_CHR(mod(i            ,power(2,8))) )
Back to top
View user's profile Send private message
rajeshkoratti
Beginner


Joined: 14 Feb 2006
Posts: 42
Topics: 22

PostPosted: Fri Oct 14, 2011 9:36 am    Post subject: Reply with quote

Hello GuyC

Please could you explain your solution a bit more..
_________________
Thanks and Regards..
Rajesh
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
rajeshkoratti
Beginner


Joined: 14 Feb 2006
Posts: 42
Topics: 22

PostPosted: Fri Oct 14, 2011 10:24 am    Post subject: Reply with quote

GuyC
I believe this works only for DB2 v 10
_________________
Thanks and Regards..
Rajesh
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Oct 14, 2011 10:50 am    Post subject: Reply with quote

rajeshkoratti,


Are you asking to help setting up the SQL in the program or is this a 1 time data clean up work? If your intention is to have 37546819 in the varchar column then isn't it simple to use the CHAR function?

why can't use CHAR function directly and insert into table?
Code:

INSERT INTO table VALUES(37546819,CHAR(INT(37546819)));


will make both columns have 37546819, 37546819

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri Oct 14, 2011 1:25 pm    Post subject: Reply with quote

Kolusu,

I think what he wants is a 4-byte comp (binary) field in the varchar column.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Oct 14, 2011 3:25 pm    Post subject: Reply with quote

dbzTHEdinosauer wrote:
Kolusu,

I think what he wants is a 4-byte comp (binary) field in the varchar column.


hmm well then he can generate the integer values in hex and use them as hex strings to insert into the table

Code:

INSERT INTO table VALUES(37546819,X'023CEB43');
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rajeshkoratti
Beginner


Joined: 14 Feb 2006
Posts: 42
Topics: 22

PostPosted: Fri Oct 14, 2011 6:35 pm    Post subject: Reply with quote

Thanks GuyC

Your solution worked. I wrote a SQL script similar to this

Code:
  UPDATE TABLENAME                                 
  SET VARCHAR_COL = (                                           
         EBCDIC_CHR(MOD(INTEGER_COL/POWER(2,24),POWER(2,8))) ||
         EBCDIC_CHR(MOD(INTEGER_COL/POWER(2,16),POWER(2,8))) ||
         EBCDIC_CHR(MOD(INTEGER_COL/POWER(2,8),POWER(2,8))) ||
         EBCDIC_CHR(MOD(INTEGER_COL,POWER(2,8)))               
                       )                                           
   ;

_________________
Thanks and Regards..
Rajesh
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Fri Oct 14, 2011 11:07 pm    Post subject: Reply with quote

Suggest you also try the code from Kolusu.

I suspect that most of the people who will maintain your code will be confused by the mod/power code. . . Though it is rather neat Smile
_________________
All the best,

di
Back to top
View user's profile Send private message
GuyC
Supermod


Joined: 27 May 2011
Posts: 35
Topics: 0

PostPosted: Mon Oct 17, 2011 3:09 am    Post subject: Reply with quote

split any integer in to 4 separate bytes :
the right-most byte is : i mod 256
the tree left bytes are : i / 256
so repeating this process 3 times you get (from right to left)
i mod 256
( i / 256) mod 256
((i / 256) / 256 ) mod 256
(((i /256) / 256 ) / 256 ) mod 256
on these 4 bytes you then perform EBCDIC_CHR()
Back to top
View user's profile Send private message
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