HP 3000 Manuals

HP COBOL II/XL Enhancements [ COMMUNICATOR 3000/XL XL RELEASE 3.0 ] MPE/iX Communicators


COMMUNICATOR 3000/XL XL RELEASE 3.0

HP COBOL II/XL Enhancements 

by Jan Merrill 
Systems Technology Division  

DYNAMIC FILE ASSIGNMENT 

With dynamic file assignment, you can assign logical files to physical
files at run time.  This assignment can be changed during the course of
program execution.

The USING phrase of the ASSIGN clause adds dynamic file assignment
capability to HP COBOL II/XL programs.

The new syntax of the ASSIGN clause of the SELECT statement is:

     SELECT [OPTIONAL] file-name-1

               { TO file-info-1  [USING data-name-1] }
     ASSIGN    {                                     }
               { USING data-name-1                   }

The ASSIGN clause specifies the association of the file referenced by
file-name-1 with a storage medium referenced by file-info-1 or the
contents of the data item referenced by data-name-1.  The association
occurs at the time of executionof an OPEN, SORT, or MERGE statement that
referenced the file-name-1, according to the following rules:

   1.  If the TO phrase of the ASSIGN clause is specified and the USING
       phrase is omitted, the file referenced by the file-name-1 is
       associated with a storage medium referenced by the specification
       of file-info-1 in the program that executes the OPEN, SORT, or
       MERGE statement.

   2.  If the USING phrase of the ASSIGN clause is specified, the file
       referenced by file-name-1 is associated with a storage medium
       referenced by the contents ofthe data item referenced by
       data-name-1 in the program that executes the OPEN, SORT, or MERGE
       statement.  The contents of the data item referenced by
       data-name-1 must be the operating system file designator for the
       file.  The file designator in file-info-1 is ignored if the USING
       clause is specified.

       If the association cannot be made because the contents of the data
       item referenced by data-name-1 are not consistent with the
       specification for file-info-1 the OPEN, SORT, or MERGE statement
       is unsuccessful.

       Data-name-1 must reference an alphanumeric data item and must not
       be subordinate to the file description entry for file-name-1.

       When creating an indexed file, the KSAM key file will be named as
       follows:  If the file designator length is less than 8, the letter
       K will be appended to it.  If the file designator length is equal
       to 8, the letter K will be substituted for the last character.

You can change the file assignment by closing the file referenced by
file-name-1, modifying the contents of the data item referenced by
data-name-1, and then issuing an OPEN, SORT, or MERGE statement that
references file-name-1.

A File Status Code, 31, has been added.  It is described below:

     A permanent error exists during execution of an OPEN, SORT, or MERGE
     statement because the contents of the data item referenced by the
     data-name-1 specified in the USING phrase of the SELECT clause are
     not consistent with the specification for the file-info-1 in the
     ASSIGN phrase of that SELECT clause.  For example, this error occurs
     if data-name-1 contains an invalid file name.

SPECIAL REGISTER FOR INTERPROGRAM COMMUNICATION 

The RETURN-CODE special register can be set in a called program and
passed to the calling program through the GIVING phrase of the CALL
statement.  The RETURN-CODE special register must be set prior to the
execution of an EXIT PROGRAM or GOBACK statement in the called program.
In the called program, the RETURN-CODE is valid as a data-name in a
procedure division statement wherever an elementary data item may be
referenced.

The calling program can access the RETURN-CODE value by calling the
subprogram with the GIVING phrase.  Define the data item of the GIVING
phrase with a PICTURE clause of S9(9) BINARY to match the size of the
implied definition of RETURN-CODE. Otherwise, a type checking error may
occur at link time.

If a program already contains a declaration for a data item called
RETURN-CODE, the compiler assumes that you do not want to use the special
register and uses the user-defined declaration instead of the implied
special register declaration.  Therefore, existing programs that do not
use the special register require no modification.

Note that if you call a program that contains RETURN-CODE as a
user-defined data item, the RETURN-CODE special register will not be set,
and the data item used in the GIVING phrase in the calling program will
contain uninitialized data.  To avoid this problem, rename the
user-defined RETURN-CODE data item so that the RETURN-CODE special
register will be activated.

