FUNCTION zmm_jsd_post.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(EBELN) TYPE EKPO-EBELN
*" VALUE(EBELP) TYPE EKPO-EBELP
*" VALUE(PODATE) TYPE SY-DATUM
*" EXPORTING
*" VALUE(E_FLAG) TYPE CHAR1
*" VALUE(E_INFO) TYPE TEXT60
*" VALUE(F_LBLNI) TYPE CHAR10
*"----------------------------------------------------------------------
* 采购订单 过账接口
*"----------------------------------------------------------------------
***数据定义
DATA: g_jsd TYPE zmm_ys_jsd_item-jsd. " 结算单号
DATA: nownum TYPE n LENGTH 10. "流水号
DATA: maxnum TYPE n LENGTH 10. "流水号
DATA: lw_jspost TYPE zmm_jspost_info .
***采购订单行项目
DATA: gw_ekpo TYPE ekpo.
DATA: gt_ekpo TYPE TABLE OF ekpo.
***采购订单行项目服务明细
DATA: gw_esll_item TYPE esll,
gt_esll_item TYPE TABLE OF esll.
** Bapi Create Post
DATA: lw_esllc TYPE bapiesllc.
DATA: lt_esllc TYPE TABLE OF bapiesllc. "通讯结构:创建服务行
DATA: lw_essrc TYPE bapiessrc. "通讯结构: 创建输入单
DATA: po_item TYPE TABLE OF bapiekpo WITH HEADER LINE. "传输结构:显示/清单PO条目
DATA: po_serv TYPE TABLE OF bapiesll WITH HEADER LINE. "通讯结构: 服务行
DATA: lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE. "返回参数
DATA: l_string TYPE string.
DATA: l_line TYPE i VALUE 0.
e_flag = ‘0‘.
e_info = ‘过账成功!‘.
"取得采购订单行项目
SELECT SINGLE * FROM ekpo INTO gw_ekpo WHERE ebeln EQ ebeln AND ebelp EQ ebelp.
"取得行项目服务包的明细
SELECT SINGLE * FROM esll INTO gw_esll_item WHERE packno EQ gw_ekpo-packno.
gw_esll_item-packno = gw_esll_item-packno + 1.
SELECT * FROM esll INTO TABLE gt_esll_item WHERE packno EQ gw_esll_item-packno.
CONCATENATE ‘采购订单:‘ ebeln ‘行项目编号‘ ebelp INTO l_string.
"----------------------------------
CALL FUNCTION ‘BAPI_PO_GETDETAIL‘
EXPORTING
purchaseorder = ebeln "采购凭证号
items = ‘X‘
services = ‘X‘
TABLES
po_items = po_item
po_item_services = po_serv.
"----------------------------------
CLEAR lw_essrc.
lw_essrc-pckg_no = 1.
lw_essrc-short_text = l_string.
lw_essrc-po_number = ebeln. "采购凭证号
lw_essrc-po_item = ebelp. "采购凭证的项目编号
lw_essrc-doc_date = podate. "凭证中的凭证日期
lw_essrc-post_date = podate. "凭证中的过帐日期
lw_essrc-acceptance = ‘X‘. "承诺标识
"-------------------------------------
CLEAR: lw_esllc, lt_esllc.
l_line = 1.
lw_esllc-pckg_no = 1. "软件包编号
lw_esllc-line_no = l_line. "内部行编号
lw_esllc-outl_level = 0. "组的层次水平
lw_esllc-outl_no = ‘‘. "框架层次
lw_esllc-outl_ind = ‘X‘. "标识符:概要行
lw_esllc-subpckg_no = 2. "分包编号
APPEND lw_esllc TO lt_esllc.
"-----------------------------------
CLEAR gw_esll_item.
LOOP AT gt_esll_item INTO gw_esll_item.
CLEAR lw_esllc.
READ TABLE po_serv WITH KEY ext_serv = gw_esll_item-extsrvno.
l_line = l_line + 1.
lw_esllc-pckg_no = 2. "软件包编号
lw_esllc-line_no = l_line. "内部行编号
lw_esllc-service = gw_esll_item-srvpos. "作业编号
lw_esllc-short_text = gw_esll_item-ktext1. "短文本
lw_esllc-quantity = gw_esll_item-menge. "数量
lw_esllc-base_uom = gw_esll_item-meins. "单位
lw_esllc-gr_price = gw_esll_item-tbtwr. "总价格
lw_esllc-taxjurcode = gw_esll_item-mwskz. "税码
lw_esllc-matl_group = gw_esll_item-matkl. "物料组
lw_esllc-pln_pckg = po_serv-pckg_no. "原始包装编号
lw_esllc-pln_line = po_serv-line_no. "输入:计划包行
lw_esllc-ext_serv = gw_esll_item-extsrvno. "供应商的服务编号
APPEND lw_esllc TO lt_esllc.
ENDLOOP.
CLEAR f_lblni.
CALL FUNCTION ‘BAPI_ENTRYSHEET_CREATE‘
EXPORTING
entrysheetheader = lw_essrc
IMPORTING
entrysheet = f_lblni
TABLES
entrysheetservices = lt_esllc
return = lt_return[].
READ TABLE lt_return WITH KEY type = ‘E‘.
IF sy-subrc NE 0 AND f_lblni IS NOT INITIAL.
ELSE.
LOOP AT lt_return.
CALL FUNCTION ‘MESSAGE_STORE‘
EXPORTING
arbgb = lt_return-id
msgv1 = lt_return-message_v1
msgv2 = lt_return-message_v2
msgv3 = lt_return-message_v3
msgv4 = lt_return-message_v4
msgty = ‘E‘
txtnr = lt_return-number
EXCEPTIONS
not_active = 1
OTHERS = 2.
ENDLOOP.
ROLLBACK WORK.
e_flag = ‘2‘.
e_info = lt_return-message.
ENDIF.
IF e_flag EQ ‘0‘.
e_flag = ‘0‘.
e_info = ‘过账成功!‘.
ENDIF.
"过账信息记录
CLEAR:nownum,maxnum.
SELECT MAX( num ) FROM zmm_jspost_info INTO nownum. "流水号
IF nownum IS NOT INITIAL.
maxnum = nownum + 1.
ELSE.
CONCATENATE ‘10‘ ‘00000000‘ INTO maxnum.
ENDIF.
"--------------------------------------------
lw_jspost-num = maxnum.
lw_jspost-jsd = g_jsd.
lw_jspost-ebeln = ebeln.
lw_jspost-ebelp = ebelp.
lw_jspost-poston = sy-datum.
lw_jspost-flag = e_flag.
lw_jspost-text = e_info.
MODIFY zmm_jspost_info FROM lw_jspost.
ENDFUNCTION.