文章目录
- 1.前台操作
- 2.需求分析
- 2.1调用方式
- 2.2分为两大概括:
- 2.3业务逻辑细节图
- 3.BAPI_GOODSMVT_CREATE
- 4.RFC接口代码
- 5.总结
1.前台操作
SAP CO01(创建生产订单)/MIGO(发货投料)前台操作
这里面有migo的前台操作,首先了解前台操作后再去写RFC接口是比较容易理解的.!!
2.需求分析
2.1调用方式
mesOS->SAPOS
2.2分为两大概括:
同一过账标识 1 和 0
- 为 0 的时候单一过账,无论行项目中有多少个物料号,都会对应生成多少个物料凭证号
- 为 1的时候同一过账,也就是无论行项目中有多少个物料号,都只生成一个物料凭证编号.
这两个逻辑是是相反的.
2.3业务逻辑细节图
3.BAPI_GOODSMVT_CREATE
下面的这些参数我只介绍了此需求用过的.
EXPORTING部分
bapi2017_gm_head_01, "凭证中的过帐日期等一些抬头信息
bapi2017_gm_code, "这个是你要进行的是什么样的操作比如说是发货,收货,取消等都对应相应的编号比如01 02 03
IMPORTING部分
bapi2017_gm_head_ret, "物料凭证号,凭证年度
bapi2017_gm_head_ret-mat_doc, "物料凭证号
bapi2017_gm_head_ret-doc_year, "凭证年度
TABLES部分
bapi2017_gm_item_create, "行项目
bapiret2, "返回值
4.RFC接口代码
代码感觉比较臃肿,欢迎大佬前来补充优化!!!
FUNCTION zmigo_carry_to.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IN_NUM) TYPE BAPI_MTYPE
*" EXPORTING
*" VALUE(MSG_TYPE) TYPE BAPI_MTYPE
*" VALUE(MESSAGE) TYPE BAPI_MSG
*" TABLES
*" IT_TAB_IN STRUCTURE ZCARRY_TO_INPUT OPTIONAL
*" INT_TAB_OUT STRUCTURE ZCARRY_TO_OUTPUT OPTIONAL
*"----------------------------------------------------------------------
DATA:goodsmvt_header LIKE bapi2017_gm_head_01,
goodsmvt_code LIKE bapi2017_gm_code,
goodsmvt_headret LIKE bapi2017_gm_head_ret,
materialdocument TYPE bapi2017_gm_head_ret-mat_doc,
matdocumentyear TYPE bapi2017_gm_head_ret-doc_year,
goodsmvt_item TYPE TABLE OF bapi2017_gm_item_create,
goodsmvt_item_0 TYPE TABLE OF bapi2017_gm_item_create,
w_goodsmvt_item TYPE bapi2017_gm_item_create,
goodsmvt_serialnumber LIKE bapi2017_gm_serialnumber,
it_return TYPE TABLE OF bapiret2,
wa_return TYPE bapiret2.
DATA gs_tab_in TYPE zcarry_to_input .
DATA gt_tab_in TYPE TABLE OF zcarry_to_input .
DATA gs_tab_out TYPE zcarry_to_output .
IF in_num = 1 .
MOVE-CORRESPONDING it_tab_in[] TO gt_tab_in.
SORT gt_tab_in BY bwart.
LOOP AT gt_tab_in INTO DATA(ls_tab).
DELETE ADJACENT DUPLICATES FROM gt_tab_in COMPARING bwart.
ENDLOOP.
IF lines( gt_tab_in ) > 1.
CLEAR:gt_tab_in, ls_tab.
msg_type = 'E'.
message = '不同移动类型请分批出库!'.
RETURN.
ENDIF.
LOOP AT it_tab_in[] INTO gs_tab_in.
gs_tab_in-zeile = sy-tabix.
MODIFY it_tab_in FROM gs_tab_in.
goodsmvt_header-pstng_date = gs_tab_in-budat_mkpf. "过账日期
goodsmvt_code-gm_code = '03'.
w_goodsmvt_item-material = gs_tab_in-matnr. "物料号
w_goodsmvt_item-plant = gs_tab_in-werks. "工厂
w_goodsmvt_item-stge_loc = gs_tab_in-lgort. "库位
w_goodsmvt_item-costcenter = it_tab_in-kostl. "成本中心
w_goodsmvt_item-entry_qnt = gs_tab_in-menge. "数量
w_goodsmvt_item-ref_doc_it = gs_tab_in-zeile. "物料参考项目
w_goodsmvt_item-move_type = gs_tab_in-bwart. "移动类型(库存管理)
APPEND w_goodsmvt_item TO goodsmvt_item.
CLEAR: w_goodsmvt_item,gs_tab_in.
ENDLOOP.
IF goodsmvt_item[] IS NOT INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = goodsmvt_header
goodsmvt_code = goodsmvt_code
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
* goodsmvt_headret = goodsmvt_header
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = goodsmvt_item[]
* GOODSMVT_SERIALNUMBER =
return = it_return[]
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
.
READ TABLE it_return INTO wa_return WITH KEY type = 'E'.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
msg_type = 'E'.
message = wa_return-message.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
msg_type = 'S'.
" message = '物料凭证:' && materialdocument && '已过账!'.
LOOP AT it_tab_in[] INTO gs_tab_in.
int_tab_out-mjahr = matdocumentyear. "凭证年份
int_tab_out-mblnr = materialdocument."物料凭证
int_tab_out-zeile = gs_tab_in-zeile."物料参考项目
int_tab_out-budat_mkpf = gs_tab_in-budat_mkpf. "过账日期
int_tab_out-matnr = gs_tab_in-matnr. "物料号
int_tab_out-werks = gs_tab_in-werks. "工厂
int_tab_out-lgort = gs_tab_in-lgort. "库位
int_tab_out-kostl = it_tab_in-kostl. "成本中心
int_tab_out-menge = gs_tab_in-menge. "数量
int_tab_out-bwart = gs_tab_in-bwart. "移动类型(库存管理)
APPEND int_tab_out.
ENDLOOP.
ENDIF.
ENDIF.
ELSEIF in_num = 0.
LOOP AT it_tab_in[] INTO gs_tab_in .
goodsmvt_header-pstng_date = gs_tab_in-budat_mkpf. "过账日期
goodsmvt_code-gm_code = '03'.
w_goodsmvt_item-material = gs_tab_in-matnr. "物料号
w_goodsmvt_item-plant = gs_tab_in-werks. "工厂
w_goodsmvt_item-stge_loc = gs_tab_in-lgort. "库位
w_goodsmvt_item-costcenter = it_tab_in-kostl. "成本中心
w_goodsmvt_item-entry_qnt = gs_tab_in-menge. "数量
w_goodsmvt_item-move_type = gs_tab_in-bwart. "移动类型(库存管理)
w_goodsmvt_item-ref_doc_it = '1'. "物料参考项目
APPEND w_goodsmvt_item TO goodsmvt_item_0.
IF goodsmvt_item_0[] IS NOT INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = goodsmvt_header
goodsmvt_code = goodsmvt_code
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
* goodsmvt_headret = goodsmvt_header
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = goodsmvt_item_0[]
* GOODSMVT_SERIALNUMBER =
return = it_return[]
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
.
ENDIF.
READ TABLE it_return INTO wa_return WITH KEY type = 'E'.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
msg_type = 'E'.
message = wa_return-message.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
msg_type = 'S'.
" message = '物料凭证已过账!'.
int_tab_out-mjahr = matdocumentyear. "凭证年份
int_tab_out-mblnr = materialdocument."物料凭证
int_tab_out-zeile = w_goodsmvt_item-ref_doc_it ."物料参考项目
int_tab_out-budat_mkpf = gs_tab_in-budat_mkpf. "过账日期
int_tab_out-matnr = gs_tab_in-matnr. "物料号
int_tab_out-werks = gs_tab_in-werks. "工厂
int_tab_out-lgort = gs_tab_in-lgort. "库位
int_tab_out-kostl = it_tab_in-kostl. "成本中心
int_tab_out-menge = gs_tab_in-menge. "数量
int_tab_out-bwart = gs_tab_in-bwart. "移动类型(库存管理)
APPEND int_tab_out.
ENDIF.
CLEAR:
goodsmvt_item_0[] ,
goodsmvt_header,
goodsmvt_code.
CLEAR: w_goodsmvt_item.
ENDLOOP.
ENDIF.
ENDFUNCTION.
5.总结
RFC接口首先要明确的是,接口参数以及业务逻辑.(我尼玛,说的都是废话);如果调用bapi就需要研究一下bapi中的参数.