Click here for HP sponsor message

New Features of COBOL II

By Shawn M. Gordon

Boy, was I caught by surprise by this one. There are a number of new features that have been added to COBOL as of the Express 4 MPE/iX upgrade. After checking with Walter Murray in the COBOL labs, I’ll begin by relaying HP’s message on the parts that have been added, and then get into some specifics on the last part of the enhancement. Version A.04.16 of HP COBOL II/iX, released in Express 4 for 5.5, makes available several additional enhancements that were requested by Interex’s SIGCOBOL special interest group:

1. Internal data structures of the compiler have been expanded again to permit compiling even larger programs. With Express 3 for 5.5, it was possible to compile programs in excess of 100,000 lines. While there is no specific limit on the number of lines permitted in a source program, the version of the compiler on Express 4 should be capable of processing programs well in excess of 200,000 lines.

2. The compiler has been enhanced to permit an index-name to be used as an operand of a DISPLAY statement. This is an ANSI extension, and if this feature is used and $CONTROL STDWARN is specified, the compiler will display warning 517, “DISPLAY of index-name is nonconforming nonstandard (HP extension).”

3. The run-time library has been enhanced with a set of procedures to simplify bit manipulation in COBOL II/iX.

It’s item 3 that needs further explanation, in my opinion. There are six new routines for performing boolean operations: HP_BYTE_AND, HP_BYTE_OR, HP_BYTE_XOR, HP_BYTE_NOT, HP_BYTE_UNPACK, and HP_BYTE_PACK. These procedures reside in the COBOL II run-time library in XL.PUB.SYS, but may be called from any program running in Native Mode.

The routines HP_BYTE_AND, HP_BYTE_OR, and HP_BYTE_XOR perform bitwise AND, bitwise inclusive OR, and bitwise exclusive OR. The two operands and the result may be any length, but must be the same length, and must be an integral number of bytes.

The three routines have identical calling sequences. The first two parameters are the two operands, passed by reference. The third parameter is the result, also passed by reference. The final parameter is the length, in bytes, of the operands, and is passed by value. The first three parameters may not overlap, except in the case where two of them, or all three, are the same data item.

For example;

CALL “HP_BYTE_AND” USING OPERAND-1, OPERAND-2, RESULT, \4\.
CALL “HP_BYTE_OR” USING DATA-ITEM, MY-BIT-MASK, RESULT, \2\.
CALL “HP_BYTE_XOR” USING INPUT-BUFFER (J:1), RUNNING-XOR,
RUNNING-XOR, \1\.

Note: In COBOL II/iX, backslashes (“\”) are used to indicate that a parameter is passed by value. If the parameter is a literal, the backslashes are optional.

At first glance these may not seem that useful, but I recently ran into a situation where I wanted to read the bits out of a call to the CLOCK intrinsic, and I never did find a good way to do it. If I were to use the new HP_BYTE_UNPACK function then I could unpack the integer field into a byte array. For example;

01 FIELD-A PIC S9(4) COMP.
01 RESULT PIC X(16).
...
MOVE 5 TO FIELD-A.
CALL “HP_BYTE_UNPACK” USING FIELD-A, RESULT, \2\. DISPLAY RESULT
.
Results in “0000000000000101”.
This gives you the binary representation for the field. From here you can do a variety of things, such as use the BITMAPCNV intrinsic to get the actual number out.

The HP_BYTE_PACK function is the same, but in reverse:

Figure 1

01 FIELD-A PIC S9(4) COMP.
01 RESULT PIC X(16).
...
MOVE 5 TO FIELD-A.
CALL “HP_BYTE_UNPACK” USING FIELD-A, RESULT, \2\. DISPLAY RESULT
.
Results in “0000000000000101”.

Figure 2

01 BYTE-STRING PIC X(16).
01 RESULT-N PIC S9(4) COMP.
...
MOVE “0000000000001111” TO BYTE-STRING.
CALL “HP_BYTE_PACK” USING BYTE-STRING, RESULT-N, \2\. DISPLAY RESULT-N.

Results in +15.
For some of you the uses will be obvious because you were asking for them (I wouldn’t want to see that 200,000 line program, though). For others it’s a matter of knowing the functions are now available and having that light come on at some point when you’re working on a project.

Don’t forget, if your tips make it into The Wire, you get a free 3000 Always Online hat. Send them to me at smga@compuserve.com, or fax them to the NewsWire at 512.331.3807.

Shawn M. Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.


Copyright 1998, The 3000 NewsWire. All rights reserved.