COBOL RANGES
- Rather of specifying the very same kind of information numerous times that might fall under the very same classification or group, COBOL supplies us with an effective function called as range
- To enhance the use and home of components, these components of the very same type and behaviour can be organized in the internal table, and described as range.
- The records/data, which are to be saved in a range should include comparable homes, i.e., PHOTO STIPULATION.
- Varieties are divided in the kind of rows and columns.
- A selection can be of various types; 1– dimensional, 2-dimensional.
INTERNAL TABLE COMMAND OR RANGES
FOR INSTANCE,
Expect we need to specify the days of the week, either we can represent declarations like this.
01 WEEK.
05 DAY01 PHOTO X( 9) WORTH ‘MONDAY’.
05 DAY02 PHOTO X( 9) WORTH ‘TUESDAY’.
05 DAY03 PHOTO X( 9) WORTH ‘WEDNESDAY’.
05 DAY04 PHOTO X( 9) WORTH ‘THURSDAY’.
05 DAY05 PHOTO X( 9) WORTH ‘FRIDAY’.
05 DAY06 PHOTO X( 9) WORTH ‘SATURDAY’.
05 DAY07 PHOTO X( 9) WORTH ‘SUNDAY’.
01 WEEK 05 DAY01 PHOTO X( 9) WORTH ‘ MONDAY’ 05 DAY02 PHOTO X( 9) WORTH ‘ TUESDAY’ 05 DAY03 PHOTO X( 9) WORTH ‘ WEDNESDAY’ 05 DAY04 PHOTO X( 9) WORTH ‘ THURSDAY’ 05 DAY05 PHOTO X( 9) WORTH ‘ FRIDAY’ 05 DAY06 PHOTO X( 9) WORTH ‘ SATURDAY’ 05 DAY07 PHOTO X( 9) WORTH ‘ SUNDAY’ |
Rather of doing this, we can merely specify internal table week and later on input these components in a single group making it simple for us to control information.
01 WEEK-TABLE.
05 DAY-NAME PHOTO X( 9) TAKES PLACE 7 TIMES.
OR.
01 WEEK-TABLE.
05 DAY-NAME TAKES PLACE 7 TIMES PHOTO X( 9 ).
01 WEEK– TABLE 05 DAY– NAME PHOTO X( 9) TAKES PLACE 7 TIMES OR 01 WEEK– TABLE 05 DAY– NAME TAKES PLACE 7 TIMES PHOTO X( 9) |
HAPPEN STIPULATION:
- The take place Claus is utilized to specify the variety of events of a component in a table or range.
- Occur Claus need to be utilized for group or primary information products just.
- Depending upon the kind of range, i.e., one dimensional or two-dimensional, we can have numerous take place Claus.
- To access the components of the table, we can utilize index or subscript.
- One dimensional range consists of one OCCUR provision, and the two-dimensional range consists of 2 OCCUR Claus.
REFERRING ASPECTS IN AN SELECTION:
There are 2 methods to describe the components in a range:
1) INDEX:-
It describes the displacement position of number from the starting of a range, likewise referred to as balanced out. We utilize the” INDEX BY” provision to state index, and we do not specify index in the working storage area.
SYNTAX =>>
01 TABLE-WEEK.
05 NAME-DAY PHOTO X( 09) TAKES PLACE 7 TIMES.
[ ASCENDING / DESCENDING KEY IS key-1 . . . ]
[ INDEXED BY index-name ]
01 TABLE– WEEK 05 NAME– DAY PHOTO X( 09) TAKES PLACE 7 TIMES [ ASCENDING / DESCENDING KEY IS key–1 . . . ] [ INDEXED BY index–name ] |
EXAMPLE => > utilizing the above syntax
NAME-DAY( 1) has a displacement of 0.
NAME-DAY( 2) has a displacement of 9.
NAME-DAY( 1) has a displacement of 18 and so on …
NAME– DAY( 1) has a displacement of 0 NAME– DAY( 2) has a displacement of 9 NAME– DAY( 1) has a displacement of 18 and so on |
If we increase the index by 1, the length gets increased by the length specified in the PHOTO provision.
How to appoint a worth to the index?
The SET STIPULATION is utilized to start INDEX or to set the worth of the INDEX.
EXAMPLE =>>
a) SET index-1 to index-2
b) SET index-1 to 1
c) SET index-1 UP BY 1
d) SET index-1 DOWN BY 1
KEEP IN MIND:- SET is likewise utilized to set the worth of switch to ON/ OFF. It can likewise be utilized to appoint REAL/ FALSE to a conditional declaration.
2) SUBSCRIPT:-
- An important information product that explains the variety of event of components in a range.
- Subscript describes the memory place of a specific information product and where it lives. It suggests the assigned memory is not the real memory; rather points towards the position of the information product.
- The subscripts are specified in the working storage area with
‘ PHOTO a9( 04) COMPENSATION ‘.
- To initialize the subscript, we need to utilize the RELOCATION declaration.
- Subscript begins with number 1 and later on 1 is increased each time with the aid of ADD function.
EXAMPLE =>>
— To refer a component one in the last example, we need to provide NAME-DAY( 1 )
— In order to choose component 2 in the last example, we need to do the following
NAME– DAY (2) and so on …
SAMPLE PROGRAM–
This is a demonstration program to find out and comprehend the principle of one-dimensional range and how to appoint worths to range.
DEVELOPING 1 DIMENSIONAL SELECTION.
RECOGNITION DEPARTMENT.
PROGRAM-ID. ONE-D-ARR.
DATA DEPARTMENT.
WORKING-STORAGE AREA.
01 WS-STR-TABLE.
05 WS-PRD TAKES PLACE 3 TIMES PHOTO X( 10 ).
TREATMENT DEPARTMENT.
MOVE “SOAP” TO WS-PRD( 1 ).
MOVE “CLEANING AGENT” TO WS-PRD( 2 ).
MOVE “HAIR SHAMPOO” TO WS-PRD( 3 ).
DISPLAY SCREEN “I AM EXAMPLE OF ONE DIMENSIONAL SELECTION”.
DISPLAY SCREEN “ITEM 1:” WS-PRD( 1 ).
DISPLAY SCREEN “ITEM 2:” WS-PRD( 2 ).
DISPLAY SCREEN “ITEM 3:” WS-PRD( 3 ).
STOP RUN..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
DEVELOPING 1 DIMENSIONAL SELECTION RECOGNITION DEPARTMENT PROGRAM– ID ONE– D– ARR DATA DEPARTMENT WORKING– STORAGE AREA 01 WS– STR– TABLE 05 WS– PRD TAKES PLACE 3 TIMES PHOTO X( 10) TREATMENT DEPARTMENT RELOCATION ” SOAP “ TO WS– PRD( 1) RELOCATION ” CLEANING AGENT “ TO WS– PRD( 2) RELOCATION ” HAIR SHAMPOO “ TO WS– PRD( 3) DISPLAY SCREEN ” I AM EXAMPLE OF ONE DIMENSIONAL SELECTION” DISPLAY SCREEN ” ITEM 1: “ WS– PRD( 1) DISPLAY SCREEN ” ITEM 2: “ WS– PRD( 2) DISPLAY SCREEN ” ITEM 3: “ WS– PRD( 3) STOP RUN |
THE OUTPUT WILL BE
I AM EXAMPLE OF ONE DIMENSIONAL SELECTION.
ITEM 1: SOAP.
ITEM 2: CLEANING AGENT.
ITEM 3: HAIR SHAMPOO.
I AM EXAMPLE OF ONE DIMENSIONAL SELECTION ITEM 1 : SOAP ITEM 2 : CLEANING AGENT ITEM 3 : HAIR SHAMPOO |
Here in this program, we have actually designated a couple of variables with various worths and later on controlled the output utilizing various homes of a range to make you clear about the various ideas connected to ONE DIMENSIONAL SELECTION. With this program and output, you will have the ability to comprehend how practical and simple selections are.

