Drunken Lion

GENERATE SUBROUTINE POOL 본문

SAP/ABAP

GENERATE SUBROUTINE POOL

DrkLion 2012. 3. 7. 14:32

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

'SAP > ABAP' 카테고리의 다른 글

[WDA] WEB DYNPRO 에서 Dropdown 만들기  (0) 2012.06.07
이벤트를 이용한 back job 실행  (0) 2012.04.09
세무서 제출용 양식에 공백 처리  (1) 2012.02.24
ALV 에서 SY-UCOMM 발생 시키기  (0) 2012.02.16
CL_GOS_SERVICE_TOOLS  (0) 2011.11.23