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

Read from a table using many conditions

Former Member
0 Likes
1,043

Hi Experts,

I have 2 internal tables

Table 1

col1 col2 col3 col4 ....... col53

Table 2

col1 col2 col3 col4 ....... col53

I need to read from table 1 with the condition that the column 3 to colum 53 of internal table 1 matches with column 3 to column 53 of internal table 2.

Is using 50 where conditions is the only way out is there any other solution.?

Loop it_tab1 into wa_itab1

Read table it_tab2 into wa_tab2 where <condition to be used here>

EndLoop.

Please help.

Hi Experts,

I have 2 internal tables

Table 1

col1 col2 col3 col4 ....... col53

Table 2

col1 col2 col3 col4 ....... col53

I need to read from table 1 with the condition that the column 3 to colum 53 of internal table 1 matches with column 3 to column 53 of internal table 2.

Is using 50 where conditions is the only way out is there any other solution.?

Loop it_tab1 into wa_itab1

Read table it_tab2 into wa_tab2 where <condition to be used here>

EndLoop.

Please help.

10 REPLIES 10
Read only

Former Member
0 Likes
997

Please check what are the Unique fields from "column 3 to column 53", then use the Unique fields only in the Where conditions.

Read only

0 Likes
997

Hi Ashok,

If the data type of all the fields col3 to col53 are CHAR, then you can try using an offset on the work area and compare it.

Regards,

Chen

Read only

agnihotro_sinha2
Active Contributor
0 Likes
997

Hi Ashok,

You can use DO...VARYING statement. the column names have to be in a pattern like COL01,COL02 etc till COL53.

Now inside this DO VARYING use another DO>>VARYING on the 2nd Internal Table.

Although its a bit bulky code, but i think if you cannt fit in CASE ENDCASE, this is the next best solution

ags.

Read only

0 Likes
997

Hi,

Can you show some more light on do.. varying??

Read only

0 Likes
997

Table 1 and table 2 have the same structure.

Column 3 to 53 have the type as char.

The thing is that i need to find whether the rows in table 1 are present in table 2 or not. If yes i need to find how many times it has been present.

I dont have any unique keys.

Column 3 to Column 53 should be common in table 1 and table 2 to call it as repeated row.

Read only

0 Likes
997

Hi

Create two Work areas from field3 to field53 as WA1 & WA2 and use below code.

loop at itab.

move-corresponding itab to wa1.

loop at itab2.

move-corresponding itab2 to wa2.

if wa1 = wa2.

write:/ 'found'.

write:/ sy-tabix.

endif.

endloop.

endloop.

Thanks!

kishore

Read only

0 Likes
997

Hi,

If there are fields other than character try this,

loop at itab1 into wa1.

wa_temp = wa1.

clear: wa_temp-col1, wa_temp-col2, wa_temp-col3.

loop at itab2 into wa2. (or you can use read table too)

wa_temp2 = wa2.

clear: wa_temp2-col1, wa_temp2-col2, wa_temp2-col3.

if wa_temp EQ wa_temp2.

  • Code

else.

  • Code

endif.

Endloop.

endloop.

Edited by: Chen K V on Mar 24, 2010 9:41 AM

Read only

MarcinPciak
Active Contributor
0 Likes
997

For each rown in table 1

- get column names

- concatenate them to form WHERE condition

- use that where condition in LOOP to get corresponding entry from table 2


loop at itab1.
   do.
      "here concatenate to create string like
      "FIELD_NAME = 'FIELD_VALUE' and FIELD_NAME2 = 'FIELD_VALUE2' and ....  
   enddo.

  "find appropriate entry in itab2
   Loop at itab2 where (here_dynamic_condition).
      ..."here you have matching entries
   endloop.
endloop.

Regards

Marcin

Read only

Former Member
0 Likes
997

Hi ashok,

You can't use logical expresions in read statements.

You acn use one read statemnet.afetr that

If sy-subrc = 0 and ...............................................give ur all conditions.

endif.

this will work in logical condition also.

Regards,

Pravin

Read only

Former Member
0 Likes
997

Dear Ashok,

As per my understanding, this is the proposed solution. Kindly check the same if it works.

1) Create a new column for the itab2, say col54.

2) Loop on the itab2 for every entry, and now concatenate fields from col3 to col53, and store it in col54.

3) Now Loop on itab1 into wa1 for every entry.

4) Concatenate all the fields of wa1 from col3 to col53 into a string variable, say lv_string.

5) Now read the itab2 as follows:

Read table itab2 into wa2 with key col54 = lv_string.

6) if sy-subrc eq 0, your search is success.

Hope it helps.

Thank you,

Regards,

Shashi