[SAP Abap] X-DOC: SE18/19 - SAP fourth generation enhanced concept understanding

1、Tcode

SE18: Business Add-Ins: Definitions (enhancement point definition/view), used for viewing and maintaining enhancement options.
Insert image description here
SE19: Business Add-Ins: Implementations (enhanced implementation), create and maintain enhanced implementations based on enhancement points.
Insert image description here

2. Concept

(1) Enhancement Spot (enhancement container) , used to organize enhancement options. There can be multiple enhancement options in a Spot. Generally, one Spot can be built in one program.
(2) Enhancement Options , including the following two types of enhancement options: Point and Section. One program can create multiple Options.
(3) Enhancement Implementation Point , a location defined in the ABAP program for inserting enhancement implementation code.
(4) Enhancement Implementation Section , an area defined in the ABAP program where the code will be replaced by enhancement implementation.
Insert image description here

3. Enhanced option types

(1) Explicit enhancement options:
ENHANCEMENT-POINT/SECTION zen_name SPOTS zspots_name STATIC.
Explicit enhancement options are managed by enhancement points and must be inserted into the source code in advance and enhanced through enhancement implementation.
(2) Implicit enhancement options
Implicit enhancement options are provided by the enhancement framework and do not require developers to make any specific preparations. They do not have to belong to the container (enhancement point).
They are also enhanced through enhanced implementations.

4. Enhance implementation type

(1) Static form (Declaration) : Add STATIC to the enhancement option, which corresponds to the declaration type when implementing implicit enhancement. It is generally used for the enhancement of data declaration. When the switch state of the package where the enhancement implementation is located is On & Stand-by, the code will be executed; the data declaration in ENHANCEMENT-SECTION can be redefined.
(2) Dynamic form (Code) : The enhancement option does not add STATIC, corresponds to the code type when implementing implicit enhancement, and is generally used for enhancement of executable code. The code will only be executed when the switch state of the package where the enhanced implementation is located is On. The data declaration in ENHANCEMENT-SECTION is a static global variable and cannot be replaced.
The difference between the two :
When the enhanced implementation does not set a switch, the code will be executed, but the static form is more efficient.
It is not recommended to use static SECTION because it will change the data declaration and may cause unpredictable problems.
Insert image description here

5. Enhance operation methods

Reference: [SAP Abap] SAP fourth generation enhanced development DEMO
enhanced demo:

REPORT yz_demo_enhancement_4g.

WRITE: / 'BEGIN,来自主程序'.
SKIP.

" 静态增强点
ENHANCEMENT-POINT YPOINT1 SPOTS YSPOTS1 STATIC .
*$*$-Start: YPOINT1-----------------------------------------------------------------------------$*$*
ENHANCEMENT 1  YEH001.    "active version
  data: gv_po1(10) VALUE 'Test1'.
  write: / '增强点1-静态YPOINT1实施:' && gv_po1.
ENDENHANCEMENT.
ENHANCEMENT 2  YEH002.    "active version
*
  write: / '增强点1-静态YPOINT1实施2:' && gv_po1.
ENDENHANCEMENT.
*$*$-End:   YPOINT1-----------------------------------------------------------------------------$*$*

SKIP.
" 动态增强点
ENHANCEMENT-POINT YPOINT2 SPOTS YSPOTS1 .
*$*$-Start: YPOINT2-----------------------------------------------------------------------------$*$*
ENHANCEMENT 2  YEH001.    "active version
  write: / '增强点2-YPOINT2实施,获取YPOINT1中的变量:' && gv_po1.
  data: gv_po2(10) VALUE 'Test2'.
  write: / '增强点2-YPOINT2实施:' && gv_po2.
ENDENHANCEMENT.
*$*$-End:   YPOINT2-----------------------------------------------------------------------------$*$*

SKIP.
" 静态增强段(数据能重定义)
ENHANCEMENT-SECTION YSECTION1 SPOTS YSPOTS1 STATIC .
  DATA: gv_sec1(10) VALUE 'SEC1'.
  WRITE: / 'YSECTION1预留代码:' && gv_sec1. " 实施后代码被替代
END-ENHANCEMENT-SECTION.
*$*$-Start: YSECTION1---------------------------------------------------------------------------$*$*
ENHANCEMENT 3  YEH001.    "active version
  DATA: gv_sec1 type d VALUE '20230517'.  " 变更数据定义
  WRITE: / '增强段1-静态YSECTION1实施:' && gv_sec1.
  write: / '增强段1-静态YSECTION1实施,获取YPOINT1中的变量:' && gv_po1.
ENDENHANCEMENT.
*$*$-End:   YSECTION1---------------------------------------------------------------------------$*$*

SKIP.
WRITE: / '主程序-获取YSECTION1中的变量:' && gv_sec1.
SKIP.

" 静态增强段(数据不能重定义)
ENHANCEMENT-SECTION YSECTION2 SPOTS YSPOTS1 .
  DATA: gv_sec2(10) VALUE 'SEC2'.               "此处变量在其定义后全局可用
  WRITE: / 'YSECTION2预留代码:' && gv_sec2.     " 实施后代码被替代,不再执行
END-ENHANCEMENT-SECTION.
*$*$-Start: YSECTION2---------------------------------------------------------------------------$*$*
ENHANCEMENT 4  YEH001.    "active version
  "DATA: gv_sec2(10) VALUE 'SEC2'.              "不能重定义
  "WRITE: / 'YSECTION2预留代码:' && gv_sec2.  "不能获取被替换代码中的变量
  write: / '增强段2-YSECTION2实施:不能重定义变量'.
  write: / '增强段2-YSECTION2实施,获取YPOINT2中的变量:' && gv_po2.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Enhancement Exit YSECTION2, Enhancement YEH001, End                                                                                               A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1  YEH003S.    "active version
*
  write: / '增强段2-YSECTION2实施,来自静态隐式增强'.
ENDENHANCEMENT.
*$*$-End:   (1)---------------------------------------------------------------------------------$*$*
ENDENHANCEMENT.
ENHANCEMENT 1  YEH002.    "active version
  WRITE: / '增强实施2 YEH002:不能获取被替代代码中的变量'. " 仅此第一个实施生效
ENDENHANCEMENT.
*$*$-End:   YSECTION2---------------------------------------------------------------------------$*$*

SKIP.
WRITE: / '主程序-获取YSECTION2中的变量:' && gv_sec2.     "可以获取

SKIP.
WRITE: / 'END,来自主程序'.

6. Enhancement options and enhancement implementation relationship

An enhancement point can have multiple enhancement implementation codes, sorted from top to bottom in the order of creation, and the same is true for the execution order;
an enhancement segment can have multiple enhancement implementations, sorted from top to bottom in the order of creation, but only the first one The implementation takes effect;
an enhancement implementation can span multiple enhancement points/sections. The code blocks are displayed in the order of implementation: ENHANCEMENT 1, 2, 3,..., they all belong to the same implementation and take effect at the same time. The code in them can have certain logic. coherence.

7. Enhance implementation suggestions

Related functions can be implemented in one implementation, and irrelevant functions are recommended to be implemented separately.

Original article, please indicate the source when reprinting - X-Files

Guess you like

Origin blog.csdn.net/XLevon/article/details/130743020