Application Development 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: 

loop within loop optimization

Former Member
0 Kudos

Dear friends,

LOOP AT i_po.

LOOP AT i_eban WHERE banfn = i_po-banfn

AND bnfpo = i_po-bnfpo.

i_prpo-matnr = i_eban-matnr.

i_prpo-txz01 = i_eban-txz01.

i_prpo-banfn = i_eban-banfn.

i_prpo-bnfpo = i_eban-bnfpo.

i_prpo-badat = i_eban-badat.

i_prpo-menger = i_eban-menge.

i_prpo-meinsr = i_eban-meins.

i_prpo-ebeln = i_po-ebeln.

i_prpo-ebelp = i_po-ebelp.

i_prpo-bedat = i_po-bedat.

i_prpo-menge = i_po-menge.

i_prpo-lifnr = i_po-lifnr.

APPEND i_prpo.

CLEAR i_prpo.

ENDLOOP.

IF sy-subrc <> 0.

  • only PO details

i_prpo-ebeln = i_po-ebeln.

i_prpo-ebelp = i_po-ebelp.

i_prpo-bedat = i_po-bedat.

i_prpo-menge = i_po-menge.

i_prpo-lifnr = i_po-lifnr.

APPEND i_prpo.

CLEAR i_prpo.

ENDIF.

ENDLOOP.

is there a way as 2 how i could remove loop within loop and still get the same o/p..

Please guide me.

Regards,

Essam

5 REPLIES 5

Former Member
0 Kudos

Hi,

Do the logic in reverse way.

Loop at i_EBAN

Read table I_EKKO where banfn = i_eban-banfn bnfpo = i_eban-bnfpo.

Endloop.

This is how you have to develope the logic.

Thanks

Pavan

ThomasZloch
Active Contributor
0 Kudos

or fill your internal table i_prpo in one go by selecting on EKPO with a join on EKKO and an outer join on EBAN, avoiding i_po, i_eban and the "loop inside loop" altogether.

Former Member
0 Kudos

Hi friend,

Try this it will surely help you,

Don't use loop under loop it will effect your program.

&----


*& Report ZINTRPT004

*&

&----


REPORT ztmp.

Tables: Equi, Ihpa, Kna1.

DATA: BEGIN OF it_Equi OCCURS 0,

EQUNR TYPE Equi-EQUNR,

ERDAT TYPE Equi-ERDAT,

HERST TYPE Equi-HERST,

KUNDE TYPE Equi-KUNDE,

OBJNR TYPE Equi-OBJNR,

SERNR TYPE Equi-SERNR,

END OF it_Equi.

DATA: BEGIN OF it_Ihpa OCCURS 0,

OBJNR TYPE Ihpa-OBJNR,

PARVW TYPE Ihpa-PARVW,

OBTYP TYPE Ihpa-OBTYP,

PARNR TYPE Ihpa-PARNR,

END OF it_Ihpa.

DATA: BEGIN OF it_Kna1 OCCURS 0,

KUNNR TYPE Kna1-KUNNR,

NAME1 TYPE Kna1-NAME1,

NAME2 TYPE Kna1-NAME2,

ORT01 TYPE Kna1-ORT01,

PSTLZ TYPE Kna1-PSTLZ,

ADRNR TYPE Kna1-ADRNR,

END OF it_Kna1.

DATA: BEGIN OF it_FINAL OCCURS 0,

ERDAT TYPE Equi-ERDAT,

EQUNR TYPE Equi-EQUNR,

HERST TYPE Equi-HERST,

OBJNR TYPE Equi-OBJNR,

SERNR TYPE Equi-SERNR,

KUNDE TYPE Equi-KUNDE,

NAME1 TYPE Kna1-NAME1,

NAME2 TYPE Kna1-NAME2,

ORT01 TYPE Kna1-ORT01,

PSTLZ TYPE Kna1-PSTLZ,

ADRNR TYPE Kna1-ADRNR,

END OF it_FINAL.

DATA: w_index LIKE sy-index,

WA_EQUI LIKE IT_EQUI,

WA_IHPA LIKE IT_IHPA,

WA_KNA1 LIKE IT_KNA1,

WA_FINAL LIKE IT_FINAL.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : S_ERDAT FOR Equi-ERDAT Obligatory.

SELECTION-SCREEN END OF BLOCK b1.

SELECT EQUNR ERDAT HERST KUNDE OBJNR SERNR

FROM Equi

INTO TABLE it_Equi

WHERE ERDAT in S_ERDAT.

IF NOT IT_EQUI[] IS INITIAL.

SELECT OBJNR PARVW OBTYP PARNR

FROM Ihpa

INTO TABLE it_Ihpa

FOR ALL ENTRIES IN it_Equi

WHERE PARVW = 'SP'

and OBJNR = it_Equi-OBJNR.

IF NOT IT_IHPA[] IS INITIAL.

SELECT KUNNR NAME1 NAME2 ORT01 PSTLZ ADRNR

FROM Kna1

INTO TABLE it_Kna1

FOR ALL ENTRIES IN it_Equi

WHERE KUNNR = it_Equi-KUNDE.

ENDIF.

ENDIF.

LOOP AT IT_EQUI INTO WA_EQUI.

WA_FINAL-EQUNR = WA_EQUI-EQUNR.

WA_FINAL-ERDAT = WA_EQUI-ERDAT.

WA_FINAL-HERST = WA_EQUI-HERST.

WA_FINAL-KUNDE = WA_EQUI-KUNDE.

READ TABLE IT_IHPA INTO WA_IHPA WITH KEY PARVW = 'SP'

OBJNR = WA_Equi-OBJNR.

WA_FINAL-OBJNR = WA_IHPA-OBJNR.

READ TABLE it_Kna1 INTO WA_KNA1 WITH KEY KUNNR = WA_Equi-KUNDE.

WA_FINAL-NAME1 = WA_KNA1-NAME1.

APPEND WA_FINAL TO IT_FINAL.

IF SY-SUBRC = 0.

ENDIF.

ENDLOOP.

raymond_giuseppi
Active Contributor
0 Kudos

You may keep the loop within loop, but you must declare the EBAN table as a SORTED type table with the two keys used to. that would improve performance on big amount of data.

Regards

Former Member
0 Kudos

Hi pal. Here are some steps that may help you:

- Sort both your internal tables by the main keys that will link them.

- Choose the main table (the straighter course for the data you want), in this case I guess it may be I_PO.

- Loop the main table.

- Move the desired values from the main table to the destiny.

- Read the data on the secondary table using the key fields you sorted before. For that you can use the READ TABLE command. As you sorted the tables you can use the BINARY SEARCH clause, which will make it seek faster.

- Move the desired values from the secondary table to the destiny.

Hope it can help!