Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

CHAR to FIXED BIN in PL/I

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
Neeraj Kumar

New User


Joined: 24 Nov 2007
Posts: 7
Location: ABC

PostPosted: Mon Oct 17, 2011 9:12 pm    Post subject: CHAR to FIXED BIN in PL/I
Reply with quote

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
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 17, 2011 9:32 pm    Post subject: Reply to: CHAR to FIXED BIN in PL/I
Reply with quote

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
View user's profile Send private message
Neeraj Kumar

New User


Joined: 24 Nov 2007
Posts: 7
Location: ABC

PostPosted: Mon Oct 17, 2011 9:39 pm    Post subject: Reply to: CHAR to FIXED BIN in PL/I
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 17, 2011 9:48 pm    Post subject: Reply to: CHAR to FIXED BIN in PL/I
Reply with quote

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
Code:
ffffF
12345

with a fixed bib 31 thing would return anything good

reread Your program an think a bit about what it means icon_evil.gif
Back to top
View user's profile Send private message
Neeraj Kumar

New User


Joined: 24 Nov 2007
Posts: 7
Location: ABC

PostPosted: Mon Oct 17, 2011 10:02 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon Oct 17, 2011 10:05 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Oct 17, 2011 10:10 pm    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 17, 2011 10:12 pm    Post subject: Reply to: CHAR to FIXED BIN in PL/I
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 17, 2011 10:14 pm    Post subject: Reply to: CHAR to FIXED BIN in PL/I
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 17, 2011 11:14 pm    Post subject: Reply to: CHAR to FIXED BIN in PL/I
Reply with quote

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:

ffff
1234



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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts conversion from char to packed decimal Musab Ahmed DFSORT/ICETOOL 7 Fri Apr 08, 2016 1:12 pm
No new posts Converting field from char to number danylele74 DB2 4 Tue Mar 29, 2016 4:24 pm
No new posts How to copy data with delimters to fi... Venkata Ramayya DFSORT/ICETOOL 2 Wed Feb 24, 2016 10:03 pm
No new posts Converting s9(9) comp field to char l.nethaji DFSORT/ICETOOL 3 Fri Jan 22, 2016 12:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us