ILE COBOL Programmer's Guide

Data Manipulation Statements

Data Manipulation Statements

Arithmetic Statements

Because COBOL treats DBCS characters in the same manner that it treats SBCS characters, do not use DBCS characters in numeric operations, nor manipulate them with arithmetic statements.

INSPECT Statement

You can use any DBCS data item as an operand for the INSPECT statement. The system tallies and replaces on each half of a DBCS character, including the shift control characters in these operations. Therefore, the data may not be matched properly.

You can only use DBCS character operands with other DBCS character literals or data items. Mixed operands are treated as alphanumeric. If you use the REPLACING phrase, you might cause parts of an inspected mixed data item to be replaced by alphanumeric data, or parts of an inspected alphanumeric data item to be replaced by mixed data.

You cannot replace a character string with a string of a different length. Consider this when replacing SBCS characters with DBCS characters in a mixed data item, or replacing DBCS characters with SBCS characters in a mixed data item.

If you want to control the use of the INSPECT statement with mixed items containing DBCS characters, define data items containing shift control characters. Use the shift-out and shift-in characters as BEFORE/AFTER operands in the INSPECT statement.

The following example shows how you can use the INSPECT statement to replace one DBCS character with another in a mixed data item.

01  SUBJECT-ITEM                 PICTURE X(50).
01  DBCS-CHARACTERS              VALUE "0EK1K20F".
    05  SHIFT-OUT                PICTURE X.
    05  DBCS-CHARACTER-1         PICTURE XX.
    05  DBCS-CHARACTER-2         PICTURE XX.
    05  SHIFT-IN                 PICTURE X.

The INSPECT statement would be coded as follows:

INSPECT SUBJECT-ITEM
    REPLACING ALL DBCS-CHARACTER-1
              BY  DBCS-CHARACTER-2
    AFTER INITIAL SHIFT-OUT.
Note:
Using the AFTER INITIAL SHIFT-OUT phrase helps you to avoid the risk of accidentally replacing two consecutive alphanumeric characters that have the same EBCDIC values as DBCS-CHARACTER-1 (in cases where SUBJECT-ITEM contains mixed data).

You can also use the INSPECT statement to determine if a data item contains DBCS characters, so that appropriate processing can occur. For example:

01  SUBJECT-FIELD          PICTURE X(50).
01  TALLY-FIELD            PICTURE 9(3) COMP.
01  SHIFTS                 VALUE "0E0F".
    05  SHIFT-OUT          PICTURE X.
    05  SHIFT-IN           PICTURE X.

In the Procedure Division you might enter the following:

MOVE ZERO TO TALLY-FIELD.
INSPECT SUBJECT-FIELD TALLYING TALLY-FIELD
                                FOR ALL  SHIFT-OUT.
IF TALLY-FIELD IS GREATER THAN ZERO THEN
    PERFORM DBCS-PROCESSING
ELSE
    PERFORM A-N-K-PROCESSING.

MOVE Statement

All DBCS characters are moved as alphanumeric character strings. The system does not convert the data or examine it.

You can move mixed literals to group items and alphanumeric items. You can only move DBCS data items or DBCS literals to DBCS data items.

If the length of the receiving field is different from that of the sending field, COBOL does one of the following:

To understand more about the effect of editing symbols in the PICTURE clause of the receiving data item, see the WebSphere Development Studio: ILE COBOL Reference.

SET Statement (Condition-Name Format)

When you set the condition name to TRUE on this statement, COBOL moves the literal from the VALUE clause to the associated data item. You can move a literal with DBCS characters.

STRING Statement

You can use the STRING statement to construct a data item that contains DBCS subfields. All data in the source data items or literals, including shift control characters, is moved to the receiving data item, one-half of a DBCS character at a time.

UNSTRING Statement

The UNSTRING statement treats DBCS data and mixed data the same as alphanumeric data. The UNSTRING operation is performed on one-half of a DBCS character at a time.

Data items can contain both alphanumeric and DBCS characters within the same field.

Use the DELIMITED BY phrase to locate double-byte and alphanumeric subfields within a data field. Identify the data items containing shift control characters, and use those data items as identifiers on the DELIMITED BY phrase. See the following examples for more information on how to do this. Use the POINTER variable to continue scanning through subfields of the sending field.

After the system performs the UNSTRING operation, you can check the delimiters stored by the DELIMITER IN phrases against the shift control character values to see which subfields contain DBCS and which contain alphanumeric characters.

The following example shows how you might set up fields to prepare for the unstring operation on a character string that contain mixed data:

01  SUBJECT-FIELD      PICTURE X(40)
01  FILLER.
    05  UNSTRING-TABLE OCCURS 4 TIMES.
        10  RECEIVER   PICTURE X(40).
        10  DELIMTR    PICTURE X.
        10  COUNTS     PICTURE 99 COMP.
01  SHIFTS             VALUE "0E0F".
    05  SHIFT-OUT      PICTURE X.
    05  SHIFT-IN       PICTURE X.

Code the UNSTRING statement as follows:

UNSTRING SUBJECT-FIELD  DELIMITED BY SHIFT-OUT
                                    OR SHIFT-IN
INTO RECEIVER (1) DELIMITER IN DELIMTR (1)
                   COUNT     IN COUNTS (1)
INTO RECEIVER (2) DELIMITER IN DELIMTR (2)
                   COUNT     IN COUNTS (2)
INTO RECEIVER (3) DELIMITER IN DELIMTR (3)
                   COUNT     IN COUNTS (3)
INTO RECEIVER (4) DELIMITER IN DELIMTR (4)
                   COUNT     IN COUNTS (4)
ON OVERFLOW PERFORM UNSTRING-OVERFLOW-MESSAGE.

This UNSTRING statement divides a character string into its alphanumeric and DBCS parts. Assuming that the data in the character string is valid, a delimiter value of shift-out indicates that the corresponding receiving field contains alphanumeric data, while a value of shift-in indicates that corresponding receiving field has DBCS data. You can check the COUNT data items to determine whether each receiving field received any characters. The following figure is an example that shows the results of the UNSTRING operation just described:

SUBJECT-FIELD = ABC0EK1K2K30FD0EK4K5K60F
RECEIVER (1) = ABC       DELIMTR (1) = 0E   COUNTS (1) = 3
RECEIVER (2) = K1K2K3    DELIMTR (2) = 0F   COUNTS (2) = 6
RECEIVER (3) = D         DELIMTR (3) = 0E   COUNTS (3) = 1
RECEIVER (4) = K4K5K6    DELIMTR (4) = 0F   COUNTS (4) = 6
SUBJECT-FIELD = 0EK1K2K30FABC0EK40F
RECEIVER (1) = (blanks)  DELIMTR (1) = 0E   COUNTS (1) = 0
RECEIVER (2) = K1K2K3    DELIMTR (2) = 0F   COUNTS (2) = 6
RECEIVER (3) = ABC       DELIMTR (3) = 0E   COUNTS (3) = 3
RECEIVER (4) = K4        DELIMTR (4) = 0F   COUNTS (4) = 2


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]