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

CHARACTER to FIXED DECIMAL


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Appu

New User


Joined: 26 Apr 2010
Posts: 73
Location: India

PostPosted: Fri Dec 17, 2010 9:11 pm
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: 1788
Location: Bloomington, IL

PostPosted: Fri Dec 17, 2010 9:22 pm
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

Senior Member


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

PostPosted: Fri Dec 17, 2010 9:23 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Dec 17, 2010 9:26 pm
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: 73
Location: India

PostPosted: Mon Dec 20, 2010 7:50 pm
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

Senior Member


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

PostPosted: Mon Dec 20, 2010 7:59 pm
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

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Mon Dec 20, 2010 8:02 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Need Help with Packed Decimal Signs DFSORT/ICETOOL 4
No new posts Converting fixed length file to excel... IBM Tools 7
No new posts Panvalet - 9 Character name - Issue c... CA Products 6
Search our Forums:

Back to Top