LOOP in einem LOOP

Getting started ... Alles für einen gelungenen Start.
5 Beiträge • Seite 1 von 1
5 Beiträge Seite 1 von 1

LOOP in einem LOOP

Beitrag von Bjuti (ForumUser / 45 / 14 / 0 ) »
Hallo zusammen,

folgende Ausgangssituation:

Tabelle1:
X ______Y__________Z
1 | 01.10.2012 |
1 | 02.11.2012 |
2 | 03.10.2012 |
3 | 08.08.2011 |

Tabelle2:
A______B___________C_______D
1 | 20.09.2012 | 02.10.2012 | V1
1 | 21.10.2012 | 12.12.2012 | V2
3 | 21.07.2012 | 12.12.2012 | V3

Code: Alles auswählen.

  LOOP AT Tabelle1 ASSIGNING <Tabelle1>.
    LOOP AT Tabelle2 ASSIGNING <Tabelle2>.

    IF  <Tabelle1>-X = <Tabelle2>-A
    AND <Tabelle1>-Y BETWEEN <Tabelle2>-B AND <Tabelle2>-C.

     MOVE: <Tabelle2>-D        TO <Tabelle1>-Z,

    ENDIF.
    ENDLOOP.
  ENDLOOP.
Ergebnis:
X ______Y_______Z
1 | 01.10.2012 | V1
1 | 02.11.2012 | V2
2 | 03.10.2012 |
3 | 08.08.2011 | V3

Nur leider ist dies nicht sehr performant. Habt ihr eine Idee? Die Tabellen sind interne Tabellen.

VG Bjuti

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Re: LOOP in einem LOOP

Beitrag von JHM (Top Expert / 1225 / 2 / 204 ) »
Bjuti hat geschrieben:Nur leider ist dies nicht sehr performant. Habt ihr eine Idee? Die Tabellen sind interne Tabellen.
Entweder das füllen der ITABs ändern.

Oder beim 2. Loop die IF-Abfrage als LOOP WHERE umbauen.

Wenn es ganz viele Daten sind, den Index des ersten X-Eintrags per READ TABLE BINARY SEARCH bestimmen und dann mit WHERE und FROM INDEX im 2. LOOP arbeiten.
Gruß Hendrik

Re: LOOP in einem LOOP

Beitrag von jensschladitz (Specialist / 417 / 0 / 56 ) »
Sali,

auch recht performant

REPORT zjens_loop.

TYPES: BEGIN OF ty_table1,
zahl TYPE i,
datum1 TYPE sy-datum,
value TYPE char2.
TYPES: END OF ty_table1.

TYPES: BEGIN OF ty_table,
zahl TYPE i,
datum1 TYPE sy-datum,
datum2 TYPE sy-datum,
value TYPE char2,
datum3 TYPE RANGE OF sy-datum.
TYPES: END OF ty_table.

DATA r_datum TYPE RANGE OF sy-datum.
DATA it_table TYPE STANDARD TABLE OF ty_table1.
DATA ref_table TYPE REF TO ty_table1.
DATA it_table_2 TYPE STANDARD TABLE OF ty_table.
DATA ref_table_2 TYPE REF TO ty_table.
DATA ls_datum LIKE LINE OF r_datum.
DATA ref_datum3 LIKE REF TO ls_datum.

START-OF-SELECTION.

*Tabelle1:
*X ______Y__________Z
*1 | 01.10.2012 |
*1 | 02.11.2012 |
*2 | 03.10.2012 |
*3 | 08.08.2011 |



APPEND INITIAL LINE TO it_table REFERENCE INTO ref_table.
ref_table->zahl = 1.
ref_table->datum1 = '20121001'.
APPEND INITIAL LINE TO it_table REFERENCE INTO ref_table.
ref_table->zahl = 1.
ref_table->datum1 = '20121102'.
APPEND INITIAL LINE TO it_table REFERENCE INTO ref_table.
ref_table->zahl = 2.
ref_table->datum1 = '20121003'.
APPEND INITIAL LINE TO it_table REFERENCE INTO ref_table.
ref_table->datum1 = '20120808'.
ref_table->zahl = 3.



*1 | 20.09.2012 | 02.10.2012 | v1
APPEND INITIAL LINE TO it_table_2 REFERENCE INTO ref_table_2.
ref_table_2->zahl = 1.
ref_table_2->datum1 = '20120920'.
ref_table_2->datum2 = '20121002'.
ref_table_2->value = 'V1'.
ls_datum = 'IBT2012092020121002'.
APPEND ls_datum TO ref_table_2->datum3.

*1 | 21.10.2012 | 12.12.2012 | v2
APPEND INITIAL LINE TO it_table_2 REFERENCE INTO ref_table_2.
ref_table_2->zahl = 1.
ref_table_2->datum1 = '20121021'.
ref_table_2->datum2 = '20121212'.
ref_table_2->value = 'V2'.
ls_datum = 'IBT2012102120121212'.
APPEND ls_datum TO ref_table_2->datum3.

*3 | 21.07.2012 | 12.12.2012 | v3
APPEND INITIAL LINE TO it_table_2 REFERENCE INTO ref_table_2.
ref_table_2->zahl = 3.
ref_table_2->datum1 = '20120721'.
ref_table_2->datum2 = '20121212'.
ref_table_2->value = 'V3'.
ls_datum = 'IBT2012072120121212'.
APPEND ls_datum TO ref_table_2->datum3.

LOOP AT it_table REFERENCE INTO ref_table.
LOOP AT it_table_2 REFERENCE INTO ref_table_2 WHERE zahl = ref_table->zahl.
CHECK ref_table->datum1 IN ref_table_2->datum3[].
ref_table->value = ref_table_2->value.
ENDLOOP.
ENDLOOP.

LOOP AT it_table REFERENCE INTO ref_table.
WRITE: / ref_table->zahl, ref_table->datum1,ref_table->value.
ENDLOOP.

END-OF-SELECTION.

Gruss
thanks Jens

Re: LOOP in einem LOOP

Beitrag von Dele (Specialist / 307 / 4 / 47 ) »
gemäß Online Hilfe zum Loop:
While with standard tables all rows of the internal table are checked for the logical expression of the WHERE- addition, with sorted tables and hash tables (as of Release 7.0) you can achieve optimized access by checking that at least the beginning part of the table key in sorted tables and the entire table key in hash tables is equal in the logical expression through queries linked with AND. Optimization also takes effect if the logical expression contains other queries linked with AND with arbitrary operators.
sollte folgendes coding auch recht performant sein:

Code: Alles auswählen.

data: tabelle2 type sorted table of "table type"
                    with non-unique key a b c.

  LOOP AT Tabelle1 ASSIGNING <Tabelle1>.
    LOOP AT Tabelle2 ASSIGNING <Tabelle2> 
         where a =  <Tabelle1>-X
           and b <= <Tabelle1>-Y
           and c => <Tabelle1>-Y.

     MOVE: <Tabelle2>-D        TO <Tabelle1>-Z.

    ENDLOOP.
  ENDLOOP.

Re: LOOP in einem LOOP

Beitrag von Bjuti (ForumUser / 45 / 14 / 0 ) »
Huhu,

danke für eure Hilfe.

Wir haben das Konzept dahingehend umgestellt das ich nun keinen LOOP in einem LOOP mehr benötige. :)

VG

Seite 1 von 1

Über diesen Beitrag


Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Aktuelle Forenbeiträge

Feldroutine ADSO Transformation
vor einer Woche von codemaster1 2 / 74931
Stücklisten
vor einer Woche von Selma.schwarz 1 / 76424
Belege
vor einer Woche von Selma.schwarz 1 / 74344

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Vergleichbare Themen

Loop
von Kai999 » 27.07.2017 16:15
LOOP AT
von cuncon » 01.02.2018 09:28
ein loop
von user2008 » 19.07.2017 10:50
Loop-Problem
von TobiB » 17.12.2007 13:15

Aktuelle Forenbeiträge

Feldroutine ADSO Transformation
vor einer Woche von codemaster1 2 / 74931
Stücklisten
vor einer Woche von Selma.schwarz 1 / 76424
Belege
vor einer Woche von Selma.schwarz 1 / 74344

Unbeantwortete Forenbeiträge

Stücklisten
vor einer Woche von Selma.schwarz 1 / 76424
Belege
vor einer Woche von Selma.schwarz 1 / 74344