ML81N服务条目表创建审批

ML81N服务条目表创建

ME23N创建服务类采购订单
ML81N服务条目表创建审批_第1张图片

ML81N根据采购订单明细创建服务条目表
ML81N服务条目表创建审批_第2张图片
保存后采购订单会生成物料凭证
ML81N服务条目表创建审批_第3张图片
删除
ML81N服务条目表创建审批_第4张图片

创建

参考ESLL表,需要区分父包,子包;其中ls_esll-pln_pckg需要根据EKPO关联ESSR关联ESLL获取到原始包装编号

    LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<fs_alv>) WHERE sel = 'X' AND icon <> '@08@'.
      CLEAR:<fs_alv>-icon,<fs_alv>-msg.
      IF sy-ucomm = 'ZRUN' AND <fs_alv>-test = ''.
        <fs_alv>-msg = TEXT-035.
        <fs_alv>-icon = '@0A@'.
        CONTINUE.
      ENDIF.
      AT NEW ebelp.
        ls_header-pckg_no = '1'.
        ls_header-po_number = <fs_alv>-ebeln.
        ls_header-po_item = <fs_alv>-ebelp.
        ls_header-fin_entry = <fs_alv>-final.

        ls_esll-pckg_no = ls_header-pckg_no.
        lv_line_no = lv_line_no + 1.
        ls_esll-subpckg_no = lv_line_no + 1.
        ls_esll-line_no = lv_line_no .
        CLEAR:ls_esll-ext_line .
        ls_esll-outl_ind = 'X'.
        APPEND ls_esll TO lt_esll.
      ENDAT.
      lv_serial_no = lv_serial_no + 1.
      ls_eskn-serial_no = lv_serial_no.
      ls_eskn-costcenter = <fs_alv>-kostl.
      APPEND ls_eskn TO lt_eskn.

      ls_esll-pckg_no = ls_header-pckg_no + 1.
      lv_line_no = lv_line_no + 1.
      ls_esll-line_no = lv_line_no.
      lv_extrow = lv_extrow + 10.
      ls_esll-ext_line = lv_extrow .
      ls_esll-quantity = <fs_alv>-menge.
      ls_esll-short_text = <fs_alv>-ktext1.
      ls_esll-userf1_txt = <fs_alv>-userf1_txt.
      ls_esll-pln_pckg = <fs_alv>-packno.
      ls_esll-pln_line = <fs_alv>-introw.
      CLEAR:ls_esll-outl_ind,ls_esll-subpckg_no.
      APPEND ls_esll TO lt_esll.

      ls_eskl-pckg_no = ls_header-pckg_no + 1.
      ls_eskl-line_no = lv_line_no.
      ls_eskl-serial_no = lv_serial_no.
      APPEND ls_eskl TO lt_eskl.

      AT END OF ebelp.

        CALL FUNCTION 'BAPI_ENTRYSHEET_CREATE'
          EXPORTING
            entrysheetheader            = ls_header
            testrun                     = lv_test
            no_commit                   = lv_no_commit
          IMPORTING
            entrysheet                  = lv_sheet
          TABLES
            entrysheetaccountassignment = lt_eskn
            entrysheetservices          = lt_esll
            entrysheetsrvaccassvalues   = lt_eskl
            return                      = lt_return.
        IF lv_sheet IS NOT INITIAL.
          IF sy-ucomm = 'ZTEST'.
            gs_alv-test = 'X'.
            CLEAR:gs_alv-icon.
            gs_alv-msg = TEXT-036.
          ENDIF.
          IF sy-ucomm = 'ZRUN'.
            gs_alv-icon = '@08@'.
            gs_alv-msg = TEXT-033 && lv_sheet.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.
          ENDIF.
        ELSE.
          LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
            lv_msg = lv_msg && ls_return-message.
          ENDLOOP.
          gs_alv-icon = '@0A@'.
          gs_alv-msg = TEXT-034 && lv_msg.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        ENDIF.

        MODIFY gt_alv  FROM gs_alv TRANSPORTING test icon msg WHERE ebeln = <fs_alv>-ebeln AND ebelp = <fs_alv>-ebelp.
        CLEAR:gs_alv,ls_header,lt_eskn,lt_esll,lt_eskl,lt_return,lv_serial_no,lv_line_no,lv_extrow,lv_msg.
        IF sy-ucomm = 'ZRUN'.
          WAIT UP TO '0.5' SECONDS.
        ENDIF.
      ENDAT.

      CLEAR:ls_eskn,ls_esll,ls_eskl.
    ENDLOOP.

审批

审批时默认使用创建日期进行过账,跨月审批会报错,需要修改过账日期

ML81N服务条目表创建审批_第5张图片

调用BAPI需要传参过账日期,参考note:1240639

ML81N服务条目表创建审批_第6张图片

    SET PARAMETER ID 'SESPOSTINGDATE' FIELD sy-datum.
    CALL FUNCTION 'BAPI_ENTRYSHEET_RELEASE'
      EXPORTING
        entrysheet     = i_business_key+0(10)
        rel_code       = 'F2'
        no_commit_work = ' '
      TABLES
        return         = gt_return.

取消审批

    CALL FUNCTION 'BAPI_ENTRYSHEET_RESET_RELEASE'
      EXPORTING
        entrysheet = i_business_key+0(10)
        rel_code   = 'F1'
      TABLES
        return     = gt_return.

你可能感兴趣的:(SAP)