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 

Integer to Varchar

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


Joined: 15 May 2005
Posts: 72
Topics: 24

PostPosted: Thu Jun 28, 2012 12:54 pm    Post subject: Integer to Varchar Reply with quote

Hi,

I have integer variable X data in a flat file from 10-14 positions and 15th is occupied by Null indicator.Now I want to load this data into a DB2 table but X is defined as Varchar(20) nullable. How do I change my Load cards to fit the data?

I tried this in my load cards but didn't work
X position (10:5) varchar NULLIF(15)='?'
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Thu Jun 28, 2012 10:38 pm    Post subject: Reply with quote

Hello,

If you want this more quickly, you could copy the file and make the needed changes to the data and then load this new file. NOT a solution, but alllows you to load the data to db2.

Then, continue with the diagnosis of the "real" solution. . .
_________________
All the best,

di
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Fri Jun 29, 2012 9:58 am    Post subject: Reply with quote

How about this:
Code:

POSITION(10) CHAR(05)  STRIP TRAILING,
NULLIF(10:14) = '     ',             


I know your column is VARCHAR. I load my VARCHAR colums like this all the time.
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


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

PostPosted: Fri Jun 29, 2012 10:38 am    Post subject: Reply with quote

one of the side benefits of this particular thread is: (wait for it!)

the solution to having a file with fields in a format different than the datatype of the column
is
learning this scripting language
so that the appropriate values are populated in the column.

i don't know, but i would not be surprised if
you could cast a display numeric to a integer column
or as we are doing here
casting replace(char(5),' ','') to varchar(20)

to which utility do these control cards belong?
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
maverick05
Beginner


Joined: 15 May 2005
Posts: 72
Topics: 24

PostPosted: Mon Jul 02, 2012 1:42 pm    Post subject: Reply with quote

dbzTHEdinosauer wrote:
one of the side benefits of this particular thread is: (wait for it!)

the solution to having a file with fields in a format different than the datatype of the column
is
learning this scripting language
so that the appropriate values are populated in the column.

i don't know, but i would not be surprised if
you could cast a display numeric to a integer column
or as we are doing here
casting replace(char(5),' ','') to varchar(20)

to which utility do these control cards belong?


the load cards belongs to DSNUPROC
Back to top
View user's profile Send private message
delta403
Beginner


Joined: 07 Oct 2010
Posts: 7
Topics: 0
Location: india

PostPosted: Tue Jul 03, 2012 1:24 pm    Post subject: Reply with quote

Please do as below:
Step1: Reformat your input file as per the syspunch by using SORT utility.
Code:

OPTION ZDPRINT
INREC BUILD=(1,12,SFF,TO=ZD,LENGTH=12)
SORT FIELDS=(1,12,A),FORMAT=ZD
SUM FIELDS=(1,12,ZD)
OUTREC FIELDS=(1,12,ZD,EDIT=(SIIIIIIII.IT),SIGNS=(,-)

Step2: Change the Syspunch to load only char data; so you need to advance the position of your varchar field by 2(length field) and use CHAR instead of VARCHAR for this field.
And do NULLIF(15)='?" ; where 15 will be the end of the VARCHAR field after the length.

Step3: Run the load jcl.

Hope it will work for you. Please let me know if any question. Thanks.
Back to top
View user's profile Send private message
maverick05
Beginner


Joined: 15 May 2005
Posts: 72
Topics: 24

PostPosted: Thu Jul 05, 2012 11:17 am    Post subject: Reply with quote

delta403 wrote:
Please do as below:
Step1: Reformat your input file as per the syspunch by using SORT utility.
Code:

OPTION ZDPRINT
INREC BUILD=(1,12,SFF,TO=ZD,LENGTH=12)
SORT FIELDS=(1,12,A),FORMAT=ZD
SUM FIELDS=(1,12,ZD)
OUTREC FIELDS=(1,12,ZD,EDIT=(SIIIIIIII.IT),SIGNS=(,-)

Step2: Change the Syspunch to load only char data; so you need to advance the position of your varchar field by 2(length field) and use CHAR instead of VARCHAR for this field.
And do NULLIF(15)='?" ; where 15 will be the end of the VARCHAR field after the length.

Step3: Run the load jcl.

Hope it will work for you. Please let me know if any question. Thanks.


Hi,

I have a question on this.
1) What is this lenght 12?
OPTION ZDPRINT
INREC BUILD=(1,12,SFF,TO=ZD,LENGTH=12)
SORT FIELDS=(1,12,A),FORMAT=ZD
SUM FIELDS=(1,12,ZD)
OUTREC FIELDS=(1,12,ZD,EDIT=(SIIIIIIII.IT),SIGNS=(,-)


2) How do I change SYSPUNCH to load only char data.Because I was assuming that SYSPUNCH will tell from which position to take data from the input file.Can we also tell from which position to load data into Db2 field?Can you please provide me the example?

3) So for my req, from where I do need to load integer value from 10-13 into varchar field of 20,can you specify the syspunch change for this?
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: Thu Jul 05, 2012 11:18 am    Post subject: Reply with quote

