cancel
Showing results for 
Search instead for 
Did you mean: 

Abap : Loop at bapi function module not working

middleeast
Explorer
309

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/...
View Entire Topic
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!