Results for "Sub Procedures"
PROCEDURE CALLING TWO SUBPROCEDURES



PROCEDURE CALLING TWO SUBPROCEDURES



PRA1/QRPGLESRC
TWOSUBPROC

0000.01 DA                S              3  0                                  
0000.02 DB                S              3  0                                   
0000.03 DS                S              3  0                                  
0000.04 DG                S              3  0                                  
0000.05 DSUBPR1           PR             3  0                                   
0000.06 DA                               3  0                                  
0000.07 DB                               3  0                                  
0000.08 Dres1                S              3  0                                  
0000.09 DSUBPR2           PR             6  0                                  
0000.10 DS                               3  0                                  
0000.11 DG                               3  0                                  
0000.12 Dres2                s              6  0                                  
0000.14 C                   EVAL      A=7                                      
0000.15 C                   EVAL      B=4                                      
0000.16 C                   EVAL      res1=SUBPR1(A:B)                            
0000.17 C     res1             DSPLY                                              
0000.18 C                   EVAL      G=2                    
0000.19 C                   EVAL      S=res1                     
0000.20 C                   EVAL      res2=SUBPR2(S:G)          
0000.21 C     res2             DSPLY                            
0000.22 c                   eval      *inlr=*on              
0000.23 C                   RETURN                            
0000.24 PSUBPR2           B                                  
0000.25 DSUBPR2           PI             6  0                
0000.26 DS                               3  0                
0000.27 DG                               3  0   
0000.28 DZ                S              6  0                            
0000.29 C                   EVAL      Z=S*G                              
0000.30 C                   RETURN    Z                                  
0000.31 PSUBPR2           E                                               
0001.00 PSUBPR1           B                                              
0002.00 DSUBPR1           PI             3  0                            
0002.01 DA                               3  0                             
0002.02 DB                               3  0                            
0005.00 DC                S              3  0                            
0006.00 C                   EVAL      C=A+B                              
0007.00 C                   RETURN    C                                  
0008.00 PSUBPR1           E                                              


output is :-


DSPLY   11    

DSPLY   22

Unknown Tuesday, 28 May 2013


SUB PROCEDURE


SUB PROCEDURE WHEN RETURNING ANY VALUE ( since this subprocedure is returning a value so procedure interface should be used , callp should not be used, and the length of the subprocedure should be defined)
   
PRA1/QRPGLESRC
SUBPROC
0001.00 da                s              3  0                                   
0001.01 db                s              3  0                                  
0002.00 Dsubpr1           pr            12  0                                  
0003.00 Da                               3  0                                   
0004.00 Db                               3  0                                  
0005.00 Dc                s             12  0                                  
0007.00 C                   eval      a=10                                      
0008.00 C                   eval      b=20                                     
0008.03 c                   eval      c=subpr1(a:b)                            
0010.00 c     c             dsply                                              
0011.00 c                   eval      *inlr=*on                                
0012.00 c                   return                                             
0013.00                                                                        
0014.00                                                                         
0015.00 psubpr1           b                                                    
0016.00 dsubpr1           pi            12  0                                  
0017.00 da                               3  0                    
0018.00 db                               3  0                    
0019.00 dx                s             12  0                    
0020.00 c                   eval      x=a+b                      
0021.00 c                   return    x                          
0022.00 psubpr1           e

output is :-

DSPLY            30  



How to see output:-

1) Here in subprocedures we should not compile directly I mean 14 option should not be used.
First use crtrpgmod then press <f4> and enter module name if u write crtrpgmod and press enter then default module will be created in qgpl library with the module name as proof.

2) then crtpgm <f4> and write the programs name (any name) .


3) to see output  type on the command line as call <program name> . [ here call proc1 ].
Unknown
subprocedures

subprocedures

Important points:-

 1)In the calling procedure , we have to declare prototype of the returning value.

 2) if the procedure is not returning any value (void) then callp should be used.,and importantly
     length of the subprocedure need not be defined if the procedure is not returning any value.

Ex:-  callp ( opcode )  subpr1 parm(a b)

3) Procedure interface includes the return value , and the parameters like *entry plist. It is receiving values from outside procedure.

TYPE1 :- MAIN PROCEDURE CALLING SUBPROCEDURE

   SUB PROCEDURE WHEN NOT RETURNING ANY VALUE
  ( since not returning any value  callp should be used  && length
    of subprocedure need not be specified ).

PRA1/QRPGLESRC
MODULE3
0001.00 DSUBPR1           PR                                                    
0002.00 C     'RAVI'        DSPLY                                              
0003.00 C                   callp     subpr1                                   
0004.00 C                   EVAL      *INLR=*ON                                 
0005.00 C                   RETURN                                             
0006.00                                                                        
0007.00 PSUBPR1           B                                                     
0008.00 DSUBPR1           PI                                                   
0009.00 C     'KUMAR'       DSPLY                                              
0010.00 PSUBPR1           E                  

NOTE:-

Therz no p spec  but subprocedure should be informed  as subpr1 b (while beginning)
 abd subpr1 e  ( while ending) so first insert I mean  write I and press enter, then write p in column 1
and press <f4> then u can  view like this


 Procedure Name                Begin/End                                        
 subpr1                                 e                                           

                                                                         
output is :-

DSPLY  RAVI  
 DSPLY  KUMAR                                    

 

How to see output:-


1) Here in subprocedures we should not compile directly I mean 14 option should not be used.
First use crtrpgmod then press <f4> and enter module name if u write crtrpgmod and press enter then default module will be created in qgpl library with the module name as proof.

2) then crtpgm <f4> and write the programs name (any name) .

3) to see output  type on the command line as call <program name> . [ here call module3 ].


Unknown