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
 

 

redefine an alphanumeric variable to comp

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: redefine an alphanumeric variable to comp
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Sat Jul 17, 2010 8:04 pm    Post subject: Re: redefine an alphanumeric variable to comp
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Sat Jul 17, 2010 8:09 pm    Post subject: Reply to: redefine an alphanumeric variable to comp
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: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Sat Jul 17, 2010 10:08 pm    Post subject:
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    Post subject: Reply to: redefine an alphanumeric variable to comp
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: 2150
Location: At my coffee table

PostPosted: Sun Jul 18, 2010 10:55 am    Post subject: Re: Reply to: redefine an alphanumeric variable to comp
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: 8055
Location: East Dubuque, Illinois, USA

PostPosted: Sun Jul 18, 2010 7:04 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Redefine SYS1.PROCLIB farhad_evan JCL & VSAM 12 Mon May 22, 2017 10:54 pm
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm


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