View previous topic :: View next topic
|
Author |
Message |
Neeraj Kumar
New User
Joined: 24 Nov 2007 Posts: 7 Location: ABC
|
|
|
|
Hi,
I have a PL\I-DB2 Program, which reads an input record and retrieve data from DB2 table. My Input record is of CHAR(20) which is Alpha-Numeric. It has two parts CHAR and NUMERIC separated by a '^'. I have to separate the INREC into CHAR and NUMERIC, which will be used to read the DB2 table. One Column is CHAR and other Column is INTEGER in my DB2 Table.
Please refer to the code below:
Code: |
DCL INREC CHAR(20) VAR INIT('ABCDE^12345) ;
DCL IND FIXED BIN(31) INIT(20) ;
DCL WS_LEN FIXED BIN(31) INIT(20) ;
DCL WS_VAR1 CHAR(10) INIT(' ') ;
DCL WS_TEMP CHAR(10) INIT(' ') ;
DCL WS_VAR2 FIXED BIN(31) BASED(ADDR(WS_TEMP));
/* PROGRAM MAINLINE */
IND = INDEX(INREC,'^') ;
WS_LEN =STG(INREC) - IND ;
WS_VAR1 = SUBSTR(INREC,1,IND-1) ;
WS_TEMP = SUBSTR(INREC,IND+1,WS_LEN);
|
Value in WS_TEMP is coming as 12345 but in WS_VAR2 is coming as junk and while running its giving error code 8097. If I use other Numeric types for WS_VAR2 like FIXED DEC, PIC '(9)9' then I'm getting an error in DB2 precompilation(unusable host variable). Could you please tell me what I'm doing wrong here?
Thanks
Neeraj. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
why not reread the PL/1 manual about the differences in data types ?
fixed bin(31) is a fullword ( 4bytes ) of binary data ...
just meditate on it |
|
Back to top |
|
|
Neeraj Kumar
New User
Joined: 24 Nov 2007 Posts: 7 Location: ABC
|
|
|
|
Thanks enrico !!!
But I was expecting may be a little more, kind of straight answer, than sarcasm. And that's why I gave a detailed description of my problem.
Probably it was not worth it. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
thank Your &deity that my reply was not sarcastic at all
You get what You deserve ...
why in heaven would You think that mapping a char string
with a fixed bib 31 thing would return anything good
reread Your program an think a bit about what it means |
|
Back to top |
|
|
Neeraj Kumar
New User
Joined: 24 Nov 2007 Posts: 7 Location: ABC
|
|
|
|
I'm not sure about thanking but I'm really cursing that moment when I took the trouble to post here. Nothing but sheer arrogance. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Why do you believe there is any arragonce telling you that what you have coded cannot work and you need to consider what the manual says about the data definitions you are trying to use? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
dick scherrer wrote: |
Hello,
Why do you believe there is any arragonce telling you that what you have coded cannot work and you need to consider what the manual says about the data definitions you are trying to use? |
Neeraj Kumar shoulda wrote: |
because you did not provide me with the answer,
i don't want to read any manuals or learn anything.
i just want someone else to do my work,
after all, that is what the internet is for.... |
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
THIS snippet does what You ask for ( and points the difference from what You have coded )
The snippet
Code: |
****** ***************************** Top of Data ******************************
000001 zmf01:
000002 Proc Options(Main);
000003 dcl rec char(20) init('abcdef¬12345') ;
000004 dcl ind fixed bin(31) ;
000005 dcl len fixed bin(31) ;
000006 dcl var1 char(20) ;
000007 dcl temp char(20) ;
000008 dcl var2 fixed bin(31) ;
000009
000010 ind = index(rec,'¬') ;
000011 put skip list('ind =',ind);
000012
000013 len = stg(rec) - ind ;
000014 put skip list('len =',len);
000015
000016 var1 = substr(rec, 1, ind - 1);
000017 put skip list('var1 =',var1) ;
000018
000019 temp = substr(rec, ind + 1);
000020 put skip list('temp =',temp) ;
000021
000022 var2 = temp
000023 put skip list('var2 =',var2) ;
000024 End;
****** **************************** Bottom of Data **************************** |
The result
Code: |
********************************* TOP OF DATA **********************************
ind = 7
len = 13
var1 = abcdef
temp = 12345
var2 = 12345
******************************** BOTTOM OF DATA ******************************** |
the len mangling is completely useless
instead of trying to use sophisticated techniques it would be better
to start reviewing the basics |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
Nothing but sheer arrogance. |
and on Your side nothing but sheer incompetence
and I regret the time I wasted in coding and testing the snipped I posted to show how to do it
edited to add a comment ...
NOT TRUE, I do not regret it at all, i like to show how to do things in a simple way
it' s a pity that the world is full of ***holes who do not appreciate it,
or worse do not even understand it
edited to fix a few typos |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
The same with the silly/wrong BASED ADDR ( and a DEFINED )
to show what happens when a <...> writes code to interpret a char string as a fixed bin 31
( notice the two flavors of the wrongdoing )
Code: |
****** ***************************** Top of Data ******************************
000001 zmf01:
000002 Proc Options(Main);
000003 dcl rec char(20) init('abcdef¬12345') ;
000004 dcl ind fixed bin(31) ;
000005 dcl len fixed bin(31) ;
000006 dcl var1 char(20) ;
000007 dcl tmp1 char(20) ;
000008 dcl tmp2 fixed bin(31) based(addr(tmp1));
000009 dcl tmp3 fixed bin(31) def(tmp1) ;
000010 dcl var2 fixed bin(31) ;
000011
000012 ind = index(rec,'¬') ;
000013 put skip list('ind =',ind);
000014
000015 len = stg(rec) - ind ;
000016 put skip list('len =',len);
000017
000018 var1 = substr(rec, 1, ind - 1);
000019 put skip list('var1 =',var1) ;
000020
000021 tmp1 = substr(rec, ind + 1);
000022 put skip list('tmp1 =',tmp1) ;
000023 put skip list('tmp2 =',tmp2) ;
000024 put skip list('tmp3 =',tmp3) ;
000025
000026 var2 = tmp1 ;
000027 put skip list('var2 =',var2) ;
000028 End;
****** **************************** Bottom of Data ****************************
|
Code: |
********************************* TOP OF DATA **********************************
ind = 7
len = 13
var1 = abcdef
tmp1 = 12345
tmp2 = -235736076
tmp3 = -235736076
var2 = 12345
******************************** BOTTOM OF DATA ********************************
|
|
|
Back to top |
|
|
|