maverick05,

Did you try Nascar9 suggestion ?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
delta403
Beginner


Joined: 07 Oct 2010
Posts: 7
Topics: 0
Location: india

PostPosted: Thu Jul 05, 2012 4:09 pm    Post subject: Reply with quote

OPTION ZDPRINT
INREC BUILD=(1,12,SFF,TO=ZD,LENGTH=12)
SORT FIELDS=(1,12,A),FORMAT=ZD
SUM FIELDS=(1,12,ZD)
OUTREC FIELDS=(1,12,ZD,EDIT=(SIIIIIIII.IT),SIGNS=(,-)

Consider the above as an example; What I meant; please reformat the input file as per the table structure in ur case - convert from integer to character and move this field by 2 position forward;
use
OUTREC FIELDS=(10,2X,12:10,5,ZD,EDIT=(SIIII),SIGNS=(,-)
(Not tested)
because varchar fields start with 2 byte length followed by the actual data and end by a character for NULLIF.

And then you need to change the syspunch while loading:
for example: for varchar column would be defined as below in the table:

ws_column POSITION (10) VARCHAR NULLIF(17) = '?'

Before loading change the above syspunch like below:
ws_column POSITION (12) CHAR(5) NULLIF(17)='?'

POSITION(12): because varchar columns start with length of the field which takes 2 byte length (S9(4) COMP).
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Thu Jul 05, 2012 8:28 pm    Post subject: Reply with quote

Is there any Good reason why the suggestion from NASCAR9 has not been tried (and some feedback posted)?
_________________
All the best,

di
Back to top
View user's profile Send private message
maverick05
Beginner


Joined: 15 May 2005
Posts: 72
Topics: 24

PostPosted: Fri Jul 06, 2012 2:32 pm    Post subject: Reply with quote

kolusu wrote:
maverick05,

Did you try Nascar9 suggestion ?


Nascar9 suggestion worked .I somehow missed his message before.Thanks very much Nascar for the solution and Kolusu
Back to top
View user's profile Send private message
maverick05
Beginner


Joined: 15 May 2005
Posts: 72
Topics: 24

PostPosted: Fri Jul 06, 2012 2:34 pm    Post subject: Reply with quote

delta403 wrote:
OPTION ZDPRINT
INREC BUILD=(1,12,SFF,TO=ZD,LENGTH=12)
SORT FIELDS=(1,12,A),FORMAT=ZD
SUM FIELDS=(1,12,ZD)
OUTREC FIELDS=(1,12,ZD,EDIT=(SIIIIIIII.IT),SIGNS=(,-)

Consider the above as an example; What I meant; please reformat the input file as per the table structure in ur case - convert from integer to character and move this field by 2 position forward;
use
OUTREC FIELDS=(10,2X,12:10,5,ZD,EDIT=(SIIII),SIGNS=(,-)
(Not tested)
because varchar fields start with 2 byte length followed by the actual data and end by a character for NULLIF.

And then you need to change the syspunch while loading:
for example: for varchar column would be defined as below in the table:

ws_column POSITION (10) VARCHAR NULLIF(17) = '?'

Before loading change the above syspunch like below:
ws_column POSITION (12) CHAR(5) NULLIF(17)='?'

POSITION(12): because varchar columns start with length of the field which takes 2 byte length (S9(4) COMP).


I had tried but was not allowed to format the input.Anyhow thanks for your solution delta.I had applied Nascar's solution and it worked very well
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