[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

3.6.3 Multiple Receiving Items

If you write a MOVE statement containing more than one receiving item, the compiler moves the same sending item value to each of the receiving items. It has essentially the same effect as a series of separate MOVE statements, all with the same sending item.

The receiving items need have no relationship to each other. The compiler checks the validity of each one independently and performs an independent move operation on each one.

Multiple receiving items on MOVE statements provide a convenient way to set many items equal to the same value, such as during initialization code at the beginning of a section of processing. For example:


MOVE SPACES TO LIST-LINE, EXCEPTION-LINE, NAME-FLD.

MOVE ZEROS TO EOL-FLAG, EXCEPT-FLAG, NAME-FLAG.

MOVE 1 TO COUNT-1, CHAR-PTR, CURSOR.

3.6.4 Subscripted Moves

Any item (other than a data item that is not subordinate to an OCCURS clause) of a MOVE statement can be subscripted, and the referenced item can be used to subscript another name in the same statement.

For example, when more than one receiving item is named in the same MOVE statement, the order in which the compiler evaluates the subscripts affects the results of the move. Consider the following examples:


MOVE FIELD1(FIELD2) TO FIELD2 FIELD3.

In this example, the compiler evaluates FIELD1(FIELD2) only once, before it moves any data to the receiving items. It is as if the single MOVE statement were replaced with the following three statements:


MOVE FIELD1(FIELD2) TO TEMP.

MOVE TEMP TO FIELD2.

MOVE TEMP TO FIELD3.

In the following example, the compiler evaluates FIELD3(FIELD2) immediately before moving the data into it, but after moving the data from FIELD1 to FIELD2:


MOVE FIELD1 TO FIELD2 FIELD3(FIELD2).

Thus, it uses the newly stored value of FIELD2 as the subscript value. It is as if the single MOVE statement were replaced with the following two statements:


MOVE FIELD1 TO FIELD2.

MOVE FIELD1 TO FIELD3(FIELD2).

3.6.5 Common Nonnumeric Item MOVE Statement Errors

The compiler considers any MOVE statement that contains a group item (whether sending or receiving) to be a group move. If an elementary item contains editing characters or a numeric integer, these attributes of the receiving item have no effect on the action of a group move.

3.6.6 Using the MOVE CORRESPONDING Statement for Nonnumeric Items

The MOVE CORRESPONDING statement allows you to move multiple items from one group item to another group item, using a single MOVE statement. Refer to the HP COBOL Reference Manual for rules concerning the CORRESPONDING phrase. When you use the CORRESPONDING phrase, the compiler performs an independent move operation on each pair of corresponding items from the operands and checks the validity of each. Example 3-2 shows the use of the MOVE CORRESPONDING statement.

Example 3-2 Sample Record Description Using the MOVE CORRESPONDING Statement

01 A-GROUP.                       01 B-GROUP.
   02 FIELD1.                        02 FIELD1.
      03 A PIC X.                       03 A PIC X.
      03 B PIC 9.                       03 C PIC XX.
      03 C PIC XX.                      03 E PIC XXX.
      03 D PIC 99.
      03 E PIC XXX.

    MOVE CORRESPONDING
         A-GROUP TO B-GROUP.


Equivalent MOVE statements:

MOVE A OF A-GROUP TO A OF B-GROUP.

MOVE C OF A-GROUP TO C OF B-GROUP.

MOVE E OF A-GROUP TO E OF B-GROUP.

3.6.7 Using Reference Modification

You can use reference modification to define a subset of a data item by specifying its leftmost character position and length. Reference modification is valid anywhere an alphanumeric identifier is allowed unless specific rules for a general format prohibit it. The following is an example of reference modification:


WORKING-STORAGE SECTION.
01  ITEMA  PIC X(10)  VALUE IS "XYZABCDEFG".
        .
        .
        .
    MOVE ITEMA(4:3) TO...





IDENTIFIER                 VALUE

ITEMA (4:3)                ABC

For more information on reference modification rules, refer to the HP COBOL Reference Manual.


Chapter 4
Handling Tables

A table is one or more repetitions of one element, composed of one or more data items, stored in contiguous memory locations.

In this chapter you will find:

4.1 Defining Tables

You define a table by using an OCCURS clause following a data description entry. The literal integer value you specify in the OCCURS clause determines the number of repetitions, or occurrences, of the data description entry, thus creating a table. HP COBOL allows you to define from 1- to 48-dimension tables.

After you have defined a table, you can load it with data. One way to load a table is to use the INITIALIZE statement or the VALUE clause to assign values to the table when you define it (see Figure 4-10).

To access data stored in tables, use subscripted or indexed procedural instructions. In either case, you can directly access a known table element occurrence or search for an occurrence based on some known condition.

You can define either fixed-length tables or variable-length tables, and they may be single or multidimensional. The following sections describe how to use the OCCURS clause and its options. For more information on tables and subscripting, refer to the HP COBOL Reference Manual.

4.1.1 Defining Fixed-Length, One-Dimensional Tables

To define fixed-length tables, use Format 1 of the OCCURS clause (refer to the HP COBOL Reference Manual). This format is useful when you are storing large amounts of stable or frequently used reference data. Options allow you to define single or multiple keys, or indexes, or both.

A definition of a one-dimensional table is shown in Example 4-1. The integer 2 in the OCCURS 2 TIMES clause determines the number of element repetitions. For the table to have any real meaning, this integer must be equal to or greater than 2.

Example 4-1 One-Dimensional Table

01  TABLE-A.
    05  ITEM-B PIC X OCCURS 2 TIMES.

The organization of TABLE-A is shown in Figure 4-1.

Figure 4-1 Organization of the One-Dimensional Table


Example 4-1 specifies only a single data item. However, you can specify as many data items as you need in the table. Multiple data items are shown in Example 4-2.

Example 4-2 Multiple Data Items in a One-Dimensional Table

01  TABLE-A.
    05  GROUP-B OCCURS 2 TIMES.
        10  ITEMC PIC X.
        10  ITEMD PIC X.

The organization of this table is shown in Figure 4-2.

Figure 4-2 Organization of Multiple Data Items in a One-Dimensional Table


Example 4-1 and Example 4-2 both do not use the KEY IS or INDEXED BY optional phrases. The INDEXED BY phrase implicitly defines an index name. This phrase must be used if any Procedure Division statements contain indexed references to the data name that contains the OCCURS clause. The KEY IS phrase means that repeated data is arranged in ascending or descending order according to the values in the data items that contain the OCCURS clause. (The KEY IS phrase does not cause the data in the table to be placed in ascending or descending order; rather, it allows you to state how you have arranged the data.) For further information about these OCCURS clause options, refer to the HP COBOL Reference Manual.

If you use either the SEARCH or the SEARCH ALL statement, you must specify at least one index. The SEARCH ALL statement also requires that you specify at least one key. Specify the search key using the ASCENDING/DESCENDING KEY IS phrase. (See Section 4.3.8 for information about the SEARCH statement and Section 4.3.4 for information about indexing.) When you use the INDEXED BY phrase, the index is internally defined and cannot be defined elsewhere. Example 4-3 defines a table with an ascending search key and an index.

Example 4-3 Defining a Table with an Index and an Ascending Search Key

01  TABLE-A.
    05  ELEMENTB OCCURS 5 TIMES
                 ASCENDING KEY IS ITEMC
                 INDEXED BY INDX1.
        10  ITEMC PIC X.
        10  ITEMD PIC X.

The organization of this table is shown in Figure 4-3.

Figure 4-3 Organization of a Table with an Index and an Ascending Search Key



Previous Next Contents Index