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

DSNUTILB - loading char field into varchar field


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

New User


Joined: 31 Jan 2007
Posts: 27
Location: virginia

PostPosted: Wed Jul 07, 2010 5:53 am
Reply with quote

hi,
i have never used db2 laod utility like DSNUTILIB or any other.
i have a incoming file of fixed length of 32 bytes(this is only one field). the data in it is right padded with spaces for all the values whose length is less than 32 bytes.

here is an example of input file with a field lets say Last Name:
---------------------------------------------
12345678901234567890123456789012
lineone
lineonehundred
linethreethousandfourtysix
thislinehasthirtytwocharacterstoloadnow
---------------------------------------------

i need to load this data into my db2 table on MVS where the table column is defined as varchar(32). i have reviewed some posts and understand that we need a binary length field before the field. Is it must to have the binary length field? Cant we do it without having that field. i am getting this file from another system and another team and they say they cant put a binary length field. What are my options? are there any options i can use in my LOAD statement that converts CHAR to VARCHAR?

Appreciate your prompt reply.

thanks
krish
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 Jul 07, 2010 7:48 am
Reply with quote

Hello,

One way to do this is Copy the file appending the length to each record. . .

Use any utility you know and are comfortable with or write a bit of code.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed Jul 07, 2010 9:07 am
Reply with quote

Krish,

Quote:
i am getting this file from another system and another team and they say they cant put a binary length field. What are my options? are there any options i can use in my LOAD statement that converts CHAR to VARCHAR?


I think you don't need length field and you also don't need to convert into varchar.

Try loading with the below field positions. Not Tested.
Code:

column-name POSITION (1:32) CHAR(32),


Sushanth
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 Jul 07, 2010 9:21 am
Reply with quote

Hi Susanth,

If i understand what is needed it is to reduce the field length by the number of trailing spaces.

I may misunderstand icon_smile.gif
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Jul 07, 2010 11:46 am
Reply with quote

worse case you can always do an update afterwards :
update tab1 set col1 = strip(col1)
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed Jul 07, 2010 10:22 pm
Reply with quote

Hi,

Strip functionality in LOAD can be used to remove all the trailing and leading spaces,

Code:
DUMMY_TEXT POSITION (1:32) CHAR(32) STRIP BOTH 



Thanks,
Sushanth
Back to top
View user's profile Send private message
vamskrish
Warnings : 1

New User


Joined: 31 Jan 2007
Posts: 27
Location: virginia

PostPosted: Thu Jul 08, 2010 6:58 pm
Reply with quote

hi all,
thanks a lot for your solutions. the 'strip' worked.

COLUMN1 POSITION(1:32) CHARACTER STRIP TRAILING ' '

i think it would be the same as what sushanth had suggested.


thanks again
krish
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jul 08, 2010 7:06 pm
Reply with quote

vamskrish wrote:
hi all,
i think it would be the same as what sushanth had suggested.


no,
if there are leading spaces, they have been included in the varchar.
Back to top
View user's profile Send private message
vamskrish
Warnings : 1

New User


Joined: 31 Jan 2007
Posts: 27
Location: virginia

PostPosted: Fri Jul 09, 2010 8:12 pm
Reply with quote

yes, because i am using 'Trailing'. what i meant was they both work depending upon how u want to handle your spaces.

thanks
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top