更改在 ME_INFORECORD_MAINTAIN_MULTI 的 RFC 之后不会提交



我用RFC调用ME_INFORECORD_MAINTAIN_MULTI。购买信息记录将获取新编号,但更改不会提交到数据库。

提交应该是在 RFC 之后隐式的,但事实并非如此。我尝试在函数调用后添加显式COMMIT WORK,但这没有帮助。

如果我使用常规函数调用(非远程),则会正确提交更改,但是性能非常慢。

请帮忙。

FORM CALL_BAPI_PIR.
lv_taskname = |PIR-{ lv_sentjobs WIDTH = 3 ALIGN = RIGHT PAD = '0' }|.
CALL FUNCTION 'ME_INFORECORD_MAINTAIN_MULTI'
STARTING NEW TASK lv_taskname
DESTINATION IN GROUP DEFAULT
PERFORMING RETURN_BAPI_PIR ON END OF TASK
EXPORTING
testrun          = p_test
TABLES
t_eina           = GT_ME_EINA
t_einax          = GT_ME_EINAX
t_eine           = GT_ME_EINE
t_einex          = GT_ME_EINEX
return           = GT_ME_INFORECORD_RETURN
EXCEPTIONS
system_failure        = 1 MESSAGE lv_exceptionmsg
communication_failure = 2 MESSAGE lv_exceptionmsg
resource_failure      = 3
.
CASE sy-subrc.
WHEN 0.
lv_sentjobs = lv_sentjobs + 1.
COMMIT WORK.
WHEN 1 OR 2.
MESSAGE lv_exceptionmsg TYPE 'I'.
WRITE: / lv_taskname, ':', lv_exceptionmsg.
ENDCASE.
ENDFORM.
FORM RETURN_BAPI_PIR USING TASKNAME.
DATA INFO LIKE RFCSI.
RECEIVE RESULTS FROM FUNCTION 'ME_INFORECORD_MAINTAIN_MULTI'
IMPORTING
RFCSI_EXPORT = INFO
RETURN = GT_ME_INFORECORD_RETURN.
lv_recvjobs = lv_recvjobs + 1.
ENDFORM.

我已经通过创建一个以提交结尾的包装函数并调用包装函数而不是标准函数来解决这个问题。

FUNCTION z_inforecord_maintain_mult2
IMPORTING
VALUE(testrun) TYPE bapiflag-bapiflag OPTIONAL
EXPORTING
VALUE(et_eina) TYPE mewieina_mig_t
VALUE(et_eine) TYPE mewieine_t
TABLES
t_eina TYPE mewieina_mig_t OPTIONAL
t_einax TYPE mewieinax_t OPTIONAL
t_eine TYPE mewieine_t OPTIONAL
t_einex TYPE mewieinex_t OPTIONAL
txt_lines TYPE mewipirtext_tt OPTIONAL
cond_validity TYPE mewivalidity_tt OPTIONAL
condition TYPE mewicondition_tt OPTIONAL
cond_scale_value TYPE mewiscaleval_tt OPTIONAL
cond_scale_quan TYPE mewiscalequan_tt OPTIONAL
return TYPE fs4mig_t_bapiret2 OPTIONAL.

CALL FUNCTION 'ME_INFORECORD_MAINTAIN_MULTI'
EXPORTING
testrun          = testrun
IMPORTING
et_eina          = et_eina
et_eine          = et_eine
TABLES
t_eina           = t_eina
t_einax          = t_einax
t_eine           = t_eine
t_einex          = t_einex
txt_lines        = txt_lines
cond_validity    = cond_validity
condition        = condition
cond_scale_value = cond_scale_value
cond_scale_quan  = cond_scale_quan
return           = return
.
IF SY-subrc = 0.
COMMIT WORK.
ENDIF.
ENDFUNCTION.

使用 RFC,在调用程序中的某个时间点有一个隐式数据库提交,但在 RFC 会话中没有,就像SUBMIT后没有隐式数据库提交一样。

可以在同一 RFC 会话中链接多个函数模块调用,要在 RFC 会话中链接 SAP LUW 提交,可以调用函数模块BAPI_TRANSACTION_COMMIT执行COMMIT WORK。然后,解决方案取决于您使用的 RFC 类型。

在您的情况下,您将异步 RFC 与回调一起使用,即等待,因此解决方案将是

  • 指示KEEPING TASKatRECEIVE RESULTS,以便在调用ME_INFORECORD_MAINTAIN_MULTI后保持 RFC 会话打开
  • 使用WAIT FOR ASYNCHRONOUS TASKS以便在ME_INFORECORD_MAINTAIN_MULTI结束后按顺序调用BAPI_TRANSACTION_COMMIT
CALL FUNCTION 'ME_INFORECORD_MAINTAIN_MULTI'
STARTING NEW TASK lv_taskname
DESTINATION IN GROUP DEFAULT
PERFORMING RETURN_BAPI_PIR ON END OF TASK
...
EXCEPTIONS
system_failure        = 1 MESSAGE lv_exceptionmsg
communication_failure = 2 MESSAGE lv_exceptionmsg
resource_failure      = 3.
IF sy-subrc = 0.
WAIT FOR ASYNCHRONOUS TASKS UNTIL lv_recvjobs = lv_sentjobs.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
STARTING NEW TASK lv_taskname " <====== reuse existing RFC session/closed implicitly right after
DESTINATION IN GROUP DEFAULT
EXCEPTIONS
system_failure        = 1 MESSAGE lv_exceptionmsg
communication_failure = 2 MESSAGE lv_exceptionmsg
resource_failure      = 3.
...
FORM RETURN_BAPI_PIR USING TASKNAME.
DATA INFO LIKE RFCSI.
RECEIVE RESULTS FROM FUNCTION 'ME_INFORECORD_MAINTAIN_MULTI'
KEEPING TASK " <============== add this to not close the RFC session
IMPORTING
RFCSI_EXPORT = INFO
RETURN = GT_ME_INFORECORD_RETURN.
lv_recvjobs = lv_recvjobs + 1.
ENDFORM.

铌:

  • 我没有处理异常来简化演示。
  • 如果在多个任务名称下运行 RFC,则会启动多个 RFC 会话,因此必须在每个 RFC 会话中调用BAPI_TRANSACTION_COMMIT

相关内容

  • 没有找到相关文章

最新更新