SAMPLE PROGRAM–
This is a demonstration program to find out and comprehend the principle of two-dimensional range and how to appoint worths to range.
DEVELOPING 2 DIMENSIONAL SELECTION.
RECOGNITION DEPARTMENT.
PROGRAM-ID. TWO-D-ARR.
DATA DEPARTMENT.
WORKING-STORAGE AREA.
01 WS-STORE-PROD-TABLE.
05 WS-STORE-ID TAKES PLACE 3 TIMES.
10 WS-PRODUCT TAKES PLACE 5 TIMES PHOTO 9( 08 ).
01 WS-TIME PHOTO 9( 08 ).
01 I PIC 9( 01 ).
01 J PHOTO 9( 01 ).
TREATMENT DEPARTMENT.
ACCEPT WS-TIME FROM TIME.
DISPLAY SCREEN “I AM EXAMPLE OF 2 DIMENSIONAL SELECTION”.
CARRY OUT PRODUCT-PARA VARYING I FROM 1 BY 1 UNTIL I > > 3.
AFTER J FROM 1 BY 1 UNTIL J > > 5.
STOP RUN.
PRODUCT-PARA.
MOVE WS-TIME TO WS-PRODUCT( I, J).
DISPLAY SCREEN “ITEM” I “,” J.
WS-PRODUCT ( I, J).
ADD 1 TO WS-TIME..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
DEVELOPING 2 DIMENSIONAL SELECTION RECOGNITION DEPARTMENT PROGRAM– ID 2– D– ARR DATA DEPARTMENT WORKING– STORAGE AREA 01 WS– SHOP– PROD– TABLE 05 WS– SHOP– ID TAKES PLACE 3 TIMES 10 WS– ITEM TAKES PLACE 5 TIMES PHOTO 9( 08) 01 WS– TIME PHOTO 9( 08) 01 I PHOTO 9( 01) 01 J PHOTO 9( 01) TREATMENT DEPARTMENT ACCEPT WS– TIME FROM TIME DISPLAY SCREEN ” I AM EXAMPLE OF 2 DIMENSIONAL SELECTION” PERFORM ITEM– PARA DIFFERING I FROM 1 BY 1 UNTIL I >> 3 AFTER J FROM 1 BY 1 UNTIL J >> 5. STOP RUN ITEM– PARA RELOCATION WS– TIME TO WS– ITEM( I, J) DISPLAY SCREEN ” ITEM” I “,” J WS– ITEM( I, J) ADD 1 TO WS– TIME |
THE OUTPUT WILL BE
I AM EXAMPLE OF 2 DIMENSIONAL SELECTION.
PRODUCT1, 114350661.
PRODUCT1, 214350662.
PRODUCT1, 314350663.
PRODUCT1, 414350664.
PRODUCT1, 514350665.
PRODUCT2, 114350666.
PRODUCT2, 214350667.
PRODUCT2, 314350668.
PRODUCT2, 414350669.
PRODUCT2, 514350670.
PRODUCT3, 114350671.
PRODUCT3, 214350672.
PRODUCT3, 314350673.
PRODUCT3, 414350674.
PRODUCT3, 514350675.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
I AM EXAMPLE OF 2 DIMENSIONAL SELECTION PRODUCT1 , 114350661 PRODUCT1 , 214350662 PRODUCT1 , 314350663 PRODUCT1 , 414350664 PRODUCT1 , 514350665 PRODUCT2 , 114350666 PRODUCT2 , 214350667 PRODUCT2 , 314350668 PRODUCT2 , 414350669 PRODUCT2 , 514350670 PRODUCT3 , 114350671 PRODUCT3 , 214350672 PRODUCT3 , 314350673 PRODUCT3 , 414350674 PRODUCT3 , 514350675 |
Here in this program, we have actually designated a couple of variables with various worths and later on controlled the output utilizing various homes of a range to make you clear about the various ideas connected to TWO-DIMENSIONAL SELECTION. With this program and output, you will have the ability to comprehend how practical and simple multi-dimensional selections are.