In the following sample program, the calling program defines RESULT in
the GIVING phrase of the CALL statement.  The called program uses
RETURN-CODE to pass the functional return value back to RESULT in the
calling program.

     001000 IDENTIFICATION DIVISION.
     001100 PROGRAM-ID. RETURN-CODE-TEST.
     001200 DATA DIVISION.
     001300 WORKING-STORAGE SECTION.
     001400 01 BUF        PIC S9(09) BINARY VALUE 99.
     001500 01 RESULT     PIC S9(09) BINARY VALUE -99.
     001600 PROCEDURE DIVISION.
     001700 START-IT.
     001800     CALL "ABCD" USING BUF GIVING RESULT.
     001900     DISPLAY RESULT.
     002000     CALL "CCCC"          GIVING RESULT.
     002100     DISPLAY RESULT.
     002200 END PROGRAM RETURN-CODE-TEST.
     002300$CONTROL DYNAMIC
     002400 IDENTIFICATION DIVISION.
     002500 PROGRAM-ID. ABCD.
     002600 DATA DIVISION.
     002700 LINKAGE SECTION.
     002800 01 BUF        PIC S9(09) BINARY.
     002900 PROCEDURE DIVISION USING BUF.
     003100 AA. ADD 1 TO BUF GIVING RETURN-CODE.
     003200     EXIT PROGRAM.
     003300 BB.
     003400 ENTRY "CCCC".
     003500     MOVE -100 TO RETURN-CODE.

When this program is run, the program displays 100 and -100 as output.

REVIEW OF VALIDATE AND NOVALIDATE 

On MPE V/E systems, validity checking of numeric DISPLAY and
PACKED-DECIMAL data items is automatically done in the microcode.  When
HP COBOL II/V programs are run on MPE XL systems, the operating system
simulates all of the validity checking that is done by the microcode on
MPE V/E systems.  With HP COBOL II/XL, validity checking is not done
automatically.  You can code your own validity checking in your source
code.  Or, you can control validity checking by setting the VALIDATE or
NOVALIDATE compiler option at compile time, and optionally setting the
COBRUNTIME variable at run time.  When you request validity checking, the
checking is done in the software, since MPE XL systems do not contain
microcode.

The default validity checking option is $CONTROL NOVALIDATE; that is, no
validation other than that which takes place within your program is
performed.  Your program can explicitly check data when transferring
numeric data items.  For example, you can use a de-edited MOVE to move a
numeric edited field to a numeric field:  the MOVE checks that no illegal
characters or blanks are moved to the numeric field.  You can also use
the NUMERIC class condition to detect invalid digits.  In addition, some
correction of invalid data is done if the data requires conversion from
one data type to another (for example, when a DISPLAY data item is moved
to a BINARY or PACKED-DECIMAL data item).  Blanks in numeric DISPLAY data
items are treated as zeroes in some calculations, although the invalid
data is not corrected when the NOVALIDATE option is used.  NOVALIDATE
provides better performance because no additional validity checking code
is generated with this option.

The $CONTROL VALIDATE option allows you to specify that you want numeric
data to be checked for validity.  With VALIDATE, the compiler generates
code for each arithmetic operation or MOVE or other reference, and checks
for valid decimal digits and signs in the data associated with all
identifiers having USAGE is DISPLAY, PACKED-DECIMAL, or COMPUTATIONAL-3
clauses.  When a program that was compiled with the VALIDATE option
encounters an illegal ASCII or decimal digit or an invalid sign, control
is passed to a trap handling routine, and the action you specify with the
COBRUNTIME variable at run time is performed.

Using VALIDATE may have an impact on performance because extra code is
generated by the compiler to check the validity of each arithmetic, MOVE,
or other statement which references numeric data.  If invalid data is
detected, thousands of machine instructions are executed to correct the
illegal data, if you request data correction.

This performance impact should be taken into account when considering use
of the illegal ASCII/decimal digit trap to correct leading blanks and
invalid signs.  You should consider changing the source code of the
program when it is likely that this trap will occur every time a
particular field is referenced, and the number of references is a large
percentage of the statements of the program.  Your source code changes
would check numeric fields for illegal data and correct them.  This would
eliminate the need for VALIDATE.

In summary, when you migrate COBOL II source code from MPE V/E to MPE XL
systems, compiling with VALIDATE and testing the programs helps you
determine what code is dependent on the MPE V/E microcode validity
checking.  For better performance, you can add your own checking and
recompile without VALIDATE.

SUMMARY OF COBRUNTIME OPTIONS 

