2013 Sep 04 12:06 PM
Hi experts,
I have 2 DSO containing information about some articles as following:
Table 1
Article | Exisiting |
AAA | True |
BBB | False |
CCC |
Table 2
Article | Exisiting |
AAA | True |
BBB | True |
CCC | False |
In table 1 I have to consolidate information upcoming from the 2 tables and compare the field existing with the following conditions:
For each article:
If one of the values in field existing for an article is initial, then take the value not initial (e.g Article AAA)
If the values contained for the same article are different in the 2 tables then take the value true (e.g Article BBB)
At the end my table 1 will be as this:
Article | Exisiting |
AAA | True |
BBB | True |
CCC | False |
I guess that I have to use a read table with key article statement, but I have issues with abap syntax.
Thanks for your support.
Amine
Hi experts,
I have 2 DSO containing information about some articles as following:
Table 1
Article | Exisiting |
AAA | True |
BBB | False |
CCC |
Table 2
Article | Exisiting |
AAA | True |
BBB | True |
CCC | False |
In table 1 I have to consolidate information upcoming from the 2 tables and compare the field existing with the following conditions:
For each article:
If one of the values in field existing for an article is initial, then take the value not initial (e.g Article AAA)
If the values contained for the same article are different in the 2 tables then take the value true (e.g Article BBB)
At the end my table 1 will be as this:
Article | Exisiting |
AAA | True |
BBB | True |
CCC | False |
I guess that I have to use a read table with key article statement, but I have issues with abap syntax.
Thanks for your support.
Amine
2013 Sep 04 12:44 PM
LOOP AT table1 INTO struc1.
IF struc1-existing = 'False' OR
struc1-existing IS INITIAL.
READ TABLE table2 INTO struc2 WITH KEY article = struc1-article.
IF sy-subrc = 0.
struc1-existing = struc2-existing.
ENDIF.
ENDIF.
ENDLOOP.
The above piece of code should do the trick.
2013 Sep 04 1:15 PM
2013 Sep 04 1:30 PM
Hi Kumar,
I will just add a sort statement by Article before the read table statement to have an efficient code.
Thanks.
Amine
2013 Sep 04 1:31 PM
if you made a sort add a BINARY SEARCH option (for big table)
Fred
2013 Sep 30 8:02 PM
Hi Amine,
Since you are reading the table with a key, you would better create a hashed table with a unique key and then read with table key. The larger the table gets, the higher the performance gain for a hashed table. The rule I use is quite simple :
I don't use binary search. A sorted table works the same and if you forget to sort the table before you use binary search, your result might be wrong. In case you need differents sorts on one table, use secondary indexex.
Regards,
Freek
2013 Sep 04 1:13 PM
Hi Amine,
buy a good Abap book, it's always very easy what you are asking. You will win time !
regards
Fred
2013 Sep 04 1:17 PM
Hi Frederic,
I learned too many intersting things in this forum
Amine
2013 Sep 04 1:30 PM
Hello Amine,
Please try this.
LOOP AT table1 INTO wa_table1 WHERE existing <> ‘true’.
READ TABLE table2 INTO wa_table2 WITH KEY artical = wa_table1-artical.
CHECK sy-subrc = 0
AND wa_table2-existing IS NOT INITIAL.
wa_table1-existing = wa_table2-existing.
MODIFY table1 FROM wa_table1.
ENDLOOP.
Regards
2013 Sep 30 5:22 PM
Hi,
I guess the following code will be more generic.
sort b by x.
loop at a into wa.
read table b into wb where x = wa-x binary search.
if sy-subrc = 0.
wc-x = wb-x.
if wb-y = wa-y.
wc-y = wb-y.
elseif wb-y NE wa-y.
wc-y = 'TRUE'.
elseif NOT wb-y IS INITIAL and wa-y IS INITIAL.
wc-y = wb-y.
elseif NOT wa-y IS INITIAL and wb-y IS INITIAL.
wc-y = wa-y.
endif.
APPEND wc To C.
endif.
Endloop.
2013 Oct 01 5:06 AM
Hi
Select article
existing
from table1 into t_table1.
select article
existing
from table2 into t_table2
for all entries in t_table1
where article = t_table1-article.
loop at t_table1.
here you can use the read statement and check whether the value initial and both exisisting values
are different and set accordingly.
endloop.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |