COBOL String Handling
COBOL String Handling
This verb is used to initialize a specific item or group item. ZEROES replace numeric data items. It is not
possible to initialize data names with the RENAME clause.
Alphanumeric or alphabetic data objects are replaced by SPACES. If we include the term REPLACING, the
data items can be initialized to the replacement value.
MOVE
Move verb is used to copy data from source to destination data. We can use it for both group and
elementary data items. For group items, MOVE CORRESPONDING / CORR is used.
Use the MOVE(x: l) where x is the starting position, and l is the length to transfer data from a string. The
data will be truncated if the PIC clause for the destination data item is less than the PIC clause for the
source data item. If the PIC clause for the destination data item is above, then the PIC clause for the
source data item, the additional bytes will include ZEROS or SPACES.
Class Condition
Class condition checks if an operand contains only alphabets or numeric data. Whitespaces are
considered in ALPHABETIC, ALPHABETIC-LOWER, and ALPHABETIC-UPPER.
Syntax:
[IS] [NOT]
[NUMERIC, ALPHABETIC, ALPHABETIC-LOWER, ALPHABETIC-UPPER]
Combined Condition
A combined condition statement includes two or more conditions associated with OR or AND logical
operators.
Syntax:
COBOL Statements
END-IF.
IF [CONDITION] OR [CONDITION]
COBOL Statements
END-IF.
String handling statements are used in COBOL to perform operations of string manipulation. COBOL
provides three types of statements for string handling:
· INSPECT
· STRING
· UNSTRING
INSPECT
Inspect verb replaces or counts a character or a group of characters in a string. On numeric, alphabetic,
or alphanumeric values, we can perform string operations. Inspect operations are work from left to right.
The Inspect provides two options are as follows:
Tallying
Syntax:
INSPECT input-string
Here, input-string and output string are parameters. Input-string is the string whose characters are to be
counted. And output-string is data item to hold the count of characters.
Replacing
Syntax:
Here, the input-string parameter is the string whose characters are to be replaced from char1 to char2.
STRING
The string verb is used to concatenate the partial or full contents of two or more string or literal into one
single data item. In the String verb, the 'DELIMITED BY' clause is compulsory.
Syntax:
INTO ws-destination-string
WITH POINTER ws-count
END-STRING.
· ws-count: This is used to count the length of the new concatenated string.
UNSTRING
The UNSTRING verb breaks one string into several sub-strings. The ' DELIMITED BY ' clause is mandatory
in the unstring verb.
Syntax:
END-UNSTRING.