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

Unique values into an internal table

Former Member
0 Likes
1,011

Hi SDN,

I need to fetch just one field from a table into an internal table except that I only need unique values, not every occurance in the source table. So if the table has 100 records but the field has only four unique values, internal table would have only four records/rows.

Please help with declarations and Select code snippet.

Thanks.

Saf.

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
966

Hi,

Use distinct in select


DATA: wa   TYPE spfli, 
      ftab TYPE TABLE OF STRING. 

APPEND 'CITYFROM' TO ftab. 
APPEND 'CITYTO'   TO ftab. 

SELECT DISTINCT (ftab) 
       FROM spfli 
       INTO CORRESPONDING FIELDS OF wa 
       WHERE 
         carrid   = 'LH'. 
  WRITE: / wa-cityfrom, wa-cityto. 
ENDSELECT. 


a®

5 REPLIES 5
Read only

former_member194669
Active Contributor
0 Likes
967

Hi,

Use distinct in select


DATA: wa   TYPE spfli, 
      ftab TYPE TABLE OF STRING. 

APPEND 'CITYFROM' TO ftab. 
APPEND 'CITYTO'   TO ftab. 

SELECT DISTINCT (ftab) 
       FROM spfli 
       INTO CORRESPONDING FIELDS OF wa 
       WHERE 
         carrid   = 'LH'. 
  WRITE: / wa-cityfrom, wa-cityto. 
ENDSELECT. 


a®

Read only

0 Likes
966

Use DISTINCT keyword in the select query .

Read only

0 Likes
966

Thanks. Here is my problem with distinct.

data: begin of i_entity occurs 0,

entity like /bic/pzk_entity-/bic/zk_entity,

end of i_entity.

The following code generates a syntex error saying that /bic/zk_entity is unknown column and cannot determine this until run time.

select distinct(/bic/zk_entity)

from /bic/azpd_o6100

into corresponding fields of table i_entity

where /bic/ztimeper in r_period.

endselect.

Read only

0 Likes
966

Change select distinct(/bic/zk_entity) to

select distinct /bic/zk_entity

This should help.

ashish

Read only

0 Likes
966

Change select distinct(/bic/zk_entity) to

select distinct /bic/zk_entity

from /bic/azpd_o6100

into corresponding fields of table i_entity

where /bic/ztimeper in r_period.

Also as you are doing into table, you do not need ENDSELECT.

This should help.

ashish