其他分享
首页 > 其他分享> > PA教材提纲 TAW12-2

PA教材提纲 TAW12-2

作者:互联网

Unit1 Adjustment of SAP Standard Software(SAP标准软件修改)

1.1 Adjusting SAP Standard Software(如何修改SAP标准软件)

SAP标准应用的修改可分为三个级别:

  1. Transaction Variants
  1. Modification Assistant
  2. User Exit
  1. ABAP Dictionary: Tables, Data Elements, Domains
  2. Customer Exits
  3. Business Transaction Events
  4. Business Add-Ins( Classic )
  5. Business Add-Ins( New )
  6. Explicit Enhancements: Points, Sections
  7. Implicit Enhancements

 

几种修改方式的区别:

(注意: Modification、Enhancement、Customer Development会修改代码,所以会使用ABAP Workbench。)

 

只在以下情况下使用修改( modification ):

 

定制配置( customizing )提供以下功能:

 

个性化( personalization )包括以下功能:

1.2 Describing Classic Enhancement Types(描述经典增强类型)

ABAP Workbench三级修改结构:

  1. Executed with the help of user exits
  2. 'Hard-coded' at various points within SAP Repository objects
  1. In ABAP programs by using program exits
  2. In a GUI status by using menu exits
  3. On screens, by using screen exits to insert a subscreen in an area that SAP provides
  4. In ABAP Dictionary tables or structures by using table enhancements

 

Table Enhancements(表增强,有两种技术):

 

Program Enhancements(程序增强,有四种技术):

 

Menu Enhancements(菜单增强,有两种技术):

(通过增强获取的菜单,其对应的指令以+开头。)

 

Screen Enhancements(屏幕增强,需要五步实施):

 

New Enhancement Options Offered Through the Enhancement Framework as of SAP NetWeaver 7.0(第四代增强):

 

Overview of Enhancement Options(隐式增强项概览,可以不通过修改实现以下目的):

 

Modification(修改):

Unit2 Enhancement of Dictionary Elements(字典元素增强)

2.1 Enhancement Tables Using Append Structures and Customizing Includes(用附加结构或定制Include增强表)

Options for Adding Extra Fields to SAP Tables(增加表字段的方法):

  1. 不需提前配置: Customers can create an append structure for an SAP table( without the need for SAP preparation )
  2. 多个结构用于同一个表: Multiple append structures can be used in a single SAP table
  3. 可以当普通结构用: Append structures can also be used like normal structures as types in programs
  1. 增强位置已预置: Customizing includes are already integrated into SAP tables by SAP
  2. 可增加字段: Customers add the desired additional fields to the Customizing include
  3. 配合其它增强一起使用: Customizing includes often go hand-in-hand with program exits and screen exits for the processing of any additional fields added

 

使用Append Structures注意事项:

 

使用Customizing Includes注意事项:

2.2 Enhancing Texts of Data Elements(增强数据元素的文本)

定义(用户定制标签或文档):Text enhancements comprise(包含) customer-specific field labels and customer documentation for SAP data elements.

 

用户可以重写字段标签( field label ),比如定义屏幕字段。但要注意,可重写的屏幕字段的Dict. Modified属性值必须为F,该属性的值列表如下:

Value

Function

SPACE

Field label that best fits the field length

1

Short field label

2

Medium field label

3

Long field label

4

Field label for header

V

Variable text transfer from the dictionary ( as SPACE )

F

Fixed ( no text transfer from the dictionary )

 

修改SAP字段标签的步骤:

  1. 事务代码CMOD->Goto->Text Enhancements->Keywords->Change
  2. 如果升级后field label被还原,那么进入CMOD->Goto->Text Enhancements->keywords->Restore
  3. 如果想还原所有field label,请选择Restore SAP Version(注意: 如果还原的字段有BUKRS、MANDT这样的重要字段central fields,请不要在它们被修改时还原)

 

用户可以重写数据元素( data element )的文档( documentation ):

 

创建定制文档的步骤:

  1. 事务代码CMOD->Goto->Text Enhancement->Data Elements->New DE Customer Document
  2. 如果选择Original text选项,则会在标准文档后追加定制文档
  3. 如果选择Template选项,则定制文档将覆盖标准文档

Unit3 Customer Exits(用户出口)

3.1 Describing Enhancement Projects(描述增强工程)

The characteristics of an application enhancement are as follows(增强的特性):

 

常用事务代码:

 

增强( Enhancements )、组件( Components )、出口( Exits )、工程( Projects )的映射关系:

 

创建增强( Enhancements )的步骤:

 

实现增强( Enhancements )的步骤:

  1. Run the transaction code CMOD to start the Project Management function
  2. Name your enhancement project
  3. Go to the project attributes and enter a short text that describes the enhancement project

3.2 Enhancing Programs Using Program Exits(通过程序出口增强程序)

程序出口: allows customers to implement additional logic in SAP standard applications.

程序出口( Program Exits )代码示例:

PROGRAM <program_name>

...

CALL CUSTOMER-FUNCTION '001'

EXPORTING

...

IMPORTING

... .

  1. 调用出口的关键字为CALL CUSTOMER-FUNCTION,出口函数的ID为三位数字
  2. 函数组(即每个Enhancement),名字必然以X开头
  3. 出口函数的名称格式为EXIT_<NAME_OF_CALLING_PROGRAM>_<NNN>

FUNCTION-POOL XAAA.

 

FUNCTION exit_<program_name>_001.

...

INCLUDE zxaaau01.

...

ENDFUNCTION.

 

寻找程序出口( Program Exits )的方法:

 

实现程序出口( Program Exits )的方法:

  1. Go to transaction CMOD.
  2. Create a Project.
  3. Assign an SAP Enhancement to your Project.
  4. From the initial screen of CMOD, select the Components radio button and then Change to navigate to the enhancement components.
  5. On the Components screen, there will be an entry for Function exit. Double-click the function module name listed next to it to navigate to the Function Builder, and go straight to the Source Code tab.
  6. Double-click the include program name, which is used in the source code.(如果出现警告信息,回车即可。)
  7. Enter the source code.

 

Normal Function Group Structure(普通函数组头文件结构):

SAPLABCD: Program name(注: 这里假设函数组名称为ABCD)

  1. LABCDTOP: Global data
  2. LABCDUXX: All function modules
    1.  
      1. LABCDU01: Function module #01
      2. LABCDU02: Function module #02
  3. LABCDF01: Subroutines

 

Exit Function Group(出口函数组头文件结构):

SAPLXAAA: Program name(注: 这里假设函数组名称为XAAA)

  1. LXAAATOP: Global data
    1. LXAAATAP: Global SAP data
    2. ZXAAATOP: Global customer data
  2. LXAAAUXX: All function modules
    1.  
      1. LXAAAU01: Function module #01

        (2.1.1) ZXAAAU01: Customer source code

      2. LXAAAU02: Function module #02

        (2.2.1) ZXAAAU02: Customer source code

  3. LXAAAF00: SAP source text proposal
  4. LXAAAF01: Subroutines
  5. LXAAAO01: PBO modules
  6. LXAAAI01: PAI modules
  7. LXAAAE01: ABAP events
  8. ZXAAAZZZ: Any other customer objects
    1.  
      1. ZXAAAF01: Subroutines
      2. ZXAAAO01: PBO modules
      3. ZXAAAI01: PAI modules
      4. ZXAAAE01: ABAP events

 

注意:

  1. 在ZXAAAU01中写CALL SCREEN 9000 STARTING AT 5 5.
  2. 在ZXAAAO01中写MODULE OUTPUT.
  3. 在ZXAAAI01中写MODULE INPUT.

3.3 Enhancing Menus Using Menu Exits(用菜单出口增强菜单)

菜单出口: allow you to attach additional custom functions to menu options in SAP menus.

 

响应增强菜单的代码示例:

PROGRAM <program_name>.

DATA ok_code LIKE sy-ucomm.

 

*PAI-Module

CASE ok_code.

WHEN 'DISP'.

WHEN '+ABC'.

CALL CUSTOMER-FUNCTION '001'

EXPORTING

<i_variables>

IMPORTING

<e_variables>.

ENDCASE.

 

实现菜单增强的方法:

3.4 Enhancing Screens Using Screen Exits(通过屏幕出口增强屏幕)

屏幕出口: allow you to use reserved sections of a main screen ( which a technically subscreen areas ) to display additional information or allow the user to enter additional data.

 

普通子屏幕的注意事项:

 

调用普通子屏幕与出口子屏幕代码对比:

普通子屏幕

出口子屏幕

PBO:

PROCESS BEFORE OUTPUT.

MODULE ... .

CALL SUBSCREEN <SUBSCREEN_AREA >

INCLUDING <PRG> <DYNPRO_NO>.

MODULE ... .

PBO:

PROCESS BEFORE OUTPUT.

MODULE ... .

CALL CUSTOMER-SUBSCREEN <SUBSCREEN_AREA>

INCLUDING <PRG> <DYNPRO_NO>.

MODULE ... .

PAI:

PROCESS AFTER INPUT.

MODULE ... .

CALL SUBSCREEN <SUBSCREEN_AREA>.

MODULE user_command_<SCREEN_NO>.

PAI:

PROCESS AFTER INPUT.

MODULE ... .

CALL CUSTOMER-SUBSCREEN <SUBSCREEN_AREA>.

MODULE ... .

  1. 增强函数组的函数不能访问主调程序的全局变量,需要借助程序出口函数获取主屏幕的参数并传给函数组头文件的全局变量,这个函数需要在主调程序的PBO中被CALL
  2. 同样,如果要把出口子屏幕的值传回主调函数,需要另一个程序出口函数,这个函数需要在主调程序的PAI中被CALL
  3. 注意: 传入参数类型若与屏幕字段类型不匹配,则会读不到值,最好通过DDIC或Program导入字段,这样可以确保字段类型匹配

 

实施屏幕出口的过程:

  1. 进入Project Management(事务代码CMOD),在components界面可看到如下信息:
    1. The name of the calling program(主调程序)
    2. The four-digit screen number for the main screen(4位主屏幕编号)
    3. The name of the subscreen area(子屏幕区域名称,跟着函数组程序名、子屏幕编号)
  2. 进入components界面,创建子屏幕

Unit4 Classic Business Add-Ins(经典BAdI)

4.1 Describing an ABAP Objects Interface(描述ABAP对象的接口)

Business Add-Ins: are an object-oriented enhancement technique.

(其它类与接口知识点请参考前面的资料。第100页特别提到,接口不能通过CREATE OBJECT实例化。)

4.2 Describing Classic Business Add-Ins ( BAdIs )(描述经典BAdI)

经典BAdI: 需要至少一个接口( interface )以及一个BAdI adapter class实现接口。

 

The BAdI components are as follows(BAdI的组建包括):

 

The components that must be created when a BAdI is defined are as follows(定义BAdI时需定义的组件):

  1. Filtering: If implementations are created for a filter-dependent BAdI, the BAdI adapter class ensures that only the relevant implementations are called
  2. Control: The BAdI adaptor class calls the active implementations

 

代码示例:

REPORT <sap_program>.

DATA r_var TYPE REF TO <badi-interface>.

CALL METHOD cl_exithandler=>get_instance

CHANGING

Instance = r_var.

 

CALL METHOD r_var->meth_abc

EXPORTING

<i_variables>

IMPORTING

<e_variables>.

  1. Generate class会获取继承接口的类对象
  2. 然后类对象调用接口方法

 

搜索BAdI的方法:

  1. 在主程序搜索CL_EXITHANDLER字符串,找到BAdI定义后,可查看其documentation或实例
  2. 进入Repository Information System(事务代码SE84),选择Enhancements->Business Add-Ins搜索需要的程序
  3. 通过其它Customizing component进行关联搜索

4.3 Explaining Additional Details of Business Add-Ins ( BAdIs )(解释BAdI的细节)

Extendable Filter Types: Filter根据条件进入不同的实例,某些Filter允许增强。可增强的Filter有'Enhanceable'标志,它们可以使用域的value table以外的值进行过滤。

 

可增强Filter使用较为苛刻:

 

实现filter-dependent BAdI的过程:

  1. Create an implementation by referring to the corresponding Business Add-In definition.
  2. Assign a filter value for the implementation, or choose F4 and select a value from the list of possible entries displayed ( It is possible to define multiple filter values for each implementation ).
  3. Implement the BAdI method ( or methods ) as usual
  4. Activate your implementations

 

定义默认和样本代码( Default and Sample Code ):

  1. 查看默认实例的路径为Goto->Default Code
  2. 系统自动预创建了默认实例的类,用户可以实现类的方法,自定义默认行为
  1. 查看样本实例的路径为Goto->Sample Code
  2. 用户创建实例时可以查看并使用样本代码作为模板

 

Exits、BTE、BAdI性能对比:

 

Customer Exits

Business Transaction Events

Business Add-Ins

Program Exit

YES

YES

YES

Menu Exit

YES

NO

YES

Screen Exit

YES

NO

YES

Append Fields on Screens

YES

NO

YES

Administration Level

YES

NO

YES

Multiple Implementations

NO

YES

YES

Filters

NO

YES

YES

 

Naming Conventions(命名规则):

Unit5 New Business Add-Ins(新BAdI)

5.1 Describing the Change from Classic BAdIs to New BAdIs(描述经典BAdI到新BAdI的变化)

Why SAP Introduced New BAdI Technology(引入新BAdI的原因):

  1. Enhanced filter concept
  2. Option to inherit attributes from sample implementation classes ( selective method redefinition )

 

SAP NetWeaver 7.0 Enhancement Framework(7.0版本增强架构):

  1. Implicit enhancement points/options
  1. Explicit enhancement points/options
  2. New BAdIs

(总之,记住一句话: Unlike classic BAdIs, new BAdIs always belong to, and are managed by, enhancement spots.)

 

Classic BAdIs和New BAdIs的对比:

Classic BAdIs:

DATA r_exit TYPE REF TO <BAdI interface>.

 

CALL METHOD cl_exithandler=>get_instance

CHANGING

Instance = r_exit.

 

CALL METHOD r_exit->abc

EXPORTING

...

IMPORTING

... .

New BAdIs:

DATA r_exit TYPE REF TO <BAdI name>.

 

TRY.

GET BADI r_exit.

CATCH cx_badi_not_implemented. "若未找到实例则报此错

...

ENDTRY.

 

TRY.

CALL BADI r_exit->abc.

CATCH cx_badi_initial_reference. "若r_exit为空则报此错

...

ENDTRY.

Classic BAdIs到New BAdIs的转变目的如下:

  • BAdI performance is considerably enhanced by integrating BAdIs in the ABAP programming language through the new language elements GET BADI and CALL BADI.(新BAdI的关键字性能更好)
  • New BAdIs provide considerably more flexibility in the conversion of predefined enhancement options through new properties, such as contexts and more filtering options than BAdIs.(新BAdI支持context和更强的filter)

 

5.2 Using New Business Add-In ( BAdI ) Program Exits(使用新BAdI)

常用事务代码:

 

New BAdI与Classic BAdI的区别:

 

搜索新BAdI出口的方法:

  1. Perform a global search in the program you wish to enhance for GET BADI or CALL BADI(搜索关键字字符串)
  2. Double-click the reference variable used in the GET BADI or CALL BADI statement to navigate to the variable definition(双击引用类型找到BAdI定义)
  3. Double-click the BAdI name to navigate to the display for the corresponding enhancement spot(双击BAdI名称找到enhancement spot)

(另一种方法是在GET BADI处打断点,然后根据引用的类型获取BAdI的名称。)

 

两种特殊的BAdI implementation:

它们的运行原则如下:

 

