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

Can we move Binary field directly to Packed decimal in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Senior Member


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

PostPosted: Fri Mar 07, 2008 6:44 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Mar 07, 2008 7:48 pm
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: 2481
Location: @my desk

PostPosted: Sun Mar 09, 2008 7:37 am
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Mar 09, 2008 9:43 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Binary File format getting change whi... All Other Mainframe Topics 7
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top