SAMPLE PROGRAM–
This is a demonstration program to find out and comprehend the principle of index by home of a range and how to appoint worths to range.
RECOGNITION DEPARTMENT.
PROGRAM-ID. INDEXBY.
DATA DEPARTMENT.
WORKING – STORAGE AREA.
01 WS – SHOP..
05 WS – ITEM TAKES PLACE 3 TIMES INDEXED BY IDX.
10 WS – PRODUCT – CODE PHOTO 9( 05 ).
01 WS – PRODUCT – VAL PHOTO 9( 05) WORTH 12345..
TREATMENT DEPARTMENT.
SET IDX TO 1.
CARRY OUT PROD-DETAILS UNTIL IDX > > 3.
STOP RUN.
PROD – INFORMATION.
MOVE WS – PRODUCT – VAL TO WS – PRODUCT – CODE( IDX).
DISPLAY SCREEN” ITEM” WS – PRODUCT – CODE( IDX).
ADD 1 TO WS – PRODUCT – VAL.
SET IDX UP BY 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
RECOGNITION DEPARTMENT PROGRAM– ID INDEXBY DATA DEPARTMENT WORKING – STORAGE AREA 01 WS – SHOP 05 WS – ITEM TAKES PLACE 3 TIMES INDEXED BY IDX 10 WS – PRODUCT – CODE PHOTO 9( 05) 01 WS – PRODUCT – VAL PHOTO 9( 05) WORTH 12345 TREATMENT DEPARTMENT SET IDX TO 1 PERFORM PROD– INFORMATION UNTIL IDX >> 3 STOP RUN PROD – INFORMATION RELOCATION WS – PRODUCT – VAL TO WS – PRODUCT – CODE( IDX) DISPLAY SCREEN ” ITEM “ WS – PRODUCT – CODE( IDX) ADD 1 TO WS – PRODUCT – VAL SET IDX UP BY 1. |
THE OUTPUT WILL BE
ITEM 12345.
ITEM 12346.
ITEM 12347.
ITEM 12345 ITEM 12346 ITEM 12347 |
Here in this program, we have actually designated a couple of variables with various worths and later on controlled the output utilizing various homes of a range to make you clear about the various ideas connected to INDEX BY home of a RANGE.

