Anonymous - 2023-12-15

Below is a single program with two sub-routines. The first functionABC works fine. The second, functionABC2 uses the returning keyword but gets this error:

libcob: subProgram.cbl:44: error: BASED/LINKAGE item 'avalue2' has NULL address. I get this error if I use returnvalue or returnvalue2, either one causes this problem.

My build command: cobc --debug -x -free -g subProgram.cbl

I feel like I've tried everything and have followed the programmer's guide to no avail.

Any help please? Thanks!

   Identification Division.
       Program-ID.  TestSubProgram.
       Environment Division.
       Data Division.
   Working-Storage Section.
       01 ctr1         pic 999         value 0.
       77 returnvalue  pic 9(8)        value 0.
       77 returnvalue2 usage binary-long signed.
   Linkage Section.
   Procedure Division.
   Begin.
       Display "Hello World!"
       move 10 to ctr1.
       call 'functionABC' USING ctr1 returnvalue.  
       Display returnvalue.  
       move 0 to returnvalue2.
       call 'functionABC2' RETURNING returnvalue2.
       Display returnvalue2.
       stop run.

   identification division.
       program-id. functionABC.
   data division.
   working-storage section.
       77 localvar     pic     999.
   linkage section.
       01 countervar   pic     999.
       01 avalue       pic     9(8)     value 0.
   procedure division USING countervar avalue.
       perform countervar times
           Display "hello from sub-program"
       end-perform
       move 999 to avalue.
   exit.
   END PROGRAM functionABC.

   identification division.
       program-id. functionABC2.
   data division.
   working-storage section.
   linkage section.
       77 avalue2      USAGE BINARY-LONG signed.
   procedure division RETURNING avalue2.
       move 0 to avalue2
       compute avalue2 = aValue2 + 2
       Display avalue2
   GoBack.
   END PROGRAM functionABC2.