这个例子是在合同号中新增项目号:
1、先要读取该合同号的信息用一个BAPI
BAPI_CONTRACT_GETDETAIL
2、调用修改合同号的BAPI。
代码如下:
REPORT ztest_class.
DATA: lv_docnumber TYPE bapimeoutheader-number,
lt_item_condition TYPE TABLE OF bapimeoutcondition,
lt_item_conditionc TYPE TABLE OF bapimeoutcondition,
ls_item_condition TYPE bapimeoutcondition,
ls_item_conditionc TYPE bapimeoutcondition. DATA: lt_cond_validity TYPE TABLE OF bapimeoutvalidity,
lt_cond_validityc TYPE TABLE OF bapimeoutvalidity,
ls_cond_validity TYPE bapimeoutvalidity. DATA: lt_cond_validityx TYPE TABLE OF bapimeoutvalidityx,
ls_cond_validityx TYPE bapimeoutvalidityx. DATA: lt_item_conditionx TYPE TABLE OF bapimeoutconditionx,
ls_item_conditionx TYPE bapimeoutconditionx. DATA: lt_ctr_item TYPE TABLE OF bapimeoutitem,
lt_ctr_itemc TYPE TABLE OF bapimeoutitem,
ls_ctr_item TYPE bapimeoutitem. DATA: lt_ctr_itemx TYPE TABLE OF bapimeoutitemx,
ls_ctr_itemx TYPE bapimeoutitemx. DATA: lt_returnt TYPE TABLE OF bapiret2,
ls_returnt TYPE bapiret2. *DATA: ls_upload LIKE LINE OF gt_upload. DATA: lv_has_error TYPE xfeld. CALL FUNCTION 'BAPI_CONTRACT_GETDETAIL'
EXPORTING
purchasingdocument = lv_docnumber
item_data = 'X'
* ACCOUNT_DATA = ' '
condition_data = 'X'
* TEXT_DATA = ' '
* PARTNER_DATA = ' '
* RELEASE_DATA = ' '
* IMPORTING
* HEADER =
TABLES
item = lt_ctr_item
* ACCOUNT =
* DELIVERY_ADDRESS =
item_cond_validity = lt_cond_validity
item_condition = lt_item_condition
* ITEM_COND_SCALE_VALUE =
* ITEM_COND_SCALE_QUAN =
* ITEM_TEXT =
* HEADER_TEXT =
* HEAD_COND_VALIDITY =
* HEAD_CONDITION =
* HEAD_COND_SCALE_VAL =
* HEAD_COND_SCALE_QUAN =
* PARTNER =
* RELEASE_DOCU =
* EXTENSIONOUT =
* RETURN =
. " 设置要更新的字段
" 行项目
LOOP AT lt_ctr_item INTO ls_ctr_item.
APPEND ls_ctr_item TO lt_ctr_itemc. CLEAR ls_ctr_itemx.
ls_ctr_itemx-item_no = ls_ctr_item-item_no.
APPEND ls_ctr_itemx TO lt_ctr_itemx. CLEAR ls_ctr_item.
ENDLOOP. " 条件日期
LOOP AT lt_cond_validity INTO ls_cond_validity.
APPEND ls_cond_validity TO lt_cond_validityc. CLEAR ls_cond_validityx.
ls_cond_validityx-item_no = ls_cond_validity-item_no.
ls_cond_validityx-serial_id = ls_cond_validity-serial_id.
APPEND ls_cond_validityx TO lt_cond_validityx. CLEAR ls_cond_validity.
ENDLOOP. " 项目条件
LOOP AT lt_item_condition INTO ls_item_condition. CLEAR ls_item_conditionc.
MOVE-CORRESPONDING ls_item_condition TO ls_item_conditionc. CLEAR ls_item_conditionx.
ls_item_conditionx-item_no = ls_item_condition-item_no.
ls_item_conditionx-serial_id = ls_item_condition-serial_id.
ls_item_conditionx-cond_count = ls_item_condition-cond_count. * IF ls_item_condition-cond_type EQ 'PB00' AND ls_item_condition-deletion_ind EQ ''.
* READ TABLE gt_upload INTO ls_upload
* WITH KEY ebelp = ls_item_condition-item_no.
* IF sy-subrc EQ 0 AND ls_item_condition-cond_unit NE ls_upload-bprme.
* ls_item_conditionc-cond_unit = ls_upload-bprme.
* ls_item_conditionc-change_id = 'U'.
*
* ls_item_conditionx-cond_unit = 'X'.
* ENDIF.
* ENDIF.
ls_item_conditionc-change_id = 'I'.
APPEND ls_item_conditionc TO lt_item_conditionc.
ls_item_conditionx-cond_unit = 'X'.
APPEND ls_item_conditionx TO lt_item_conditionx. CLEAR ls_item_condition.
ENDLOOP. " 修改合同
CALL FUNCTION 'BAPI_CONTRACT_CHANGE'
EXPORTING
purchasingdocument = lv_docnumber
* HEADER =
* HEADERX =
* VENDOR_ADDRESS =
* TESTRUN =
* TECHNICAL_DATA =
* IMPORTING
* EXP_HEADER =
TABLES
item = lt_ctr_itemc
itemx = lt_ctr_itemx
* ACCOUNT =
* ACCOUNTPROFITSEGMENT =
* ACCOUNTX =
* DELIVERY_ADDRESS =
item_cond_validity = lt_cond_validityc
item_cond_validityx = lt_cond_validityx
item_condition = lt_item_conditionc
item_conditionx = lt_item_conditionx
* ITEM_COND_SCALE_VALUE =
* ITEM_COND_SCALE_QUAN =
* ITEM_TEXT =
* HEADER_TEXT =
* HEAD_COND_VALIDITY =
* HEAD_COND_VALIDITYX =
* HEAD_CONDITION =
* HEAD_CONDITIONX =
* HEAD_COND_SCALE_VAL =
* HEAD_COND_SCALE_QUAN =
* PARTNER =
* PARTNERX =
* RELEASE_DOCU =
* EXTENSIONIN =
* EXTENSIONOUT =
return = lt_returnt
. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = ls_returnt.