‎2006 Dec 12 5:25 AM
I need a select statement as follows.
SELECT RACCT HSL01 + HSL02 + HSL03 + HSL04 AS TOTAL FROM glt0
INTO TABLE i_tab.
‎2006 Dec 12 5:31 AM
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.
‎2006 Dec 12 5:31 AM
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.
‎2006 Dec 13 3:57 AM
Hi Ramudu,
Pls check this code.
data : begin of itab occurs 0,
HSL01 like glt0-HSL01,
HSL02 like glt0-HSL02,
HSL03 like glt0-HSL03,
HSL04 like glt0-HSL04,
end of itab.
data : v_total like glt0-HSL01.
start-of-selection.
SELECT sum( HSL01 ) sum( HSL02 ) sum( HSL03 ) sum( HSL04 )
into table itab
FROM glt0.
loop at itab.
total = itab-HSL01 + itab-HSL02 + itab-HSL03 + itab-HSL04.
endloop.
Pls. reward for help ful answers.
‎2006 Dec 13 4:03 AM
Hi Ramudu,
Sorry pls. ignore earlier my reply.Check with this code.
data : begin of itab occurs 0,
RACCT like glt0-RACCT,
HSL01 like glt0-HSL01,
HSL02 like glt0-HSL02,
HSL03 like glt0-HSL03,
HSL04 like glt0-HSL04,
end of itab.
data : v_total like glt0-HSL01.
start-of-selection.
SELECT RACCT sum( HSL01 ) sum( HSL02 )
sum( HSL03 ) sum( HSL04 )
into table itab
FROM glt0 group by RACCT .
loop at itab.
total = itab-HSL01 + itab-HSL02 + itab-HSL03 + itab-HSL04.
endloop.
Pls. reward for help ful answers.
‎2006 Dec 13 5:35 AM
Hi Ramudu,
I have worked out ur requirement and sent u a code u can try it..its working hope ur query is answered....reward useful answers...
code
******
TYPES : BEGIN OF types,
racct TYPE glt0-racct,
hsl01 TYPE glt0-hsl01,
hsl02 TYPE glt0-hsl02,
hsl03 TYPE glt0-hsl03,
hsl04 TYPE glt0-hsl04,
total TYPE glt0-hsl04,
END OF types.
DATA : it TYPE TABLE OF types,
wa TYPE types.
SELECT racct hsl01 hsl02 hsl03 hsl04 FROM glt0 INTO TABLE it group by RACCT .
IF sy-subrc EQ 0.
WRITE : sy-vline ,'RACCT',27 sy-vline , 'HSL01' ,50 sy-vline , 'HSL02',72 sy-vline , 'HSL03',93 sy-vline ,'HSL04',115 sy-vline ,'TOTAL' , 142 sy-vline.
ULINE.
LOOP AT it INTO wa.
wa-total = wa-hsl01 + wa-hsl02 + wa-hsl03 + wa-hsl04.
MODIFY it FROM wa TRANSPORTING total.
WRITE : / sy-vline, wa-racct, 27 sy-vline , wa-hsl01 , 50 sy-vline , wa-hsl02, 72 sy-vline , wa-hsl03 , 93 sy-vline, wa-hsl04 , 115 sy-vline, wa-total, 142 sy-vline.
ULINE.
ENDLOOP.
regards ,
Rajkumar.G
ENDIF.
‎2006 Dec 13 6:16 AM
DATA: BEGIN OF t_glt0 OCCURS 0,
RACCT like glt0-RACCT,
hsl01 LIKE glfunct-hslvt,
hsl02 LIKE glfunct-hslvt,
hsl03 LIKE glfunct-hslvt,
hsl04 LIKE glfunct-hslvt,
hsl05 LIKE glfunct-hslvt,
hsl06 LIKE glfunct-hslvt,
hsl07 LIKE glfunct-hslvt,
hsl08 LIKE glfunct-hslvt,
hsl09 LIKE glfunct-hslvt,
hsl10 LIKE glfunct-hslvt,
hsl11 LIKE glfunct-hslvt,
hsl12 LIKE glfunct-hslvt,
hsl13 LIKE glfunct-hslvt,
hsl14 LIKE glfunct-hslvt,
hsl15 LIKE glfunct-hslvt,
hsl16 LIKE glfunct-hslvt,
END OF t_glt0.
SELECT
RACCT
SUM( hsl01 ) AS hsl01
SUM( hsl02 ) AS hsl02
SUM( hsl03 ) AS hsl03
SUM( hsl04 ) AS hsl04
SUM( hsl05 ) AS hsl05
SUM( hsl06 ) AS hsl06
SUM( hsl07 ) AS hsl07
SUM( hsl08 ) AS hsl08
SUM( hsl09 ) AS hsl09
SUM( hsl10 ) AS hsl10
SUM( hsl11 ) AS hsl11
SUM( hsl12 ) AS hsl12
SUM( hsl13 ) AS hsl13
SUM( hsl14 ) AS hsl14
SUM( hsl15 ) AS hsl15
SUM( hsl16 ) AS hsl16
INTO CORRESPONDING FIELDS OF TABLE t_glt0
FROM glt0.
loop at t_glt0 into ls_glto.
total = ls_glt0-hsl01 + ls_glt0-hsl02 +.....
endloop.