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

Redefine 9(2) comp


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

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Mon Jul 02, 2012 9:49 pm
Reply with quote

Var declaration:

Code:
05  A              PIC 9(02) COMP.   
05  FILLER               REDEFINES A.
    10  FILLER                        PIC X.           
    10  B          PIC X.       


Proc Division:

Code:
ADD 1 TO A
MOVE B TO C


In here initial value of A is zero before adding one. After that A had '01' in it. But i am not getting the second byte of A in B.

Please let me know if this is a wrong way of declaring. Please help me solve this issue.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Jul 02, 2012 10:07 pm
Reply with quote

Suggest you do a lot of reading in the cobol manuals about how numeric data items are stored!!!
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: Mon Jul 02, 2012 10:31 pm
Reply with quote

What did you get for the value of B?
What did you expect the value of B to be?
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Mon Jul 02, 2012 11:37 pm
Reply with quote

I want B to have value '1'. But i have low values in there which was moved at the start of program. I know this is wrong way of declaring but not 100% sure. I like to confirm my understanding.
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: Mon Jul 02, 2012 11:48 pm
Reply with quote

When you move zero to A, B will have LOW-VALUES. That is just the way COBOL works -- as Craq mentioned, you need to spend LOTS of time in the COBOL manuals understanding internal formats for data in COBOL. If you want B to have the value '1' (hex F1), you need to move 241 to A.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jul 03, 2012 12:42 am
Reply with quote

Hello,

Do you want an x'F1' or an x'01' in B?

If you post what you Really Want, someone should be able to help.

As it is now, all we can recommend is to spend the time in the documentation. We really do not understand your goal. . .
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Jul 03, 2012 4:36 am
Reply with quote

Robert Sample wrote:
WIf you want B to have the value '1' (hex F1), you need to move 241 to A.


I know you know Robert, but it does depend, with a PIC 99 COMP, on compile options whether 241 would actually fit into the field... may end up with 41 only, and max of 99.
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: Tue Jul 03, 2012 5:25 am
Reply with quote

You are right, Bill -- and I should have said that. Thanks for catching it!
Back to top
View user's profile Send private message
jepson

New User


Joined: 24 Oct 2008
Posts: 7
Location: India

PostPosted: Tue Jul 03, 2012 4:11 pm
Reply with quote

wouldn't B have the value of x'01' ?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Jul 03, 2012 4:25 pm
Reply with quote

From what has been described, yes, X'01' would be the value of B. It is unclear if that is the "1" which is required but poorly-described, or if "1" as in X'F1' is what is expected.

We await TS's return on that.
Back to top
View user's profile Send private message
Jarek.B

New User


Joined: 21 Jun 2012
Posts: 2
Location: UK

PostPosted: Wed Jul 04, 2012 9:48 pm
Reply with quote

PrabakarV wrote:
I want B to have value '1'. But i have low values in there...


You have a binary 1 in B but DISPLAY B won't display it what may confuse you. Still, you may see it on sysout if you switch your editor to hex mode.
If you want character 1 (hex code F1 in EBCDIC) then make A a character item: A PIC 9(2) without COMP.

Coded,tested,posted. icon_smile.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jul 04, 2012 10:09 pm
Reply with quote

Hello,

Suggest PrabakarV look at the lengths and displacements generated by the compiler. . .

If this info is not clear to you, post it here and someone will be able to clarify.

It should help understand what is happening.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3049
Location: NYC,USA

PostPosted: Thu Jul 05, 2012 5:37 pm
Reply with quote

Try using TRUNC(BIN) compiler option.
Back to top
View user's profile Send private message
slade

New User


Joined: 24 Nov 2007
Posts: 1
Location: NJ

PostPosted: Sun Jul 08, 2012 9:29 am
Reply with quote

Hi,
If PrabakarV is still in the building, he might also supply us the PIC, etc. for "C".
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 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
Search our Forums:

Back to Top