There are many ways to manipulate nonnumeric data in a COBOL program. For example, you can:

  • Move data items (MOVE statement)
  • Count and replace data items (INSPECT statement)
  • Join data items (STRING statement)
  • Split data items (UNSTRING statement)
  • Initialize variables (INITIALIZE statement)
  • Manipulate addresses with pointer data items (SET statement)

Moving Data Items (MOVE Statement)

You can move data around with the MOVE statement. When you move a group item to another group item, be sure that the subordinate data descriptions are compatible. If you specify a MOVE statement for file items or Working-Storage items that overlap, you will get a warning message at compile time. However, the move will take place with destructive overlap if you choose to ignore the warning

Counting and Replacing Data Items (INSPECT Statement)

The INSPECT statement is useful for filling selective portions of a data item with a value, or for replacing portions with a corresponding portion of another data item. You can also use it for counting the number of times a specific character (zero, space, asterisk, for example) occurs in a data item.

Joining Data Items (STRING Statement)

You can use the STRING statement to join all or parts of several data items into one data item. One STRING statement can save you several MOVE statements. The STRING statement transfers data into the receiving item in the order you specify. You can specify:

  • Delimiters that cause a sending field to be ended and another to be begun
  • Special actions to be taken when an ON OVERFLOW condition occurs—that is, when the single receiving field is filled before all of the sending characters have been processed.

Splitting Data Items (UNSTRING Statement)

You can use the UNSTRING statement to split one sending field into several receiving fields. One UNSTRING statement can save you several MOVE statements. As with the STRING statement, you can specify delimiters that, when encountered in the sending field, cause the current receiving field to be switched to the next one specified. You can get back the number of characters placed in each receiving field, and you can keep a count of the total number cjf characters transferred. If all the receiving fields are filled before the end of the sending item is reached, you can specify special actions for the program to take.

Initializing Variables

You can use a VALUE clause in the Data Division to initialize data items, or you can initialize them in the Procedure Division. Use the VALUE clause to set data items to the values you want them to have when the program is in its initial state. In the Procedure Division, you can use any of the following statements to initialize data items: INITIALIZE, INSPECT, MOVE, SET, etc. It is recommended that initialization in the Procedure Division be done in a separate paragraph at the beginning of the division. This paragraph can also contain OPEN statements for files used in the program.

Manipulating Addresses with Pointer Data Items

Pointer data items can contain virtual storage addresses. You define them explicitly with the USAGE IS POINTER clause in the Data Division or implicitly as ADDRESS OF special registers. Pointer data items can be:

  • Passed between programs (CALL... BY REFERENCE statement)
  • Moved to other pointers (SET statement)
  • Compared to other pointers for equality (relation condition)
  • Initialized to contain an invalid address (VALUE IS NULL)

You can use pointer data items when you want to accomplish limited base addressing, particularly when you want to pass and receive addresses of a variably located record area. You can also use pointers to handle a chained list.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

IBM Mainframe Topics