Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problems with BAPI for ML81N

Former Member
0 Likes
668

Hello guys! In this moment I need to implement a BAPI for T ML81N. I am to use the BAPI BAPI_ENTRYSHEET_CREATE for this but I hava a problem.
1. I only can to create a service entry for a PO.
2. I can not to add any position for the service entry created before.
3. With all this I only can to get a service entry for a PO with status red.

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_header-po_number   = '4500088939'.     
  ls_header-po_item     = '00010'.           
  ls_header-short_text  = 'Text'. 
  ls_header-pckg_no     = '0000996718'.      
  ls_header-acceptance  = 'X'.               
  ls_header-doc_date    = '20160101'.       
  ls_header-post_date   = '20160101'.       

  ls_service-pckg_no    = '0000996718'.     
  ls_service-line_no    = '1'.              
  ls_service-outl_ind   = 'X'.              
  ls_service-subpckg_no = '2'.              
  APPEND ls_service TO lt_service.
  CLEAR ls_service.


  ls_service-pckg_no    = '2'.               
  ls_service-line_no    = '10'.              
  ls_service-short_text = 'Text'.   
  ls_service-quantity   = '1.00'.           
  ls_service-base_uom   = 'UN'.             
  ls_service-pln_line   = '0000000010'.      
  ls_service-gr_price   = '10.000'.          
  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 sy-subrc NE 0.
* Check for abend message
    READ TABLE lt_return INTO ls_return WITH KEY type = 'A'.
* Check sy-subrc after read
    IF sy-subrc 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_return-id
          no        = ls_return-number
          v1        = ls_return-message_v1
          v2        = ls_return-message_v2
          v3        = ls_return-message_v3
          v4        = ls_return-message_v4
        IMPORTING
          msg       = lv_message
        EXCEPTIONS
          not_found = 1
          OTHERS    = 2.
* Check sy-subrc after calling a FM
      IF sy-subrc NE 0.
        lv_message = ls_return-message.
      ENDIF.
    ENDIF.
  ELSE.
    CLEAR lv_lblni.
* Formating the Message
    CALL FUNCTION 'FORMAT_MESSAGE'
      EXPORTING
        id        = ls_return-id
        no        = ls_return-number
        v1        = ls_return-message_v1
        v2        = ls_return-message_v2
        v3        = ls_return-message_v3
        v4        = ls_return-message_v4
      IMPORTING
        msg       = lv_message
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.
* Check sy-subrc after calling a FM
    IF sy-subrc NE 0.
      lv_message = ls_return-message.
    ENDIF.


  ENDIF.


ENDFUNCTION.
0 REPLIES 0