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

VARCHAR to CHAR conversion


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

New User


Joined: 20 Jul 2006
Posts: 30

PostPosted: Wed Jan 27, 2010 10:08 am
Reply with quote

Hi,

In my DB2 table, I have a VARCHAR field which is 120 bytes long (length not inlcuded). The first 40 bytes of this field should be moved into a MAP field which is defined as CHAR X(40). I am manually editing the table field to have data. But while doing an XPEDITOR on the program this field is showing junk.

I have 2 questions here,

1) How do we enter data into a VARCHAR field?
2) How can we move the VARCHAR data into CHAR field?

Thanks in advance.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Jan 27, 2010 12:08 pm
Reply with quote

Hello,

Possibly there is something i misunderstand, but the way to get data into a varchar column or get data from a varchar column is to move the data to or from the host variables for the column. . .
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Jan 27, 2010 1:37 pm
Reply with quote

Show us the declaration of the host variable in your program. Also tell us how are you editing table data. Did you run SPUFI/QMF to verify the data that you edited?
Back to top
View user's profile Send private message
lvbntapasvi

New User


Joined: 20 Jul 2006
Posts: 30

PostPosted: Wed Jan 27, 2010 5:06 pm
Reply with quote

Hi Bharat, this is how the host variable is defined for the VARCHAR field,

Code:
10    DCB0765-TRN-EXT-CDE-DESC.               
   49 DCB0765-TRN-EXT-CDE-DESC-LEN         
                         PIC S9(4)                USAGE COMP. 
   49 DCB0765-TRN-EXT-CDE-DESC-TEXT         
                        PIC X(120).       

Also, I have not run SPUFI, I have entered some text direclty in the field of the table by editing it.
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Jan 27, 2010 5:23 pm
Reply with quote

Is the program abending or giving unexpected results? or are you just wondering why XPEDITOR is showing junk?
If you are looking at the variable DCB0765-TRN-EXT-CDE-DESC in xpeditor, it will display the first two bytes as junk. But, DCB0765-TRN-EXT-CDE-DESC-TEXT might still contain the expected values.
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Wed Jan 27, 2010 5:25 pm
Reply with quote

Quote:
Also, I have not run SPUFI, I have entered some text direclty in the field of the table by editing it.


Hi lvbntapasvi,

How can you edit a table without using QMF/SPUFI or Other DB2 tools.
Not sure how we can do that
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Jan 28, 2010 4:06 pm
Reply with quote

probably editing thru fileaid.

if varchar-len > 0
move varchar-text(1:varchar-len) to map-field
end-if

Another possible cause is unicode/ebcdic conversion with columns defined for bit data.
Back to top
View user's profile Send private message
lvbntapasvi

New User


Joined: 20 Jul 2006
Posts: 30

PostPosted: Tue Feb 02, 2010 9:51 am
Reply with quote

Hi Guyc, we tried populating the CHAR field thru the suggestion given by you. But, it didnt work. Any idea about the UTF8 and EBCDIC conversion if we need to do it?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Feb 02, 2010 2:06 pm
Reply with quote

In normal situations any conversion is handled by DB2.
Back to top
View user's profile Send private message
prashant_2420

New User


Joined: 06 Jan 2010
Posts: 2
Location: Oregon

PostPosted: Sat Feb 06, 2010 5:26 am
Reply with quote

Hi lvbntapasvi,

If you know that first 40 bytes are required,

And you are using COBOL to achieve this:
you can directly use
MOVE DCB0765-TRN-EXT-CDE-DESC-TEXT(1:40) TO MAP-FIELD (this answers your question 2)
You can use a loop if you want it for all the rows.

To answer qusetion 1, you can set the length variable of the VARCHAR field to the max limit of characters you can have. Then, move the actual value (string or any other variable as per your requirement) in the TEXT part of the VARCHAR field.


If you want to use DB2:
you can use SET command as follows:
ALTER TABLE SET MAP-FIELD = SUBSTR(DCB0765-TRN-EXT-CDE-DESC,1,40)
This command will set MAP-FIELD with first 40 bytes of DCB0765-TRN-EXT-CDE-DESC field.

Hope I understood your problem correctly and this helps!
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 SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts file manager is doing string conversion IBM Tools 3
Search our Forums:

Back to Top