‎2007 Jun 15 4:29 AM
hello experts
I have a table with seven feilds in which i want total sum for 2 feilds the output is displaying sum for 2 feilds i want these 2 feilds in seprate internal table what to do
points for sure
‎2007 Jun 15 4:46 AM
hi,
check the below coding
types : begin of ty_tab ,
v_1 type i,
v_2 type i,
v_3 type i,
v_4 type i,
v_5 type i,
v_6 type i,
v_7 type i,
end of ty_tab,
begin of ty_sum,
v_sum1 type i,
v_sum2 type i,
v_sum3 type i,
end of ty_sum.
data : i_tab type standard table of ty_tab with header line,
i_sum type standard table of ty_sum with header line.
i_tab-v_1 = 1 .
i_tab-v_2 = 2 .
i_tab-v_3 = 3 .
i_tab-v_4 = 4 .
i_tab-v_5 = 5 .
i_tab-v_6 = 6 .
i_tab-v_7 = 7 .
append i_tab.
loop at i_tab.
i_sum-v_sum1 = i_tab-v_1 + i_tab-v_2.
i_sum-v_sum2 = i_tab-v_3 + i_tab-v_4.
i_sum-v_sum3 = i_tab-v_5 + i_tab-v_6.
append i_sum.
write 😕 i_tab-v_1,i_tab-v_2,i_tab-v_3,i_tab-v_4,i_tab-v_5,i_tab-v_6,i_tab-v_7.
endloop.
loop at i_sum.
write 😕 i_sum-v_sum1, i_sum-v_sum2, i_sum-v_sum3.
endloop.
‎2007 Jun 15 4:34 AM
Did not get your question exactly but from what i understood:
ITAB has 7 fields. Assume that you have to do total of FIELD1, FIELD2.
Assume that ITAB2 has 2 fields.
Loop AT ITAB.
ITAB2-FIELD1 = ITAB2-FIELD1 + ITAB-FIELD1.
ITAB2-FIELD2 = ITAB2-FIELD2 + ITAB-FIELD2.
ENDLOOP.
APPEND ITAB2.
‎2007 Jun 15 4:36 AM
Hi,
Can you please be more clear with your requirements.
Regards,
Atish
‎2007 Jun 15 4:39 AM
The internal table for the total stored is <b>it_sortcat.</b>
* ALV data declarations
data: it_sortcat type slis_sortinfo_alv occurs 1,
wa_sort like line of it_sortcat
perform build_sortcat.
*&------------------------------------------------------------------*
*& Form build_sortcat
*&------------------------------------------------------------------*
* Build Sort catalog
*-------------------------------------------------------------------*
FORM build_sortcat .
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field
* gd_sortcat-tabname
APPEND wa_sort TO <b>it_sortcat.</b>
wa_sort-spos = 2.
wa_sort-fieldname = 'EBELP'.
* gd_sortcat-tabname
APPEND wa_sort TO <b>it_sortcat.</b>
ENDFORM. " build_sortcat
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE'
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_sort = it_sortcat
i_save = 'X'
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
reward points if it is usefulll ....
Girish
‎2007 Jun 15 4:46 AM
hi,
check the below coding
types : begin of ty_tab ,
v_1 type i,
v_2 type i,
v_3 type i,
v_4 type i,
v_5 type i,
v_6 type i,
v_7 type i,
end of ty_tab,
begin of ty_sum,
v_sum1 type i,
v_sum2 type i,
v_sum3 type i,
end of ty_sum.
data : i_tab type standard table of ty_tab with header line,
i_sum type standard table of ty_sum with header line.
i_tab-v_1 = 1 .
i_tab-v_2 = 2 .
i_tab-v_3 = 3 .
i_tab-v_4 = 4 .
i_tab-v_5 = 5 .
i_tab-v_6 = 6 .
i_tab-v_7 = 7 .
append i_tab.
loop at i_tab.
i_sum-v_sum1 = i_tab-v_1 + i_tab-v_2.
i_sum-v_sum2 = i_tab-v_3 + i_tab-v_4.
i_sum-v_sum3 = i_tab-v_5 + i_tab-v_6.
append i_sum.
write 😕 i_tab-v_1,i_tab-v_2,i_tab-v_3,i_tab-v_4,i_tab-v_5,i_tab-v_6,i_tab-v_7.
endloop.
loop at i_sum.
write 😕 i_sum-v_sum1, i_sum-v_sum2, i_sum-v_sum3.
endloop.
‎2007 Jun 15 5:06 AM
hello Shah
ITAB has 7 fields. Assume that you have to do total of FIELD1, FIELD2.
Assume that ITAB2 has 2 fields.
Loop AT ITAB.
ITAB2-FIELD1 = ITAB2-FIELD1 + ITAB-FIELD1.
ITAB2-FIELD2 = ITAB2-FIELD2 + ITAB-FIELD2.
ENDLOOP.
APPEND ITAB2.
is this the right way or can we go by move-corresponding
‎2007 Jun 15 5:07 AM
no this is the right way.
Move-corresponding will just move values.
As we have to do the totals, these statements are necessary.
If you have requirements exactly as you have specified in the question, this should work.
Let me know if you any other requirement.
‎2007 Jun 15 5:19 AM
Thank Q
No i just wanted to find out which is the better method
‎2007 Jun 15 5:23 AM
Please reward all helpful answers and close the thread if your question is answered.