Microsoft KB Archive/47513

How to Get Address of a Data Item in COBOL 3.00/3.00a

PSS ID Number: Q47513 Article last modified on 08-31-1989

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: The SET statement in Microsoft COBOL Versions 3.00 and 3.00a can be used to assign the address of a data item to another data item with a type of USAGE IS POINTER. This allows a program to obtain the segment and offset of a data item. The program can then display the address of a data item during run time, or use the address in calling BIOS and DOS interrupts that require the segment and offset of a data item. This information applies to Microsoft COBOL 3.00 and 3.00a.

More Information: For information on the SET statement, refer to Pages 3-158 through 3-160 of “Microsoft COBOL Compiler Version 3.00: Language Reference Manual” for Versions 3.00 and 3.00a. For information on the USAGE is POINTER clause, refer to Pages 2-38 and 3-57 of the same manual. The following code sample shows how to retrieve the segment and offset for each of the data items used in the program. Also, a sample listing of expected results for this program are provided further below. In some cases, two or more data items will have the same address. These cases would normally include REDEFINED data items and the first data items under a group item.

Code Sample
* This program can display the segment and offset * for a data-item, by using the POINTER-TYPE. WORKING-STORAGE SECTION. 01 WORK-FIELD. 05 COUNTER      PIC 9(02)    VALUE ZERO. 05 TABLE-ITEM   PIC X(32768) OCCURS 10 TIMES. * Set up the pointer fields, and the format for * the offset and segment data-items. 01 POINTER-WORK-AREA. 05 POINTER-ITEM       USAGE IS POINTER. 05 POINTER-WRK        REDEFINES POINTER-ITEM. 10 P-OFFSET       PIC 9(04) COMP-5. 10 P-SEGMENT      PIC 9(04) COMP-5. PROCEDURE DIVISION. MAIN-PROGRAM. *** Display Headings DISPLAY &quot; &quot;. DISPLAY &quot;DATA ITEM         |  SEG:OFF ADDRESS&quot;. DISPLAY &quot; &quot;. *** WORK-FIELD is a group item SET POINTER-ITEM TO ADDRESS WORK-FIELD. DISPLAY &quot;WORK-FIELD       = &quot;, P-SEGMENT, &quot;:&quot;, P-OFFSET. SET POINTER-ITEM TO ADDRESS COUNTER. DISPLAY &quot;COUNTER          = &quot;, P-SEGMENT, &quot;:&quot;, P-OFFSET. PERFORM SET-DATA-ITEM-POINTER 10 TIMES. *** POINTER-WORK-AREA is a group item SET POINTER-ITEM TO ADDRESS POINTER-WORK-AREA. DISPLAY &quot;POINTER-WORK-AREA = &quot;, P-SEGMENT, &quot;:&quot;, P-OFFSET. *** POINTER-ITEM and POINTER-WRK are redefines identities SET POINTER-ITEM TO ADDRESS POINTER-ITEM. DISPLAY &quot;POINTER-ITEM     = &quot;, P-SEGMENT, &quot;:&quot;, P-OFFSET. SET POINTER-ITEM TO ADDRESS POINTER-WRK. DISPLAY &quot;POINTER-WRK      = &quot;, P-SEGMENT, &quot;:&quot;, P-OFFSET. SET POINTER-ITEM TO ADDRESS P-OFFSET. DISPLAY &quot;P-OFFSET         = &quot;, P-SEGMENT, &quot;:&quot;, P-OFFSET. SET POINTER-ITEM TO ADDRESS P-SEGMENT. DISPLAY &quot;P-SEGMENT        = &quot;, P-SEGMENT, &quot;:&quot;, P-OFFSET. stop run. set-data-item-pointer. add 1 to counter. SET POINTER-ITEM TO ADDRESS TABLE-ITEM(counter). display &quot;TABLE-ITEM(&quot;, counter, &quot;)   = &quot;, p-segment, &quot;:&quot;, p-offset.

Output at Run Time
DATA ITEM | SEG:OFF ADDRESS WORK-FIELD = 12579:00600 COUNTER = 12579:00600 TABLE-ITEM(01) = 12579:00602 TABLE-ITEM(02) = 12579:33370 TABLE-ITEM(03) = 16675:00602 TABLE-ITEM(04) = 16675:33370 TABLE-ITEM(05) = 20771:00602 TABLE-ITEM(06) = 20771:33370 TABLE-ITEM(07) = 24867:00602 TABLE-ITEM(08) = 24867:33370 TABLE-ITEM(09) = 28963:00602 TABLE-ITEM(10) = 28963:33370 POINTER-WORK-AREA = 33059:00608 POINTER-ITEM = 33059:00608 POINTER-WRK = 33059:00608 P-OFFSET = 33059:00608 P-SEGMENT = 33059:00610

Copyright Microsoft Corporation 1989.