实现New BAdI的方法:

  1. Display the corresponding enhancement spot
  2. Choose Implement Enhancement Spot and create the enhancement implementation.
  3. Specify a name for the enhancement implementation, the BAdI implementation, and the Implementing Class. ( If there is a Sample Class for the BAdI, you can choose to inherit from it or copy it. )
  4. In the Navigation area for the BAdI, double-click the implementing class, then, double-click the method or methods to implement or adjust them
  5. Activate the method and all other related objects, including the enhancement implementation

 

Filter-dependent BAdIs now allow the following(目前带过滤的BAdI允许以下功能):

5.3 Using New Business Add-In ( BAdI ) Menu Exits(使用新BAdI菜单增强)

BAdI菜单增强( BAdI Menu Exits ): provide customers with the option to implement additional menu entries on SAP screens, which trigger custom code.

 

代码示例:

DATA r_exit TYPE REF TO <BAdI name>.

 

TRY.

GET BADI r_exit.

CATCH cx_badi_not_implemented.

ENDTRY.

 

*PAI module

CASE ok_code.

WHEN 'DISP'. ...

WHEN 'EDIT'. ...

WHEN '+XXX'.

TRY.

CALL BADI r_exit->abc.

CATCH cx_badi_initial_reference.

ENDTRY.

ENDCASE.

 

5.4 Using New Business Add-In (BAdI) Screen Exits(使用新BAdI屏幕增强)

BAdI屏幕增强( BAdI Screen Exits ): provide customers with the option to display addtional fields or other screen elements on an SAP screen.

 

示例代码:

*PBO of the SAP container screen

GET BADI r_exit.

CALL BADI r_exit->put_data.

CALL METHOD cl_enh_badi_runtime_functions=>get_prog_and_dynp_for_subscr.

CALL SUBSCREEN ... INCLUDING ... .

 

*PAI of the SAP container screen

CALL SUBSCREEN ... .

CALL BADI r_exit->get_data.

 

搜索和使用BAdI屏幕增强的步骤:

  1. On the SAP standard screen, search for a subscreen area ( optional pre-search )(在被增强屏幕上搜索子屏幕区域)
  2. In the SAP standard program, search for the GET BADI command(用户也可以搜索GET_PROG_AND_DYNP_FOR_SUCSCR或CL_ENH_BADI_RUNTIME_FUNCTIONS)(搜索关键字)
  3. Double-click the reference variable used in the GET BADI statement to navigate to the definition of the reference variable(双击引用类型,查看BAdI定义)
  4. To navigate to the enhancement spot to which the BAdI belongs, double-click the BAdI used to type the reference variable(找到enhancement spot以及引用使用的BAdI)
  5. Read the BAdI documentation and perform the subsequent steps for the BAdI implementation(阅读说明文档)
  6. Create the function group, including the subscreen, the TABLES structure ( in the TOP include ), and the corresponding function modules(创建函数组,包括子屏幕和全局变量,以及逻辑函数)
  7. Create an implementation for the enhancement spot and for the BAdI(创建enhancement implementation)
  8. In the BAdI implementation, implement the available program exits ( the PUT and GET methods )(实现PUT和GET函数)
  9. In the BAdI implementation, double-click the available screen exit to implement it(实现屏幕出口)
  10. Specify the subscreen and the master program of the function group ( the name of the master program is the name of the function group with the prefix SAPL )(填写子屏幕名称和函数组主程序名称)
  11. Activate all objects(激活)

5.5 Using New Business Add-Ins ( BAdIs )(使用新BAdI)

定义和使用新BAdI的步骤:

  1. 进入BAdI Builder(事务代码SE18,或路径Tools->ABAP Workbench->Utilities->Business Add-Ins->Definition)
  2. 创建enhancement spot,再创建New BAdI
  3. 在New BAdI界面,点击Interface,定义接口名称、接口方法、方法参数
  4. 激活接口,再激活enhancement spot
  5. 在被增强程序中定义增强点( jump-points ),即跟GET BADI、CALL BADI有关的语句
  6. 如果有filter、菜单增强、屏幕增强,则需要额外的配置
    1. Filter需要定义名称和数据类型
    2. 如果包含菜单增强,则不可定义filter,也不可设置为multiple use,也不能用在switch语句中,但可以包含独立于菜单增强的方法
    3. 如果包含屏幕增强,则必须定义Instance Creation Mode为Reusing Instantiation,且不可设置为multiple use,但可以包含填写屏幕字段或计算屏幕字段的方法
    4. Instance Create Mode会影响GET BADI语句的性能,如果值为Newly Creating Instantiation,则每个BAdI handler都会创建自己的实例;如果值为Reusing Instantiation,则同一个internal session的BAdI handler会复用实例;如果值为Context-Specific Instantiation,则同一个internal session中Context值相同的BAdI handler会共用同一个plug-in object单件(只对context-dependent BAdI有效)
    5. 对于context-dependent BAdI,必须定义Context class,该类必须包含IF_BADI_CONTEXT接口
  7. 定义fallback BAdI implementation class(可选)

 

代码示例:

*Call in Program

DATA: badi_ref TYPE REF TO badi_name.

GET BADI badi_ref.

CALL BADI badi_ref->meth.

*BAdI with Filter

DATA: badi_ref TYPE REF TO badi_name.

GET BADI badi_ref

FILTERS

<filter> = <filter_value>.

CALL BADI badi_ref->meth.

*BAdI with Context

DATA: bd TYPE REF TO badi_ctx_badi,

ctx TYPE REF TO cl_badi_report_context. "指向当前程序特有的context class实例

ctx = cl_badi_report=>get_instance( repid = sy-repid ). "绑定plug-in和context class实例

GET BADI bd CONTEXT ctx.

CALL BADI bd->meth.

 

Unit6 Explicit Enhancement Options(显式增强)

6.1 Describing the Enhancement Framework(描述增强架构)

(SAP增强的总架构请参考1.1节的内容。Enhancement Spot与Explicit Enhancement、Implicit Enhancement的关系,请参考5.1节内容。)

 

Composite Enhancement Spot: 复合增强Spot,可以包含其它复合增强点或普通增强点

Simple Enhancement Spot: 普通增强Spot,可以包含Explicit Enhancement Points、Explicit Enhancement Sections、BAdIs(New BAdI需要Enhancement Spot的管理,所以New BAdI可以视为特殊的Explicit Enhancement)。

Enhancement Implementation: 增强实现,每个Enhancement Spot可以创建多个对应的Enhancement Implementations,每个实现可以用于实现增强点下的所有组件(用户可以为复合增强Spot创建复合实现,但是这不是必须的)。

 

To Search for an Enhancement Spot(搜索增强Spot的步骤):

  1. Start the Repository Information System ( transaction SE18 ).
  2. Choose Enhancements->Enhancement Spots.
  3. Specify the search criteria ( package or application component ) for the enhancement spots you are looking for and execute to display a list of results.
  4. Pick one of the results to display ( from the list of enhancement points and sections ).
  5. On the Enhancement Implementations tab pages, you can see any existing enhancement implementations of the spot. Choose the enhancement implementation that you want to display.
  6. The result shows all enhancement implementation elements related to the enhancement implementation name.
  7. Choose Source to see the implementation code at the bottom of the screen. Choose Editor to display the source code of the enhancement in-place in the program.

(另一个用户查看增强点和增强实现的工具是Enhancement Browser,事务代码SPAU_ENH。)

6.2 Using Explicit Enhancements(使用显式增强)

Explicit enhancement points are provided by SAP and allow you to enhance SAP source code by inserting your own logic, without making modifications.

 

Explicit enhancement section is an option provided by SAP that allow you to replace an SAP source code section without making modifications.

 

注意事项:

 

Define your own Explicit Enhancements(定义显式增强的步骤):

  1. Switch to Change mode(进入编辑模式);
  2. Use the menu Enhancement Operations->Create Option to create your own explicit enhancement(创建显式增强);
    1. 如果在增强(Enhancement Points或Enhancement Sections)增加STATIC关键字,那么该增强将用于变量声明( data declarations ),如果没有该关键字,则该增强将用于逻辑代码;
    2. 如果在增强(Enhancement Points或Enhancement Sections)增加INCLUDE BOUND关键字,则该增强的代码会在所有调用它的编译对象( compilation unit )中执行link动作(一般头文件才这样做,因为头文件会被多个主程序调用),如果没有该关键字,则增强中的代码只在本程序执行(在未指定编译对象时,用户需要从列表中手动选择编译对象)。头文件中INCLUDE BOUND增强和普通增强不能并存,若头文件被同一个主程序调用多次,则只能包含INCLUDE BOUND增强;
  3. Create an enhancement implementation(创建增强实现)
    1. Display the SAP object ( program, function module, method )(显示SAP对象)
    2. Search for the required enhancement point or section(搜索增强点和增强区)
    3. Choose Enhance(选择Enhance图标,是一个螺旋图标)
    4. Position your cursor on the enhancement spot that you want to create the implementation for, then choose Create Enhancement Implementation(选中增强点,创建增强实现)
    5. Specify the name of the enhancement implementation ( comply with customer namespace Y* or Z* )(命名增强实现)
    6. Enter the source code between ENHANCEMENT ... ENDENHANCEMENT.(增加逻辑代码)
    7. Choose Activate Enhancements(激活)

 

Risks of Multiple Implementations of Explicit Enhancement Sections(增强区有多个实现时的风险):

 

Risks of Multiple Implementation for Explicit Enhancement Points(增强点有多个实现时的风险):

Unit7 Implicit Enhancements(隐式增强)

7.1 Explaining Implicit Enhancements(解释隐式增强)

Implicit Enhancement Points: provide you with the option to insert additional source code at certain points in SAP programs, function modules, and methods, without making modifications and without explicit preparation by SAP developers.(隐式增强不需要修改或预准备工作)

 

SAP provides options to create the following without making modifications(使用隐式增强可实现下述功能):

7.2 Implementing Implicit Enhancements in Function Modules(在函数模块中实现隐式增强)

The following implicit enhancements are available for SAP function modules(隐式增强可以为函数模块提供以下功能):

  1. The parameters can be IMPORTING, EXPORTING, CHANGING, or TABLES parameters, but additional EXCEPTIONS cannot be defined.
  2. To use the implicit enhancement option to create additional parameters for an SAP function module, it is necessary to switch to Enhancement mode. This is done by using the usual button on the toolbar, and you will then be asked to create an enhancement implementation. Once this has been done, you will be able to define the new parameters with a suitable type under the appropriate tab page in the Function Builder.
  3. Once you have activated the enhancement implementation, its name will be display against each of the new parameters, so that it is easy to distinguish between standard parameters and parameters created using an enhancement.
  4. 若我们使用pattern插入FM,则增强的参数也会被带出,且它们必须为optional
  1. To do this, under the Source Code tab, in enhancement mode, it is necessary to use the appropriate menu entry to show where the available implicit enhancement points are located. ( This will be at the beginning and end of the function module. )
  2. 增加逻辑往往配合增加参数一起使用

(详细步骤请参考204页,Unit7 Solution10。)

7.3 Implementing Implicit Enhancements in Global SAP Classes(在全局类实现隐式增强)

Implicit Enhancement Points and Options in SAP Classes(SAP类中的隐式增强点/项):

  1. Adding optional parameters ( importing, exporting, changing but no returning parameters and exceptions ) to method interfaces
  2. Defining additional attributes and methods ( public, protected, private )
  3. Defining a pre-method or a post-method for an SAP method ( alternatively, defining an overwrite method )
  1. Adding additional logic ( possibly using additional interface parameters, methods, or attributes )
  2. Implementing additional methods

 

在全局类增加属性和方法的步骤如下:

  1. Display the class in the Class Builder
  2. Choose Class->Enhance and create an enhancement implementation
  3. Define new attributes ( must always be optional ) , new methods, and new parameters for existing methods
  4. To branch to the method editor so you can add the code, double-click the name of any additional methods you have created
  5. Choose Activate Enhancements

 

Pre-Methods, Post-Methods, and Overwrite Methods(预处理方法、后续处理方法、重写方法):

  1. IPR_<enhancement_name> for pre-methods
  2. IPO_<enhancement_name> for post-methods
  3. IOW_<enhancement_name> for overwrite methods

 

Restrictions of Pre-, Post-, and Overwrite Methods(预处理方法、后续处理方法、重写方法使用限制):

(注意: 主要有两点,EXPORT和RETURNING参数变成CHANGING参数,重写时signature不能改变)

 

定义预处理方法、后续处理方法、重写方法:

  1. Display the class in the Class Builder.
  2. Choose Class->Enhance to create an enhancement implementation.
  3. Use the cursor to mark the required SAP method.
  4. Choose Edit->Enhancement Operations and choose Insert Pre-Method, Insert Post-Method, or Add Overwrite Method.
  5. Choose the button in the Pre-/Post-/Overwrite-Exit column to implement the corresponding method. To access components of the global class in the method, you have to use the reference variable core_object, which is filled in the local constructor.
  6. Save the method.
  7. Choose the Activate Enhancements button.

(详细步骤请参考214页Unit7 Solution11。)

 

通过隐式增强实现预处理、后续处理的优点:

7.4 Using Other Implicit Enhancements(使用其它隐式增强)

Local SAP Class: Implicit Enhancements Options and Points(本地类隐式增强项/点):

  1. Adding optional parameters ( importing, exporting, and changing, but no returning parameters and exceptions ) to method interfaces
  2. Defining additional attributes and methods ( public, protected, and private )
  1. At the beginning and end of methods to add logic ( possibly using additional interface parameters, attributes, or methods )
  2. At the end of the IMPLEMENTATION block ( to implement any additional methods )

(注意: 本地类要使用隐式增强,需建立enhancement implementation。)

 

To Enhance a Local SAP Class(增强本地类的步骤):

  1. Display the source code of the local class
  2. Choose Enhance(为一螺旋状图标)
  3. Choose Edit->Enhancement Operations->Show Implicit Enhancement Options to show the implicit enhancement options
  4. In the editor, use the context menu of one of the implicit enhancement options or displayed points to create an enhancement implementation
  5. Insert the source code
  6. Choose Activate Enhancement

(详细步骤请参考224页Unit7 Solution12。)

 

Other Enhancement Points(其它隐式增强点):

(但SAP Basis Object没有隐式增强点。)

(注意: 增强structure时,需要用DATA关键字定义额外字段,否则会报错。)

 

升级的影响: 尽管隐式增强没有修改标准代码,但是升级后依然需要手动调整。后面的Adjustment of Enhancement Implementation章节会有介绍。

 

To Use Other Implicit Enhancement Points(使用其它隐式增强的步骤):

  1. Display the source code of the corresponding SAP object.
  2. Choose the Enhance.(一个螺旋状图标)
  3. Choose Edit->Enhancement Operations->Show Implicit Enhancement Options.
  4. In the editor, use the context menu of one of the implicit enhancement points displayed to create an enhancement implementation.
  5. Insert the source code.
  6. Choose the Activate Enhancement pushbutton.

 

已有增强的实施( Enhancement Implementations )中也有隐式增强:

路径为Edit->Enhancement Operations->Show Implicit Enhancement Options

在ENHANCEMENT <num> <name>. ... ENDENHANCEMENT.的开头和结束位置就能看到隐式增强点。

7.5 Using Composite Enhancements(使用复合增强)

Enhancement Spots: are Repository objects that contain one or more enhancements ( either explicit enhancements or new BAdIs ).

Composite Enhancement Spots: are used to semantically group simple enhancement spots. They contain one or more simple enhancement spots or one or more composite enhancement spots of the relevant type as described in the figure. ( Composite Enhancement Spots are therefore used to combine simple enhancement spots into meaningful units. )

Enhancement Implementations: are repository objects that serve as containers for enhancement implementation elements.

Simple Enhancement Implementation: can contain one or more enhancement implementation elements, which relate to elements of the same enhancement spot.

New Enhancement Implementation: for something that belongs to a different enhancement spot, or implementation for an implicit enhancement.

Composite Enhancement Implementation: are used for the semantic grouping of simple enhancement implementations. ( either one or more simple enhancement implementations or one or more composite enhancement implementations of the relevant type )

 

注意:

Composite Enhancement Implementation和Composite Enhancement Spots并没有必然联系,一个Composite Enhancement Spot可以包含多个Simple Enhancement Implementations,一个Simple Enhancement Spot也可以包含多个Composite Enhancement Implementations。

Unit8 Modifications of the SAP Standard Application(修改SAP标准应用)

8.1 Modifying SAP Standard Software(修改SAP标准软件)

A repository object is original in only one system. In the case of objects delivered by SAP, the original system belongs to SAP. In customer systems, these objects are only available as copies. This applies to your development system and all other systems that follow on from it.(SAP架构中,原始版本SAP对象只存在于SAP公司,用户系统使用的是复制版SAP对象。)

 

If you create your own applications and repository objects, the objects that you create are original in your development system. You assign your developments to a change request of the type Development/Correction. When released, this change request can be used to transport objects from the development system to subsequent systems.(如果开发机创建原始版本Customer对象,则生成修改请求,然后从开发机传往下游系统。)

 

Correction and Repairs(更正与修正):

总之,不管是SAP对象还是用户对象,修改原始版本的为correction,修改复制版本的为repair,而修改SAP对象还可称为modification。

 

Modification and Upgrades(修改与升级):

 

