cancel
Showing results for 
Search instead for 
Did you mean: 

Abap : Loop at bapi function module not working

middleeast
Explorer
295

Hello i have a problem with loop,, date retrieve 1 time at first tabx and when debugging i see tabx not going to tabx 2 or 3 and fm not retrieve any data really i cant understand.. image for code attched

REPORT YEH_TEST_BAPI.
TABLES : EKKo.
  DATA: lo_msg_handler     TYPE REF TO cl_message_handler_mm.
DATA :
      LT_PO_DETAILS TYPE TABLE OF BAPIEKBES,
      LS_PO_DETAILS TYPE BAPIEKBES,
      T_RETURN      TYPE TABLE OF BAPIRET2,
      W_RETURN      LIKE BAPIRET2.

DATA counter TYPE i.
SELECT-OPTIONS:
PO_NO FOR EKKO-EBELN NO INTERVALS.

START-OF-SELECTION .
LOOP at PO_NO.
  CALL FUNCTION 'BAPI_PO_GETDETAIL1'
  EXPORTING
    PURCHASEORDER    = PO_NO-LOW
  TABLES
    POHISTORY_TOTALS = LT_PO_DETAILS
    RETURN           = T_RETURN.

  IF T_RETURN IS INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT = 'X'.
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.
   cl_demo_output=>display( LT_PO_DETAILS ).
ENDLOOP.
Sandra_Rossi
Active Contributor
0 Kudos
Please post code as text instead of image, and use the buttons "..." and "</>" to display your code nicely. See how to do it here: https://community.sap.com/t5/questions-about-sap-websites/how-to-post-code-in-sap-community-gt-2024/...

Accepted Solutions (0)

Answers (2)

Answers (2)

jakob_steen-petersen
Active Participant

Some things here:

 

1. You should not loop at select-options. 
2. You don’t need BAPI_TRANSACTION_COMMIT… when using a read bapi. These are only for create basis…

Try something like this:

select * from ekko
into table @DATA(lt_ekko)
where ebeln in @PO_no.

loop at lt_ekko into data(ls_ekko).

“Read details with bapi here….

endloop.

middleeast
Explorer
0 Kudos
thanks jakob , i tried your solution but the same problem , Although when i use any FM everything working OK
jakob_steen-petersen
Active Participant
0 Kudos

Actually i am not sure what your problem is? You say “not going indx 2 and 3”?

Do you mean not looping to next entry in itab?

It’s hard to help when we only see subset of code!

middleeast
Explorer
0 Kudos

sorry for late answer , I edit my Question with Add Code ,

Yes my problem is not going to tabx 2 and 3 ..... 

Bapi fm just retrieve the first index , second and third and .... not retrieve any data in table .  

jakob_steen-petersen
Active Participant
0 Kudos
Okay - as said; your code is wrong. Looping at PO_NO is not correct. But if you insist the let’s start:
jakob_steen-petersen
Active Participant
0 Kudos
How many entries do you se in PO_NO (in debugger)?
jakob_steen-petersen
Active Participant
0 Kudos

Hi again

I have no idea what you are trying to get with you code? But if i should do it i would do it like this (except it makes no sence to print multiple POs like this):

*&---------------------------------------------------------------------*
*& Report ZJSP_TEST_IO
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zjsp_test_io.

TABLES : ekko.
DATA: lo_msg_handler     TYPE REF TO cl_message_handler_mm.
DATA :
  lt_po_details TYPE TABLE OF bapiekbes,
  ls_po_details TYPE bapiekbes,
  lt_items      TYPE bapimepoitem_tp,
  t_return      TYPE TABLE OF bapiret2,
  w_return      LIKE bapiret2.

DATA counter TYPE i.
SELECT-OPTIONS:
po_no FOR ekko-ebeln NO INTERVALS.

START-OF-SELECTION .

  SELECT * FROM ekko
    INTO TABLE @DATA(lt_ekko)
    WHERE ebeln IN @PO_no
    AND   bstyp EQ 'F'.


  LOOP AT lt_ekko INTO DATA(ls_ekko).
    CALL FUNCTION 'BAPI_PO_GETDETAIL1'
      EXPORTING
        purchaseorder    = ls_ekko-ebeln
      TABLES
        poitem           = lt_items
        pohistory_totals = lt_po_details
        return           = t_return.

    cl_demo_output=>display( lt_items ).
    cl_demo_output=>display( lt_po_details ).


  ENDLOOP.


Also: be aware that pohistory_totals will only contain data if there acually is any (Goods Receipts or likely). A brand new PO would have nothing in this table...