[Info-vax] COBOL, <gack!> again! Return status.

bill bill.gunshannon at gmail.com
Mon Sep 11 16:54:49 EDT 2023


On 9/11/2023 4:12 PM, Brian Schenkenberger wrote:
> On 2023-09-11 19:59:05 +0000, Arne Vajhj said:
> 
>> On 9/11/2023 3:01 PM, Brian Schenkenberger wrote:
>>> How does a COBOL program return a status (ie. R0) to a calling 
>>> program? I found a reference to RETURN-CODE but compiler balks at that.
>>
>> Disclaimer: I really don't know Cobol, but the following seems to work:
>>
>> $ type m.cob
>> identification division.
>> program-id.m.
>> data division.
>> working-storage section.
>> 01  a       pic 9(9) comp.
>> 01  b       pic 9(9) comp.
>> 01  res     pic 9(9) comp.
>> 01  res2    pic 9(9) display.
>> procedure division.
>> main-paragraph.
>>      move 123 to a
>>      move 456 to b
>>      call "ADD2" using a,b giving res
>>      move res to res2
>>      display res2
>>      stop run.
>> $ cob m
>> $ type add2.cob
>> identification division.
>> program-id.add2.
>> data division.
>> working-storage section.
>> 01  res     pic 9(9) comp.
>> linkage section.
>> 01  a       pic 9(9) comp.
>> 01  b       pic 9(9) comp.
>> procedure division using a,b giving res.
>> main-paragraph.
>>      compute res = a + b.
>>      end program add2.
>> $ cob add2
>> $ link m + add2
>> $ run m
>> 000000579
>>
>> Arne
> 
> I've tried that but compiler pukes on it.  I've tried:
> 
> MOVE SS$_NORMAL TO RES.
> 
> and
> 
> COMPUTE RES = SS$_NORMAL *1.
> 
> It just doesn't like it.
> 
> —VAXman
> 

OK Brian,  here's a solution to your problem.

identification division.
program-id.m.
data division.
working-storage section.
01  a       pic 9(9) comp.
01  b       pic 9(9) comp.
01  res     pic 9(9) comp.
01  res2    pic 9(9) display.
procedure division.
main-paragraph.
      move 123 to a
      move 456 to b
      call "add2" using a,b,res
      move res to res2
      display res2
      stop run.

identification division.
program-id.add2.
data division.
linkage section.
01  res     pic 9(9) comp.
01  a       pic 9(9) comp.
01  b       pic 9(9) comp.
procedure division using a,b,res.
main-paragraph.
      compute res = a + b.
      end program add2.

Notice that rather than using the RETURNING|GIVING part this program
just uses another argument to bring back the return value.  This works
because all of the arguments are BY REFERENCE.

I intend to look deeper into why the RETURNING is exhibiting strange
behavior but in the meantime this will get the job done and according
to what I just read is considered normal practice for COBOL CALLs.

bill




More information about the Info-vax mailing list