SAMPLE PROGRAM–
This is a demonstration program to find out and comprehend the principle of subscript home of a range and how to appoint worths to range.
RECOGNITION DEPARTMENT.
PROGRAM-ID. SUBSCR.
DATA DEPARTMENT.
WORKING-STORAGE AREA.
01 WS-STORE..
05 WS-PRODUCT TAKES PLACE 3 TIMES INDEXED BY IDX.
10 WS-ITEM-CODE PHOTO 9( 05 ).
01 WS-ITEM-VAL PHOTO 9( 05) WORTH 12345..
01 WS-SUB PHOTO 9( 01) WORTH 01.
TREATMENT DEPARTMENT.
RELOCATION 1 TO WS-SUB.
CARRY OUT PROD-DETAILS TILL WS-SUB > > 3.
STOP RUN.
PROD-DETAILS.
MOVE WS-ITEM-VAL TO WS-ITEM-CODE( IDX).
DISPLAY SCREEN “ITEM” WS-SUB”” WS-ITEM-CODE( IDX).
ADD 1 TO WS-ITEM-VAL.
ADD 1 TO WS-SUB.
SET IDX UP BY 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
RECOGNITION DEPARTMENT PROGRAM– ID SUBSCR DATA DEPARTMENT WORKING– STORAGE AREA 01 WS– SHOP 05 WS– ITEM TAKES PLACE 3 TIMES INDEXED BY IDX 10 WS– PRODUCT– CODE PHOTO 9( 05) 01 WS– PRODUCT– VAL PHOTO 9( 05) WORTH 12345. 01 WS– SUB PHOTO 9( 01) WORTH 01. TREATMENT DEPARTMENT RELOCATION 1 TO WS– SUB PERFORM PROD– INFORMATION UNTIL WS– SUB >> 3. STOP RUN PROD– INFORMATION RELOCATION WS– PRODUCT– VAL TO WS– PRODUCT– CODE( IDX) DISPLAY SCREEN ” ITEM “ WS– SUB ” “ WS– PRODUCT– CODE( IDX) ADD 1 TO WS– PRODUCT– VAL ADD 1 TO WS– SUB SET IDX UP BY 1. |
THE OUTPUT WILL BE
ITEM 1 12345.
ITEM 2 12346.
ITEM 3 12347.
ITEM 1 12345 ITEM 2 12346 ITEM 3 12347 |

