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
 

 

CHARACTER to FIXED DECIMAL

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

New User


Joined: 26 Apr 2010
Posts: 74
Location: India

PostPosted: Fri Dec 17, 2010 9:11 pm    Post subject: CHARACTER to FIXED DECIMAL
Reply with quote

Hello,

I have tried the below code :

Code:

DCL 1 STR CHAR(4);
DCL 1 NUM FIXED DECIMAL(7) BASED(ADDR(STR));
STR = '1234';


When i tried to print the variables, it is giving SOC7.
Could you please tell me whether the BASED option cannot be used with FIXED DECIMAL datatype. Because I could see that this works fine with FIXED BINARY values. Thanks.
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1755
Location: Bloomington, IL

PostPosted: Fri Dec 17, 2010 9:22 pm    Post subject:
Reply with quote

You are aware that character data is, by definition, always binary, but rarely decimal?
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 962
Location: Richmond, Virginia

PostPosted: Fri Dec 17, 2010 9:23 pm    Post subject:
Reply with quote

The code you show cannot issue a S0C7 (note - zero-C7, not oh-C7), because you have not shown any executable code.

Please show your results that "worked" with FIXED BIN.

Every bit pattern can be interpreted as a binary value, but not so with packed-decimal. Let's see what you got for the FIXED BIN value.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Fri Dec 17, 2010 9:26 pm    Post subject:
Reply with quote

You are leaping to entirely the wrong conclusion. The internal format for STR will be X'F1F2F3F4', which is not compatible with FIXED DECIMAL. FIXED BINARY is not going to give you 1234 as a value either when BASED on STR.

The bottom line: BASED is not the issue. The internal format used to store the data should be the same when using BASED, or you will get unpredictable results up to and including possible ABENDS.
Back to top
View user's profile Send private message
Appu

New User


Joined: 26 Apr 2010
Posts: 74
Location: India

PostPosted: Mon Dec 20, 2010 7:50 pm    Post subject:
Reply with quote

Hi Guys,

Thanks . Now i understood the problem was that while using based, we should base compatible types as follows :
Code:


dcl 1 ptr1 pointer;                               
dcl 1 str1 char(5) based(ptr1);                   
dcl 1 bin1 fixed bin(15) init(100);               
dcl 1 bin1_pic pic'99999';                         
dcl 1 fdec1 fixed decimal(5) init(700);           
dcl 1 fdec1_pic pic'99999';                       
bin1_pic = bin1;                                   
ptr1 = addr(bin1_pic);                             
put skip list('str1 assigned bin value :',str1);   
fdec1_pic = fdec1;                                 
ptr1 = addr(fdec1_pic);                           
put skip list('str1 assigned fdec value :',str1); 

Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 962
Location: Richmond, Virginia

PostPosted: Mon Dec 20, 2010 7:59 pm    Post subject:
Reply with quote

Quote:
Now i understood the problem was that while using based, we should base compatible types


More than that - while using any redefinition of fields one needs compatability, unless one is specifically doing something fancy.

This would include a COBOL explicit REDEFINE, and also an implicit redefine such as multiple 01 records for a file.
Back to top
View user's profile Send private message
Garry Carroll

Active Member


Joined: 08 May 2006
Posts: 995
Location: Dublin, Ireland / Edinburgh, Scotland

PostPosted: Mon Dec 20, 2010 8:02 pm    Post subject:
Reply with quote

I think it would be more readable as

Code:
dcl 1 str1 char(5) ;
dcl str1_pic pic'(5)9';
dcl 1 bin1 fixed bin(15) init(100);
dcl 1 fdec1 fixed decimal(5) init(700);           
                       
str1_pic = bin1;         
put skip list('str1 assigned bin value :',str1);   
str1_pic = fdec1;       
put skip list('str1 assigned fdec value :',str1);


Garry
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 Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts the use of 'B3'x character in a panel Pedro TSO/ISPF 1 Thu Feb 16, 2017 3:09 am
No new posts Joinkeys with decimal scdinesh DFSORT/ICETOOL 3 Fri Feb 10, 2017 4:46 am
No new posts Converting decimal to numeric using I... Balaryan DFSORT/ICETOOL 4 Thu Feb 02, 2017 11:27 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


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