[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

Additional examples containing Hewlett-Packard extensions to the ACCEPT statement (Formats 3, 4, and 5) are described in the HP COBOL User Manual. Refer to the description of programming video forms.

Also, examples containing extensions to the ACCEPT statement (Formats 6, 7 and 8) that access command line arguments are described in the HP COBOL User Manual.

6.8.2 ADD

Function

The ADD statement adds two or more numeric operands and stores the sum in one or more receiving fields.


num

is a numeric literal or the identifier of an elementary numeric item.

rsult

is the identifier of an elementary numeric item. However, in Format 2, rsult can be an elementary numeric edited item. It is the resultant identifier.

stment

is an imperative statement executed when a size error condition has occurred.

stment2

is an imperative statement executed when no on size error condition has occurred.

grp-1

is the identifier of numeric group item.

grp-2

is the identifier of numeric group item.

Syntax Rule

CORR is an abbreviation for CORRESPONDING.

General Rules

  1. In Format 1, the values of the operands before the word TO are added together. This total is then added to each occurrence of rsult.
  2. In Format 2, the values of the operands before the word GIVING are added. The sum is then stored in each rsult.
  3. In Format 3, data items in grp-1 are added to and stored in the corresponding data items in grp-2.

Additional References

Examples

Each of the examples assume the following data descriptions and initial values:

INITIAL VALUES


     03  ITEMA  PIC 99 VALUE 85.                85
     03  ITEMB  PIC 99 VALUE 2.                 2
     03  ITEMC  VALUE "123".
         05  ITEMD  OCCURS 3 TIMES              1 2 3
                 PIC 9.
  1. TO phrase: RESULTS


    ADD 2 ITEMB TO ITEMA.                           ITEMA = 89
    
  2. SIZE ERROR clause:


    ADD 38 TO ITEMA ITEMB                           ITEMA = 85
                                                    ITEMB = 40
      ON SIZE ERROR
        MOVE 0 TO ITEMB.                            ITEMB = 0
    

    (When the SIZE ERROR condition occurs, the value of the affected resultant identifier does not change. The SIZE ERROR condition occurs on ITEMA but not on ITEMB.)
  3. NOT ON SIZE ERROR clause:


    ADD 14 TO ITEMA                                 ITEMA = 99
       ON SIZE ERROR
           MOVE 0 TO ITEMB.
       NOT ON SIZE ERROR
           MOVE 1 TO ITEMB.                         ITEMB = 1
    

    (If the SIZE ERROR condition had occurred, the value of ITEMA would have been 85 and ITEMB would have been 0.)

  4. Multiple receiving fields:


    ADD 1 TO ITEMB ITEMD (ITEMB).                   ITEMB = 3
                                                    ITEMD (3) = 4
    

    (The operations proceed from left to right. Therefore, the subscript for ITEMD is evaluated after the addition changes its value.)
  5. GIVING phrase:


    ADD ITEMB ITEMD (ITEMB) GIVING ITEMA.           ITEMA = 4
    
  6. END-ADD:


    IF ITEMB < 10
      ADD 7 ITEMB TO ITEMD (ITEMB)                  ITEMD (2) = 2
        ON SIZE ERROR
          MOVE 0 TO ITEMB                           ITEMB = 0
      END-ADD
      ADD 1 TO ITEMB.                               ITEMB = 1
    

    (The first ADD terminates with END-ADD. If the SIZE ERROR condition had not occurred, the second ADD statement would have executed anyway; the value of ITEMB would have been 3.)

6.8.3 ALTER

Function

The ALTER statement changes the destination of a GO TO statement.


proc

is the name of a paragraph that contains one sentence: a GO TO statement without the DEPENDING phrase.

new-proc

is a procedure-name.

General Rules

  1. The ALTER statement changes the destination of the GO TO statement in proc.
  2. When the changed GO TO executes, it transfers control to new-proc instead of the procedure it previously referred to.
    However, when the GO TO statement is in an independent segment (segment-number 50 to 99), the GO TO statement could return to its initial state under some circumstances.
  3. A GO TO statement in a section with a segment-number greater than 49 cannot be changed by an ALTER statement in a section with a different segment-number.

Additional References

Examples

The examples assume the following Procedure Division code:


PROC-AA.
        DISPLAY "PROC-A".
PROC-A.
        GO TO PROC-BB.
PROC-BB.
        DISPLAY "PROC-B".
PROC-B.
        GO TO PROC-DD.
PROC-CC.
        DISPLAY "PROC-C".
PROC-C.
        GO TO PROC-FF.
PROC-DD.
        DISPLAY "PROC-D".
PROC-D.
        GO TO PROC-CC.
PROC-EE.
        DISPLAY "PROC-E".
PROC-E.
        GO TO.
PROC-FF.
        DISPLAY "PROC-F".
PROC-F.
        EXIT.
  1. As written.
    Output
    PROC-A
    PROC-B
    PROC-D
    PROC-C
    PROC-F
  2. ALTER PROC-A TO PROC-EE PROC-E TO PROC-CC.
    Output
    PROC-A
    PROC-E
    PROC-C
    PROC-F
  3. ALTER PROC-D TO PROC-EE PROC-C TO PROC-AA.
    Output
    PROC-A
    PROC-B
    PROC-D
    PROC-E
    error at PROC-E

6.8.4 CALL

Function

The CALL statement transfers control to another program in the executable image.


prog-name

is a nonnumeric literal or the identifier of an alphanumeric data item. It is the name of the program to which control transfers.

arg

is the argument. It identifies the data that is available to both the calling and called programs. It is any data item described in the File Section, Working-Storage Section, or Linkage Section, or it is a nonnumeric literal. It must not be a function-identifier.

function-res

is the identifier of an elementary integer numeric data item with COMP, COMP-1, or COMP-2 usage and no scaling positions. function-res can be subscripted, and it can be qualified. When control returns to the calling program, function-res can contain a function result.

stment

is an imperative statement executed for an on exception or an overflow condition.

stment2

is an imperative statement executed for a not on exception or a not on overflow condition.

Syntax Rules

  1. prog-name must be from 1 to 31 characters long. It can contain the characters "A" to "Z", "a" to "z", "0" to "9", and hyphen (-), dollar sign ($), and underline (_).
  2. prog-name is the entry-point in the called program. For COBOL programs, prog-name is the program-name specified in the PROGRAM-ID paragraph.
  3. The same arg can appear more than once in the USING phrase.
  4. The maximum number of arguments is 255.
  5. If there is no initial argument-passing mechanism (REFERENCE, VALUE, CONTENT, or, for DESCRIPTOR), BY REFERENCE is the default.
  6. An argument-passing mechanism applies to every arg following it until a new mechanism (if any) appears.
  7. The CALL statement has a USING phrase only if a USING phrase is in the Procedure Division header of the called program. Both USING phrases must have the same number of arguments.
  8. If arg is a nonnumeric literal, only BY REFERENCE, BY CONTENT, or for OpenVMS systems, BY DESCRIPTOR can be used.
  9. OMITTED, a reserved word, indicates the absence of a specific argument. OMITTED does not change the default argument-passing mechanism; it generates BY VALUE 0 for the omitted argument.
  10. If the argument-passing mechanism is BY VALUE, arg must be either: (a) an integer numeric literal in the range -2**31 to +2**31-1, (b) a COMP-1 data item, or (c) a word or longword integer COMP data item.

General Rules

  1. The program whose name is specified by prog-name is the called program. The program containing the CALL statement is the calling program.
  2. When the CALL statement executes, the contents of prog-name are interpreted as follows:
    • Hyphens are treated as underline characters.
    • Lowercase letters are treated as uppercase (See the Technical Notes relating to case sensitivity later in this section).
    • Leading and trailing spaces and tab characters are ignored.
  3. The CALL statement transfers control to the called program.
  4. Two or more programs in the run unit can have the same prog-name. The scope of names conventions for program-names resolve the CALL statement references to duplicate prog-names. (See the section on Conventions for Resolving Program-Name References.)
  5. If prog-name is an identifier, the CALL statement can transfer control only to HP COBOL programs.
  6. The ON EXCEPTION phrase is interchangeable with the ON OVERFLOW phrase.
  7. If prog-name is not in the executable image and there is an ON EXCEPTION phrase, any NOT ON EXCEPTION phrase is ignored, stment executes, and control is transferred to the end of the CALL statement.
  8. If prog-name is in the executable image, and there is an ON OVERFLOW phrase or ON EXCEPTION phrase, both phrases are ignored. Control is transferred either to the end of the CALL statement or, if NOT ON EXCEPTION is specified, to stment2. After stment2 executes, control is transferred to the end of the CALL statement.
  9. If prog-name is not in the executable image and there is no ON EXCEPTION phrase, an error condition exists; the program terminates abnormally.
  10. If the called program does not have the initial attribute, it, and each program directly or indirectly contained in it, is in its initial state: (a) the first time it is called in an image, and (b) the first time it is called after a CANCEL to the called program.
    On all other entries, the state of the called program is the same as when it was last exited. The program state includes internal data.
  11. If the called program has the initial attribute, it, and each program directly or indirectly contained in it, is in its initial state every time it is called.
  12. Files associated with a called program's internal file connectors are not in the open mode:
    • The first time the program is called
    • The first time the program is called after execution of a CANCEL statement referring to the program
    • Every time the program is called, if it has the initial attribute

    On all other entries, the status and positioning of such files in a called program are the same as when the program was last exited.
  13. The process of calling a program or exiting from a called program does not alter the status or positioning of a file associated with any external file connector.
  14. The arguments' order of appearance in the USING phrases of the CALL statement and the called program's Procedure Division header determine correspondence between the data-names used by the calling and called programs. Data-names correspond by position in the USING phrase, not by name.
    No correspondence exists for index-names. If a table is passed as an argument, the index associated with that table in the called program will be the one specified in the INDEXED BY phrase in the called program, not the index specified in the calling program.
  15. The arguments in the CALL statement USING phrase are made available to the called program when the CALL executes.
  16. Called programs can contain CALL statements. However, a called program must not execute a CALL statement that directly or indirectly calls the calling program.
  17. The CALL statement can make data available to the called program by four argument-passing mechanisms:
    • REFERENCE---The address of (pointer to) arg is passed to the called program. This is the default mechanism: arguments are passed BY REFERENCE if there is no explicit mechanism in the CALL statement.
    • CONTENT---The address of a temporary data item that contains the contents of arg is passed to the called program.
    • On OpenVMS, DESCRIPTOR---The address of (pointer to) the data item's descriptor is passed to the called program.
      The parameter-passing mechanism BY DESCRIPTOR is not supported on Tru64 UNIX systems, because the Tru64 UNIX calling standard does not define such a mechanism. Programs that include BY DESCRIPTOR will receive a compile-time diagnostic. <>
    • VALUE---The value of arg is passed to the called program. If arg is a data-name, its description in the Data Division can be either:
      • COMP usage with no scaling positions; the picture can specify no more than nine digits
      • COMP-1 usage

    Note that OMITTED, an HP COBOL reserved word, is equivalent to BY VALUE 0 and can be used in place of that BY VALUE argument-passing mechanism.
  18. If the called program is a COBOL program, the CALL statement can pass arguments only BY REFERENCE or BY CONTENT. If the called program is a non-COBOL program, the mechanism for each arg in the CALL statement USING phrase must be the same as the mechanism for each data-name in the called program's argument list.
  19. If the BY REFERENCE phrase is either specified or implied for a parameter, the called program references the same storage area for the data item as the calling program. This mechanism ensures that the contents of the parameter in the calling program are always identical with the contents of the parameter in the called program.
  20. If the BY CONTENT phrase is either specified or implied for a parameter, a copy of arg is moved to a temporary memory location, and the address of the temporary memory location is passed to the called program. This mechanism ensures that the called program cannot change the original contents of arg. However, the called program can change the value of the temporary memory location.
  21. The data description of each arg in the calling program must be identical to each arg in the called program. The compiler does not convert, extend, or truncate any arg passed to a called program.
  22. On Alpha and I64 systems, if the GIVING phrase of the CALL statement is not specified, the function result is made available in the RETURN-CODE special register when control returns to the calling program. <>
  23. If the GIVING phrase is specified, the function result is made available in function-res when control returns to the calling program.


Previous Next Contents Index