COBOL Set Verb

COBOL 88 Level Number COBOL Data Type Justifications

Advertisements


SET verb using to initializing the index of table.

SET verb is mainly used to set the particular item value to true. i.e. It is one way to assign a value to a particular data item.

SET verb can increment/decrement the occurrence of a data item.

SET verb can set the external data item switches to ON or OFF.

SET verb can pass values to conditional items to validate.

SET verb is closely related to Condition names. So we will get a good understanding if the closely related topics discussed along with rather than discussing it separately.

There are three different formats of SET verb in regular programming.


Format-1: Initializing the index


SET verb used to initialize the index of table/Array.


Syntax:

SET	index-name 	TO 	index-value.

In the above case, index-name is the table index defined for the table.

Index-value is the value from which the index to be initialized. In other words, it will set the index value from where the reading of table can be started either from ending or beginning of array.


Example:

To calculate student percentage by taking 6 subjects marks as input.


Code:


IDENTIFICATION DIVISION.  
PROGRAM-ID. ARRYINDX.  
ENVIRONMENT DIVISION.  
DATA DIVISION.       
WORKING-STORAGE SECTION.  
01 STD-DET OCCURES 6 TIMES INDEXED BY STD-INDEX.  
   05 STD-MARKS              PIC 9(03).           
01 TOTAL-MARKS               PIC 9(03) VALUE ZERO.
01 STD-PERCENT               PIC 9(03).9(02).    
01 I                         PIC 9(01).        
PROCEDURE DIVISION.                       
    MOVE ZEROES     TO TOTAL-MARKS.       
    PERFORM VARYING I FROM 1 BY 1         
      UNTIL I > 6                         
       SET STD-INDEX TO 1                 
       ACCEPT STD-MARKS (STD-INDEX)       
       ADD STD-MARKS (STD-INDEX) TO TOTAL-MARKS   
       SET STD-INDEX UP BY 1                
    END-PERFORM.                           
    COMPUTE STD-PERCENT = TOTAL-MARKS/6.   
    DISPLAY 'STUDENT PERCENTAGE : ' STD-PERCENT.  
    STOP RUN.               
           

Format-2: increment/decrement the index


SET verb used to increment/decrement the index of table/Array once it was initialized.


Syntax:

SET	index-name 	UP BY//DOWN BY 	identifier/literal.

In the above case, index-name is the table index defined for the table.

Identifier/ literal will provide that how many occurrences the index need to be incremented/decremented.


Example:

To calculate student percentage by taking 6 subjects marks as input.


Code:


IDENTIFICATION DIVISION.                                       
PROGRAM-ID. PERFTIMI.                                           
ENVIRONMENT DIVISION.                                           
DATA DIVISION.                                                  
WORKING-STORAGE SECTION.                                        
01 STD-DET OCCURES 6 TIMES INDEXED BY STD-INDEX.               
   05 STD-MARKS              PIC 9(03).                         
01 TOTAL-MARKS               PIC 9(03) VALUE ZERO.              
01 STD-PERCENT               PIC 9(03).9(02).                   
01 I                         PIC 9(01).                         
PROCEDURE DIVISION.                                            
    MOVE ZEROES     TO TOTAL-MARKS.                             
    PERFORM VARYING I FROM 6 BY 1   
      UNTIL I = 0                                               
       SET STD-INDEX TO 6                                       
       ACCEPT STD-MARKS (STD-INDEX)                             
       ADD STD-MARKS (STD-INDEX) TO TOTAL-MARKS                 
       SET STD-INDEX DOWN BY 1                                  
    END-PERFORM.                                                
    COMPUTE STD-PERCENT = TOTAL-MARKS/6.                        
    DISPLAY 'STUDENT PERCENTAGE : ' STD-PERCENT.                
    STOP RUN.                                                   


Format-3: Set conditional names


SET verb used to set the conditional names to true.

This will initialize the variable with the value which is existed in 88 level number VALUE clause.


Syntax:

SET	conditional-name 	TO 	TRUE.

In the above case, conditional-name is nothing but the 88 level names defined for a particular variable.


Example:

To validate the student marks entered as input.


Code:



In the above example, "SET STD-MARKS-VALID TO TRUE" will set STD-MARKS-SW to 'Y'


Output:



COBOL 88 Level Number COBOL Data Type Justifications

Advertisements