Summary -

In this topic, we described about the below sections -

The STRING statement concatenates the partial or complete contents of two or more data items or literals into one single data item. One STRING statement does the task of a series of MOVE statements. STRING used to concatenate one or more data items to a single data item.

STRING requires minimum two data items/identifiers/literals to concatenate. STRING statement can concatenate alphabetic and alpha-numeric items.

STRING statement can’t do concatenation on numeric and floating-point items. STRING allows only SPACE from the figurative constants and consider all multiple spaces as a single space.

STRING can remove multiple instances of delimiter character. DELIMITED BY, WITH POINTER, ON OVERFLOW and NOT ON OVERFLOW clause is optional in STRING usage. END-STRING used as a scope terminator for STRING statement and is optional.

Syntax -

STRING Syntax

identifier-1, literal-1 -

Specifies the sending fields.

DELIMITED BY phrase -

Sets the string limits.

identifier-2, literal-2 -

Delimiters. Specifies characters that delimit the data to be transferred. DELIMITED BY phase used to set the limit of the string during the concatenation. DELIMITED BY phase is optional in STRING statement. Below are the ways of delimitation -

  1. SIZE -
    Transfers the complete sending area.The string concatenates with the same size of the input identifiers/literals/data item value.Entire source string is moved to the destination field. No additional characters added to destination field.
  2. SPACE -
    The string concatenates with the data up to the first space found in the identifier. Entire source string is moved to the destination field. SPACE added to destination field between every input identifier.
  3. Specified delimiter -
    The string concatenates with the data up to the specified delimiter found in the identifier. Entire source string is moved to the destination field. No additional characters added to destination field.

INTO phrase -

Specifies the receiving field.

identifier-3 -

Represents the receiving field.

WITH POINTER -

POINTER option is used to points the first position of the destination data item. POINTER option is optional in STRING statement. If the POINTER option specified, then the value should be greater than ZERO or less than the length of data item.

ON OVERFLOW -

ON OVERFLOW is used to execute a set of imperative statements when overflow occurs during STRING concatenation. ON OVERFLOW triggers the imperative statements based on the implicit or explicit pointer value.

ON OVERFLOW triggers when the size of the concatenated strings is greater than the receiving field. ON OVERFLOW phrase is optional in STRING statement.

NOT ON OVERFLOW -

NOT ON OVERFLOW is used to execute the set of imperative statements when the STRING concatenation is successful. NOT ON OVERFLOW phrase is full reverse to ON OVERFLOW phrase functionality. NOT ON OVERFLOW phrase is optional in STRING statement.

END-STRING phrase -

The END-STRING used to end the scope of the STRING statement. END-STRING is not required when STRING statement ended with period.END-STRING can also be used with an imperative STRING statement. END-STRING permits conditional STRING to be nested in another conditional statement.

Practical Example:

Below program shows the STRING coding in COBOL program.

Code:


   IDENTIFICATION DIVISION.                                        
   PROGRAM-ID. STRFUNC.                                            
   ENVIRONMENT DIVISION.                                           
   DATA DIVISION.                                                  
   WORKING-STORAGE SECTION.                                        
   01 WS-DATA		PIC X(20) VALUE ‘MAINFRAMESTECHHELP’.  
   01 WS-DATA1 	 	PIC X(40)                              
                                VALUE 'IS A MAINFRAME COMMUNITY'.  
   01 WS-OUTPUT-DATA        PIC X(70).                             
   PROCEDURE DIVISION.                                             
       DISPLAY 'STRING FUNCTION DISPLAY....'.                      
       STRING WS-DATA, WS-DATA1 DELIMITED BY SPACE                
         INTO WS-OUTPUT-DATA                                       
         ON OVERFLOW DISPLAY "ERROR OCCURED"                       
         NOT ON OVERFLOW DISPLAY "NO ERROR"                        
       END-STRING.                                                 
       DISPLAY 'DATA AFTER STRING FUNCTION : ' WS-OUTPUT-DATA.    
       STOP RUN.