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

Table maintenance in a loop?

Former Member
0 Likes
634

I have a situation that I'm having trouble resolving.

I'm looping through this list, each time getting a table of keys and offsets. But each time I loop through it, I only want to retain the records that are common and get rid of new or unique records.

I'm thinking the code should be something like:

Loop at itab1.
  call function ...
     exporting
        e_result = reference []
  if count = 0.
     master_list = reference.
     count = count + 1.
  ELSE.
     DELETE FROM MASTER_LIST WHERE RECORDS DON'T MATCH UP IN reference. ???
  ENDIF.
ENDLOOP.

Please help out,

Natasha

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
599

Hi Natasha, when i read your problem i understand that you wanna do this:

Loop at itab1.
  call function ...
     exporting
        e_result = reference []
  if count = 0.
     master_list = reference.
     count = count + 1.
  ELSE.

**-
 loop at master_list.
  read table reference with key FIELD = master_list-field.
   if sy-subrc <> 0.
    delete master_list.
   endif.
 endloop.
**-

  ENDIF.
ENDLOOP.

Is this what are you looking for?

Regards,

Carlos A. Lerzundy

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
599

Not the prettiest way of doing it, but here is a sample program.



report zrich_0002 .


data: begin of itab occurs 0,
      field1 type c,
      field2 type c,
      field3 type c,
      end of itab.


start-of-selection.


  itab-field1 = 'A'.
  itab-field2 = 'B'.
  itab-field3 = 'C'.
  append itab.
  append itab.

  itab-field1 = 'C'.
  itab-field2 = 'D'.
  itab-field3 = 'E'.
  append itab.

  itab-field1 = 'F'.
  itab-field2 = 'G'.
  itab-field3 = 'H'.
  append itab.
  append itab.


  data: counter type i.

  loop at itab.

    clear counter.
    loop at itab where field1 = itab-field1.
      counter =  counter + 1.
    endloop.

    if counter =  1.
      delete itab.
      continue.
    endif.

  endloop.

  check sy-subrc  = 0.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
600

Hi Natasha, when i read your problem i understand that you wanna do this:

Loop at itab1.
  call function ...
     exporting
        e_result = reference []
  if count = 0.
     master_list = reference.
     count = count + 1.
  ELSE.

**-
 loop at master_list.
  read table reference with key FIELD = master_list-field.
   if sy-subrc <> 0.
    delete master_list.
   endif.
 endloop.
**-

  ENDIF.
ENDLOOP.

Is this what are you looking for?

Regards,

Carlos A. Lerzundy

Read only

0 Likes
599

How can I enable the read to check multiple fields.

Both reference and master_list have fields KEY and OFFSET.

So when I want to check that both fields are equal in the condition, how do I do this (syntactically)?

I tried:

read: table reference with key key = itab_mstr-key, OFS = itab_mstr-OFS.  

Read only

0 Likes
599
read table reference with key key = itab_mstr-key
                              OFS = itab_mstr-OFS.

I think that I have misunderstood your requirment.

Regards,

Rich Heilman

Read only

0 Likes
599

You will do


read table reference with key key = itab_mstr-key
                              OFS = itab_mstr-OFS.