Calling RPG Proc from COBOL ILE

40 pts.
Tags:
AS/400
COBOL
ILE COBOL
Procedure
RPG ILE
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?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • RPGPGM
    Thanks for the reply. Its very clear... I will try to implement it and get back if any queries.
    40 pointsBadges:
    report
  • RPGPGM
    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?
    40 pointsBadges:
    report
  • bvining
    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.
    6,485 pointsBadges:
    report
  • bvining
    And just in case, is the error at compile time or is this an editor (like SEU) reported error?
    6,485 pointsBadges:
    report
  • Cindyssite
    Bruce, Thanks so much! With your guidance, my COBOL program is now calling an RPG service program external sub-procedure. What I learned: 1) PROCESS NOMONOPRC must be placed above the IDENTIFICATION DIVISION. 2) SPECIAL-NAMES must follow SOURCE-COMPUTER & OBJECT-COMPUTER (if they exist). 2) CPD5D02 Definition not found for symbol 'MyServicePgm' error if anything amiss, such as parms not matching the definition. In my case, I finally realized although my RPG service program source defined the sub-procedure as mixed case, the extproc was all UPPER, and so my COBOL call had to match that. Here are my compile instructions for the next programmer who has to update this program: 1) CRTCBLMOD MODULE(mylib/MYCOBOL) DBGVIEW(*LIST) 2) CRTPGM PGM(mylib/COBOLPGM) BNDSRVPGM(MYSRVPGM) BNDDIR(MYBNDDIR) ACTGRP(*CALLER) Just leaving my share of bread crumbs for the next guy. Thanks again so much!!!
    30 pointsBadges:
    report
  • Cindyssite
    For folks struggling with calling an RPG service program procedure from COBOL, here are some things I learned: If the procedure uses the %parms BIF to handle an optional parm, you must use operational descriptors. The way to do this in COBOL is to add "USING ALL DESCRIBED" as follows: SPECIAL-NAMES. LINKAGE TYPE PROCEDURE FOR "MyRPGProcedure" USING ALL DESCRIBED. Some links I found hepful: http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/apis/ile1a2.htm and http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.pgmgd.doc/c0925405220.htm Also a special thanks to Scott Klement who indirectly helped by posting articles and blog comments that finally lead me to Google "cobol operational descriptor". But mostly Bruce for his very good explanation above. :-)
    30 pointsBadges:
    report
  • Cindyssite
    Correction: you must use operational descriptors to get the called RPG procedure to count that parm (assuming you want to pass it).
    30 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following