View previous topic :: View next topic
|
Author |
Message |
Appu
New User
Joined: 26 Apr 2010 Posts: 73 Location: India
|
|
|
|
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 |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
You are aware that character data is, by definition, always binary, but rarely decimal? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Appu
New User
Joined: 26 Apr 2010 Posts: 73 Location: India
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
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 |
|
|
|