Saturday, March 05, 2005

Pointers in COBOL85

It's better to use> them in C but it is possible in COBOL.


>> In my program, I was getting structures from the MEASURE subsystem.
> Since each NSK version and MEASURE version has different structure lengths, I used pointers to line up properly.

>> In the WORKING-STORAGE section
I have the following:
>> 01 CPU-PNTR USAGE POINTER VALUE IS NULL.
> 01 DISC-PNTR USAGE POINTER VALUE IS NULL.
> 01 DISCOPEN-PNTR USAGE POINTER VALUE IS NULL.
> 01 PROCESS-PNTR USAGE POINTER VALUE IS NULL.

>> In the actual code:

>> SET CPU-PNTR TO ADDRESS OF MEASREAD-BUFFER.
>> where MEASREAD-BUFFER is the buffer returned by MEASREAD.

>> Also,
>> SET ADDRESS OF CPU-DEFINITION TO CPU-PNTR.
> SET CPU-PNTR UP BY CPU-ENTITY-LENGTH OF VERSION-TABLE> (VERSION-INDEX).

>> where CPU-DEFINITION is a structure of the CPU entity.
> CPU-ENTITY-LENGTH is the length of the cpu-buffer as returned by> MEASREADCONF.

This length varies from version to version.
>> I also used pointers to check if certain fields were present in the> structure.
>> IF (ADDRESS OF CPU-SUBTYPE OF CPU-DEFINITION <>
MOVE CPU-SUBTYPE OF CPU-DEFINITION TO CPU-POWER-SEARCH-SUBTYPE> ELSE> MOVE ZERO TO CPU-POWER-SEARCH-SUBTYPE>
END-IF.>>

NOTE: CPU-PNTR was set earlier to point to the next structure element.
> This IF verifies if the current MEASURE version has the SUBTYPE element> or not.

No comments: