Ü   ENDSR (End of Subroutine)

§  It represents the end of a subroutine.

Factor 1

Op-code

Factor 2

Result Field

Resulting Indicators

       HI                            LO                      EQ

Label

ENDSR

Return point

 

 

 

 

 

Example

 

In the program below, we are using return point define how the program should continue processing after reaching the ENDSR.

 


Columns . . . :    6  80               Browse                                AMINEM/QRPGLESRC
SEU==>                                                                               PSSR_PGM
FMT H  HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*************** Beginning of data ****************************************************
0001.00 HOPTION(*SRCSTMT)                                                               130122
0002.00 DMYPSDS          SDS                                                            130121
0003.00 DPROC_NAME          *PROC                                                       130121
0004.00  * Procedure name                                                               130121
0005.00 DPGM_STATUS         *STATUS                                                     130122
0006.00  * Status code                                                                  130121
0007.00                                                                                 130121
0008.00 D LINE_NUM               21     28                                              130121
0009.00  * Source statement line no.                                                    130122
0010.00                                                                                 130121
0011.00 DA                S              2  0 INZ(*ZEROS)                               130122
0012.00 DB                S              2  0 INZ(10)                                   130122
0013.00 DC                S              2  0 INZ(*ZEROS)                               130122
0014.00 D@ERR             S             50    INZ(*BLANKS)                              130122
0015.00 C     B             DIV       A             C                    667788         130122
0016.00 C     TAG1          TAG                                                         130122
0017.00 C     'C=Infinite'  DSPLY                                                       130122
0018.00 C                   SETON                                        LR             130122
0019.00 C     *PSSR         BEGSR                                                       130122
0020.00 C                   IF        PGM_STATUS=00102                                  130122
0021.00 C                   EVAL      @ERR='Error at line no.'+                         130122
0022.00 C                                  LINE_NUM + ' with status code '+             130122
0023.00 c                                  %CHAR(PGM_STATUS)                            130122
0024.00 C     @ERR          DSPLY                                                       130122
0025.00 C                   GOTO      TAG1                                              130122
0026.00 C*                  MOVE      '*GETIN'      Retur             6    >>>>>>>>>>>  130122
0027.00 C                   ELSE                                                        130122
0028.00 C     'FATAL ERR'   DSPLY                                                       130122
0029.00 C                   MOVE      '*CANCL'      Retur                  >>>>>>>>>>>  130122
0030.00 C                   ENDIF                                                       130122
0031.00 C                   ENDSR     Retur           >>>>>>>>>>>>> Using return point  130122
 
****************** End of data *******************************************************

 

 

Here, *GETIN is equivalent to ‘G’. The control of the program will return to the start of the main section. *CANCEL will simply end the program.

 

 

 

Label use:

 

On the ENDSR, We can mention the Label in factor-1. Suppose while we are inside a subroutine and after processing some lines we want to go directly to ENDSR, for this we can use Label as in the example below.

 


0122.00      C           VALID     BEGSR                                       
0123.00      C           PTNUM     CHAINREC2                 85    |           
0124.00      C           PTNUM     IFEQ *BLANKS                    |           
0125.00      C                     MOVELARY,1     MSG2             |           
0126.00      C                     SETON                     20    |           
0127.00      C                     GOTO AAA                        | >>>>>>>> Control goes
0128.00      C                     ENDIF                           |           to ENDSR
0129.00      C           PTNAME    IFEQ *BLANKS                    |      
0130.00      C                     MOVELARY,2     MSG2             | 
0131.00      C                     SETON                     21    |
0132.00      C                     GOTO AAA                        | >>>>>>>> Control goes
0133.00      C                     ENDIF                           |            to ENDSR
0134.00      C           PTADDR    IFEQ *BLANKS                    |           
0136.00      C                     MOVELARY,3     MSG2             |           
0137.00      C                     SETON                     22    |           
0138.00      C                     GOTO AAA                        |           
0139.00      C                     ENDIF                           |           
0145.00      C           AAA       ENDSR                           |>>>>>>>>> LABEL ‘AAA’

 

 











User Comments:



Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy