| PERFORMsubroutine-name | 
 | 
 | 
 | M | 
 | 
 |     | |||
| operand1 | ( AD= | O | ) | |||||||
| A | ||||||||||
| n X | ||||||||||
This document covers the following topics:
For explanations of the symbols used in the syntax diagram, see Syntax Symbols.
Related Statements: CALL | CALL FILE |
                  		  CALL LOOP |
                  		  CALLNAT |
                  		  DEFINE SUBROUTINE |
                  		  ESCAPE |
                  		  FETCH 
               
Belongs to Function Group: Invoking Programs and Routines
The PERFORM statement is used to invoke a Natural
                  			 subroutine.
               
The invoked subroutine may contain a PERFORM
                  				statement to invoke another subroutine (the number of nested levels is limited
                  				by the size of the required memory).
               
A subroutine may invoke itself (recursive subroutine). If database operations are contained within an external subroutine that is invoked recursively, Natural will ensure that the database operations are logically separated.
See the statement CALLNAT.
               
Operand Definition Table:
| Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| operand1 | C | S | A | G | A | U | N | P | I | F | B | D | T | L | C | G | O | yes | yes | |
Syntax Element Description:
| Syntax Element | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| subroutine-name |  Subroutine to be Invoked:  For a subroutine name (maximum 32 characters), the same naming conventions apply as for user-defined variables. The subroutine name is independent of the name of the module in which the subroutine is defined (it may but need not be the same). The subroutine to be invoked must be defined with a
                              						   Within one object, no more than 50 external subroutines may be referenced.  Data Available in a
                                 						  Subroutine 
 | ||||||||||
| operand1 | Parameters to be Passed:  When an external subroutine is invoked with the
                              						   If parameters are passed, the structure of the parameter
                              						  list must be defined in a  By default, the parameters are passed "by
                              						  reference", that is, the data are transferred via address parameters,
                              						  the parameter values themselves are not moved. However, it is also possible to
                              						  pass parameters "by value", that is, pass the actual parameter
                              						  values. To do so, you define these fields in the
                              						   
 Note: For both ways of passing parameters, the following applies: 
 Note: Note: | ||||||||||
| AD= | 
 | ||||||||||
| nX | Parameters to be Skipped:  With the notation
                              						   A parameter that is to be skipped must be defined with the
                              						  keyword  | ||||||||||
** Example 'PEREX1': PERFORM   (as inline subroutine)                   
************************************************************************
DEFINE DATA LOCAL                                                       
1 EMPLOY-VIEW VIEW OF EMPLOYEES                                         
  2 NAME                                                                
  2 ADDRESS-LINE  (A20/2)                                               
  2 PHONE                                                               
*                                                                       
1 #ARRAY    (A75/1:4)                                                   
1 REDEFINE #ARRAY                                                       
  2 #ALINE  (A25/1:4,1:3)                                               
1 #X        (N2) INIT <1>                                               
1 #Y        (N2) INIT <1>                                               
END-DEFINE                                                              
*                                                                       
LIMIT 5                                                                 
FIND EMPLOY-VIEW WITH CITY = 'BALTIMORE'                                
  MOVE NAME            TO #ALINE (#X,#Y)                                
  MOVE ADDRESS-LINE(1) TO #ALINE (#X+1,#Y)                              
  MOVE ADDRESS-LINE(2) TO #ALINE (#X+2,#Y)
  MOVE PHONE           TO #ALINE (#X+3,#Y)
  IF  #Y = 3                              
    RESET INITIAL #Y                      
    /*                                    
    PERFORM PRINT                         
    /*                                    
  ELSE                                    
    ADD 1 TO #Y                           
  END-IF                                  
  AT END OF DATA                          
    /*                                    
    PERFORM PRINT                         
    /*                                    
  END-ENDDATA                             
END-FIND                                  
*                                         
DEFINE SUBROUTINE PRINT                   
  WRITE NOTITLE (AD=OI) #ARRAY(*)         
  RESET #ARRAY(*) 
  SKIP 1          
END-SUBROUTINE   
*                 
END 
               			 Output of Program PEREX1:
               
JENSON                   LAWLER                   FORREST          
2120 HASSELL             4588 CANDLEBERRY AVE     37 TENNYSON DRIVE
 #206                    BALTIMORE                BALTIMORE        
998-5038                 629-0403                 881-3609         
                                                                   
ALEXANDER                NEEDHAM                                   
409 SENECA DRIVE         12609 BUILDERS LANE                       
BALTIMORE                BALTIMORE                                 
345-3690                 641-9789 
               		   
               		  
               Program containing PERFORM statement:
               
** Example 'PEREX2': PERFORM (as external subroutine)                   
************************************************************************
DEFINE DATA LOCAL                                                       
1 EMPLOY-VIEW VIEW OF EMPLOYEES                                         
  2 NAME                                                                
  2 ADDRESS-LINE  (A20/2)                                               
  2 PHONE                                                               
*                                                                       
1 #ALINE   (A25/1:4,1:3)                                                
1 #X       (N2)            INIT <1>                                     
1 #Y       (N2)            INIT <1>                                     
END-DEFINE                                                              
*                                                                       
LIMIT 5                                                                 
*                                                                       
FIND EMPLOY-VIEW WITH CITY = 'BALTIMORE'                                
  MOVE NAME            TO #ALINE (#X,#Y)                                
  MOVE ADDRESS-LINE(1) TO #ALINE (#X+1,#Y)                              
  MOVE ADDRESS-LINE(2) TO #ALINE (#X+2,#Y)                              
  MOVE PHONE           TO #ALINE (#X+3,#Y)
  IF  #Y = 3                              
    RESET INITIAL #Y                      
    /*                                    
    PERFORM PEREX2E #ALINE(*,*)           
    /*                                    
  ELSE                                    
    ADD 1 TO #Y                           
  END-IF                                  
  AT END OF DATA                          
    /*                                    
    PERFORM PEREX2E #ALINE(*,*)           
    /*                                    
  END-ENDDATA                             
END-FIND                                  
*                                         
END 
               			 External subroutine PEREX3 with parameters called by
                  				program PEREX2:
               
** Example 'PEREX3': SUBROUTINE (external subroutine with parameters) ************************************************************************ DEFINE DATA PARAMETER 1 #ALINE (A25/1:4,1:3) END-DEFINE * DEFINE SUBROUTINE PEREX2E WRITE NOTITLE (AD=OI) #ALINE(*,*) RESET #ALINE(*,*) SKIP 1 END-SUBROUTINE * END
Output of Program PEREX2:
               
JENSON                    LAWLER                    FORREST          
2120 HASSELL              4588 CANDLEBERRY AVE      37 TENNYSON DRIVE
 #206                     BALTIMORE                 BALTIMORE        
998-5038                  629-0403                  881-3609         
                                                                     
ALEXANDER                 NEEDHAM                                    
409 SENECA DRIVE          12609 BUILDERS LANE                        
BALTIMORE                 BALTIMORE                                  
345-3690                  641-9789