Question

  Asked: Jan 28 2008   6:11 PM GMT
  Asked by: RPGPGM


Calling RPG Proc from COBOL ILE


COBOL, COBOL ILE, RPG ILE, Procedure, AS/400

How do I call a RPGILE procedure embedded in a service program from COBOL ILE? I am not very well versed in cobol as I worked mostly on RPG/400 and ILE. I checked few of the notes but was confused abt the 'Call Linkage type' and Call Procedure? Can anyone say when each one is used and what is their significance?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0



They're just different ways of accomplishing the same goal -- calling a procedure.

Loosely think of CALL PROCEDURE as being similiar to RPG's CALLB -- both specify right there in the CALL that a procedure is being called. If you had a *SRVPGM exporting the procedure SgnMax, which takes two integer const inputs and returns the larger of the two values, then:


PROCESS NOMONOPRC.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 Numeric-Value-1 PIC S9(9) BINARY VALUE 10.
01 Numeric-Value-2 PIC S9(9) BINARY VALUE 13.
01 Answer PIC S9(9) BINARY.

PROCEDURE DIVISION.
MAIN-LINE.
CALL PROCEDURE "SgnMax" USING
BY CONTENT Numeric-Value-1,
BY CONTENT Numeric-Value-2,
GIVING Answer.
DISPLAY "The larger number is: " Answer.
STOP RUN.


would call that procedure.

Using the Special-Names paragraph and specifying LINKAGE TYPE PROCEDURE allows you to identify SngMax as being a procedure without having to explicitly respecify it on each call (VERY loosely like how a RPG prototype can distinguish between a program call and a procedure call. Using SgnMax again, this would also work:


PROCESS NOMONOPRC.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
LINKAGE TYPE PROCEDURE FOR "SgnMax".

DATA DIVISION.
WORKING-STORAGE SECTION.
01 Numeric-Value-1 PIC S9(9) BINARY VALUE 10.
01 Numeric-Value-2 PIC S9(9) BINARY VALUE 13.
01 Answer PIC S9(9) BINARY.

PROCEDURE DIVISION.
MAIN-LINE.
CALL "SgnMax" USING BY CONTENT Numeric-Value-1,
BY CONTENT Numeric-Value-2,
GIVING Answer.
DISPLAY "The larger number is: " Answer.
STOP RUN.


Simply pick one way and use it. Personally I use the CALL PROCEDURE approach.

One key difference between the two languages that you need to be aware of -- in RPG you expect quoted names to be left as is. COBOL, on the other hand, will monocase mixed case procedure name literals. So if you're not careful you will find "SgnMax" becoming SGNMAX when trying to bind to the function. To turn this feature off you use the PROCESS NOMONOPRC statement. The PROCESS statement is, again loosely speaking, like the RPG H spec (though unfortunately you can't specify binding directories or service program names on the PROCESS statement).

If your RPG procedure prototypes a parameter as VALUE you'll use BY VALUE in COBOL. If the prototype has CONST you'll use BY CONTENT. And if neither VALUE or CONST, use BY REFERENCE. GIVING identifies the procedures RETURN value.

I hope this helps,
Bruce Vining
http://www.brucevining.com/
  • AddThis Social Bookmark Button

Browse more Questions and Answers on DataCenter and AS/400.

Looking for relevant DataCenter Whitepapers? Visit the SearchDataCenter.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

RPGPGM  |   Jan 30 2008  3:58AM GMT

Thanks for the reply. Its very clear… I will try to implement it and get back if any queries.

 

RPGPGM  |   Jan 31 2008  10:31PM GMT

I used both the formats… Call Procedure and Call Linkage Type but it throws me an Error…”Program-name in CALL or CANCEL statement is not valid”. Can you say what could be the mistake?

 

Bvining  |   Feb 1 2008  4:35PM GMT

Please provide the source code that’s causing the problem. It will be much easier to debug if I can see what you’re doing. The equivalent working RPG CALL would also be great.

 

Bvining  |   Feb 1 2008  5:53PM GMT

And just in case, is the error at compile time or is this an editor (like SEU) reported error?