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

Select from an Internal Table.

Former Member
0 Likes
458

Following is my urgent requirement:

I have an Internal Table ITAB with several possible entries of Company Code under its field BUKRS.

From this ITAB I want to display only those records for which the column 'Company Code' occur more than twice and then display those records.

For example:

CC DOCNo

1000 100000011

1000 100000023

1000 120000021

1100 120000031

1100 120000033

1200 120000043

1200 120000055

1200 211130001

In above case I have 3 occurence of 1000 and 1200....so I only want to show their records...while 1100 has only 2 instances...so I want those 2 records to be deleted.

Whats the best way to do this.

I was wondering if there is a way to 'count' the number of records for 'distinct' Company Codes....and if Count > 2 then move those records to a new ITAB.

Please advise,

Thanks,

Rohit.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
434

Try this

DATA: BEGIN OF itab_bukrs occurs 0,

bukrs LIKE t001-bukrs,

count TYPE i.

DATA: END OF itab_bukrs.

LOOP AT itab.

itab_bukrs-bukrs = itab-bukrs.

itab_bukrs-count = 1.

COLLECT itab_bukrs.

ENDLOOP.

DELETE itab_bukrs WHERE count < 3.

Now you know which company codes have more than 2 documents. You can either loop at your itab and read this itab_bukrs and proceed only if a record exists in here, else delete itab where bukrs = current itab-bukrs.

LOOP AT itab.

READ TABLE itab_bukrs WITH KEY bukrs = itab-bukrs.

IF sy-subrc <> 0.

DELETE itab WHERE bukrs = itab-bukrs.

CONTINUE.

ENDIF.

.... show these records

ENDLOOP.

2 REPLIES 2
Read only

Former Member
0 Likes
435

Try this

DATA: BEGIN OF itab_bukrs occurs 0,

bukrs LIKE t001-bukrs,

count TYPE i.

DATA: END OF itab_bukrs.

LOOP AT itab.

itab_bukrs-bukrs = itab-bukrs.

itab_bukrs-count = 1.

COLLECT itab_bukrs.

ENDLOOP.

DELETE itab_bukrs WHERE count < 3.

Now you know which company codes have more than 2 documents. You can either loop at your itab and read this itab_bukrs and proceed only if a record exists in here, else delete itab where bukrs = current itab-bukrs.

LOOP AT itab.

READ TABLE itab_bukrs WITH KEY bukrs = itab-bukrs.

IF sy-subrc <> 0.

DELETE itab WHERE bukrs = itab-bukrs.

CONTINUE.

ENDIF.

.... show these records

ENDLOOP.

Read only

0 Likes
434

Excellent...thanks so much !!!