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

To filter the data from Internal table.

Former Member
0 Likes
1,123

Hi,

I have the custom database table and i'm fetching records from this table in to my internal table. Now i need to filter this internal table with respect two fields po and version as below:-

1.) Let say 10 records are fetched from custom databas table into ITAB1 in the following manner:

PO No. VERSION No.

po1 1

p01 2

p01 3

p02 1

p02 2

p03 1

p04 1

p05 1

p05 2

po5 3

2.) Now this should be filtered in to ITAB2 as below:-

PO No. VERSION No.

p01 3

p02 2

p03 1

p04 1

p05 3

Please let me know the logic to get this. I was trying SORT ITAB1 by VERSION No.

DELETE ADJACENT DUPLICATES COMPARING PO No. field.

But that did'nt work for me.

Thanks in advance,

Naveen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,079

Hi

Please refer the below code snippet.

REPORT ZTEXT_EDITOR .
data : begin of itab1 occurs 1,
       ponum(3),
       versnum(1),
       end of itab1.

data : begin of itab2 occurs 1,
       ponum(3),
       versnum(1),
       end of itab2.

clear itab1.
itab1-ponum = 'PO1'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO1'.
itab1-versnum = '2'.
append itab1.

clear itab1.
itab1-ponum = 'PO1'.
itab1-versnum = '3'.
append itab1.

clear itab1.
itab1-ponum = 'PO2'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO2'.
itab1-versnum = '2'.
append itab1.

clear itab1.
itab1-ponum = 'PO3'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO4'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO5'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO5'.
itab1-versnum = '2'.
append itab1.

clear itab1.
itab1-ponum = 'PO5'.
itab1-versnum = '3'.
append itab1.

sort itab1 by ponum versnum descending.
delete adjacent duplicates from itab1 comparing ponum.

itab2[] = itab1[].

write itab1.

Close the thread if this solves your query.

Regards

Abhii

Hi,

I have the custom database table and i'm fetching records from this table in to my internal table. Now i need to filter this internal table with respect two fields po and version as below:-

1.) Let say 10 records are fetched from custom databas table into ITAB1 in the following manner:

PO No. VERSION No.

po1 1

p01 2

p01 3

p02 1

p02 2

p03 1

p04 1

p05 1

p05 2

po5 3

2.) Now this should be filtered in to ITAB2 as below:-

PO No. VERSION No.

p01 3

p02 2

p03 1

p04 1

p05 3

Please let me know the logic to get this. I was trying SORT ITAB1 by VERSION No.

DELETE ADJACENT DUPLICATES COMPARING PO No. field.

But that did'nt work for me.

Thanks in advance,

Naveen

7 REPLIES 7
Read only

Former Member
0 Likes
1,079

Sort gt_out by po version descending.

Delete adjacent duplicates from gt_out comparing po.

Read only

Former Member
0 Likes
1,080

Hi

Please refer the below code snippet.

REPORT ZTEXT_EDITOR .
data : begin of itab1 occurs 1,
       ponum(3),
       versnum(1),
       end of itab1.

data : begin of itab2 occurs 1,
       ponum(3),
       versnum(1),
       end of itab2.

clear itab1.
itab1-ponum = 'PO1'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO1'.
itab1-versnum = '2'.
append itab1.

clear itab1.
itab1-ponum = 'PO1'.
itab1-versnum = '3'.
append itab1.

clear itab1.
itab1-ponum = 'PO2'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO2'.
itab1-versnum = '2'.
append itab1.

clear itab1.
itab1-ponum = 'PO3'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO4'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO5'.
itab1-versnum = '1'.
append itab1.

clear itab1.
itab1-ponum = 'PO5'.
itab1-versnum = '2'.
append itab1.

clear itab1.
itab1-ponum = 'PO5'.
itab1-versnum = '3'.
append itab1.

sort itab1 by ponum versnum descending.
delete adjacent duplicates from itab1 comparing ponum.

itab2[] = itab1[].

write itab1.

Close the thread if this solves your query.

Regards

Abhii

Read only

Former Member
0 Likes
1,079

This message was moderated.

Read only

Former Member
0 Likes
1,079

This message was moderated.

Read only

Former Member
0 Likes
1,079

hi,

loop at the internal table itab1. and at last of PO NO append the work area to itab2.

you get the desired output.

regards,

sirisha

Read only

0 Likes
1,079

Hi Sirisha,

on AT LAST you cannot specify any field like you said AT LAST PO.

Jaikrishna,

Follow the code I have written, you will get the desired output.

Regards

Abhii

Read only

0 Likes
1,079

Abhii,

yes you were right, i mean it was AT END OF PO.

regards,

sirisha