2

I called a cobol program from rpgle. I want to return a value from the cobol program to rpgle. I'm new to these and am not sure if I'm doing the right way. Can someone explain me the procedure to do this. below is the command I used in rpgle to call cobol.

callp prog(id:name);

and in cobol i used

working storage section.
linkage section.
01 newid.
01 newname.
procedure division using newid, newname.

If the values are edited in cobol, will the value newid and newname be automatically passed to rpg or is there any other way? how to pass the value in cobol back to rpgle.

Praveen Sundar
  • 79
  • 1
  • 2
  • 8

1 Answers1

4

You have the basics right. That should be fine as long as you provide matching field definitions in both programs. In the ILE COBOL Linkage Section you need to add the definition of what your parameter names refer to. You have no PIC or LIKE clause.

In your ILE RPG program you will need to define a prototype for the call to your COBOL code. The parameter definitions in the prototype need to match the format of the parameters in COBOL. If you are using packed, zoned, or binary integer on one side, then you must use the same for that parm on the other.

(see http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frzase%2Fsc092540419.htm)

For example, in RPG PROG1 you might commonly have something like:

 D   someID                       7p 0                                                         
 D   someName                    10a                                                            

 D addInfo         PR                  EXTPROG("PROG2")                                                    
 D                                7p 0 
 D                               10a                                                            

         callp addInfo (someID:someName);

         // or omit the optional callp opcode

         addInfo (someID:someName);

Then in COBOL PROG2 you could have something like:

  working storage section.
  linkage section.
  01 newid           pic s9(7)    packed-decimal.
  01 newname         pic x(10).

  procedure division using newid, newname.

Your simplest option at this point is to compile them both as individual programs. But it is also possible to use ILE techniques to combine your COBOL procedure into the final RPG program object. But save that for another time.

WarrenT
  • 4,502
  • 19
  • 27
  • Thanks for your valuble input. I'm able to pass characters and retrieve in my rpgle program. But when I try to pass integer values, I get decimal data error saying `a packed or zoned value does not contain valid numeric data. A digit and/or sign is invalid.` – Praveen Sundar Nov 07 '13 at 07:13
  • I figured it out. I passed both the parameters as character type. After receiving it in rpgle, I converted it to numeric using %DEC. It worked, thanks a lot. – Praveen Sundar Nov 07 '13 at 07:30
  • @BillWoodger I first tried with Zoned decimal in rpgle, didn't work out. Then I tried packed. After failing many times to get it right, I opted for this method. – Praveen Sundar Nov 07 '13 at 08:20
  • 2
    @PraveenSundar common best practices would say don't convert numerics to character, just to pass them. See my edits. – WarrenT Nov 07 '13 at 23:45
  • @WarrenT Finally, I got it right. Earlier I tried this too. But, I wasn't specifying the `packed-decimal` in my cobol program. Now I rectified it. It's working perfectly. Thanks again. – Praveen Sundar Nov 08 '13 at 05:24
  • alternatively, you could have defined the RPG variable as zoned (ex: 7s 0) – WarrenT Nov 08 '13 at 05:27
  • @WarrenT Yeah, thanks. It worked too. Now, I learnt the right way to pass parameters with their attributes. – Praveen Sundar Nov 08 '13 at 05:47
  • @BillWoodger I agree with you, It should direct others who search for info, in the right way. Thats it for this post. – Praveen Sundar Nov 09 '13 at 12:38