首页 > 代码库 > 服务确定(服务类收货ML81N)

服务确定(服务类收货ML81N)

FUNCTION zrfc_mm005.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(CALLNO) TYPE  ZCALLNO
*"     VALUE(PO_NUMBER) LIKE  BAPIESSRC-PO_NUMBER
*"     VALUE(PO_ITEM) LIKE  BAPIESSRC-PO_ITEM
*"     VALUE(SHORT_TEXT) LIKE  BAPIESSRC-SHORT_TEXT
*"     VALUE(POST_DATE) LIKE  BAPIESSRC-POST_DATE DEFAULT SY-DATUM
*"     VALUE(DOC_DATE) LIKE  BAPIESSRC-DOC_DATE DEFAULT SY-DATUM
*"  EXPORTING
*"     VALUE(ENTRYSHEET) LIKE  BAPIESSR-SHEET_NO
*"     VALUE(FLAG) LIKE  BAPIRET2-TYPE
*"     VALUE(MESSAGE) LIKE  BAPIRET2-MESSAGE
*"  TABLES
*"      ZENTRYSHEET01 STRUCTURE  ZENTRYSHEET01
*"----------------------------------------------------------------------
DATA: ls_heetheader    LIKE bapiessrc,
      lt_sheetservices LIKE TABLE OF bapiesllc,
      ls_sheetservices LIKE bapiesllc,
      ls_zentrysheet01 TYPE zentrysheet01,
      lv_pckg_no       LIKE bapiesllc-pckg_no  VALUE 0000000001,
      lv_line_no       LIKE bapiesllc-line_no  VALUE 0000000001,
      lv_entrysheet       LIKE    bapiessr-sheet_no,
      lv_message       LIKE bapiret2-message.
DATA  lv_datano        TYPE zdatano.
DATA: lt_zmms003       TYPE TABLE OF zmms003,
      ls_zmms003       TYPE zmms003.

DATA: lt_zmmt002       TYPE TABLE OF zmmt002,                             "记录会计凭证
      ls_zmmt002       TYPE zmmt002,
      lv_awkey         TYPE awkey,
      lv_mblnr         TYPE mseg-mblnr,                                   "物料凭证
      lv_mjahr         TYPE mseg-mjahr,                                   "年度
      lv_bukrs         TYPE bkpf-bukrs,                                   "公司代码
      lv_belnr         TYPE bkpf-belnr,                                   "会计凭证号
      lv_gjahrs        TYPE bkpf-gjahr,                                   "会计年度号
      lv_blart         TYPE bkpf-blart.                                   "会计凭证类型

*服务确定抬头数据
 ls_heetheader-pckg_no    = lv_pckg_no.                                   "软件包编号
 ls_heetheader-po_number  = po_number.                                    "PO编号
 ls_heetheader-po_item    = po_item.                                      "PO项目编号
 ls_heetheader-short_text = short_text.                                   "预算号)
 ls_heetheader-acceptance = g_flag.                                       "接受服务确认标识
 ls_heetheader-post_date  = post_date.                                    "凭证中的凭证日期
 ls_heetheader-doc_date   = doc_date.                                     "凭证中的过帐日期

*服务确定行项目数据
 ls_sheetservices-pckg_no    = lv_pckg_no.                                "软件包编号
 ls_sheetservices-line_no    = lv_line_no.                                "内部行编号
 ls_sheetservices-subpckg_no = lv_pckg_no + 1.                            "分包编号
 ls_sheetservices-outl_no    = g_flag.                                    "标识符:概要行
 APPEND ls_sheetservices TO lt_sheetservices.
 CLEAR: ls_sheetservices,lv_entrysheet.

  lv_pckg_no = lv_pckg_no + 1.
  LOOP AT zentrysheet01 INTO ls_zentrysheet01.
    lv_line_no = lv_line_no + 1.
    ls_sheetservices-pckg_no    = lv_pckg_no.
    ls_sheetservices-line_no    = lv_line_no.
    ls_sheetservices-ext_line   = ls_zentrysheet01-ext_line.               "服务确认行项目编号
    ls_sheetservices-quantity   = ls_zentrysheet01-quantity.               "数量
    ls_sheetservices-base_uom   = ls_zentrysheet01-base_uom.               "单位
    ls_sheetservices-gr_price   = ls_zentrysheet01-gr_price.               "总价
    ls_sheetservices-short_text = ls_zentrysheet01-short_text.             "短文本
    APPEND ls_sheetservices TO lt_sheetservices.

    ls_zmms003-bstnr            = po_number.
    ls_zmms003-ebelp            = po_item.
    ls_zmms003-xref2            = ls_zentrysheet01-xref2.                  "参考码2(预算)
    ls_zmms003-zuonr            = ls_zentrysheet01-zuonr.                  "分配号(ECM单号)
    APPEND ls_zmms003 TO lt_zmms003.
    CLEAR: ls_zentrysheet01,ls_zentrysheet01,ls_zmms003.
  ENDLOOP.


