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_PO_CHANGE

Former Member
0 Likes
1,879
data(lt_temp) = lt_data. 


LOOP AT lt_temp ASSIGNING FIELD-SYMBOL(<fsl_temp>).
        ls_poheader-po_number = <fsl_temp>-ebeln.
        ls_poheaderx-po_number = 'X'.
        READ TABLE lt_data INTO DATA(ls_data) WITH KEY ebeln = <fsl_temp>-ebeln BINARY SEARCH.
        IF sy-subrc IS INITIAL.
          ls_poitem-po_item = ls_data-ebelp.
          ls_poitem-delete_ind = 'L'.
          ls_poitemx-po_item = 'X'.
          ls_poitemx-delete_ind = 'X'.
          APPEND ls_poitem TO lt_poitem.
          APPEND ls_poitemx TO lt_poitemx.
          CLEAR: <fsl_temp>.
        ENDIF.
    CALL FUNCTION 'BAPI_PO_CHANGE'
      EXPORTING
        purchaseorder = ls_data-ebeln
*       poheader      = ls_poheader
*       poheaderx     = ls_poheaderx
      TABLES
        return        = lt_return
        poitem        = lt_poitem
        poitemx       = lt_poitemx.
endloop.


    READ TABLE lt_return INTO ls_return WITH KEY  type = 'E'.
    IF sy-subrc NE 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ENDIF.<br>

Hello.

I have fetched ebeln,ebelp and other fields using select query into table lt_data using select options given in selection screen.

Now I have multiple purchase orders & multiple line items.Need to call BAPI

"BAPI_PO_CHANGE".

How to fill the purchase order and its corresponding line items and pass it to BAPI.

This is the code i have written.

1 ACCEPTED SOLUTION
Read only

MateuszAdamus
Active Contributor
1,677

Hello vamshisaichand23

Your LT_TEMP has the same data as LT_DATA. So basically your changing all POs item by item. That's not very efficient. Have a look at the code below.

SORT lt_data BY ebeln ebelp.
LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<ls_data>).
  AT NEW ebeln.
    CLEAR:
      lt_return[],
      lt_poitem[],
      lt_poitemx[].
  ENDAT.

  ls_poitem-po_item = <ls_data>-ebelp.
  ls_poitem-delete_ind = 'L'.
  ls_poitemx-po_item = abap_true.
  ls_poitemx-delete_ind = abap_true.
  APPEND ls_poitem TO lt_poitem.
  APPEND ls_poitemx TO lt_poitemx.

  AT END OF ebeln.
    CALL FUNCTION 'BAPI_PO_CHANGE'
      EXPORTING
        purchaseorder = <ls_data>-ebeln
      TABLES
        return        = lt_return
        poitem        = lt_poitem
        poitemx       = lt_poitemx.

    READ TABLE lt_return TRANSPORTING NO FIELDS
      WITH KEY type = 'E'.
    IF sy-subrc <> 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ENDIF.
  ENDAT.
ENDLOOP.
Kind regards,
Mateusz

Hello vamshisaichand23

Your LT_TEMP has the same data as LT_DATA. So basically your changing all POs item by item. That's not very efficient. Have a look at the code below.

SORT lt_data BY ebeln ebelp.
LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<ls_data>).
  AT NEW ebeln.
    CLEAR:
      lt_return[],
      lt_poitem[],
      lt_poitemx[].
  ENDAT.

  ls_poitem-po_item = <ls_data>-ebelp.
  ls_poitem-delete_ind = 'L'.
  ls_poitemx-po_item = abap_true.
  ls_poitemx-delete_ind = abap_true.
  APPEND ls_poitem TO lt_poitem.
  APPEND ls_poitemx TO lt_poitemx.

  AT END OF ebeln.
    CALL FUNCTION 'BAPI_PO_CHANGE'
      EXPORTING
        purchaseorder = <ls_data>-ebeln
      TABLES
        return        = lt_return
        poitem        = lt_poitem
        poitemx       = lt_poitemx.

    READ TABLE lt_return TRANSPORTING NO FIELDS
      WITH KEY type = 'E'.
    IF sy-subrc <> 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ENDIF.
  ENDAT.
ENDLOOP.
Kind regards,
Mateusz
3 REPLIES 3
Read only

KatiNonhebel
Advisor
Advisor
1,677

Hi,

Thank you for visiting SAP Community to get answers to your questions. I am here to help you to get the most out of it.

First of all, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members.

For example you :

  • Can outline what steps you took to find answers (and why they weren't helpful)
  • Can share screenshots of what you've seen/done
  • Can use a descriptive subject line
  • Should also make sure you're using all the appropriate tags, so the right experts can find your question

The more details you provide, the more likely it is that members will be able to assist you

Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question -- but if that happens, you can leave more details in a comment).

Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

Good Luck

Kati - SAP Community Moderator

Read only

MateuszAdamus
Active Contributor
1,678

Hello vamshisaichand23

Your LT_TEMP has the same data as LT_DATA. So basically your changing all POs item by item. That's not very efficient. Have a look at the code below.

SORT lt_data BY ebeln ebelp.
LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<ls_data>).
  AT NEW ebeln.
    CLEAR:
      lt_return[],
      lt_poitem[],
      lt_poitemx[].
  ENDAT.

  ls_poitem-po_item = <ls_data>-ebelp.
  ls_poitem-delete_ind = 'L'.
  ls_poitemx-po_item = abap_true.
  ls_poitemx-delete_ind = abap_true.
  APPEND ls_poitem TO lt_poitem.
  APPEND ls_poitemx TO lt_poitemx.

  AT END OF ebeln.
    CALL FUNCTION 'BAPI_PO_CHANGE'
      EXPORTING
        purchaseorder = <ls_data>-ebeln
      TABLES
        return        = lt_return
        poitem        = lt_poitem
        poitemx       = lt_poitemx.

    READ TABLE lt_return TRANSPORTING NO FIELDS
      WITH KEY type = 'E'.
    IF sy-subrc <> 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ENDIF.
  ENDAT.
ENDLOOP.
Kind regards,
Mateusz
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,677

Solution:

  • Run your program
  • Analyze the error message of the BAPI
  • Correct your program
  • Repeat