ITPub博客

首页 > Linux操作系统 > Linux操作系统 > GENERATE SUBROUTINE POOL

GENERATE SUBROUTINE POOL

原创 Linux操作系统 作者:yangjulei 时间:2010-03-09 15:19:07 1 删除 编辑

Syntax

GENERATE SUBROUTINE POOL itab NAME prog [error_handling].

Effect

This statement generates a temporary subroutine pool. The source code of the subroutine pool is taken from the internal table itab. The generated subroutine pool is stored internally in the current internal mode. The eight-character name of the temporary subroutine pool is assigned to the variable prog.

The line type for itab must be character type (prior to Release 6.10 flat). A source code line in itab may contain a maximum of 255 characters. The data object prog must also be character type (prior to Release 6.10 flat). In an internal mode, a maximum of 36 temporary subroutine pools may be created.

If the source text contained in itab has a syntax error, the subroutine pool is not generated and initialized using prog. Using the addition error_handling, syntax and generation errors can be analyzed. Syntax errors can either occur in the source code specified in itab or in the include programs included using the statement INCLUDE. check. For the syntax check, the switch configuration of the Switch Framework in its current status when the transaction was called.

In the source code of the subroutine pool, subroutines can be called from all programs that are loaded in the same internal mode by specifying the program name prog using the statement PERFORM. At the first call of a subroutine in the subroutine pool, this is loaded into internal mode, whereby the event LOAD-OF-PROGRAM is initialized.

System Fields

sy-subrc Meaning
0 Generation was successful.
4 Source code contains a syntax error.
8 A generation error occurred.

Notes

  • If the creating program is a Unicode program, the corresponding syntax rules apply for the generated subroutine pool.
  • Using the switch configuration available at the time the transaction was called for the syntax check guarantees the assurance of the Switch Framework that the whole transaction is executed using the same switch configuration.
  • The source code in the internal table itab must contain a complete ABAP program, including the statement that introduces the program.
  • In a temporary subroutine pool, the same global declarations and editing rules are defined as in the static subroutine pool of the repository (see table).
  • Temporarily generated subroutine pools can be executed in the ABAP Debugger in single steps.
  • A temporary subroutine pool generated for an internal mode cannot be explicitly deleted. It remains available from its generation up to the point where the internal session is terminated.
  • GENERATE SUBROUTINE POOL should only be used in exceptional cases in application programs. ABAP offers many other methods for dynamic programming, which generally render the creation of source code unnecessary (see the list under processing dynamic programs).


Example

Dynamic creation and generation of a subroutine pool that implements the event block LOAD-OF-PROGRAM and two subroutines. Depending on the return value sy-subrc, a subroutine is called or a message is issued.

DATA: prog TYPE string,
      tab  TYPE STANDARD TABLE OF string,
      mess TYPE string,
      sid  TYPE string.

APPEND 'PROGRAM subpool.'                        TO tab.
APPEND `DATA spfli_tab TYPE TABLE OF spfli.`     TO tab.
APPEND `LOAD-OF-PROGRAM.`                        TO tab.
APPEND `  SELECT *` &
       `         FROM spfli` &
       `         INTO TABLE spfli_tab.`          TO tab.
APPEND `FORM. loop_at_tab.`                       TO tab.
APPEND `  DATA spfli_wa TYPE spfli.`             TO tab.
APPEND `  LOOP AT spfli_tab INTO spfli_wa.`      TO tab.
APPEND `    PERFORM. evaluate_wa USING spfli_wa.` TO tab.
APPEND `  ENDLOOP.`                              TO tab.
APPEND `ENDFORM.`                                TO tab.
APPEND `FORM. evaluate_wa USING l_wa TYPE spfli.` TO tab.
APPEND `  WRITE: / l_wa-carrid, l_wa-connid.`    TO tab.
APPEND `ENDFORM.`                                TO tab.

GENERATE SUBROUTINE POOL tab NAME prog
         MESSAGE mess
         SHORTDUMP-ID sid.

IF sy-subrc = 0.
  PERFORM. ('LOOP_AT_TAB') IN PROGRAM (prog) IF FOUND.
ELSEIF sy-subrc = 4.
  MESSAGE mess TYPE 'I'.
ELSEIF sy-subrc = 8.
  MESSAGE sid TYPE 'I'.
ENDIF.

Example

Dynamic creation and generation of a subroutine pool that implements a local class. The static method meth of the class can be called with the absolute type name of the class.

DATA itab  TYPE TABLE OF string.
DATA prog  TYPE string.
DATA class TYPE string.

APPEND `program.`                     TO itab.
APPEND `class main definition.`       TO itab.
APPEND `  public section.`            TO itab.
APPEND `    class-methods meth.`      TO itab.
APPEND `endclass.`                    TO itab.
APPEND `class main implementation.`   TO itab.
APPEND `  method meth.`               TO itab.
APPEND `    message 'Test' type 'I'.` TO itab.
APPEND `  endmethod.`                 TO itab.
APPEND `endclass.`                    TO itab.

GENERATE SUBROUTINE POOL itab NAME prog.

CONCATENATE `\PROGRAM=` prog `\CLASS=MAIN` INTO class.

CALL METHOD (class)=>meth.

Example

Dynamic creation and generation of a subroutine pool that implements a local class. The class is instanced with its absolute type name, and the instance method meth is called dynamically.

DATA itab  TYPE TABLE OF string.
DATA prog  TYPE string.
DATA class TYPE string.
DATA oref  TYPE REF TO object.

APPEND `program.`                     TO itab.
APPEND `class main definition.`       TO itab.
APPEND `  public section.`            TO itab.
APPEND `    methods meth.`            TO itab.
APPEND `endclass.`                    TO itab.
APPEND `class main implementation.`   TO itab.
APPEND `  method meth.`               TO itab.
APPEND `    message 'Test' type 'I'.` TO itab.
APPEND `  endmethod.`                 TO itab.
APPEND `endclass.`                    TO itab.

GENERATE SUBROUTINE POOL itab NAME prog.

CONCATENATE `\PROGRAM=` prog `\CLASS=MAIN` INTO class.

CREATE OBJECT oref TYPE (class).

CALL METHOD oref->('METH').

Exceptions

Catchable Exceptions

CX_SY_GENERATE_SUBPOOL_FULL

  • Cause: A further temporary subroutine pool can be generated.
    Runtime Error: GENERATE_SUBPOOL_DIR_FULL (catchable)

CX_SY_GEN_SOURCE_TOO_WIDE

  • Cause: The source code is in a table consisting of strings that contains rows with more than 255 characters.
    Runtime Error: GEN_SOURCE_TOO_WIDE

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7714329/viewspace-628970/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2010-03-08

  • 博文量
    72
  • 访问量
    229974