1

i got a problem with simple cobol call - returning test program.

I am using micro focus cobol.

here are my 2 codes.

 ***************** CALLING PROGRAM 
   IDENTIFICATION DIVISION.
   PROGRAM-ID. callreturning.

   ENVIRONMENT DIVISION.

   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 VA PIC S9(8) USAGE DISPLAY.
   01 VB PIC S9(8) USAGE DISPLAY.
   01 VC PIC 9(4) USAGE DISPLAY value 0.

   PROCEDURE DIVISION.
   MOVE 1 TO VA.
   MOVE 2 TO VB.
   move 3 to VC.
   CALL "add_two" USING  VA VB returning VC.

  * DISPLAY VA VB VC.
   EXIT PROGRAM.


   END PROGRAM callreturning.


  *********CALLED PROGRAM
   IDENTIFICATION DIVISION.
   PROGRAM-ID. add_two.

   ENVIRONMENT DIVISION.

   DATA DIVISION.

   LINKAGE SECTION.
   01 PARM_A PIC S9(8) USAGE DISPLAY.
   01 PARM_B PIC S9(8) USAGE DISPLAY.
   01 PARM_C PIC 9(4) USAGE DISPLAY value 0.

   PROCEDURE DIVISION USING PARM_A PARM_B returning PARM_C.
   move 3 to PARM_C.
  * ADD PARM_A TO PARM_B GIVING PARM_C.
   goback.
   END PROGRAM add_two.

CALLING program simply calls the second program with using returing value.

But when i compile both program and run, error happens.

error code: 114, pc=0, call=1, seg=0 114 Attempt to access item beyond bounds of memory (Signal 11)

Did i make a wrong code? or other problem? please help me :)

  • I am testing 'RETURNING' phrase
user3167430
  • 11
  • 1
  • 3
  • 2
    Why do you want to use `RETURNING`? It is not necessary when COBOL CALLs COBOL. Have you registered for Micro Focus support at their website, and asked there? www.microfocus.com – Bill Woodger Jun 20 '14 at 12:57
  • small question. is the call or the move to parm_c that fails? ie: a display "test" as the first line of called program is ever shown or the abend is before? – Davide Jun 20 '14 at 13:46
  • I know that RETURNING is not necessary and it can be replaced with using reference. But I'm just testing CALL with using RETURNING. I didn't ask micro focus website.. anyway thx. if you have other advices, please do :) – user3167430 Jun 23 '14 at 02:37
  • nope just complie error – user3167430 Jun 23 '14 at 02:37
  • What do you mean by `just compile error`? Is that different from the error shown? Although RETURNING is primarily for inter-language use (for languages which naturally `return` a value), it *should* work COBOL-to-COBOL (it works on IBM's Enterprise COBOL) so you probably need to take it up with Micro Focus to get anywhere. – Bill Woodger Jun 23 '14 at 06:11

3 Answers3

1

Your program compiles and works just fine if you get rid of the returning statement.

Molusco
  • 59
  • 6
0

Background

01 levels defined in the linkage section are more like pointers in a C program. For normal parameters they are set by the calling program. But returning parameters will be unassigned.

The error is probably caused by trying to use an unallocated pointer.

Solution

  1. Do not use returning as it is for working with languages like java.
  2. Allocate storage to the return-value before using it.

See:

Finally, returning is for working with java. Anything "type" defined on returning should be java compatible (i.e. binary-long and not 9(4)). I strongly suggest not using Returning in Cobol unless you are calling other languages.

Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
  • How would you `allocate storage to the return-value before using it`? The compiler should allocate, or otherwise access, valid storage. On the Mainframe, it is a similar type of thing to the RETURN-CODE special register. Works with Enterprise COBOL, so don't see why it shouldn't work elsewhere :-) Certainly no actual point in using `RETURNING` for COBOL-to-COBOL. – Bill Woodger Jun 23 '14 at 06:16
  • Allocating Storage -you can initiate a class (OO Cobol - Mainframe or Microfocus) otherwise it is System Dependent. In CICS in the old days before pointers you could use GETMAIN to allocate storage to linkage Section Items. Microfocus looks to have memory allocation function – Bruce Martin Jun 23 '14 at 12:04
  • Returning and Return-Code look to be quite separate. Returning Looks to be for use in OO-Cobol + compatibility with other languages; not Cobol-Cobol – Bruce Martin Jun 23 '14 at 12:06
  • I don't know for Micro Focus. RETURNING can be used to allow a COBOL "function" (a COBOL program) to be called by C/C++ (for instance) or to use a C/C++ funtion which uses `return`. Perhaps in Micro Focus it is down to the user to allocate storage, I don't know. The code shown works out of the box with Enterprise COBOL, although that is little direct help (and there is no *need* to use it for COBOL-to-COBOL). There is more than one "Micro Focus COBOL", but I'd assume their Mainframe-compatible one should work like this. Again, not necessarily helpful. Still think "contact Micro Focus". – Bill Woodger Jun 23 '14 at 13:22
  • @BillWoodger; With GNU Cobol the linkage section variable would be 'allocated' with `SET ADDRESS OF param_c TO ADDRESS OF ws-param_c` with the associated entry in working-storage. `RETURNING` becomes far more important with `FUNCTION-ID` support, and although it is mentioned in the `LINKAGE SECTION` the RETURNING field is allocated on entry, memory managed by simply discarding the transient FUNCTION return value(s) at the end of each statement. – Brian Tiffin Jul 10 '14 at 10:42
0

Old Question, so i try a short Answer:

First, there is nothing wrong with using returning in MF-COBOL. So, this is native COBOL (NetExpress as IDE, i assume). To correct ist just change the second Program:

  1. Move PARM_C from the linkage to the working-storage section
  2. The Procedure Division doesn't get the returning Phrase in its opening declaration. Move it instead to the goback phrase:
PROCEDURE DIVISION USING PARM_A PARM_B.
  *>...
goback returning PARM_C.
  • It seems the OP did go to the Micro Focus site, and got this answer. However, neither there nor here is there anything about *why* the RETURNING on the PROCEDURE DIVISION doesn't work as expected (it does with other COBOL compilers) for COBOL-to-COBOL communication. Any thoughts? – Bill Woodger Nov 20 '15 at 12:53