Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Dynamic SQL SELECT

Hello, this is my first question in a forum:

Can I make a select like this?

SELECT RACCT HSL01 + HSL02 + HSL03 + HSL04 AS TOTAL

FROM glt0

INTO TABLE i_tab.

I think it's not possible because it give me a lot of errors. Thanks in advance.

Esther

Tags:
Former Member
Former Member replied

Hi Albert,

Welcome to SDN..........

It is not possible to add fields at select statement. To achiever your requirement, collect data into internal table and sum-up required fields.

The code for this is as follows::

types: begin of ty_tab,

racct like glto-racct,

hsl01 like glto-hsl01,

hsl02 like glto-hsl02,

hsl03 like glto-hsl03,

hsl04 like glto-hsl04,

end of ty_tab.

types: begin of ty_tab_sum,

racct like glto-racct,

sum like glto-hsl04,

end of ty_tab_sum.

data:

i_tab like standard table of ty_tab with header line,

i_tab_sum like standard table of ty_tab_sum with header line.

data:

wa_tab type ty_tab.

select racct hsl01 hsl02 hsl03 hsl04

from glto

intotable i_tab.

if not i_tab[] is not initial.

loop at i_tab into wa_tab.

i_tab_sum-racct = wa_tab-racct.

i_tab_sum-sum = wa_tab-hsl01 + wa_tab-hsl02 + wa_tab-hsl03 + wa_tab-hsl04.

append i_tab_sum.

clear wa_tab.

endloop.

endif.

Thanks,

Vinay

Note: Plz reward points if it is helpful

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question