Here in this program, we have actually designated a couple of variables with various worths and later on controlled the output utilizing various homes of a range to make you clear about the various ideas connected to the SUBSCRIPT home of a RANGE.
DISTINCTION BETWEEN INDEX AND SUBSCRIPT
As we are currently mindful, both index and subscript are effective tools in COLOB shows and mainly do the very same job, however still, there’s a substantial distinction that we will be talking about.
INDEX =>>
- Describes the balanced out or displacement in the starting of a range.
- We utilize INDEX BY Claus to start the worth.
- INDEX is much quicker compared to SUBSCRIPT as it describes the memory place, so it has relatively much better and faster efficiency.
- INDEX is not specified in the working storage area and is initialized by the SET operation.
SUBSCRIPT =>>
- It describes the range components’ event, and we do not utilize the INDEX BY provision to start.
- SUBSCRIPT is much slower compared to INDEX, as it does not describe memory place.
- We need to specify SUBSCRIPT in the working storage area and is initialized by WORTH or RELOCATION declarations.
SEARCH AND SEARCH ALL
In specific scenarios, we need to look for a specific record or worth present in a table. We will browse all the information by hand, discovering specific information, however that is not that simple. Rather, we can utilize commands like search or browse all t o quickly filter the total information and discover our wanted outcome.
SEARCH =>>
It is a direct or consecutive search and is mainly utilized in tables and range where information is not arranged.
SYNTAX =>>
SEARCH TABLE – NAME[ VARYING { identifier1 / index1 } ]
[ AT END Statement ]
{WHEN ConditionPass.
{declaration/ NEXT SENTENCE/ CONTINUE} …}
END – SEARCH.
SEARCH TABLE – NAME [ VARYING { identifier1 / index1 } ] [ AT END Statement ] { WHEN ConditionPass { declaration / NEXT SENTENCE / CONTINUE } . } END – SEARCH |
SEARCH ALL =>>
It is a kind of binary search and is mainly utilized when selections and tables are currently arranged.
SYNTAX =>>
SEARCH ALL TABLE – NAME.
[ AT END Statement ]
{WHEN ConditionPass.
{declaration/ NEXT SENTENCE/ CONTINUE} …}
END – SEARCH.
SEARCH ALL TABLE – NAME [ AT END Statement ] { WHEN ConditionPass { declaration / NEXT SENTENCE / CONTINUE } . } END – SEARCH |
DISTINCTION IN BETWEEN SEARCH AND SEARCH ALL
SEARCH =>>
- SEARCH is utilized to discover a component or record present in a direct way, likewise referred to as consecutive search.
- We can code the SEARCH command for the tables and selections that have record either arranged or unsorted, however we mainly utilize look for unsorted tables.
- In this kind of search, the index should be initialized.
- There is no principle for rising and coming down type in SEARCH.
SEARCH ALL =>>
- SEARCH ALL is utilized to discover components or record present in BINARY format, likewise referred to as BINARY search.
- We can code the SEARCH ALL command for the tables and selections that have actually arranged records.
- In this kind of search, the index does not need to be initialized.
- Rising and coming down essential need to be specified in a range while utilizing the SEARCH ALL command.
SAMPLE PROGRAM–
This is a demonstration program to find out and comprehend the principle of search all home of a range and how to appoint worths to range.
RECOGNITION DEPARTMENT.
PROGRAM-ID. SEARCH.
DATA DEPARTMENT.
WORKING-STORAGE AREA.
01 WS-STORE..
05 WS-PRODUCT TAKES PLACE 3 TIMES RISING SECRET IS.
WS-ITEM-CODE INDEXED BY IDX.
10 WS-ITEM-CODE PHOTO 9( 05 ).
01 WS-ITEM-VAL PHOTO 9( 05) WORTH 12345..
TREATMENT DEPARTMENT.
SET IDX TO 1.
CARRY OUT PROD-DETAILS UNTIL IDX > > 3.
CARRY OUT SEARCH-ALL-PARA.
STOP RUN.
PROD-DETAILS.
MOVE WS-ITEM-VAL TO WS-ITEM-CODE( IDX).
DISPLAY SCREEN” ITEM” WS-ITEM-CODE( IDX).
ADD 1 TO WS-ITEM-VAL.
SET IDX UP BY 1.
SEARCH-ALL-PARA.
SEARCH ALL WS-PRODUCT.
AT END DISPLAY SCREEN “RECORD NOT FOUND”.
WHEN WS-ITEM-CODE( IDX) = 12346.
DISPLAY SCREEN “RECORD FOUND”.
DISPLAY SCREEN WS-ITEM-CODE( IDX).
END-SEARCH.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
RECOGNITION DEPARTMENT PROGRAM– ID SEARCH DATA DEPARTMENT WORKING– STORAGE AREA 01 WS– SHOP 05 WS– ITEM TAKES PLACE 3 TIMES ASCENDING SECRET IS WS– PRODUCT– CODE INDEXED BY IDX 10 WS– PRODUCT– CODE PHOTO 9( 05) 01 WS– PRODUCT– VAL PHOTO 9( 05) WORTH 12345. TREATMENT DEPARTMENT SET IDX TO 1. PERFORM PROD– INFORMATION UNTIL IDX >> 3. PERFORM SEARCH– ALL– PARA STOP RUN PROD– INFORMATION RELOCATION WS– PRODUCT– VAL TO WS– PRODUCT– CODE( IDX) DISPLAY SCREEN ” ITEM “ WS– PRODUCT– CODE( IDX) ADD 1 TO WS– PRODUCT– VAL SET IDX UP BY 1. SEARCH– ALL– PARA SEARCH ALL WS– ITEM AT END DISPLAY SCREEN ” RECORD NOT FOUND” WHEN WS– PRODUCT– CODE( IDX) = 12346 DISPLAY SCREEN ” RECORD FOUND” DISPLAY SCREEN WS– PRODUCT– CODE( IDX) END– SEARCH |
THE OUTPUT WILL BE
ITEM 12345.
ITEM 12346.
ITEM 12347.
RECORD FOUND.
12346.
ITEM 12345 ITEM 12346 ITEM 12347 RECORD FOUND 12346 |
Here in this program, we have actually designated a couple of variables with various worths and later on controlled the output utilizing various homes of a range to make you clear about the various ideas connected to the SEARCH ALL home of a RANGE.
