以前总是担心BW的专家routine会让运维工作变的复杂,因为很多BW顾问的abap水平不够。这几天研究了下,再对复杂逻辑的处理上,感觉专家routine更适合,因为逻辑在一个地方,更容易处理维护。但需要注意以下几点:
1 代码逻辑注释–这是必须
2 错误记录的log信息(建议将对应的source package的关键字段的信息输出)
3 特别复杂的,再次封装在一个类里或者函数里,在那里再进行一次分块处理
至于error dtp的数据处理,是可选项。我觉得这个不是必须的,当然不排除某些情况下,要单独处理。
在sdn看到,有人分享关于amdp在tr里的运用,他说amdp方式是最适合专家routine。从性能的角度来说确实是这样,基本让数据库一次性把逻辑做完,但是写outtab字段是件痛苦的事情,hana sql也有很多地方也不是那么完美。(至少少一个move-corrosponding的功能)
------------------------------------------------------------------------2022/01/26 更新--------------------------------------------------------------------------------------
如何处理错误消息给erro handling?
Note the following design rules in particular, in order to ensure consistent runtime behavior in the case of a data-driven error situation. The default behavior of a data status that is not expected in the case of the expert routine is as follows: the data package that has already been processed is terminated, resulting in the termination of the entire request with an error status. The example below deals with the following topics:
Sending messages to the data transfer process (DTP) monitor.
Creating reference relationships between the data records of the inbound data package SOURCE_PACKAGE and the outbound data package RESULT_PACKAGE. These are required for the functioning of the settings in DTP error handling.
METHOD expert_routine.
DATA: l_t_msg type rstr_ty_t_monitors,
l_s_msg type rstmonitor.
LOOP AT source_package ASSIGNING <source_fields>.
*-- put the message to corresponding fields of structure l_s_msg
*- append l_s_msg to l_t_msg
*-- note: if you like to skip the inbound data record
*- you have to set the skip flag SKIPPED in structure l_s_msg
*- and don’t append that record into the outbound RESULT_PACKAGE
- The RECNO field in l_s_msg has to be filled by the record#
- of the inbound data record of SOURCE_PACKAGE.
IF <source_fields>-‘a’ IS INITIAL.
*-- send message to monitor and skip record
l_s_msg-msgid = ‘XXX’.
l_s_msg-msgty = ‘E’. " Error
l_s_msg-msgno = ‘900’.
l_s_msg-msgv1, v2, v3, v4, "set context according the definition
"of the variables
*-- source record needs to be set as erroneous and skipped
l_s_msg-recno = <source_fields>-record
l_s_msg-skipped = ‘X’.
APPEND l_s_msg TO l_t_msg.
CALL METHOD cl_rstran_expert_rout_srv=>send_message
EXPORTING
i_r_log = log
i_rule_context = p_curr_rule
i_seg_id = “i_sc”
"i_sc value depends on segment id of the SOURCE_PACKAGE
"is only <> 1 in case of a segmented DataSource
"in this case naming of source_package is like
"source_package_i i = segment ID
CHANGING
c_t_msg = l_t_msg.
CONTINUE. "continue with the next source packages record
ELSE.
CALL METHOD new_record__expert_routine
EXPORTING
log = log
source_segid = “i_sc” "i_sc see above
source_record = <source_fields>-record
target_segid = “i_tg”
"Release 7.0x i_tg is always ‘1’
"Release 7.3+
"i_tg value depends on segment id of the RESULT_PACKAGE
"is only <> 1 in case of InfoObject with Hierarchy
"in this case naming of result_package is like
"result_package_i i = segment ID
IMPORTING
record_new = result_fields-record.
*-- Put source_record to result_package
APPEND result_fields TO result_package.
ENDIF.
ENDLOOP.
ENDMETHOD. "expert_routine
------------------------------------------------------------------------2023/09/20 更新--------------------------------------------------------------------------------------
关于abap expert routine和hana expert routine,几点对比:
1 编辑器,abap code 可以美化代码,hana code暂时没有找到此功能只能手撸,太不友好
2 debug调试,abap比hana更直观,可能是自己更习惯gui的界面
3 hana routine要注意字段conversion exit,(abap的系统程序会在后面自动处理)否则容易报错:
BRAIN 019 Value ‘&’ of characteristic & is not a number with & spacesT
这种错误,常见于以下几个类型:PERI6, ALPHA, NUMC, NUMCV, GJAHR, PERI7, SNUMC ,Date,Time
Considering the above example with the NUMC field, the result of the HANA function should be extended with the leading zeroes. The easiest way to do this is to add the HANA function ABAP_NUMC or ABAP_ALPHANUM, which does the same on HANA level as the ALPHA conversion exit on ABAP level.
参考note:2800346 - Consulting: Handling of fields with conversion exits in AMDP routines
4 运行速度,hana肯定比abap快,abap毕竟是row by row,hana是块处理,abap还需要从hana db传输到app server进行处理再返回db。