Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Can we move Binary field directly to Packed decimal in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
leo_sangha

New User


Joined: 11 Aug 2005
Posts: 85
Location: England

PostPosted: Fri Mar 07, 2008 6:07 pm    Post subject: Can we move Binary field directly to Packed decimal in cobol
Reply with quote

Can somebody explain, Will the below MOVE statement work, if YES, why?

01 WS-CODE-1 PIC S9(04) COMP.
01 WS-CODE-2 PIC S9(03) COMP-3.



MOVE WS-CODE-1 TO WS-CODE-2
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


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

PostPosted: Fri Mar 07, 2008 6:40 pm    Post subject: Re: Can we move Binary field directly to Packed decimal in c
Reply with quote

leo_sangha wrote:
Can somebody explain, Will the below MOVE statement work, if YES, why?

01 WS-CODE-1 PIC S9(04) COMP.
01 WS-CODE-2 PIC S9(03) COMP-3.



MOVE WS-CODE-1 TO WS-CODE-2


If you had looked in any COBOL manual or book you would find the answer. Yes. Why -- Because it is allowed.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


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

PostPosted: Fri Mar 07, 2008 6:44 pm    Post subject:
Reply with quote

leo - didn't you even think to try it out? That's the only way to really learn and remember the answer.
Back to top
View user's profile Send private message
leo_sangha

New User


Joined: 11 Aug 2005
Posts: 85
Location: England

PostPosted: Fri Mar 07, 2008 7:30 pm    Post subject: Reply to: Can we move Binary field directly to Packed decima
Reply with quote

ok guys, dont get upset. Thanks for your prompt replies.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Fri Mar 07, 2008 7:48 pm    Post subject: Can we move Binary field directly to Packed decimal in cobol
Reply with quote

IMHO, you'd be better off moving the S9(04) COMP field to an S9(09) COMP field and then, move the S9(09) COMP field to the COMP-3 field.

The maximum positive signed value you can have in an S9(04) COMP field is +32767 and when the COMP field is unsigned, this maximum grows to 65535, which is X'FFFF', which would be regarded as -1 in an S9(04) COMP field.

If the COMP-3 field is S9(05) or greater, you could have a high-order truncation issue on the MOVE to an S9(04) COMP field.

However, by moving it to the S9(09) COMP field beforehand, the high-order truncation issue will be reduced, but not eliminated.

Also, be very aware of the COBOL TRUNC compiler option, as it relates to binary-data, because it can burn you big time.

Regards,

Bill
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2285
Location: @my desk

PostPosted: Sun Mar 09, 2008 7:37 am    Post subject:
Reply with quote

Quote:
he maximum positive signed value you can have in an S9(04) COMP field is +32767


The maximum positive value that can be stored in s9(4) COMP is +9999

Always there is a chance of higher order truncation when you are trying to move from s9(4) to s9(3) whichever numeric type it is in.

There'll not be any problem in moving s9(4) COMP to s9(4) COMP-3.

Thanks,
Arun
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Sun Mar 09, 2008 8:12 am    Post subject:
Reply with quote

Quote:
The maximum positive value that can be stored in s9(4) COMP is +9999


That depends on the compiler and the compiler options!
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Sun Mar 09, 2008 9:43 am    Post subject: Can we move Binary field directly to Packed decimal in cobol
Reply with quote

arcvns wrote:
The maximum positive signed value you can have in an S9(04) COMP field is +32767

The maximum positive value that can be stored in s9(4) COMP is +9999

Always there is a chance of higher order truncation when you are trying to move from s9(4) to s9(3) whichever numeric type it is in.

There'll not be any problem in moving s9(4) COMP to s9(4) COMP-3.

Thanks,
Arun

You need to review your information and understanding of binary. icon_confused.gif

If this were true, then why can an S9(04) COMP field such as EIBCALEN in CICS, have a maximum-value of +32763 or for that matter, any other CICS-API which uses a binary-halfword length, whose values often exceed +9999?

BTW, the only COMP-3 field which uses an even number of digits effectively (without specifying the ARITH EXTEND option) is 9(18), whereas 9(02), 9(04), 9(06), etc, are wasted definitions as you're limiting the number of digits, but the same number of bytes are allocated, regardless.

As far as the high-order truncation, I had pointed out (either implicitly or explicitly) that moving a binary-halfword to a two-packed packed-decimal field, would in high-order truncation if the halfword value exceeded +999, which makes perfect sense.

One case in which TRUNC(OPT) can burn you is in a VALUE clause of a binary-field and that value exceeds the defined number of digits. However, TRUNC(BIN) will ensure that the value clause is honored, regardless, but generates brutally inefficient code, treating binary-data as packed-decimal.

Bill
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 IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Extend the decimal values in DIVISION Balaryan DFSORT/ICETOOL 3 Thu Oct 05, 2017 4:05 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us