[Info-vax] COBOL example $MGBLSC

Arne Vajhøj arne at vajhoej.dk
Fri Sep 8 13:13:08 EDT 2023


On 9/8/2023 12:45 PM, Brian Schenkenberger wrote:
> I have the SYS$MGBLSC working... at least, in the debugger.  I defined a 
> test global section with two longwords.
> 
> 1,-1
> 2,-2
> 3,-3
> etc.,-etc.
> 0,0
> 
> I have the following for the global section's element definition:
> 
> LINKAGE SECTION.
> 
> 01 GLOBAL-SECTION.
>   02 ELEMENT OCCURS 2000 TIMES.
>     03 A        PIC S9(9) COMP.
>     03 B        PIC S9(9) COMP.
> 
> and the procedure...
> 
> PROCEDURE DIVISION USING GLOBAL_SECTION.
> PARAGRAPH-MAIN.
>     PERFORM PARAGRAPH-ENTER THRU PARAGRAPH-EXIT
>             VARYING I FROM 1 BY 1 UNTIL A(I) = 0 AND B(I) = 0.
> PARAGRAPH-ENTER.
>     DISPLAY "First[" I "]: " A(I) "  Second[" I "]: " B(I).
> PARAGRAPH-EXIT.
>     EXIT.
> END PROGRAM GBLSEC.
> 
> In the debugger, A(I) and B(I) show me the values but DISPLAY pukes on 
> them. It'd be great too if there was a way to DISPLAY them in HEX but 
> just getting it to DISPLAY without regurgitaing garbage would be great.

Add a couple of temporary variables:

WORKING-STORAGE SECTION.
01 AI PIC 9(4) DISPLAY.
01 BI PIC 9(4) DISPLAY.

and do:

MOVE A(I) TO AI
MOVE B(I) TO BI
DISPLAY "First[" I "]: " AI "  Second[" I "]: " BI.

If anyone that actually knows Cobol has a better solution then
I am also interested!

> I also can't figure out how to define GLOBA:L-SECTION ELEMENT OCCURS * 
> TIMES. The number of the elements in the global section could be quite 
> variable.

I don't think it is possible.

Just declare it big enough and only access what actually exist.

It is just an address that is being passed.

Arne




More information about the Info-vax mailing list