这里我们聊一下动态调用和Mapping。
作为一个比较大型的应用,动态调用和Mapping是必不可少的,有了这两样法宝,可以减少很多冗余代码,同时也简化日后维护。
下面给一个例子:分两部分,一个是function group,另一个运行用的report
Function pool: SAPLZKEVIN_A
*******************************************************************
* System-defined Include-files. *
*******************************************************************
INCLUDE LZKEVIN_ATOP. " Global Data
INCLUDE LZKEVIN_AUXX. " Function Modules
*******************************************************************
* User-defined Include-files (if necessary). *
*******************************************************************
* INCLUDE LZKEVIN_AF. " Subprograms
* INCLUDE LZKEVIN_AO... " PBO-Modules
* INCLUDE LZKEVIN_AI... " PAI-Modules
INCLUDE LZKEVIN_AF01.
*INCLUDE LZKEVIN_AF02.
INCLUDE LZKEVIN_AF02.
LZKEVIN_AF01
*----------------------------------------------------------------------*
***INCLUDE LZKEVIN_AF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CHECK_02
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_02 .
WRITE / 'CHECK_02'.
ENDFORM. " CHECK_02
*&---------------------------------------------------------------------*
*& Form CHECK_03
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_03 .
WRITE / 'CHECK_03'.
ENDFORM. " CHECK_03
LZKEVIN_AF02
*----------------------------------------------------------------------*
***INCLUDE LZKEVIN_AF02 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CHECK_01
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_01 .
WRITE / 'CHECK_01'.
ENDFORM. " CHECK_01
Report
*----------------------------------------------------------------------*
* Program Name: Z_KEVIN_ARCH
* Project : N/A
* Author : Kevin.Zhang
* Date : 2007.1.1
* Module : N/A
* Description : Template of Program
*
*
*
* Special features: N/A
*
*
*----------------------------------------------------------------------*
* Modifications:
* Author Date Commented as Description
*----------- -------- ----------- ----------------------------------*
*
*----------------------------------------------------------------------*
REPORT Z_KEVIN_ARCH.
*$*$----------------------------------------------------------------$*$*
*$*$ Global Types, Data Statements, Ranges, Constants $*$*
*$*$----------------------------------------------------------------$*$*
*-----------------------------------------------------------------------
* Internal Tables and Work Areas
*-----------------------------------------------------------------------
DATA GS_CHECK TYPE ZCHECK.
DATA GT_CHECK TYPE TABLE OF ZCHECK.
DATA GS_ZKEVINA TYPE ZKEVINA.
DATA GT_ZKEVINA TYPE TABLE OF ZKEVINA.
*$*$----------------------------------------------------------------$*$*
*$*$ Main Program $*$*
*$*$----------------------------------------------------------------$*$*
SELECT * FROM ZKEVINA
INTO TABLE GT_ZKEVINA
WHERE ID = '1'.
SELECT * FROM ZCHECK
INTO TABLE GT_CHECK.
SORT GT_CHECK BY SEQ.
LOOP AT GT_ZKEVINA INTO GS_ZKEVINA.
READ TABLE GT_CHECK INTO GS_CHECK WITH KEY ID = GS_ZKEVINA-ID.
IF ( SY-SUBRC = 0 ).
LOOP AT GT_CHECK INTO GS_CHECK WHERE ID = GS_ZKEVINA-ID.
PERFORM (GS_CHECK-CHECK_ROUTINE) IN PROGRAM SAPLZKEVIN_A.
ENDLOOP.
ENDIF.
ENDLOOP.
表结构:
ZCHECK
MANDT MANDT CLNT 3 0 Client
ID CHAR 4 0
SEQ NUMC3 NUMC 3 0 Numc3, internal use
CHECK_ROUTINE CHAR30 CHAR 30 0 30 Characters
ZKEVINA
ID CHAR 4 0 ID
NAME CHAR 20 0 Name
阅读(1344) | 评论(0) | 转发(0) |