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

compare multiple variable selections between two internal tables

Former Member
0 Likes
2,600

I am trying to work out the syntax for the following, however i am stumped on the 2nd part of the requirement....

I have two internal tables. and i need to compare the records.

1st, line by line, which i can do, however the 2nd requirement, i need to check a range of data against the same table...

here is an example of the tables:

Internal Table1 has the following records.

TL1

TL2

TL3

TL4

TL5

TL6

Internal table 2 has the following records...

LDOC1 TL1

LDOC1 TL2

LDOC1 TL3

LDOC1 TL7

LDOC2 TL1

LDOC2 TL5

LDOC3 TL6

LDOC3 TL7

but for the 2nd requirement, i have to group the LDOC1 (2, 3) and search for all TL* and report if they all exist, some exist or none exist within the 1st internal table.

so for requirement 1, the answer would be yes (as i can do a read table using the TL*), however i am not sure how i can check "for all entries" for TL1, Tl2, TL3, TL7 and return that only some entries exist.... LDOC1 should return "some", LDOC2 should return "all" and LDOC3 should return "none".

Hopefully that makes sense???

Can someone give me a keyword to investigate as i am not sure the At new would work.... Unless i do an at new and then loop and maybe add the record to a "range" to then compare and log the result as it runs through each result...

so if Itab1 = itab2 then variable = yes. else None.

if variable = yes, and itab1 = itab2 then variable = yes.

if variable = yes and itab1 <> itab2 then variable = some.

would that work?? i am worried about performance too as there could be 1000's of records....

and can i have an "at end" so at end, if variable = yes, then variable = all?

i have written all the rest of the report to get all the data into these tables... i am just a little baffled as to how i can validate and compare the multiple selection.... :o(

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,901

Just trying to understand your question..

>

>LDOC3 should return "none".

How?

LDOC3 TL6 has TL6 which is present in itab1 and it should return some.. right?

Thanks,

Senthil

8 REPLIES 8
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,901

Its hard to mention the logic here.

You can make use of range table for comparison.

Append all the values to the range table.

TL1

TL2

TL3

TL4

TL5

TL6

loop at second itab.

Then a if condition with in statement will do.

if wa-field in r_1.

exists.

endif.

Hope i understood your question properly.

Read only

Former Member
0 Likes
1,902

Just trying to understand your question..

>

>LDOC3 should return "none".

How?

LDOC3 TL6 has TL6 which is present in itab1 and it should return some.. right?

Thanks,

Senthil

Read only

0 Likes
1,901

that was a typo! and for some reason i cannot edit the post....

if TL6 is not in internal table 1...

but i have to return the three answers based upon all the entries in both tables.

Read only

0 Likes
1,901

You cannot edit a post once it has been replied to.

But I can.

If you can tell me the exact wording that is in the post and what you want it changed to, I will take care of that and then get rid of the posts referring to it.

Rob

Read only

0 Likes
1,901

thanks Rob.

in the first internal table1 i wanted the TL6 removed so there is just TL1 - TL5.

i think i have worked out the logic now, but will post the code once i have it working...

it may need some optimisation afterwards, but i can't run before i can walk! 🐵

Read only

0 Likes
1,901

Hi,

It is really confusing :-).. But i have tried to figure out.. may be this could be useful for you.

Internal Table1 has the following records.

TL1

TL2

TL3

TL4

TL5

Internal table 2 has the following records...

LDOC1 TL1

LDOC1 TL2

LDOC1 TL3

LDOC1 TL7

LDOC2 TL1

LDOC2 TL5

LDOC3 TL6

LDOC3 TL7

itab3[] = itab2[]

sort itab3 by field1.

delete adjacent duplicates from itab3 comparing field1.

itab3

LDCO1

LDCO2

LDCO3

loop at itab3.

clear: lv_flag, index, ind.

loop at itab2 where field1 = itab3-field1.

index = index + 1.

read table itab1 with key field1 = itab2-field2.

if sy-subrc NE 0.

lv_flag = 'X'.

ind = ind + 1.

endif.

endloop.

if lv_flag = 'X'.

if ind = index.

lv_val = 'NONE'.

elseif ind NE index.

lv_val = 'SOME'.

endif.

else.

lv_val = 'ALL'.

endif.

"here you can modify itab3 with lv_val in one field, so that you can figure out which is SOME, NONE, ALL

endloop.

Regards,

senthil

Read only

0 Likes
1,901

Thank you Senthil.

this is my working code based upon your suggestion:


  lt_objky1[] = lt_objky[].
  SORT lt_objky1 BY doknr.
  DELETE ADJACENT DUPLICATES FROM lt_objky1 COMPARING doknr.

  LOOP AT lt_objky1 INTO ls_objky1.
    CLEAR: lv_flag, index, ind.
    LOOP AT lt_objky INTO ls_objky WHERE doknr = ls_objky1-doknr.
      index = index + 1.
      READ TABLE lt_task_list WITH KEY objky = ls_objky-objky TRANSPORTING NO FIELDS.
      IF sy-subrc NE 0.
        lv_flag = 'X'.
        ind = ind + 1.
      ENDIF.
    ENDLOOP.

    IF lv_flag = 'X'.
      IF ind = index.
        lv_value = 'NONE'.
      ELSEIF ind NE index.
        lv_value = 'SOME'.
      ENDIF.
    ELSE.
      lv_value = 'ALL'.
    ENDIF.

    LOOP AT lt_objky INTO ls_objky WHERE doknr = ls_objky1-doknr.
      ls_objky-selection = lv_value.
      MODIFY lt_objky FROM ls_objky.
    ENDLOOP.

  ENDLOOP. 

Read only

Former Member
0 Likes
1,901

This code may be can help you


  DATA: ZM_MEN(5) TYPE C,
        ZM_LD(5)  TYPE C.

  LOOP AT TI_ITAB2.
   IF ZM_LD IS INITIAL OR ZM_LD NE TI_ITAB2-LD.
    IF NOT ZM_MEN IS INITIAL.
     CLEAR: TI_ITAB3.
     TI_ITAB3-LD    = ZM_LD.
     TI_ITAB3-ZMEN  = ZM_MEN.
     APPEND TI_ITAB3.
     CLEAR: ZM_MEN.
    ENDIF.

    ZM_LD = TI_ITAB2-LD.
    ZM_MEN = 'ZERO'.
   ENDIF. " IF ZM_LD IS INITIAL OR ZM_LD NE TI_ITAB2-LD

   READ TABLE TI_ITAB1 WITH KEY TL = TI_ITAB2-TL.

   IF SY-SUBRC EQ 0.
    IF ZM_MEN EQ 'ZERO'.
     ZM_MEN = 'ALL'.
    ENDIF. " IF ZM_MEN EQ 'ZERO'
   ELSEIF SY-SUBRC EQ 4 AND ZM_MEN EQ 'ALL'.
    ZM_MEN = 'SOME'.
   ENDIF. " IF SY-SUBRC EQ 0
  ENDLOOP. " LOOP AT ITAB2