2007 Oct 03 5:30 PM
The two internal tables mtab and ltab contain different number of entries for partner (mtab has more the ltab) in the following:
SELECT but000partner but020addrnumber " adr6~smtp_addr
INTO TABLE ltab
FROM ( ( but000 INNER JOIN but020
ON but000partner = but020partner )
INNER JOIN adr6
ON but020addrnumber = adr6addrnumber ).
SELECT partner addrnumber
INTO CORRESPONDING FIELDS OF TABLE mtab
FROM but020.
How do I display outstanding fields in mtab but not in ltab?
Ready to award.
2007 Oct 03 5:44 PM
The simplest way to do this would be
Sort table ITAB , MTAB with the respective key
LOOP AT MTAB
READ ITAB with key fieldname = mtab-fieldname binary search
if sy-subrc <> '0'.
" This implies that this line is found in mtab but not in itab
endif.
endloop.
The above should solve the problem, however the algorithm can be further improvised using index based read on the table itab.
Do let me know if I understood you well.
The two internal tables mtab and ltab contain different number of entries for partner (mtab has more the ltab) in the following:
SELECT but000partner but020addrnumber " adr6~smtp_addr
INTO TABLE ltab
FROM ( ( but000 INNER JOIN but020
ON but000partner = but020partner )
INNER JOIN adr6
ON but020addrnumber = adr6addrnumber ).
SELECT partner addrnumber
INTO CORRESPONDING FIELDS OF TABLE mtab
FROM but020.
How do I display outstanding fields in mtab but not in ltab?
Ready to award.
2007 Oct 03 5:35 PM
Try this.
create a new table mtab1 and move mtab.
loop at mtab1.
idx = sy-tabix.
read table itab with key partner = mtab1-partner.
if sy-subrc = 0.
delete mtab1 index idx.
endif.
endloop.
Then ur mtab1 will have the entries only in mtab and not in itab.
Sri
2007 Oct 03 5:44 PM
The simplest way to do this would be
Sort table ITAB , MTAB with the respective key
LOOP AT MTAB
READ ITAB with key fieldname = mtab-fieldname binary search
if sy-subrc <> '0'.
" This implies that this line is found in mtab but not in itab
endif.
endloop.
The above should solve the problem, however the algorithm can be further improvised using index based read on the table itab.
Do let me know if I understood you well.
2007 Oct 03 6:22 PM
Ok. Let me be more specific. The program that enters information into the database table ADR6 is like this:
When someone enters e-mail address for a business partner, the partner then APPEARS in the table ADR6. I want to display empty fields for e-mail in BUT000 thru BUT020 by Business partner so, this means those that appear in BUT000 without e-mail addresses DO NOT appear in ADR6. These are the ones I want to display by partner.
Are you saying I should create another internal table which stores these?
2007 Oct 03 6:28 PM
I agree with Gerson. The only thing to keep in mind - for BINARY SEARCH make sure that the table has been sorted by that field first, otherwise BINARY SEARCH won't work correctly.
Depending on the expected data, HASHED table type might be actually more efficient than BINARY SEARCH, but otherwise BINARY SEARCH is better than plain READ.
Some ABAP examples using index based read are actually available in ABAP Editor: menu Environment -> Examples -> Performance Examples.
Hope this helps.
2007 Oct 04 9:16 AM
Where am I going wrong? Here is what I did:
DATA: BEGIN OF email,
partner TYPE bu_partner,
addrnumber TYPE ad_addrnum,
smtp_addr TYPE adr6-smtp_addr,
END OF email,
ltab LIKE STANDARD TABLE OF email WITH HEADER LINE.
DATA: BEGIN OF comp,
partner TYPE bu_partner,
addrnumber TYPE ad_addrnum,
END OF comp,
mtab LIKE STANDARD TABLE OF comp WITH HEADER LINE.
SELECT but000partner but020addrnumber " adr6~smtp_addr
INTO TABLE ltab
FROM ( ( but000 INNER JOIN but020
ON but000partner = but020partner )
INNER JOIN adr6
ON but020addrnumber = adr6addrnumber ).
SELECT partner addrnumber
INTO CORRESPONDING FIELDS OF TABLE mtab
FROM but020.
SORT ltab BY partner.
SORT mtab BY partner.
IF sy-dbcnt = 0.
ULINE.
WRITE:/ 'There are no empty entries in the field: E-mail'.
ULINE.
ELSE.
ULINE.
WRITE: / 'The Field: E-mail, has',sy-dbcnt,'empty fields for the following Business Partner entries:'.
ULINE.
LOOP AT mtab INTO comp.
READ TABLE ltab WITH KEY partner = mtab-partner BINARY SEARCH.
IF sy-subrc <> '0'. " This implies that this line is found in mtab but not in ltab
WRITE:/ comp-partner, comp-addrnumber.
ENDIF.
ENDLOOP.
ENDIF.
Is it my program flow or what?
2007 Oct 04 10:29 AM
Thanx Gerson,
I understand the syntax, but am a bit new to ABAP. So, does this mean I have to put what is not found in itab into another internal table then display the contents of that table? (please provide sample if not too busy incl declarations:) )E.g. After sort by Business Partner:
MTAB ITAB
1234 1234
1235 1235
1236 1236
1237 1237
1238
1239
1240
1241
So the internal table should contain entries 1238, 1239, 1240, 1241. which are then displayed.
2007 Oct 04 12:09 PM
What you had done with the loop in your code is correct except for one thing
Your code
LOOP AT mtab INTO comp.
READ TABLE ltab WITH KEY partner = mtab-partner BINARY SEARCH.
IF sy-subrc <> '0'. " This implies that this line is found in mtab but not in ltab
WRITE:/ comp-partner, comp-addrnumber.
ENDIF.
ENDLOOP.
The way it should be
LOOP AT mtab INTO comp.
READ TABLE ltab WITH KEY partner = <b>comp-partner</b> BINARY SEARCH.
IF sy-subrc <> '0'. " This implies that this line is found in mtab but not in ltab
WRITE:/ comp-partner, comp-addrnumber.
ENDIF.
ENDLOOP.
The difference is only in the workarea you have to use in the read.
Now if your requirement is just displaying a list of these entries then I do not see the need for another internal table. The code you have written has achieved this.
However if the requirement is to have these set of entries processed ( i.e. found in mtab and not in itab) maybe with some other logic, then i see a justification for a new internal table.
Do let me know if this worked.
2007 Oct 04 4:50 PM
Thanks again Gerson. It's working just fine but the code
LOOP AT ltab INTO email.
READ TABLE ltab WITH KEY partner = mtab-partner BINARY SEARCH.
WRITE:/ email-partner, email-addrnumber.
IF sy-subrc <> '0'. " This implies that this line is found in mtab but not in ltab
ENDIF.
ENDLOOP.
is actually doing the opposite of what I want. It's displaying the entries in ltab that are in mtab and leaving out those that are in ltab but are not in mtab, which are the ones I want to display. Like for the example:
MTAB ITAB
1234 1234
1235 1235
1236 1236
1237 1237
1238
1239
1240
1241
It displays 1234, 1235, 1236, 1237, instead of 1238, 1239, 1240, 1241.
2007 Oct 04 10:02 PM
Hi,
After you READ ITAB and find an entry, you have to delete the entry from MTAB.
Something like this:
READ TABLE ltab WITH KEY partner = mtab-partner BINARY SEARCH.
IF sy-subrc = 0.
delete mtab.
endif.
ENDIF.
There is another way you can do it.
Define a RANGE for itab-partner.
RANGES: r_partner FOR itab-partner.
r_partner-sign = 'I'.
r_partner-option = 'EQ'.
loop at itab.
r_partner-low = itab-partner.
append r_partner.
endloop.
delete mtab where partner in r_partner.
now mtab will have the entries which are not there in itab.
Sri
2007 Oct 05 9:39 AM
Thanks, Sri, Gerson and Jelena. You have been a great help. This has been a good learning experience. However, I want to display the number of entries in mtab AFTER deletion of entries in ltab. The following piece of code displays the number of entries (i.e. the total) in mtab i.e. 8 in the prev example rather than 4 entries: It seems it's still looking at the db count from mtab in the second select.
IF sy-dbcnt = 0.
ULINE.
WRITE:/ 'There are no empty entries in the field: E-mail'.
ULINE.
ELSE.
ULINE.
WRITE: / 'The Field: E-mail, has',sy-dbcnt,'empty fields for the following Business Partner entries:'.
ULINE.
LOOP AT mtab INTO email.
WRITE:/ email-partner, email-addrnumber.
ENDLOOP.
ENDIF.
2007 Oct 04 9:36 AM
The table itab must not be sorted, it is anyway in the loop, the table mtab should bve a hashed table.
I am wondering whether you ca select all thse data, how large are your tables, will you need the tables later?
If you not then you should select only what you really need!
SELECT partner addrnumber
INTO TABLE ltab
FROM but020
WHERE partner NE ( SELECT partner
FROM but000 ).
2007 Oct 04 9:48 AM
Hi,
I have used these tables before the thing is in ITAB query, you are making an innerjoin with adr6 table which may not be filled at all times so just do the following
<b>SELECT but000partner but020addrnumber adr6~smtp_addr</b>
INTO TABLE ltab
FROM ( ( but000 INNER JOIN but020
ON but000partner = but020partner )
<b>LEFT OUTER JOIN adr6</b> ON but020addrnumber = adr6addrnumber ).
And now where the ITAB field for <b>adr6~smtp_addr</b> is empty, means it doesnot exist in adr6 and is present in BUT020.
Hope this will help you.
REWARD POINTS IF HELPFULL.
Khusro Habib
2007 Oct 08 3:31 PM
Thanx all. You have been a great help. I hope I will be good enough to assist others soon.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |