ABAP 修改PR bapi demo

DATA:ls_pritem TYPE bapimereqitemimp,
lt_pritem TYPE TABLE OF bapimereqitemimp,
ls_pritemx TYPE bapimereqitemx,
lt_pritemx TYPE TABLE OF bapimereqitemx,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA:lv_flag.
DATA:lv_msg TYPE string.

LOOP AT gt_alv INTO gs_alv WHERE ekgrp_n <> ‘’ AND frgzu = ‘’.
IF gs_alv-ekgrp = gs_alv-ekgrp_n.
CONTINUE.
ENDIF.

CLEAR:ls_pritem,lt_pritem,ls_pritemx,lt_pritemx,lt_return,lt_return[],lv_flag,lv_msg.

ls_pritem-preq_item = gs_alv-bnfpo.
ls_pritemx-preq_item = gs_alv-bnfpo.

ls_pritem-pur_group = gs_alv-ekgrp_n.
ls_pritemx-pur_group = 'X'.

APPEND ls_pritem TO lt_pritem.
APPEND ls_pritemx TO lt_pritemx.

CALL FUNCTION 'BAPI_PR_CHANGE'
  EXPORTING
    number  = gs_alv-banfn
  TABLES
    return  = lt_return
    pritem  = lt_pritem
    pritemx = lt_pritemx.

LOOP AT lt_return WHERE ( type = 'E' OR  type = 'A' ).
  lv_flag = 'X'.
  IF lv_msg IS INITIAL.
    lv_msg = lt_return-message.
  ELSE.
    lv_msg = lv_msg && '/' && lt_return-message.
  ENDIF.
ENDLOOP.

IF lv_flag = 'X'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

  lv_msg = '更新失败:' && lv_msg.


ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.

  lv_msg = '更新成功'.
ENDIF.

gs_alv-mess = lv_msg.
MODIFY gt_alv FROM gs_alv TRANSPORTING mess.

ENDLOOP.

你可能感兴趣的:(SAP-ABAP,SAP-MM,SAP-PP,ABAP,SAP)