Difference between Procedure & Subprocedure

425 pts.
Tags:
AS/400
Can someone tell me the difference between Procedure & Subprocedure. And how/use NOMAIN MAIN applicable to procedures?

Software/Hardware used:
Iseries

Answer Wiki

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

You can create procedure which don’t return a value or functions which have a return value. These can be placed in the same source as an actual program module or in a sorce member without any “runnable” or main module. If you put the procedure in a source that doesn’t have a main module you must use the H spec entry NOMAIN so the compiler understands that it shouldn’t be looking for in-line or main code.
Phil

========================================================

You don’t say what language you’re asking about, and you ask two different questions. But because the second question is about “NOMAIN”, all of this will be about how ILE RPG sees things as I understand it.

Can someone tell me the difference between Procedure & Subprocedure.

First, that’s not quite a correct question. It’s like asking “What’s the difference between a vehicle and a truck?” A better question than that might be “What’s the difference between a car and a truck?”

A subprocedure is a procedure, so there’s no difference except that subprocedure is a subcategory of procedure. The question you should have asked might have been better as “What’s the difference between a main procedure and a subprocedure?”

From the WebSphere Development Studio: ILE RPG Programmer’s Guide:

An ILE RPG module consists of a main procedure and zero or more subprocedures. (If there are subprocedures, the main procedure is optional.) A main procedure is a procedure that can be specified as the program entry procedure (and so receive control when an ILE program is first called). The main procedure is defined in the main source section, which is the set of H, F, D, I, C, and O specifications that begin a module. In V3R1, all ILE RPG modules had a main procedure and no other procedures.

A subprocedure is a procedure that is specified after the main source section. A subprocedure differs from a main procedure primarily in that:

* Names that are defined within subprocedure are not accessible outside the subprocedure.
* No cycle code is generated for the subprocedure.
* The call interface must be prototyped.
* Calls to subprocedures must be bound procedure calls.
* Only P, D, and C specifications can be used.

In short, a main procedure can be a PEP (program entry procedure). And a subprocedure can’t.

And how/use NOMAIN MAIN applicable to procedures?

This question also isn’t quite correct. It implies that NOMAIN is an attribute of procedures, when it’s actually an attribute of an ILE RPG module. A module can be compiled as NOMAIN. There can be one or more procedures in a NOMAIN module. All procedures in a NOMAIN module will necessarily be subprocedures.

From the WebSphere Development Studio: ILE RPG Language Reference:

The NOMAIN keyword indicates that there is no main procedure in this module. It also means that the module in which it is coded cannot be an entry module.

See NOMAIN Module for more detail.

Note that a NOMAIN module will compile more quickly since it doesn’t get any of the usual Cycle code and other parts that support main procedures. The module will also be smaller.

As you can see, all of this is in the current Information Centers and can be found by searching there.

Tom

Discuss This Question: 3  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.
  • Littlepd
    The ILE Concepts manual describes concepts and terminology for the Integrated Language Environment (ILE) architecture of the i5/OS operating system. Topics covered include module creation, binding, how to run and debug programs, and exception handling.
    1,130 pointsBadges:
    report
  • The most-watched IT questions this week: March 2, 2010 - ITKE Community Blog
    [...] Kar asks about the difference between Procedure & Subprocedure, and TomLiotta, Philpl1jb and Littlepd all help [...]
    0 pointsBadges:
    report
  • anandx
    Lexicons, concepts and governing rules have already been explained clearly earlier. This pseudo code attempts to illustrate the basic idea.
    PGM1 takes the demand from the user and services thru SRVPGMX. PGM1 starts always at (1) and ends at (2) going each step sequentially, which is loosely speaking (rpg) cycle process. SRVPGMX, as opposed to PGM1, can start at (5) and get out at (6) ignoring (3) to (4). This is (rpg) non-cycle processing. Call Pgm1 will work, Call SRVPGM1 won't. However, callP subproc_add will work if called from within another pgm. PGM1 is the main procedure. SRVPGMX is a nomain procedure which has 2 sub procedures, _add and _del which are called also as procedures. PGM1 has its own native local sub-procedure. (7) is *INZSR (not called explicitly by pgm but  gets executed even before (1) which is one of many facets of RPG cycle. (8) is a sub procedure within the main procedure. Both PGM1 and SRVPGM1 go thru steps bef executable objects creation. First CRTRPGMOD and then CRTPGM (for PGM1) and CRTSRVPGM (for SRVPGMX) (and push it in some BNDDIR). Caller can call called in two ways: by extPROC() or by extPGM(), following covers only the former.
    Hope this too late a reply, devoid of nitty-gritty, helps at least a few

    PGM1
    ctl-opt option (*srcStmt:  *nodebugIo) ;

    dcl-pr subproc_add ;
           *n      some parm ;
    end-pr ;
    dcl-pr subproc_del ;
           *n      someother parm ;
    end-pr ;
    dcl-pr local_sub_proc ;
    end-pr ;

    : local_sub_proc() ;
    exSR  find_what_user_wants ; // program starts here (1)
    select;                   
                              
         when  user_wants_to_add_rec_to_dbf ;  
               subproc_add( somedata ) ;
         when  user_wants_to_del_rec_in_dbf ;
               subproc_del( someotherdata ) ; 
    endSL ;

    *INLR = *on // program starts here (2)

    begSR  find_what_user_wants ;
           exfmt user_wants ;
    endSR ;

    begSR  *INZSR ; (7)
           clear variable1 ;
           open(e)  dbf1 ; // if, usropn
    endSR ;

    dcl-proc local_sub_proc ; (8)
    dcl-pi   local_sub_proc;
    end-pi ;
    do something here ;
    return ;
    end-proc ;


    SRVPGMX
    ctl-opt option nomain ;
    ctl-opt option (*srcStmt:  *nodebugIo) ;

    dcl-proc subproc_add export; (3)
      dcl-pi subproc_add ;
      end-pi ;
    write(e) dbf1 ;
    return;
    end-Proc ; (4)

    dcl-proc subproc_del export; (5)
      dcl-pi subproc_del ;
      end-pi ;
    delete(e) dbf1 ;
    return;
    end-Proc ; (6)
    435 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.

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

Following

Share this item with your network: