前言
在程序内使用代码获取当前程序应用名称。
网页或dynpro程序report程序
一、对于网页应用
1.根据接口方法获取
代码如下(示例):
参考类型:mo_fpm type ref to if_fpm
2.根据初始化参数获取(FPM或FBI)
在接口的IF_FPM_GUIBB~INITIALIZE方法参数中获取
二、程序内获取WEB DYNPRO组件名称
内也有获取普通程序用的方法
DATA:lt_callstack TYPE abap_callstack,
ls_callstack LIKE LINE OF lt_callstack,
ls_controller TYPE wdy_controller_key,
lv_str TYPE string,
lv_str1 TYPE string,
lv_classname TYPE seoclsname.
* SYSTEM_CALLSTACK
CALL FUNCTION 'SYSTEM_CALLSTACK'
* EXPORTING
* MAX_LEVEL = 0
IMPORTING
callstack = lt_callstack
* ET_CALLSTACK =
.
LOOP AT lt_callstack INTO ls_callstack." WHERE blocktype EQ 'METHOD' AND blockname EQ 'HANDLEDEFAULT'.
IF ls_callstack-mainprogram+0(1) EQ '/'.
* LV_STR = ls_callstack-mainprogram
SPLIT ls_callstack-mainprogram AT '==' INTO lv_str lv_str1.
lv_classname = lv_str.
CALL METHOD cl_wdy_wb_naming_service=>get_component_by_classname
EXPORTING
p_classname = lv_classname
RECEIVING
p_component = lv_str1
EXCEPTIONS
no_wdy_class = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
EXIT.
ENDIF.
ENDIF.
* CALL METHOD cl_wdy_wb_naming_service=>get_controller_by_includename
* EXPORTING
* p_includename = ls_callstack-include
* RECEIVING
* p_controller = ls_controller
** EXCEPTIONS
** no_wdy_include = 1
** others = 2
* .
* IF sy-subrc <> 0.
** Implement suitable error handling here
* ELSE.
* lv_str = ls_controller-component_name.
* ENDIF.
ENDLOOP.