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

redefine an alphanumeric variable to comp


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Amb

New User


Joined: 12 Mar 2010
Posts: 64
Location: India

PostPosted: Sat Jul 17, 2010 6:28 pm
Reply with quote

Hi guys,

I need to know how do I redefine an alphanumeric variable pic X(8) which always contains numeric data to an s9(8) COMP variable.

For example:

Code:
A1     PIC X(8) value '1'.
A2     s9(8) Comp   redefines A1.


(Hex value in A1 = 30 30 30 30 30 30 30 31)
(Hex value in A2 = 30 30 30 30 00 00 00 01)

As seen above value at A2 is not numeric as it has x'00' (ie. NULL)

My requirement is to get 30 30 30 30 30 30 30 31 in A2.
so that I can use it for numeric operations?

note: It is mandatory for me to use a comp variable.

Can you please let me know how to do this?
Pls let me know if any more information is needed from my side.
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Sat Jul 17, 2010 6:52 pm
Reply with quote

If you move A1(which is X(08)) into B1(which is 9(9)) and redefine B1 to binary value A2.
I think this should work. I need to check this when i get to office on Monday . icon_biggrin.gif
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sat Jul 17, 2010 8:04 pm
Reply with quote

Amb wrote:
I need to know how do I redefine an alphanumeric variable pic X(8) which always contains numeric data to an s9(8) COMP variable.

Code:

A1   PIC X(8) value '1'.
A1A  redefines A1
     PIC s9(8).
A2   PIC s9(8) COMP.

MOVE A1A TO A2.

Quote:
For example:

Code:
A1     PIC X(8) value '1'.
A2     s9(8) Comp   redefines A1.


(Hex value in A1 = 30 30 30 30 30 30 30 31)
(Hex value in A2 = 30 30 30 30 00 00 00 01)
Your example definition for A1would contain the character '1' followed by seven blanks.
The redef of A1 as A2 would only redefine the first four characters of A1, not the entire eight bytes of A1.
The hex value in A1 would be X'F140404040404040'.
The hex value in A2 would be X'F1404040'.
The numeric value of A2 would be 4047519808.
I have no idea how you got the ASCII values in A1.
I have no idea how you got the value '1' to right justify and leading blanks converted to zeros.
I have no idea how your redef managed to shift right four bytes.
Quote:
As seen above value at A2 is not numeric as it has x'00' (ie. NULL)
The nulls in A2 are comp numerics, along with the trailing 01.
Quote:
My requirement is to get 30 30 30 30 30 30 30 31 in A2.
so that I can use it for numeric operations?
Assuming you have valid zoned decimal in A1 and really want A2 to contain valid COMP (binary) values, see above
If you really meant A2 to contain valid zoned decimal digits to use for numeric operations, remove the 'COMP' in the A2 redef.
Quote:
note: It is mandatory for me to use a comp variable.
Why is it 'mandatory'?
Couldn't you use packed decimal or is this code being run on a machine that does not natively support packed decimal instruction?
Quote:
Pls let me know if any more information is needed from my side.
Initially, only the answers to the above questions.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sat Jul 17, 2010 8:09 pm
Reply with quote

PIC S9(08) COMP is a binary-fullword (4-bytes). You'll need an S9(18) COMP, binary-doubleword (8-Bytes).

Ensure you specify the TRUNC(BIN) compile option if your compiler does not support COMP-5. Otherwise, define the binary-doubleword as COMP-5.

Bill
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sat Jul 17, 2010 10:08 pm
Reply with quote

1. The mainframe uses EBCDIC not ASCII. So unless you do some highly unusual things, you cannot get X'3030303030303031' in a data field to represent 00000001, anyway.

2. Alphanumeric data is left justified, so the actual value stored in A1 will be X'F140404040404040' as was stated by CICS Guy.

3. What you want to do cannot be done. The internal formats for USAGE DISPLAY and COMP variables are such that it is not possible to use a REDEFINES to convert one to the other. You can use a MOVE but not the REDEFINES.

4. There is a link to manuals at the top of the page. Please spend at least 2 or 3 days reading it until you understand (a) EBCDIC, (b) internal formats for DISPLAY and COMP and COMP-3 variables, (c) justification rules for variables.
Back to top
View user's profile Send private message
Amb

New User


Joined: 12 Mar 2010
Posts: 64
Location: India

PostPosted: Sun Jul 18, 2010 9:35 am
Reply with quote

Thanks I will do that.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sun Jul 18, 2010 10:55 am
Reply with quote

Amb wrote:
Thanks I will do that.
Great answer...... icon_rolleyes.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Sun Jul 18, 2010 7:04 pm
Reply with quote

Actually, a GREAT answer would be in a few days when the response is
Quote:
Thanks I did that and now understand
Back to top
View user's profile Send private message
Amb

New User


Joined: 12 Mar 2010
Posts: 64
Location: India

PostPosted: Sun Jul 18, 2010 10:07 pm
Reply with quote

Hey Robert,

I understood my mistake...

The COBOL that I am analyzing currently runs on MICRO FOCUS environment that is the reason I got the ASCII values as in MICRO FOCUS all characters are interpreted as ASCII (in contrast to mainframes).

Variable A1 is right justified which I forgot to mention. (again sorry for that)

Also there is a piece of code which converts the leading blanks to zeros and shift operation (again sorry.. as I displayed the HEX values after this logic)


Nevertheless I got my solution from the above posts.. Thanks for that.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
Search our Forums:

Back to Top