Re: cobol truncate (458 Views)
Reply
Occasional Contributor
cachaza
Posts: 5
Registered: ‎10-18-2012
Message 1 of 4 (551 Views)

cobol truncate

Hi  all: ¿ how to move maximum possible value to a binary field ??? for example : move 32767 to ws-var ( where ws-var pic 9(04) comp.)

Thanks a lot. 

Honored Contributor
Hein van den Heuvel
Posts: 6,588
Registered: ‎05-19-2003
Message 2 of 4 (542 Views)

Re: cobol truncate

'just do it'... it works but it looks bad when using Cobol itself to display.

 

Officially you should use BINARY-SHORT or PIC 9(4)  USAGE COMP-5

 

according to IBM....

http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=%2Fcom.ibm.aix.cbl.doc%2Fcpa...

 

Native binary (COMP-5) items

Data items that you declare as USAGE COMP-5 are represented in storage as binary data. However, unlike USAGE COMP items, they can contain values of magnitude up to the capacity of the native binary representation (2, 4, or 8 bytes) rather than being limited to the value implied by the number of 9s in the PICTURE clause

 

But VMS COB REF:

BINARY is a synonym for COMPUTATIONAL and COMP.

On Alpha and I64 systems, except for restrictions on the PICTURE
clause, COMPUTATIONAL-5 and COMPUTATIONAL-X are synonyms for
COMPUTATIONAL and COMP."

 

BINARY-ALTERNATIVE...

 

Syntax Rule (Format 1)
6. The PICTURE clause is required for every elementary item except an item
specified by the USAGE IS BINARY-CHAR, BINARY-SHORT,

 

But in practice it is not supported 

( HP COBOL V2.9-1453 on OpenVMS IA64 V8.3-1H1 )

 

01 a_word USAGE IS BINARY-SHORT.
.....................^
%COBOL-F-SYN4, Invalid USAGE clause
at line number 8 in file SYS$SYSDEVICE:[HEIN]TMP.COB;11
01 a_word USAGE IS BINARY-SHORT.
...^
%COBOL-E-PICREQ, PICTURE clause required - PIC X or PIC 9 assumed, depending on usage

 

Here is how you can 'just do it', as per DEBUGGER output...

 

$ run tmp
DBG> go
 comp_5=2767 a_comp=2767 a_hack=2767
DBG> ex/word comp_5, a_comp, a_hack
MY_MAIN_PROGRAM\MY_MAIN_PROGRAM\COMP-5: +32767
MY_MAIN_PROGRAM\MY_MAIN_PROGRAM\A-COMP: +32767
A-HACK of MY_MAIN_PROGRAM\MY_MAIN_PROGRAM\ :    +32767

$ type tmp.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. my-main-program.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 comp_5   PIC 9(4) USAGE COMP-5.
01 a_comp   PIC 9(4) USAGE COMP.
* 01 a_word   USAGE IS BINARY-SHORT.
01 a_long   PIC 9(9) USAGE COMP.
01 REDEFINES a_long.
  03 a_hack PIC 9(4).

PROCEDURE DIVISION.
MY_MAIN SECTION.
MAIN.
    MOVE 32767 TO comp_5.
    MOVE 32767 TO a_comp.
*    MOVE 32767 TO a_word.
    MOVE 32767 TO a_long.
    DISPLAY " comp_5=", comp_5 WITH CONVERSION,
            " a_comp=", a_comp WITH CONVERSION,
*            " a_word=", a_comp WITH CONVERSION,
            " a_hack=", a_comp WITH CONVERSION.
    STOP RUN.

 Enjoy,

Hein.

 

 

 

 

Occasional Contributor
cachaza
Posts: 5
Registered: ‎10-18-2012
Message 3 of 4 (504 Views)

Re: cobol truncate

Thank you very very much !!!!

Trusted Contributor
Richard J Maher
Posts: 397
Registered: ‎12-26-2005
Message 4 of 4 (458 Views)

Re: cobol truncate

Unless it's VAX in which case unsigned integers are not supported

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.