When you compile with $CONTROL VALIDATE, you can set the COBRUNTIME
variable at run time to control the handling of error conditions detected
by VALIDATE. The nine positions of COBRUNTIME are associated with the
following traps:

     Character   Trap Type
     Position

     1           Illegal ASCII Digit or Illegal Decimal Digit
     2           Range Error
     3           No SIZE ERROR clause
     4           Invalid GO TO
     5           Address Alignment
     6           Paragraph Stack Overflow
     7           Leading blanks in numeric field
     8           Signed value in unsigned field/Unsigned value in signed field
     9           With IF NUMERIC test, signed value in unsigned
                    PACKED-DECIMAL field/Unsigned value in signed
                    PACKED-DECIMAL field, or any invalid sign nibble

Although VALIDATE does not completely perform all the automatic checking
and data correction that is done in the microcode on MPE V/E systems,
setting the COBRUNTIME string to MCCAAANNI closely simulates the behavior
on MPE V/E systems.

RECENT TRAP HANDLING ENHANCEMENTS 

The $CONTROL VALIDATE option of HP COBOL II/XL does not completely
perform all the automatic checking that is done in the microcode on MPE
V/E systems.  However, several recent enhancements to the trap handling
routines provide greater compatibility with the handling of illegal data
on MPE V/E systems.

Leading Blanks and Invalid Signs 

Leading blanks and invalid signs are two special cases of the illegal
ASCII/decimal digit trap.  Setting COBRUNTIME positions 7 and 8 to N
allows correction of these two cases without issuing a message, while
continuing to allow you to get a message for other instances of illegal
digits.

For example, if you want leading blanks changed to zeroes without any
messages printed, compile the program with $CONTROL VALIDATE. Then before
the program is executed, issue the SETVAR command to set COBRUNTIME to
CbbbbbN, where b is a space.  If the program encounters a numeric field
that contains illegal digits, the following actions occur:

   1.  If the only illegal digits are leading blanks:  fix up leading
       blanks and continue.

   2.  If it has an invalid sign:  print an error message and continue.

   3.  If it has any other illegal digits:  print an error message and
       continue.

Numeric Class Testing 

HP COBOL II/XL has been enhanced to allow IF NUMERIC tests to ignore
invalid signs in PACKED-DECIMAL (COMPUTATIONAL-3) data.  This enhancement
provides greater compatibility with IF NUMERIC tests in HP COBOL II/V.
With COBRUNTIME position 9 set to I, the numeric test will not return a
truth value of false because a signed numeric field contains unsigned
data or vice versa, or because a signed numeric field contains an invalid
sign nibble.  Without COBRUNTIME 9 set to I, the IF NUMERIC test returns
a truth value of false because of the invalid sign.  This enhancement is
available in HP COBOL II/XL version A.02.02 and later.

Modifying Source 

When a numeric data item containing illegal ASCII or decimal digits is
moved to another numeric item, you can request correction of the illegal
digits by compiling with $CONTROL VALIDATE and setting COBRUNTIME
position 1 to M or N, or position 7 to N. When the illegal character is
detected in the source field, the compiler corrects the illegal digits in
the source field, then executes the MOVE again.

The compiler was enhanced for moves from PIC X fields to PIC 9 fields:
instead of correcting the source field, the compiler now uses a temporary
location for correction.  Therefore, the source field is not modified.
This enhancement is available in HP COBOL II/XL version A.02.12 and
later.

IEEE Traps 

When the compiler calls COBOLTRAP to arm the trap mechanism, the compiler
now automatically sets traps for IEEE real numbers.  A side effect of
this change may cause your program to abort if you pass an invalid
parameter to the PAUSE intrinsic.  The PAUSE intrinsic expects an IEEE
real number parameter.  To call PAUSE correctly, first you can call the
utility procedure EXTIN' or HPEXTIN to convert a string of ASCII digits
to a real number output in a field defined as PIC S9(9) BINARY. Then call
PAUSE with the result of the utility procedure.  This modification is
available in HP COBOL II/XL version A.02.02 and later.

For more information on handling run-time errors, see the HP COBOL II/XL 
Reference Manual Supplement (P/N 31500-90005).

RECENT COMPILER OPTION ENHANCEMENTS 

Several enhancements to the preprocessor commands are available in later
versions of HP COBOL II/XL.

$CONTROL NLS 

