ABAP获取程序中的Include
Posted SAP剑客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP获取程序中的Include相关的知识,希望对你有一定的参考价值。
某公司自定义开发的程序都有使用次数和使用者信息的记录,这就要求每次新开发的程序均要包含指定Include程序,下面的代码就可以根据输入的程序名称校验是否遗漏Include程序。
*&---------------------------------------------------------------------*
*& Report ZTEST_GET_INCLUDETAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_GET_INCLUDETAB.
TABLES : ZTPGMUSECNT.
SELECT-OPTIONS : P_GRAM FOR ZTPGMUSECNT-PROGNAME. "程序名称
PARAMETERS : P_NO AS CHECKBOX DEFAULT ''."排除已维护的程序
START-OF-SELECTION.
IF P_GRAM[] IS INITIAL.
MESSAGE 'No Program Selected!' TYPE 'E'.
ENDIF.
DATA: IINCLUDELINES TYPE STANDARD TABLE OF STRING WITH HEADER LINE.
DATA: ITOKENS TYPE STANDARD TABLE OF STOKES WITH HEADER LINE.
DATA: IKEYWORDS TYPE STANDARD TABLE OF TEXT20 WITH HEADER LINE.
DATA: ISTATEMENTS TYPE STANDARD TABLE OF SSTMNT WITH HEADER LINE.
DATA: CASTPROGRAMNAME TYPE PROGRAM.
DATA: LV_INDEX TYPE BUZEI.
LOOP AT P_GRAM.
LV_INDEX = LV_INDEX + 1.
CASTPROGRAMNAME = P_GRAM-LOW.
READ REPORT CASTPROGRAMNAME INTO IINCLUDELINES.
APPEND 'INCLUDE' TO IKEYWORDS.
SCAN ABAP-SOURCE IINCLUDELINES TOKENS INTO ITOKENS
WITH INCLUDES STATEMENTS INTO ISTATEMENTS KEYWORDS FROM IKEYWORDS.
CLEAR IINCLUDELINES[].
LOOP AT ITOKENS WHERE STR = 'ZINCLUDE_LOG' AND TYPE = 'I'.
ENDLOOP.
IF SY-SUBRC = 0 .
IF P_NO = ''.
WRITE :/ LV_INDEX,P_GRAM-LOW,'--- Exist'.
ENDIF.
ELSE.
WRITE :/ LV_INDEX COLOR OFF,P_GRAM-LOW COLOR OFF,'--- Not Exist' COLOR = 6.
ENDIF.
ENDLOOP.
SAP也提供了标准的函数"GET_INCLUDETAB"查询程序所包含的Include程序。
FUNCTION GET_INCLUDETAB.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(PROGNAME)
*" TABLES
*" INCLTAB
*"----------------------------------------------------------------------
*----------------------------------------------------------------------*
* Iterative Bestimmung der verwendeten Includes beginnend mit dem *
* Programm / Include PROGNAME *
*----------------------------------------------------------------------*
DATA: T TYPE RSWSOURCET.
*-----Tabellen für SCAN ABAP-SOURCE-----------------------------------
DATA: BEGIN OF KW OCCURS 10,
LINE(30),
END OF KW.
DATA TK TYPE STOKESX OCCURS 0 WITH HEADER LINE.
DATA BEGIN OF STM OCCURS 1000.
INCLUDE STRUCTURE SSTMNT.
DATA END OF STM.
*----------------------------------------------------------------------
CLEAR INCLTAB. REFRESH INCLTAB.
INCLTAB = PROGNAME.
APPEND INCLTAB.
REFRESH KW. CLEAR KW.
KW = 'INCLUDE'. APPEND KW.
LOOP AT INCLTAB.
READ REPORT INCLTAB INTO T.
REFRESH: TK, STM. CLEAR: TK, STM.
SCAN ABAP-SOURCE T
TOKENS INTO TK
STATEMENTS INTO STM
KEYWORDS FROM KW
WITH ANALYSIS.
LOOP AT STM.
ADD 1 TO STM-FROM.
READ TABLE TK INDEX STM-FROM.
CHECK TK-STR NE 'STRUCTURE'.
CHECK TK-STR NE 'TYPE'. " JR 26.6.98
CHECK TK-STR NE 'LIKE'. " JR 26.6.98
CHECK TK-STR NE 'METHODS'. " JR 26.6.98
INCLTAB = TK-STR.
READ TABLE INCLTAB.
IF SY-SUBRC > 0.
APPEND INCLTAB.
ENDIF.
ENDLOOP.
ENDLOOP.
DELETE INCLTAB INDEX 1. "Rahmenprogramm wieder entfernen
ENDFUNCTION.
以上是关于ABAP获取程序中的Include的主要内容,如果未能解决你的问题,请参考以下文章