Skip to Content

In this blog lets discuss a scenario on how to use BAPI  “BAPI_ENTRYSHEET_CREATE”.

This BAPI is used to Create Service Sheets via ML81N.

These Service  sheets will be created for Service Purchase orders created Via ME21N.This is the case where the limit will be set always.

The following information needs to be passed to the BAPI for the successful creation of Service entry sheet.

DATA: ls_header      TYPE bapiessrc,
          ls_service     TYPE bapiesllc,
          ls_return      TYPE bapiret2,
          lt_return      TYPE STANDARD TABLE OF bapiret2 INITIAL SIZE 0,
          lt_service     TYPE STANDARD TABLE OF bapiesllc INITIAL SIZE 0,

          lv_lblni   TYPE lblni,

          lv_message TYPE char70.

* Populate Header
  ls_headerpo_number  ” PO Number
  ls_headerpo_item      ” Item Number
  ls_headershort_text   ” Short Description
  ls_headerpckg_no    = ‘1’. ” Header Package Number
  ls_headeracceptance ‘X’ . ” Acceptance Indicator
  ls_headerdoc_date   = sydatum.” Document Date
  ls_headerpost_date  = sydatum.” Posting Date

* Populate Service Entry Details
* Populate Header Package
  ls_servicepckg_no  = ‘1’ . ” Same as Header Package Number
  ls_serviceline_no    ‘1’.   ” Line Number
  ls_serviceoutl_ind   = ‘X’.” Indicator: Outline line
  ls_servicesubpckg_no =’2′.” Sub Package number
  APPEND ls_service TO lt_service.
  CLEAR ls_service.

  ls_servicepckg_no    = ‘2’.”  Same as Sub Package number
  ls_serviceline_no      = ’10’. ” Line Number
  ls_serviceshort_text   ” Short Description
  ls_servicequantity    = ‘1’.” Quantity
  ls_servicebase_uom   ” UOM
  ls_servicegr_price      ” Actual settlement Value
  APPEND ls_service TO lt_service.
  CLEAR ls_service.

* Call BAPI for creating service entry sheet
  CALL FUNCTION ‘BAPI_ENTRYSHEET_CREATE’
    EXPORTING
      entrysheetheader   = ls_header
    IMPORTING
      entrysheet             = lv_lblni
    TABLES
      entrysheetservices = lt_service
      return                    = lt_return.

   * Check for error message
  READ TABLE lt_return INTO ls_return WITH KEY type = ‘E’.
* Check sy-subrc after read
  IF sysubrc NE 0.
* Check for abend message
    READ TABLE lt_return INTO ls_return WITH KEY type = ‘A’.
* Check sy-subrc after read
    IF sysubrc NE 0.
* Successful creation of entry sheet
      CONCATENATE ‘Entry Sheet #’  lv_lblni ‘posted successfully’ INTO lv_message.
    ELSE.
      CLEAR lv_lblni.
* Formating the Message
      CALL FUNCTION ‘FORMAT_MESSAGE’
        EXPORTING
          id        = ls_returnid
          no        = ls_returnnumber
          v1        = ls_returnmessage_v1
          v2        = ls_returnmessage_v2
          v3        = ls_returnmessage_v3
          v4        = ls_returnmessage_v4
        IMPORTING
          msg       = lv_message
        EXCEPTIONS
          not_found = 1
          OTHERS    = 2.
* Check sy-subrc after calling a FM
      IF sysubrc NE 0.
        lv_message = ls_returnmessage.
      ENDIF.” IF sy-subrc NE 0.
    ENDIF.
  ELSE.
    CLEAR lv_lblni.
* Formating the Message
    CALL FUNCTION ‘FORMAT_MESSAGE’
      EXPORTING
        id        = ls_returnid
        no        = ls_returnnumber
        v1        = ls_returnmessage_v1
        v2        = ls_returnmessage_v2
        v3        = ls_returnmessage_v3
        v4        = ls_returnmessage_v4
      IMPORTING
        msg       = lv_message
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.
* Check sy-subrc after calling a FM
    IF sysubrc NE 0.
      lv_message = ls_returnmessage.
    ENDIF.

  ENDIF.

The FM ‘BAPI_ENTRYSHEET_RELEASE‘ can be used to release.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply