这几天做根据预留单执行MB1B生成物料移动凭证,开始用bapi调试,参数输入都正确但是就是没有return的正确返回值,只是能返回一个物料凭证号,如果有错误的时候就会报错E信息.然后在commit后,终于能更正确生成物料号了.
所以有些sap中的bapi return的返回值是不一定都能返回正误信息的.
具体调试代码如下,可以做个参考,MB1B的code是04.而且如果是根据预留单,切记将关联单号写在reserv_no,res_item中.
DATA: trqty(13).
DATA: msgtext TYPE bapi_msg.
DATA: l_oid_miscdl TYPE oid_miscdl,
itab TYPE zecst0003,
l_materialdocument type BAPI2017_GM_HEAD_RET-MAT_DOC.
* REFRESH it_message[].
DATA: gdsmt_header LIKE bapi2017_gm_head_01.
DATA: gdsmt_code LIKE bapi2017_gm_code.
DATA: gdsmt_item LIKE bapi2017_gm_item_create OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0.
CLEAR: gdsmt_header, gdsmt_code, gdsmt_item, gdsmt_item[], return.
* Setup BAPI header data.
gdsmt_header-pstng_date = sy-datum.
* gdsmt_header-ref_doc_no = sy-datum.
gdsmt_header-doc_date = sy-datum.
gdsmt_header-pr_uname = sy-uname.
gdsmt_code-gm_code = '04'. "01 - MB01 -
DATA: msgtext TYPE bapi_msg.
DATA: l_oid_miscdl TYPE oid_miscdl,
itab TYPE zecst0003,
l_materialdocument type BAPI2017_GM_HEAD_RET-MAT_DOC.
* REFRESH it_message[].
DATA: gdsmt_header LIKE bapi2017_gm_head_01.
DATA: gdsmt_code LIKE bapi2017_gm_code.
DATA: gdsmt_item LIKE bapi2017_gm_item_create OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0.
CLEAR: gdsmt_header, gdsmt_code, gdsmt_item, gdsmt_item[], return.
* Setup BAPI header data.
gdsmt_header-pstng_date = sy-datum.
* gdsmt_header-ref_doc_no = sy-datum.
gdsmt_header-doc_date = sy-datum.
gdsmt_header-pr_uname = sy-uname.
gdsmt_code-gm_code = '04'. "01 - MB01 -
* Write 101 movement to table.
LOOP AT i_ltresb INTO itab.
MOVE '301' TO gdsmt_item-move_type.
MOVE itab-matnr TO gdsmt_item-material.
MOVE itab-erfmg TO gdsmt_item-entry_qnt.
MOVE itab-erfme TO gdsmt_item-entry_uom.
MOVE 'XXXX' TO gdsmt_item-plant.
MOVE itab-lgort TO gdsmt_item-stge_loc.
MOVE itab-rsnum TO gdsmt_item-reserv_no.
MOVE itab-rspos TO gdsmt_item-res_item.
* MOVE 'X' TO gdsmt_item-withdrawn.
MOVE 'OWN' TO gdsmt_item-batch.
* MOVE itab- TO gdsmt_item-move_plant.
* MOVE 'B' TO gdsmt_item-mvt_ind.
* move 'X' to gdsmt_item-no_more_gr. "是否標識完成收貨
APPEND gdsmt_item.
ENDLOOP.
IF NOT gdsmt_item[] IS INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = gdsmt_header
goodsmvt_code = gdsmt_code
IMPORTING
materialdocument = l_materialdocument
TABLES
goodsmvt_item = gdsmt_item
return = return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
ENDIF.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17204926/viewspace-692815/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/17204926/viewspace-692815/