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.
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.