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

Dynamice field in the Select statement ?

Former Member
0 Likes
688

I want to query a table and get the SUM ( fieldx) without any where clause. However, the fieldx should be dynamic.

Select SUM ( Gross_Wt ) from table. I want the Gross_Wt field to be dynamic.

Any sugestions.

I want to query a table and get the SUM ( fieldx) without any where clause. However, the fieldx should be dynamic.

Select SUM ( Gross_Wt ) from table. I want the Gross_Wt field to be dynamic.

Any sugestions.

6 REPLIES 6
Read only

Former Member
0 Likes
656

Try using Field symbols.

Select SUM ( <FS_Gross_Wt> ) from table.

- guru

Read only

0 Likes
656

I tried field symbol its not working. Thanks.

Read only

Former Member
0 Likes
656

Welcome to SDN,

You can try like this


DATA : v_field(40) like c VALUE 'SUM(<FIELD NAME>)',
       v_var TYPE p.
 
SELECT v_field FROM <TABLE> INTO v_var.

Just this blog you will get more idea

/people/alvaro.tejadagalindo/blog/2006/12/13/dynamic-inner-join-function-module

Regards

Kathirvel

Read only

0 Likes
656

Karthir, I tried your code, its not working either. Thanks & Regards.

Read only

0 Likes
656

Plz try this


DATA : v_field(40) like c VALUE 'SUM( <FIELD NAME> )',
       v_var TYPE p.
 
SELECT v_field FROM <TABLE> INTO v_var GROUP BY <key Field>.

Regards

Kathirvel

Read only

0 Likes
656

Solved the problem

strtemp1 = 'SUM( '.

strtemp2 = ' )'.

CONCATENATE strtemp1 l_kfname strtemp2

INTO strsumfld SEPARATED BY space.

SELECT SINGLE ( strsumfld )

FROM (l_etblname)

INTO l_ecubetotal.