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

BAPI_ENTRYSHEET_CREATE Error SE149 Service quantity exceeds quantity in purchase order

carlostol
Explorer
0 Likes
2,001

Hello

I'm having a problem using BAPI_ENTRYSHEET_CREATE using a purchase order with purchase contract (outline agreement) items for creating a service entry sheet acceptance. I use BAPI_PO_GETDETAIL for copying the PO structures into the BAPI_ENTRYSHEET_CREATE structures but I keep getting the error "SE149 Service XXXX: quantity A exceeds quantity B in purchase order".

I tried to create the service entry sheet through tx. ML81N and it works fine. Here's my code:

  <DATA declarations omitted, same as BAPI's>

  CALL FUNCTION 'BAPI_PO_GETDETAIL'

    EXPORTING

      purchaseorder    = i_ebeln

      items            = 'X'

      services         = 'X'

    IMPORTING

      po_header        = ls_pohdr

    TABLES

      po_items         = lt_poitem

      po_item_services = lt_posrv

      return           = lt_poret.

* PO items

  LOOP AT lt_poitem INTO ls_poitem.

    ls_hdr-pckg_no = ls_poitem-pckg_no.

    ls_hdr-short_text = 'Automatic Acceptance'.

    ls_hdr-po_number = ls_poitem-po_number.

    ls_hdr-po_item = ls_poitem-po_item.

    ls_hdr-doc_date = sy-datum.

    ls_hdr-post_date = sy-datum.

    ls_hdr-acceptance = 'X'.

*   Main service lines

    LOOP AT lt_posrv INTO ls_posrv WHERE pckg_no = ls_poitem-pckg_no AND

                                         outl_ind = 'X'.

      MOVE-CORRESPONDING ls_posrv TO ls_srv.

      APPEND ls_srv TO lt_srv.

*     Secondary service lines

      LOOP AT lt_posrv2 INTO ls_posrv2 WHERE pckg_no = ls_posrv-subpckg_no.

        MOVE-CORRESPONDING ls_posrv2 TO ls_srv.

        APPEND ls_srv TO lt_srv.

      ENDLOOP.

    ENDLOOP.

    CALL FUNCTION 'BAPI_ENTRYSHEET_CREATE'

      EXPORTING

        entrysheetheader   = ls_hdr

      IMPORTING

        entrysheet         = ld_entrysheet

      TABLES

        return             = lt_ret

        entrysheetservices = lt_srv.

  ENDLOOP.

********

  Regards,

1 ACCEPTED SOLUTION
Read only

carlostol
Explorer
0 Likes
1,210

Solved.

3 REPLIES 3
Read only

carlostol
Explorer
0 Likes
1,211

Solved.

Read only

Former Member
0 Likes
1,210

Hi,

Could you say please how did you solve it?

I have the same problem.

Thanks so much!

Read only

0 Likes
1,210

Hi,

I hope it's not too late, so here is the final code that solved the problem:

...

   CALL FUNCTION 'BAPI_PO_GETDETAIL'

     EXPORTING

       purchaseorder    = i_ebeln

       items            = 'X'

       services         = 'X'

     IMPORTING

       po_header        = ls_pohdr

     TABLES

       po_items         = lt_poitem

       po_item_services = lt_posrv

       return           = lt_poret.

* PO Items

   LOOP AT lt_poitem INTO ls_poitem.

*     ls_hdr-pckg_no = ls_poitem-pckg_no.

     ADD 1 TO ld_pckg_no.

     ls_hdr-pckg_no = ld_pckg_no.

     ls_hdr-short_text = 'Automatic Acceptance'.

     ls_hdr-po_number = ls_poitem-po_number.

     ls_hdr-po_item = ls_poitem-po_item.

     ls_hdr-doc_date = sy-datum.

     ls_hdr-post_date = i_budat.

     ls_hdr-acceptance = 'X'.

*   Main service lines

     LOOP AT lt_posrv INTO ls_posrv WHERE pckg_no = ls_poitem-pckg_no AND

                                          outl_ind = 'X'.

       ADD 1 TO: ld_line_no,       "manual sequence

                 ld_ext_line.

       MOVE-CORRESPONDING ls_posrv TO ls_srv.

       ls_srv-pckg_no = ls_hdr-pckg_no.

       ls_srv-line_no = ld_line_no.

       ls_srv-ext_line = ld_ext_line.

       ADD 1 TO ld_pckg_no.

       ls_srv-subpckg_no = ld_pckg_no.

       APPEND ls_srv TO lt_srv.

*     Secondary service lines

       LOOP AT lt_posrv2 INTO ls_posrv2 WHERE pckg_no = ls_posrv-subpckg_no.

         CLEAR ls_srv.

         MOVE-CORRESPONDING ls_posrv2 TO ls_srv.

         ls_srv-pckg_no = ld_pckg_no.

         ADD 1 TO ld_line_no.

         ls_srv-line_no = ld_line_no.

         ADD 1 TO ld_ext_line.

         ls_srv-ext_line = ld_ext_line.

         ls_srv-pln_pckg = ls_posrv2-pckg_no. "Original pckg number

         ls_srv-pln_line = ls_posrv2-line_no.     "Original line no.

         CLEAR: ls_srv-con_pckg, ls_srv-con_line.

         APPEND ls_srv TO lt_srv.

       ENDLOOP.  "Sec. srv. lines

     ENDLOOP. "Main srv. lines

     CALL FUNCTION 'BAPI_ENTRYSHEET_CREATE'

       EXPORTING

         entrysheetheader   = ls_hdr

         testrun            = i_test

       IMPORTING

         entrysheet         = ld_entrysheet

       TABLES

         return             = lt_ret

         entrysheetservices = lt_srv.

   ENDLOOP. "PO Items

....

Regards,