The $CONTROL NLS compiler option provides support for international
(multi-byte or non-ASCII) characters in certain character operations.
NLS refers to Native Language Support.  This option makes string
comparisons sensitive to international character sets, and allows input
and output of international characters.  This option also inserts the
appropriate single-byte decimal point, comma and currency sign in edited
fields, based on the language indicated by the NLDATALANG Job Control
Word (JCW).

This compiler option is available in HP COBOL II/XL version A.02.12 and
later.  For more information, refer to the HP COBOL II/XL Technical 
Addendum (P/N 31500-90011) included with this release.

$VERSION 

The $VERSION compiler option allows you to include one or more strings of
characters in the object file generated by the compiler.  The syntax of
$VERSION is the same as the $PAGE option, except the total number of
characters used in the strings is limited to 255.  Once a program has
been compiled with $VERSION, you can display the version strings by
running the utility program, VERSION.PUB.SYS. If you compile a source
file with many $VERSION commands, only the last $VERSION command is put
in the object file.  This compiler option is available in HP COBOL II/XL
version A.02.02 and later.

$COPYRIGHT 

The $COPYRIGHT compiler option allows you to include one or more strings
of characters in the object file generated by the compiler.  The syntax
of $COPYRIGHT is the same as the $PAGE option, except the total number of
characters used in the strings is limited to 116.  Once a program has
been compiled with $COPYRIGHT, you can display the copyright strings with
FCOPY. If you compile a source file with many $COPYRIGHT commands, only
the last $COPYRIGHT command is put in the object file.  This compiler
option is available in all versions of HP COBOL II/XL.

HP COBOL II AND KSAM XL FILES 

XL Release 2.1 introduced support for Native Mode KSAM (KSAM XL) file
access, in addition to support for Compatibility Mode KSAM (CM KSAM) file
access.  This section describes several HP COBOL II-specific
considerations for using KSAM XL file access.

Accessing Data Files 

Both HP COBOL II/XL and HP COBOL II/V programs can access existing KSAM
XL files, as well as existing CM KSAM files.

Building Data Files 

HP COBOL II/V programs build CM KSAM data files by default.  You can
override this by issuing a file equation containing the ;KSAMXL keyword
and by back-referencing the file.

HP COBOL II/XL programs build KSAM XL data files, unless they are
variable length files.  Variable length files are built as CM KSAM files.
CM KSAM data files cannot be built by overriding with a file equation
because the file type cannot be specified in the file equation.

Accessing COPY Libraries 

Both the HP COBOL II/XL and HP COBOL II/V compilers can access KSAM XL
COPY libraries, as well as CM KSAM COPY libraries.  However, the HP COBOL
II/V compiler treats KSAM XL libraries as flat files, not keyed files.
This sequential access may slow down HP COBOL II/V compiles.

COBEDIT can access KSAM XL and CM KSAM COPY libraries for editing and
listing.

Building COPY Libraries 

The COBEDIT BUILD command builds a CM KSAM file by default.  You can
override this by issuing a file equation and back-referencing the file,
as in the following example:

     :FILE MYLIB;KSAMXL
     :COBEDIT
     >BUILD *MYLIB
     Name a key file to be used with *MYLIB:  <RETURN>
     Library file created.

The BUILD command asks for a key file name.  Since KSAM XL files do not
use a key file, press RETURN to respond.

Performance/Migration Considerations 

You can achieve the best performance by using the HP COBOL II/XL compiler
and KSAM XL files.  This option does not use many switch stubs to switch
processing between Native Mode and Compatibility Mode.

Because of performance improvements in KSAM XL processing compared with
CM KSAM processing, both HP COBOL II/V and HP COBOL II/XL programs may
run faster using KSAM XL files than using CM KSAM files.

If you use the HP COBOL II/V compiler as well as the HP COBOL II/XL
compiler, you may want to maintain any common COPY libraries as CM KSAM
files.  This option allows both compilers to read the COPY libraries with
keyed access.  However, the HP COBOL II/XL compiler may run slightly
faster with a KSAM XL COPY library.

If you plan to transfer KSAM XL files to an MPE V/E system, you must
convert them to CM KSAM with FCOPY before you transfer them.  Also, if
you run a HP COBOL II/V program on a pre-V-Delta-7 MPE V/E system that
accesses a KSAM XL file on an MPE XL system, the program will not be able
to read the file.



MPE/iX Communicators