0% found this document useful (0 votes)
31 views

COBOL String Handling

The document discusses COBOL verbs like INITIALIZE, MOVE, and class conditions that check data types. It also covers string handling statements like INSPECT, STRING, and UNSTRING and provides syntax examples for each.

Uploaded by

maran_g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

COBOL String Handling

The document discusses COBOL verbs like INITIALIZE, MOVE, and class conditions that check data types. It also covers string handling statements like INSPECT, STRING, and UNSTRING and provides syntax examples for each.

Uploaded by

maran_g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

INITIALIZE

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.

The following are the legal moves:

Alphabetic Alphanumeric Numeric

Alphabetic Possible Possible Not Possible

Alphanumeric Possible Possible Possible

Numeric Not Possible Possible Possible

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:

[Data Name/Arithmetic Operation>]

[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:

IF [CONDITION] AND [CONDITION]

COBOL Statements

END-IF.

IF [CONDITION] OR [CONDITION]

COBOL Statements

END-IF.

COBOL - String Handling

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

Tallying is used to count the string characters.

Syntax:

INSPECT input-string

TALLYING output-count FOR ALL CHARACTERS

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

Replacing option replaces the string characters.

Syntax:

INSPECT input-string REPLACING ALL char1 BY char2.

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:

STRING ws-string1 DELIMITED BY SPACE

ws-string2 DELIMITED BY SIZE

INTO ws-destination-string
WITH POINTER ws-count

ON OVERFLOW DISPLAY message1

NOT ON OVERFLOW DISPLAY message2

END-STRING.

Here, used parameters details are:

· ws-string1 and ws-string2: These are input strings to be concatenated.

· ws-string: This is an output string.

· ws-count: This is used to count the length of the new concatenated string.

· Delimited: used to specify the end of the string.

· Pointer and Overflow: These are optional.

UNSTRING

The UNSTRING verb breaks one string into several sub-strings. The ' DELIMITED BY ' clause is mandatory
in the unstring verb.

Syntax:

UNSTRING ws-string DELIMITED BY SPACE

INTO ws-str1, ws-str2

WITH POINTER ws-count

ON OVERFLOW DISPLAY message

NOT ON OVERFLOW DISPLAY message

END-UNSTRING.

Sending field must be Alphanumeric

You might also like