WORKING-STORAGE SECTION


  • WORKING-STORAGE SECTION is one of the important sections under the DATA DIVISION.
  • It defines all the variables and record structures required to process data in the program.
  • It defines the variables' type and size and initializes them with values if needed for processing.

Points to Note -

  • The variables are defined for internal usage in the program and can't be accessed outside.
  • Memory is allocated to all WORKING-STORAGE SECTION variables when the program starts and is deallocated when it ends.
  • It also defines the data record structures that are part of the file definition but are still used to perform file operations.

Syntax -

[DATA DIVISION.]
[WORKING-STORAGE SECTION.]
	[record-layout-definition.]
	[variables-declaration.]

Examples -

Scenario1 - Declaring a variable.

 WORKING-STORAGE SECTION.
 01 WS-VAR           PIC 9(03). 

Scenario2 - Declaring a variable with initialized.

 WORKING-STORAGE SECTION.
 01 WS-VAR           PIC 9(03) VALUE 128. 

Scenario3 - Declaring a stuent file record structure as a single variable.

 WORKING-STORAGE SECTION.
 01 WS-STD-REC 			 PIC X(80).

Scenario4 - Declaring a stuent file record structure with elementary variables.

 WORKING-STORAGE SECTION.
 01 WS-STD-REC.
    05 WS-STD-NO 			PIC 9(03).
	05 WS-STD-NAME    		PIC X(25).
	05 WS-STD-CLASS   		PIC X(05).
	05 WS-STD-TOTAL-MARKS   PIC 9(03).
	05 FILLER				PIC X(44).

Scenario5 - Declaring a group variable and elementary variable.

 WORKING-STORAGE SECTION.
* Group variable | Data item                                       
 01 WS-GROUP.                                                     
* Elementary Variable | Data item                                
    05 WS-ELEM1      PIC 9(03).                               
    05 WS-ELEM2      PIC 9(03).

Scenario6 - Declaring a conditional variable.

 WORKING-STORAGE SECTION.
* Condition Variable                                             
 01 WS-GENDER      PIC X(01).                               
    88 WS-MALE     VALUE "M".                               
    88 WS-FEMALE   VALUE "F".