*---贷方分配编号借方预算号
EXPORT  zrfc_mm003 = lt_zmms003  TO  MEMORY ID ZRFC_MM003.

CLEAR: gt_return ,gs_return  .
CALL FUNCTION BAPI_ENTRYSHEET_CREATE
  EXPORTING
    entrysheetheader                  = ls_heetheader
  IMPORTING
    entrysheet                        = lv_entrysheet
  TABLES
    entrysheetservices                = lt_sheetservices
    return                            = gt_return.


  READ TABLE gt_return INTO gs_return WITH KEY type = E.
  IF sy-subrc NE 0.
    flag = S.
    entrysheet = lv_entrysheet.
    CONCATENATE 生成服务编号: lv_entrysheet INTO message..
  ELSE.
    LOOP AT gt_return INTO gs_return WHERE type CA AEX.
        MESSAGE ID     gs_return-id
                TYPE   gs_return-type
                NUMBER gs_return-number
                WITH   gs_return-message_v1 gs_return-message_v2
                       gs_return-message_v3 gs_return-message_v4
                       INTO lv_message.
        CONCATENATE message lv_message INTO message SEPARATED BY .
    ENDLOOP.
    SHIFT message LEFT DELETING LEADING  .
    flag = E.
  ENDIF.

*----记录会计凭证
CLEAR: lt_zmmt002, ls_zmmt002, lv_awkey,  lv_mblnr, lv_mjahr,
       lv_bukrs,   lv_belnr,   lv_gjahrs, lv_blart.

SELECT SINGLE mblnr mjahr INTO (lv_mblnr,lv_mjahr)   "物料凭证
  FROM mseg
  WHERE lfbja = sy-datum+0(4)
  AND   lfbnr = lv_entrysheet.

CONCATENATE  lv_mblnr  lv_mjahr INTO lv_awkey.
IF lv_awkey IS NOT INITIAL.
SELECT SINGLE bukrs belnr gjahr blart INTO (lv_bukrs,lv_belnr,lv_gjahrs,lv_blart) "会计凭证
  FROM bkpf WHERE awtyp = MKPF
             AND  awkey = lv_awkey.
ENDIF.

SELECT  bukrs belnr gjahr buzei zuonr sgtxt xref1 xref2 xref3    "会计凭信息
  INTO CORRESPONDING FIELDS OF TABLE lt_zmmt002
  FROM bseg
  WHERE bukrs  = lv_bukrs
  AND   belnr  = lv_belnr
  AND   gjahr  = lv_gjahrs.

  ls_zmmt002-blart = lv_blart.  "会计凭证类型
  MODIFY lt_zmmt002 FROM  ls_zmmt002 TRANSPORTING blart WHERE blart IS INITIAL .

  INSERT zmmt002 FROM TABLE lt_zmmt002. "写入客制数据表
  IF sy-subrc = 0.
     COMMIT WORK AND WAIT.
  ELSE.
     ROLLBACK WORK.
  ENDIF.

*----记录日志
DATA: quantity(18),
      gr_price(27).
CLEAR:gt_log,gs_log,ls_zentrysheet01.

  LOOP AT zentrysheet01 INTO ls_zentrysheet01.
    lv_datano     = lv_datano + 1.
    gs_log-datano = lv_datano.
    gs_log-name   = ZRFC_MM005.
    gs_log-cdate  = sy-datum.
    GET TIME.
    gs_log-ctime  = sy-uzeit.
    gs_log-callno = callno.
    gs_log-flag   = flag.
    gs_log-log    = message.
    quantity      = ls_zentrysheet01-quantity.
    gr_price      = ls_zentrysheet01-gr_price.
    CONCATENATE po_number  po_item   short_text   post_date   doc_date
                ls_zentrysheet01-ext_line   quantity     ls_zentrysheet01-base_uom
                gr_price   ls_zentrysheet01-short_text
                ls_zentrysheet01-xref2
                ls_zentrysheet01-zuonr
                entrysheet
    INTO gs_log-content.
    CONDENSE gs_log-content NO-GAPS.
    gs_log-length = STRLEN( gs_log-content ).
    APPEND gs_log TO gt_log.
    CLEAR: gs_log,quantity,gr_price,ls_zentrysheet01.
  ENDLOOP.

 IF gt_log IS NOT INITIAL.
   INSERT zrfc_mm01in_log FROM TABLE gt_log.
   IF sy-subrc = 0.
     COMMIT WORK.
   ENDIF.
 ENDIF.

ENDFUNCTION.

 

服务确定(服务类收货ML81N)