RPGLE free format subprocedure example code - AS400 (iSeries)

Subprocedure consist of the following
  • Begin and End
  • May or may not return value
  • Have access to global and local variables
  • Any variables inside the definition are considered local
  • To return complex data use data structure

Sample RPGLE program with subprocedure

h dftactgrp(*no)                                  
d MyProcedure     PR            52a               
d                               30a               
d                                3s 0             
d $name           s             30a   inz('as400') 
d $age            s              3s 0 inz(21)     
d $message        s             52a               
    $message = MyProcedure($name:$age);           
    dsply $message;                               
    eval *inlr = *on;                             
p MyProcedure     B                   EXPORT      
d  MyProcedure    PI            52a                
d   $name                       30a                         
d   $age                         3s 0                       
d $message        s             52a                         
    $message = 'My name is ' + %trim($name) + ', ' +        
              'age ' + %trim(%editc($age:'Z')) + ' years.'; 
    return $message;                                        
p MyProcedure     E 

Tip: You can code one or more subprocedures in a module without coding a main procedure. Such a module is called a NOMAIN module, since it requires the specification of the NOMAIN keyword on the control specification. When there is no main procedure, no cycle code is generated for the NOMAIN module.

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.