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

distinct values from dynamic internal tabls

Former Member
0 Likes
841

Hi All,

I have a dynamic internal tables like <dy_table> , i want to get distinct values from this internal tables,

how to do that, structure of dynamic internal tables is dynamic acc. to user conditions.

regards,

Anuj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
765

Hi

use the fieldcatalog structure for geting the fields

and sort dyn table with the fields available in the dynamic fieldcat.

delete adjacent duplicates based on these fields.

reg

Ramya

Hi

use the fieldcatalog structure for geting the fields

and sort dyn table with the fields available in the dynamic fieldcat.

delete adjacent duplicates based on these fields.

reg

Ramya

5 REPLIES 5
Read only

Former Member
0 Likes
765

Hi Anuj

Just try this,

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = tb_fields_for_it

IMPORTING

ep_table = gp_dyn_table.

ASSIGN gp_dyn_table->* TO <gt_table>.

ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table> TO <fs_table>.

LOOP AT tb_output.

*To assign value for serial number.

ASSIGN COMPONENT 1 OF STRUCTURE <fs_table> TO <ls_field>.

<ls_field> = tb_output-sno.

UNASSIGN <ls_field>.

*To assign value for Sales Organization.

ASSIGN COMPONENT 2 OF STRUCTURE <fs_table> TO <ls_field>.

<ls_field> = tb_output-vkorg.

UNASSIGN <ls_field>.

*To assign Rate for its respective Condition type.

LOOP AT tb_konp WHERE knumh = tb_output-knumh.

READ TABLE tb_fieldcat1 WITH KEY fieldname = tb_output-kschl.

IF sy-subrc EQ 0.

lv_count = tb_fieldcat1-col_pos.

ASSIGN COMPONENT lv_count OF STRUCTURE <fs_table> TO <ls_field>.

IF tb_konp-konwa EQ '%'.

tb_konp-kbetr = tb_konp-kbetr / co_10.

<ls_field> = tb_konp-kbetr.

ELSE.

<ls_field> = tb_konp-kbetr.

ENDIF.

ENDIF.

ENDLOOP.

lv_count = lv_count + 1.

APPEND <fs_table> TO <gt_table>.

CLEAR <fs_table>.

ENDLOOP.

Hope this proves helpful to you.

Read only

Former Member
0 Likes
765

Hi,

Sort the table, delete adjacent duplicates from itab this will solve your problem

Read only

Former Member
0 Likes
765

Hi

even though it is dynamic

the structure or the fieldcatalog for creating this dynamic table will have a structure.

use the fields from the structure and sort itab based on those fields

and delete adjacent duplicates

reg

Ramya

Read only

Former Member
0 Likes
766

Hi

use the fieldcatalog structure for geting the fields

and sort dyn table with the fields available in the dynamic fieldcat.

delete adjacent duplicates based on these fields.

reg

Ramya

Read only

Former Member
0 Likes
765

Hi,

If you want the distinct values for all columns, then

SORT itab. "If required use the addition BY
DELETE ADJACENT DUPLICATES FROM connection_tab. "If required use COMPARING addition

"Now your internal table contains unique entries

Or else if you want distinct values of a particular column,

LOOP AT itab INTO wa_tab.

AT NEW <column name>.

(write your logic to store the value).

ENDAT.
ENDLOOP.

Regards,

Manoj Kumar P