SSCR ( SAP Software Change Registration ): The developer who will change the SAP standard objects must register those changes using SAP Software Change Registration ( SSCR ).(注册一次之后,后续修改就不用再注册了。

Benefits of SSCR:

If you want to change an SAP repository object, you must provide:

(版本控制逻辑如下,以前传入的版本为Full version,当修改后的版本传入后,新的版本为Full version,但是系统的version database会保存新版本和旧版本的区别,作为备份backward delta。Modification Adjustment就是利用这个。)

 

Critical Success Factors for Modifications(修改成功的注意事项):

 

日志基本内容:

8.2 Modifying Applications Using the Modification Assistant(用修改助手修改应用)

老版修改助手( Modification Assistant )和新版修改助手的区别:

THEN

NOW

Granularity(颗粒度): Include program

Modification adjustment: Line by line

Each modification had to be included in the new SAP version manually ( cut and paste )

Granularity: Module ( for example, subroutine )

Modification adjustment: At module level

 

Tools Supported(可使用工具):

Tool

Use of Modification Assistant

ABAP Editor

Modification mode

Screen Painter

Layout, Flow logic

Menu Painter

 

Text Elements

 

Class Builder

 

Function Builder

Adding function modules, Compatible interface enhancements

ABAP Dictionary

Append structures are registered, Data elements: field labels can be changed

Documentation

Substituting documentation objects

 

修改SAP对象需要提交:

 

Modification Assistant Functions(修改助手提供的功能):

 

Modification Browser(修改浏览器,事务代码SE95): 提供了所有被修改的对象,并将使用修改助手和不使用修改助手的修改区分开。其树状图的两层分别提供下述信息:

8.3 Implementing User Exits(实现使用者出口)

使用者出口( User Exits ):

 

使用者出口代码示例:

*Includes

PERFORM userexit_abc.

PERFORM userexit_xyz.

 

*Include MV45AFZB

FORM userexit_abc.

ENDFORM.

 

FORM userexit_xyz.

ENDFORM.

  1. Blank Subprograms(空白子程序)
  2. Includes delivered only once(Includes文件只传输一次)
  3. Mainly in SD(主要分布在SD模块,即sales and distribution分销发运模块)
  4. Technically: Modification(技术上属于修改)
  5. 子例程名称规则为USEREXIT_<NAME>
  6. 这些Include programs不会被系统修改,如果有新版本需要增加出口,则会增加新的头文件
  7. 头文件名称与主程序名称有对应关系,比如主程序为SAPMV45A,则Include文件名称为MV45AFZB
  8. 使用User Exit可以避免Modification并保证升级顺利( smooth upgrades )

 

搜索使用者出口( User Exit )的方法:

  1. System->Status, Double-click Program Name
  2. Search by Character String, Perform Userexit, Global in Program
  3. Double-click to navigate to the subprogram and Read the inline documentation
  1. S&D->System adjustment->User Exits

8.4 Adjusting Modifications(调整修改)

最初SAP系统有工具检查升级后增加了哪些对象,后来该工具演化出调整工具。当SAP升级( upgrade )或打补丁( Support Package )时,我们需要检查新增和修改的对象,并进行调整。(升级的事务代码为SPAM)

 

两种调整工具:

  1. Domains
  2. Data elements
  3. Tables ( this includes structures, transparent tables, pooled, and cluster tables, together with their technical settings )
  1. ABAP Programs
  2. Interfaces ( menus )
  3. Screens
  4. Search Helps
  5. Views
  6. Lock Objects

 

不需要使用SPDD的情况:

 

每次升级( Update/Upgrade )后,用户有14天的时间可以不借助SSCR Key使用SPAU,且只能在开发机使用。SPAU可以检查用户修改的对象,以及版本升级修改的对象,调整修改( Adjusting Modifications )可以把修改传入升级后的系统。

 

调整的传输过程: 用户在开发机进行调整,系统将为SPDD调整和SPAU调整分别创建transport requests,然后传入下游的SAP系统。

 

调整时几种图标的含义:

Unit9 Introduction to Web Dynpro(Web Dynpro介绍)

9.1 Outlining the Benefits of Web Dynpro(概括Web Dynpro的优点)

A Web Dynpro application is developed using a declarative programming approach(申明式开发).

 

A Web Dynpro ABAP application can address all kinds of reuse components directly(可复用组件):

 

Benefits of Web Dynpro(优点):

 

Web Dynpro设计理念:

9.2 Displaying Web Dynpro Component Architecture(显示Web Dynpro组件架构)

Web Dynpro Components: are containers for other entities related to a UI and Web Dynpro Program.

View: is the rectangular part of a page displayed by the client, the view contains UI elements, such as input fields and buttons.

Window: contains views and flow between views.(注意: Window可以包含多个View,View也可以用于多个Window。)

Web Dynpro Controllers: contains Web Dynpro Source Code.

Controller Attributes: Global Variables.

Context: Global Data related to the UI which are stored in a hierarchical storage area.

 

Web Dynpro components can be addressed in the following ways(访问Web Dynpro components的方法):

 

Context and Data Binding(上下文与数据绑定):

Mapping的使用规则:

Data Binding的使用限制:

Data Binding时Web Dynpro Framework执行的动作:

9.3 Navigating Between Views(视图间的跳转)

Outbound Plugs(出站接头): 触发视图间跳转( navigation )的控件,该控件以触发动作命名而非以视图名称命名。

Navigation Events(跳转事件): 出站接头抛出( raises )的异步事件( asynchronous events )。

Navigation Queue(跳转队列): 存放跳转事件的数据结构,一个视图可以有多个出站接头指向不同的界面( UI )。

Navigation Stack(跳转栈): 存放跳转队列的内存区,有新的出站接头活动时,该内存扩展,所有跳转执行完毕时,该内存区释放。

Inbound Plugs(入站接头):接收跳转的控件,拥有特殊的event handler,该控件以视图命名。出站接头和event handler可以用于传递视图输入的参数。

Navigation Links(跳转链接): 每个出站接头需要指向一个入站接头,以确定跳转顺序,该链接定义在Window中。

Action(动作): 动作可以连接event handler method(在View Controller中)和client-side event

(详细操作步骤请参考315页,Unit9 Solution18。)

9.4 Creating View Assemblies(创建嵌套视图)

Windows and Views(窗口与视图):

 

When you create a window, remember the following points(创建窗口的注意事项):

注意:

 

View Assembly(嵌套视图):

  1. 出站接头( Outbound plugs )触发容器( view container area )显示特定视图的工作
  2. 所有候选的视图都需要嵌套在容器中,用户通过跳转链接决定显示哪个视图
  3. 任意时刻,可见视图的组合( subset of views visible )被称为嵌套视图( a view assembly )
  4. 跳转可用于更换容器里的视图,也可用于更换窗口中的视图组合( view combinations )

 

(详细操作步骤请参考324页,Unit9 Solution19。)

9.5 Indentifying Web Dynpro Entities and Relationships(识别Web Dynpro实体与关系)

SAP's Web Dynpro is built on the foundation of the MVC design paradigm(SAP Web Dynpro基于MVC范型。).

The architecture of a Web Dynpro component can be divided into two parts - external and internal visibility.(Web Dynpro组件可分为外部可见型和内部可见型。)

The internally visible parts can be further divided into visual entities and programming entities.(内部可见型组件可分为可视化实体和编程实体。注: 可视化实体与UI关联。)

The internally visible entities consist of windows and views.(可视化实体可分为窗口和视图。)

A view consists of a view layout and the corresponding view controller. The view controller can contain navigation plugs, methods, and a context.(视图可分为视图显示属性和视图控制器,视图控制器包括跳转接头、方法和上下文。)

A window embeds one or more views and has a corresponding window controller. A window controller can contain navigation plugs, methods, and a context.(窗口包含了一组视图和窗口控制器,窗口控制器包括跳转接头、方法和上下文。)

 

MVC架构:

 

窗口和视图的跳转规则:

 

组件控制器( component controllers )的知识点:

 

用户控制器( custom controllers )的知识点:

 

接口控制器( interface controllers )的知识点:

  1. 如果一个Web Dynpro组件访问另一个Web Dynpro组件,则访问者为父组件,被访问者为子组件
  2. 父组件需要申明对子组件的访问,此时子组件会创建组件使用实例( component usage instance ),父组件会通过自己组件接口控制器( component interface controller )访问子组件的实例
  1. Interface controller: All Web Dynpro components have only interface controller. Through the interface controller, data, methods, and event handlers can be made accessible to other components.(一个Web Dynpro结构最多只有一个接口控制器)
  2. Interface views: Interface views represent the visual interface of a Web Dynpro component. There is a one-to-one relationship between a window and an interface view.(每个窗口有且只有一个接口视图)

 

Web Dynpro Application知识点:

 

To define a Web Dynpro application, specify the following elements(定义Web Dynpro Application需要设置如下元素):

  1. DEFAULT: 即根据GUIDELINE设置的值选择主题
  2. SAP_BLUECRYSTAL: GUIDELINE值为FIORI时的主题(该主题只支持RENDERING值为STANDARD)
  3. CORBU: GUIDELINE值为GL11或GL20时的主题(例如: 设置参数WDTHEMEROOT = SAP_CORBU)

Unit10 Web Dynpro Controllers(Web Dynpro控制器)

10.1 Outlining Controller Types and Entities(描绘控制器的类型和实体)

Types of Components in a Web Dynpro Component:

Controller Types

Description

Component controller

There is only one component controller in each Web Dynpro component. This is a global controller, visible to all other controllers.

Custom controllers

Custom controllers are optional. They are defined at design time and can be used to encapsulate subfunctions of the component controller. The coding in a custom controller should not depend on the existence of any other custom controller.

Configuration controllers

This is a special custom controller. It is only necessary if the corresponding component implements special configuration and personalization functions. Only one configuration controller may exist in any component.

View controllers

Each view consists of the layout part and one view controller. This controller handles the view-specific flow logic.

Windows controllers

Each window has exactly one window controller. You can use this controller to handle the data passed through the inbound plugs when it is reused as a child controller.

 

(Interface controller用于对外,所以此处未列出)

 

其它跟controller有关的知识点:

 

The following list describes the lifetimes of the different controller instances, depending on the controller type(不同控制器的生命周期):

 

Common Controller Entities(通用控制器实体):

  1. 所有控制器都有两个基本的引导方法,即创建实例的方法wddoinit(),和删除实例的方法wddoexit()。
  2. 每个控制器实例的生命周期( lifetime )中,这些引导方法只执行一次。
  1. 有两个预定义属性,即自指针WD_THIS,上下文WD_CONTEXT
  2. 控制器的所有方法都可以调用这些属性

 

Implications of one Controller C1 Using another Controller C2(控制器C1使用控制器C2时可以执行的动作):

 

Special Entities of Component/Custom Controllers(组件控制器与用户控制器的特殊实体):

 

Special Entities of View Controllers(视图控制器的特殊实体):

  1. 跳转事件( navigation event ): 触发出站接头( outbound plug )时抛出的事件,对应的方法为FIRE_<Outbound plug>_PLG
  2. 跳转事件响应函数( navigation event handlers ): 即入站接头( inbound plug ),对应的方法为HANDLE<Inbound plug>_PLG
  3. 跳转链接( navigation link ): 注册的链接入站接头和出站接头的静态属性。但该属性并不是视图控制器的一部分,而是注册于视图所在的窗口中,故每个窗口的注册事件可以不同。

 

Special Entities of Window Controllers(窗口控制器的特殊实体):

(窗口控制器的特殊实体与视图控制器的特殊实体类似,但是没有UI)

Unit11 Web Dynpro Context(Web Dynpro上下文)

11.1 Creating Context Nodes(创建上下文节点)

上下文节点( context ): Every Web Dynpro controller has exactly one hierarchical data storage structure, known as the context.

 

节点( context node )和属性( context attribute )的区别:

节点:

  1. Arranged hierarchically(树状结构)
  2. Permitted to have children ( nodes or attributes )(可有子节点)
  3. Metadata description declared manually or derived from a DDIC structure(元数据为手动定义或从DDIC中定义)

属性:

  1. Stores runtime data or references to runtime data(存储或指向运行时的数据)
  2. Based on DDIC types(基于DDIC类型)

 

11.2 Setting Context Node Properties(设置上下文节点属性)

Possible Cardinality Values and Permissions(基数与含义):

Cardinality Values

Description

备注

0 .. 1

Zero or one element permitted

 

0 .. n

Zero or more elements permitted

 

1 .. 1

Exactly one element permitted

根节点的Cardinality为1 .. 1,此时将自动创建index 1节点

1 .. n

One or more elements permitted

 

基数( cardinality )知识点

( 注意: context node的默认基数cardinality为1 .. 1,默认选择基数 selection cardinality为0 .. 1 )

 

主选择(Lead Selection )知识点:

 

主选择的使用场合( Lead selection index is important in the following situations ):

 

单件( Singleton )知识点:

  1. 若Singleton为false,则N1的每行数据都会有一个N2节点的实例
  2. 若Singleton为true,则N1的每行数据指向同一个N2节点的实例

11.3 Sharing Data Between Controllers with Context Mapping(通过上下文映射在控制器间共享数据)

Context Mapping: 即所有上下文指向同一个内存区

Mapping Origin Node: 源节点

Mapped Node: 目标节点

Fully Established Mapping: 源节点的所有节点都映射到了目标节点

Partially Established Mapping: 源节点的节点多于目标节点,故只有部分节点映射到了目标节点

Internal Mapping: 源节点与目标节点在同一个component里

Unit12 Web Dynpro User Interface(Web Dynpro用户接口)

12.1 Defining the View Layout(定义视图显示属性)

UI element: is any graphical entity that occupies a position within a view layout. (屏幕元素: 图形化实体)

  1. Text Category: 这类元素用于显示或输入文本
  2. Action Category: 这类元素用于触发跳转( trigger navigation )或返回( round trip )
  3. Selection Category: 这类元素允许用户从多个值中选择显示单个值或若干值
  4. Complex Category: 这类元素可以包含子元素
  5. Layout Category: 这类元素定义了子元素的显示顺序和规则
  6. Graphics Category: 这类元素用于渲染图片
  7. Integration Category: 这类元素可以嵌入non-ABAP技术
  1. RootUIElementContainer: 该元素类型为TransparentContainer,该元素的ID不可修改但属性可以修改
  2. Context_Menus: 允许用户创建上下文菜单,系统在运行时将上下文菜单实例化且指向屏幕元素

 

Available Container Elements(可选的容器元素):

(容器是一些方形屏幕区域,可将其它屏幕元素作为子节点,并通过layout的属性设置子节点的显示格式。)

 

Layout Property Possible Values(显示格式可选值):

  1. FormTopData: 块定义,通过colCount值设定每块的列数(一般是Group元素作为FormTopData)
  2. FormHeadData: 换行,如果colSpan等于-1,则元素宽度根据列数增加而扩展
  3. FormData: 不换行

12.2 Controlling UI Element Behavior with Data Binding(通过数据绑定控制屏幕元素行为)

数据绑定( data binding )的知识点:

 

数据绑定( data binding )的步骤:

  1. Create a node or attribute in the context of the view controller that contains the data.(创建节点或属性)
  2. Create the UI element in your view layout.(创建屏幕元素)
  3. For all properties that require data binding, a button with a yellow icon and an empty circle is displayed on the right side of the property. Define the required binding by choosing this button. A dialog box displays the context of the view controller. All nodes or attributes, which have the correct type for binding to the UI element property, are displayed.(绑定需要的屏幕元素属性和上下文节点/属性)
  4. Select an appropriate node or attribute.(选定合适的节点或属性,因为绑定双方的数据格式必须匹配)

 

通过数据绑定控制屏幕元素行为的步骤:

  1. 定义跟屏幕元素属性格式一致的上下文属性(比如屏幕元素的readOnly属性,需要的上下文属性是boolean型)
  2. 绑定屏幕元素属性和上下文属性
  3. 通过引导方法( hook methods )或自定义方法( additionally defined methods )控制上下文属性的值

 

在SAP NetWeaver 7.0 SAP_ABAP Support Package Stack 12以后的版本,有两种绑定方式:

 

绑定文本元素和ABAP字典的方法:

12.3 Using Composite UI Elements(使用组合屏幕元素)

Composite Element: is any UI element that requires child UI elements.(组合屏幕元素就是需要子屏幕元素的屏幕元素)

如果是Group或Tray型的组合元素,它们有默认子节点Caption(标题),其它子节点需要用户定义。

如果是Table或Tree型的组合元素,它们需要更复杂的子节点设置。

 

Table UI Element(表屏幕元素):

  1. auto: One or multiple rows, depending on context node property: Selection(根据上下文节点属性判定单选还是多选)
  2. multi: Multiple rows if the context node property, Selection, is set to {0, 1} .. n as well. Lead selection will be set.(允许多选,但是上下文节点属性必需也设置成允许多选,且需要设置主选择)
  3. multiNoLead: Like multi, lead selection will not be set.(与多选类似,但是不需要设置主选择)
  4. none: Selection column is not displayed. Row related to lead selection is not highlighted.(选择不会显示,主选择也不会高亮显示)
  5. single: One row, independent of context node property: Selection. Lead selection will be set.(单选,与上下文节点属性无关,但是需要设置主选择)
  6. singleNoLead: Like single, lead selection will not be set.(与单选类似,但是不需要设置主选择)

 

CTable(ClientTable,客户端表):

 

Web Dynpro中有标准程序WDR_TEST_UI_ELEMENTS,允许用户测试各种屏幕元素。

Unit13 Controller and Context Programming(控制器与上下文编程)

13.1 Outlining Controller Methods and Attributes(描绘控制器方法和属性)

控制器的知识点:

 

标准引导方法( Standard Hook Methods ):

控制器类型

引导方法名称

含义

所有控制器

( All Controllers )

Wddoinit()

最先执行的方法,在控制器实例化时调用,且只调用一次。

Wddoexit()

最后执行的方法,通常用于清空内存( cleanup )

组件控制器

( Component Controller )

Wddobeforenaviation()

在执行动作( action method )后,抛出事件( event )前执行

Wddopostprocessing()

是显示界面( UI )前最后一个执行的引用方法

Wddoapplicationstatechange()

在应用挂起( suspended )或恢复( resume )时执行,挂起可能是因为抛出了挂起接头( suspend plug )或有新应用运行,恢复可能是因为抛出了恢复接头( resume plug )或者新应用运行结束

视图控制器

( View Controller )

Wddobeforeaction()

通常用于输入检查,抛出与动作( action )关联的事件( event )时首先执行

Wddoafteraction()

通常用于将事件响应( action handling )有关代码模块化,在视图控制器执行完事件响应方法( action handler method )后执行

Wddomodifyview()

通常用于动态更改视图层级( UI element hierarchy ),唯一允许访问视图层级的方法,其接口参数VIEW是指向视图层级的引用,FIRST_TIME参数可以识别是否已经在控制器生命周期中执行过该方法

Wddooncontextmenu()

当用户在视图控件上右键时执行,可用于实例化静态上下文( statically defined context menus )或增加新上下文( new context menus )

窗口控制器

( Window Controller )

Wddoonopen()

当窗口以对话框形式显示时,在对话框打开前执行

Wddoonclose()

当窗口以对话框形式显示时,在对话框关闭前执行

 

When a Web Dynpro application is started, the controllers are processed as follows(Web Dynpro启动时,控制器将如下执行):

  1. All controllers needed for the first display are instantiated. This means that the wddoinit() methods are processed for component controller, window controller, and view controller.(所有用于第一次显示的控制器都实例化,执行所有控制器的wddoinit()方法)
  2. The inbound plug method of the interface view related to the application is processed. By default, the Default plug is used. This means that the handledefault() method is processed.(执行接口视图的入站接头方法,默认情况下是handledefault()方法)
  3. The component controller wddobeforenavigation() method is processed.(组件控制器运行wddobeforenavigation()方法)
  4. The view controller wddomodifyview() method is processed.(视图控制器运行wddomodifyview()方法)
  5. The component controller wddopostprocessing() mehtod is processed.(组件控制器运行wddopostprocessing()方法)

 

The phase model for a request triggered by a user interaction can be described as follows(用户交互触发的相位模式可以描述成如下样子):

 

自定义方法( Additional Controller Methods )知识点:

  1. Method: 即普通方法( Ordinary Method )
  2. Event Handler: 即事件响应函数,此时还需要在Event字段定义响应的事件
  3. Supply Function: 即供应函数,该函数可以绑定上下文节点

 

控制器属性( Controller Attributes )知识点:

 

自定义控制器属性( Additional Attributes )知识点:

13.2 Accessing the Context at Runtime with Controller Methods(运行时通过控制器方法访问上下文)

访问上下文节点和元素的代码示例:

DATA lo_nd_fights TYPE REF TO if_wd_context_node.

DATA lo_el_flights TYPE REF TO if_wd_context_element.

 

lo_nd_flights = wd_context->get_child_node( name = wd_this->wdctx_flights ).

 

*get element at lead selection

lo_el_fights = lo_nd_flights->get_element().

 

*if lead selection is not set, ELEM_FLIGHTS will be initial

IF ( lo_el_flights IS INITIAL ).

...

ENDIF.

  1. 因为屏幕元素属性properties只能跟上下文绑定,所以只能通过调整上下文的值去控制屏幕元素的属性。
  2. 上下文引用类型命名规则为IF_<ctrl>(比如这里的if_wd_context_node)。
  3. 上下文节点命名规则为WDCTX_<node>(比如这里的wd_this->wdctx_flights)。
  4. 元素引用类型恒为if_wd_context_element
  5. 要获取主选择那行数据,则使用get_element()方法。

访问上下文节点的代码写法( Reference to context node <node> )

lo_nd_<node> = wd_context->get_child_node(

name = wd_this->wdctx_<node>

).

访问主选择行( Reference to element at lead selection )

lo_el_<node> = lo_nd_<node>->get_element().

访问第n行( Reference to element with index n )

lo_el_<node> = lo_nd_<node>->get_element( index = n ).

获取行数( Get number of elements in collection )

n = lo_<node>->get_element_count().

 

获取单个属性( attributes )和静态定义属性( statically defined attributes )值:

DATA lo_nd_flights TYPE REF TO if_wd_context_node.

DATA lo_el_flights TYPE REF TO if_wd_context_element.

DATA lv_connid TYPE wd_this->element_flights-connid.

 

lo_nd_flights = wa_context->get_child_node( name = wd_this->wdctx_flights ).

 

lo_el_flights = lo_nd_flights->get_element().

 

*get single attribute

lo_el_flights->get_attributes(

EXPORTING

name = 'CONNID'

IMPORTING

value = lv_connid ).

 

DATA ls_flights TYPE wd_this->element_flights.

 

*get all statically declared attributes

lo_el_fights->get_static_attributes(

IMPORTING

static_attributes = ls_flights ).

 

DATA lt_flights TYPE wd_this->elements_flights.

 

*get all statically declared attributes of all node elements

lo_nd_flights->get_static_attributes_table(

IMPORTING

table = lt_flights ).

  1. 如果想获取某个属性的值,可以用get_attribute()函数。
  2. 如果我们的上下文节点是用DDIC的结构静态定义的,则可以通过get_static_attributes()方法直接取出整个结构的字段。
  3. 创建上下文引用IF_<ctrl>时,系统会隐式创建结构类型element_<node>,若是通过DDIC静态定义的节点,则element_<node>类型固定为DDIC结构类型,若是用户自定义的节点,则element_<node>类型与节点属性有关。
  4. 创建上下文引用IF_<ctrl>时,系统会隐式创建标准表elements_<node>,该表的每行结构类型为element_<node>。该内表可用于存放多行节点数据。
  5. 获取静态定义的上下文对应的全部数据的方法为get_static_attributes_table()。
  6. 获取用户选中的数据集的方法为get_selected_elements()。该方法返回值为表类型WDR_CONTEXT_ELEMENT_SET。返回值是否考虑主选择( lead selection )通过INCLUDING_LEAD_SELECTION参数设置。

读单属性值写法( Read value of an attribute )

DATA: lv_<attr> TYPE wd_this->element_<node>-<attr>.

lo_el_<node>->get_attribute(

EXPORTING

name = '<attr>'

IMPORTING

value = lv_<attr> ).

读单行多属性值写法( Read value of all static attributes )

DATA: ls_<node> TYPE wd_this->element_<node>.

lo_el_<node>->get_static_attributes(

IMPORTING

static_attributes = ls_<node> ).

读全部行多属性值写法( Read static attribute values for all node elements )

DATA: lt_<node> TYPE wd_this->elements_<node>.

lo_nd_<node>->get_static_attributes_table(

IMPORTING

table = lt_<node> ).

 

设置单个属性( attributes )和静态定义属性( statically defined attributes )值:

DATA lo_nd_flights TYPE REF TO if_wd_context_node.

DATA lo_el_flights TYPE REF TO if_wd_context_element.

DATA lv_connid TYPE wd_this->element_flights-connid.

 

lo_nd_flights = wd_context->get_child_node ( name = wd_this->wdctx_flights ).

 

lo_el_flights = lo_nd_flights->get_element().

 

*set value of single attribute

lo_el_flights->set_attribute(

EXPORTING

name = 'CONNID'

value = '0405' ).

 

DATA ls_flights TYPE wd_this->element_flights.

 

ls_flights-carrid = 'AZ'.

ls_flights-connid = '0123'.

 

*set values of all statically declared attributes

lo_el_flights->set_static_attributes(

EXPORTING

Static_attributes = ls_flights ).

  1. 设置单个属性的值的方法是set_attribute()。
  2. 对于静态定义的上下文,可以用结构的方式一次设置多个属性的值,方法为set_static_attributes()。

修改单行单属性值( Change a value of a single attribute )

DATA: lv_<attr> TYPE wd_this->element_<node>-<attr>.

lv_<attr> = ... .

lo_el_<node>->set_attribute(

EXPORTING

name = '<attr>'

value = lv_<attr> ).

修改单行多属性值( Change all static attributes of a node element )

DATA: ls_<node> TYPE wd_this->element_<node>.

ls_<node>-<attr> = ... .

lo_el_<node>->set_static_attributes(

EXPORTING

static_attrs = ls_<node> ).

 

13.3 Adding New Elements to a Context Node(在上下文节点上增加元素)

增加元素数据代码示例:

DATA lo_nd_fligths TYPE REF TO if_wd_context_node.

DATA lo_el_flights TYPE REF TO if_wd_context_element.

 

lo_nd_flights = wd_context->get_child_node( name = wd_this->wdctx_flights ).

 

lo_el_flights = lo_nd_flights->create_element().

 

*set attribute values

lo_el_flights->set_attribute( name = 'CARRID' value = 'LH' ).

lo_el_flights->set_attribute( name = 'CONNID' value = '0400' ).

 

*bind element FIRST_ELEMENT to node

lo_nd_flights->bind_element(

new_item = lo_el_flights

set_initial_elements = abap_false ).

  1. 创建元素对象的方法为create_element()。
  2. 创建好的元素对象需要set_attribute()方法赋值
  3. 将元素数据存入上下文的方法为bind_element()。其中参数new_item即元素对象,参数set_initial_elements = abap_false时,代表增加元素对象,set_initial_elements = abap_true时,代表用元素对象替代以前的元素

 

增加结构数据代码示例:

DATA lo_nd_flights TYPE REF TO if_wd_context_node.

DATA ls_flights TYPE wd_this->element_flights.

 

lo_nd_flights = wd_context->get_child_node( name = wd_this->wdctx_flights ).

 

*set field values of local structure

ls_flights-carrid = 'AA'.

ls_flights-connid = '0017'.

 

*bind structure to node

lo_nd_flights->bind_structure(

new_item = ls_flights

set_initial_elements = abap_false ).

  1. 将结构数据存入上下文的方法为bind_structure()。

 

增加内表数据代码示例:

DATA lo_nd_flights TYPE REF TO if_wd_context_node.

DATA ls_flight TYPE wd_this->element_flights.

DATA lt_flight TYPE wd_this->elements_flights.

 

lo_nd_flights = wd_context->get_child_node ( name = wd_this->wdctx_flights ).

 

*append lines to local table

ls_flights-carrid = 'LH'.

ls_flights-connid = '0400'.

APPEND ls_flights TO lt_flights.

 

ls_flights-carrid = 'LH'.

ls_flights-connid = '0401'.

APPEND ls_flights TO lt_flights.

 

*bind internal table to node

lo_nd_flights->bind_table(

new_items = lt_flights

set_initial_elements = abap_true

).

  1. 将内表数据存入上下文的方法为bind_table()。

创建元素对象( Create a new element )

lo_el_<node> = lo_nd_<node>->create_element().

加入元素数据( Add element to collection )

lo_nd_<node>->bind_element(

new_item = lo_el_<node>

set_initial_elements = abap_false ).

加入结构数据( Bind structure to collection )

DATA: ls_<node> TYPE wd_this->element_<node>.

lo_nd_<node>->bind_structure(

new_item = ls_<node>

set_initial_elements = abap_false ).

加入内表数据( Bind internal table to collection )

DATA: it_<node> TYPE wd_this->elements_<node>.

lo_nd_<node>->bind_table(

new_items = lt_<node>

set_initial_elements = abap_false ).

删除元素对象( Remove element from collection )

lo_nd_<node>->remove_element(

element = lo_el_<node> ).

 

13.4 Implementing Supply Functions(实现供应函数)

The Web Dynpro runtime calls the supply function automatically in the following situations(以下情况会使用供应函数):

(上述条件为必要条件而非充分条件,如果节点没有被程序访问或者未与下一个屏幕的元素绑定,那么供应函数依然不会被调用)

 

供应函数的知识点:

 

Lazy Data Instantiation: 这种实例化方式为,只有当数据需要被使用时才进行实例化。

标签:提纲,控制器,TAW12,视图,controller,PA,enhancement,SAP,BAdI
来源: https://www.cnblogs.com/Intercalaryland/p/10522542.html