2013 Jul 16 11:47 AM
Hi guys,
My question is maybe simple, but I am working at SAP only few days, so any your help will be very welcome.
Situation:
I have function module, that can match telephone number to operator. You fill gab with telephone number in parameters screen and your output is table, when you can see, that your number is under operator 202 (T-Mobile for example).
I have made a copy of this function module and made some changes in the script.
So now, I would like to compare these two modules in one report to see, if it works on the same way.
My idea:
1) Have parameters screen with range of telephone numbers.
2) Then, I would like to call module 1, generate output table A (I mean list of tel. numbers with operator codes)
3) Call module 2 and generate output table B
4) Compare these 2 outputs and generate final output table with differencies (if system will found any).
What is the best way to do it? Do you have any link to similar example? I have tried to found, but didnt found similar.
Thank you a lot in advance,
Dimitrij
2013 Jul 16 2:20 PM
Hi,
You can compare two tables just like any other variable.
If these are your output tables and work areas
itab1, wa_itab1 like line of itab
itab2, wa_itab2 like line of itab
itab_final.
* First sort both tables.
sort itab1 by phoneno
sort itab2 by phoneno
if itab1[] EQ itab2[].
write 😕 'Results are same'.
else.
loop at itab1 into wa_itab1
READ TABLE itab2 INTO wa_itab2 WITH KEY phoneno = wa_itab1-phoneno'.
* Case 1 - Phone nos in itab1 not there in itab2
if sy-subrc ne = 0.
append wa_itab1 to itab_final.
* case 2 - Phone nos in both tables but with differnt operators.
elseif wa_itab1 ne waItab2
append wa_itab1 to itab_final.
append wa_itab2 to itab_final.
endif.
clear wa_itab1, wa_itab2,
endloop.
loop at itab2 into wa_itab2.
READ TABLE itab1 INTO wa_itab1 WITH KEY phoneno = wa_itab1-phoneno.
*case 3 - phone nos in itab2 not in itab1
if sy-subrc ne = 0.
append wa_itab2 to itab_final.
endif.
clear : wa_itab1, wa_itab2.
endloop.
write 😕 ''results are not same'.
Loop at itab_final into wa_final.
write:/ wa_final.
endloop.
endif.
2013 Jul 16 11:55 AM
Hi,
Your logic sounds good. Loop at one internal table, read the other internal table based on some condition by pasing the values read in loop of first internal table.
Now compare the work areas.. if any differences are found, then write it to the user.
Regards,
Kartik
2013 Jul 16 2:00 PM
2013 Jul 16 3:21 PM
Hi Dimitrij
Your logic sounds good
Step1-You may build two internal tables, A and B lets say
Step 2- loop and compare the two based on a primary key and build the diffrences table call it C.
These tables can be of same type
You can use hash table to have unıque or you can have a normal standard table
sort the internal table and do a binary search will give you fast access.
loop at a
read table b with key x = a.x.
if sy-subrc eq 0.
else.
append initial line to C
endif.
endloop.
2013 Jul 16 2:20 PM
Hi,
You can compare two tables just like any other variable.
If these are your output tables and work areas
itab1, wa_itab1 like line of itab
itab2, wa_itab2 like line of itab
itab_final.
* First sort both tables.
sort itab1 by phoneno
sort itab2 by phoneno
if itab1[] EQ itab2[].
write 😕 'Results are same'.
else.
loop at itab1 into wa_itab1
READ TABLE itab2 INTO wa_itab2 WITH KEY phoneno = wa_itab1-phoneno'.
* Case 1 - Phone nos in itab1 not there in itab2
if sy-subrc ne = 0.
append wa_itab1 to itab_final.
* case 2 - Phone nos in both tables but with differnt operators.
elseif wa_itab1 ne waItab2
append wa_itab1 to itab_final.
append wa_itab2 to itab_final.
endif.
clear wa_itab1, wa_itab2,
endloop.
loop at itab2 into wa_itab2.
READ TABLE itab1 INTO wa_itab1 WITH KEY phoneno = wa_itab1-phoneno.
*case 3 - phone nos in itab2 not in itab1
if sy-subrc ne = 0.
append wa_itab2 to itab_final.
endif.
clear : wa_itab1, wa_itab2.
endloop.
write 😕 ''results are not same'.
Loop at itab_final into wa_final.
write:/ wa_final.
endloop.
endif.
2013 Jul 17 9:06 AM
I have Hi Susmitha,
thank you very much for your afforts. Can you, please, explain, what do you mean by:
sy-subrc, nos and wa_itab1 in Case 1? I have other names of tables, of course, but I didnt understand these your explanations in this step, and little bit lost with my code.
Regards,
Dimitrij
2013 Jul 17 10:45 AM
HI Dimitrij,
You can definitely use any name for your tables, I just used them for illustration, just to show you the logic.
In that code, itab1 is the output table for the first function module, replace it with the name you have used.
Itab2 is the output table for the second function module.
wa_itab1 and wa_itab2 are the workareas that are used for processing the tables itab1 and itab2 respectively.
Phone Nos - I meant Phone numbers.
itab1[] = itab2[] checks if both the tables are same.
If they are not the same, it can be due to three situations.
1. Phone numbers in first table, itab1 not in second table itab2.
sy-subrc ne 0, means no matching record have been found.
2. Phone numbers that are there in both the tables but with different value for the operators.
3. Phone numbers that are there in second table itab2, not there in itab1.
All these three cases have been taken care of in the program and the records with these unmatched phone number are appended to the final table itab_final.
2013 Jul 17 8:23 AM