hi,
i am doing report in alv grid i need to include subtotal text.please help me out..defenetly points will be rewarded.
REPORT ZINTORD.
&----
& Program Name : ZINTORD Date : 21/12/2006
*& Program tilte : Internal Order Analysis Report *
*&
*&----
*&
&----
*&----
*& table declaration
&----
Tables : COEP,
COAS,
TKV11,
CEPC,
cskb,
tka01,
aufk,
sscrfields,
SETHEADER.
*&----
*& type-pool declaration
&----
type-pools : slis, icon.
*&----
*& fieldcatalog declaration
&----
data : d_fieldcat type slis_t_fieldcat_alv,
d_fieldcat_wa type slis_fieldcat_alv,
gd_sort type slis_t_sp_group_alv .
data : wa_header type slis_listheader,
t_header type slis_t_listheader.
data : wsort type slis_sortinfo_alv,
isort type slis_t_sortinfo_alv.
data : t_eve type slis_t_event.
data : gd_layout type slis_layout_alv.
*data : t_eve type slis_ev_subtotal_text.
data : listsep like rfpdo-allglsep.
*&----
*& Internal tables declaration
&----
data : begin of itab_coep occurs 0,
kokrs like coep-kokrs,
gjahr like coep-gjahr,
perio like coep-perio,
kstar like coep-kstar,
bukrs like coep-bukrs,
WOGBTR like coep-WOGBTR,
mbgbtr like coep-mbgbtr,
meinh like coep-meinh,
sgtxt like coep-sgtxt,
end of itab_coep.
data : begin of itab_aufk occurs 0,
kokrs like aufk-kokrs,
aufnr like aufk-aufnr,
bukrs like aufk-bukrs,
prctr like aufk-prctr,
auart like aufk-auart,
autyp like aufk-autyp,
end of itab_aufk.
data : begin of itab_cepc occurs 0,
kokrs like cepc-kokrs,
prctr like cepc-prctr,
khinr like cepc-khinr,
end of itab_cepc.
data : begin of itab_cskb occurs 0,
kokrs like cskb-kokrs,
kstar like cskb-kstar,
katyp like cskb-katyp,
aufnr like cskb-aufnr,
end of itab_cskb.
data : begin of itab_tkv11 occurs 0,
kokrs like tkv11-kokrs,
kagru like tkv11-kagru,
end of itab_tkv11.
data : begin of itab_final occurs 0,
kokrs like coep-kokrs,
gjahr like coep-gjahr,
perio like coep-perio,
kstar like coep-kstar,
bukrs like coep-bukrs,
WOGBTR like coep-WOGBTR,
mbgbtr like coep-mbgbtr,
meinh like coep-meinh,
prctr like cepc-prctr,
khinr like cepc-khinr,
aufnr like aufk-aufnr,
auart like aufk-auart,
autyp like aufk-autyp,
katyp like cskb-katyp,
kagru like tkv11-kagru,
revenue like coep-wogbtr,
periol like coep-perio,
perioh like coep-perio,
gjahrl like coep-gjahr,
gjahrh like coep-gjahr,
ca like coep-kokrs,
ccl like coep-bukrs,
cch like coep-bukrs,
pgl like cepc-khinr,
pgh like cepc-khinr,
pcl like cepc-prctr,
pch like cepc-prctr,
kul like tkv11-kagru,
kuh like tkv11-kagru,
orl like cskb-aufnr,
orh like cskb-aufnr,
end of itab_final.
*&----
*& selection-screen
&----
selection-screen : begin of block blk1 with frame title text-001.
parameters : p_ca like coep-kokrs." obligatory.
select-options : s_year for coep-gjahr obligatory .
select-options : s_pd for coep-perio obligatory .
select-options : s_code for coep-bukrs.
select-options : s_pg for cepc-khinr matchcode object ZPROFITCENTERGROUP.
select-options : s_pc for cepc-prctr.
select-options : s_ku for tkv11-kagru matchcode object ZCOSTELEMENTGROUP .
select-options : s_or for cskb-aufnr.
selection-screen : end of block blk1.
*&----
*& start-of-selection.
&----
select kokrs gjahr perio kstar bukrs wogbtr
from coep into corresponding fields of table itab_coep
where kokrs = p_ca
and perio in s_pd
and bukrs in s_code
and gjahr in s_year.
if not itab_coep[] is initial.
select kokrs prctr khinr from cepc into corresponding fields of table itab_cepc
for all entries in itab_coep where kokrs = itab_coep-kokrs.
if not itab_cepc[] is initial.
select kokrs aufnr prctr bukrs auart autyp
from aufk into corresponding fields of table itab_aufk
where aufnr in s_or
and prctr = itab_cepc-prctr.
if not itab_aufk[] is initial.
select kokrs katyp aufnr kstar from cskb into corresponding fields of table itab_cskb
for all entries in itab_aufk where kokrs = itab_aufk-kokrs.
if not itab_cskb[] is initial.
select kokrs kagru from tkv11 into corresponding fields of table itab_tkv11
for all entries in itab_cskb where kokrs = itab_cskb-kokrs.
endif.
endif.
endif.
endif.
loop at itab_coep.
itab_final-kokrs = itab_coep-kokrs.
itab_final-gjahr = itab_coep-gjahr.
itab_final-perio = itab_coep-perio.
itab_final-kstar = itab_coep-kstar.
itab_final-bukrs = itab_coep-bukrs.
itab_final-wogbtr = itab_coep-wogbtr.
append itab_final.
clear itab_final.
endloop.
loop at itab_final.
read table itab_cepc with key kokrs = itab_final-kokrs.
if sy-subrc = 0.
itab_final-prctr = itab_cepc-prctr.
itab_final-khinr = itab_cepc-khinr.
modify itab_final transporting prctr khinr.
endif.
read table itab_aufk with key kokrs = itab_final-kokrs.
if sy-subrc = 0.
itab_final-aufnr = itab_aufk-aufnr.
modify itab_final transporting aufnr.
endif.
read table itab_cskb with key kstar = itab_final-kstar.
if sy-subrc = 0.
itab_final-katyp = itab_cskb-katyp.
*itab_final-aufnr = itab_final-aufnr.
modify itab_final transporting katyp.
endif.
read table itab_tkv11 with key kokrs = itab_final-kokrs.
if sy-subrc = 0.
itab_final-kagru = itab_tkv11-kagru.
modify itab_final transporting kagru.
endif.
endloop.
loop at itab_final.
itab_final-ca = p_ca.
itab_final-ccl = s_code-low.
itab_final-cch = s_code-high.
itab_final-pgl = s_pg-low.
itab_final-pgh = s_pg-high.
itab_final-pcl = s_pc-low.
itab_final-pch = s_pc-high.
itab_final-kul = s_ku-low.
itab_final-kuh = s_ku-high.
itab_final-orl = s_or-low.
itab_final-orh = s_or-high.
itab_final-periol = s_pd-low.
itab_final-perioh = s_pd-high.
itab_final-gjahrl = s_year-low.
itab_final-gjahrh = s_year-high.
modify itab_final transporting periol perioh gjahrl gjahrh ca ccl cch pgl pgh pcl pch kul kuh orl orh.
endloop.
sort itab_final by katyp descending.
d_fieldcat_wa-fieldname = 'KATYP'.
d_fieldcat_wa-seltext_m = 'CostelementType'.
d_fieldcat_wa-col_pos = 1.
append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.
d_fieldcat_wa-fieldname = 'WOGBTR'.
d_fieldcat_wa-seltext_m = 'AMount'.
d_fieldcat_wa-do_sum = 'X'.
d_fieldcat_wa-col_pos = 1.
append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.
d_fieldcat_wa-fieldname = 'PERIO'.
d_fieldcat_wa-seltext_m = 'Period'.
d_fieldcat_wa-col_pos = 4.
append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.
d_fieldcat_wa-fieldname = 'GJAHRL'.
d_fieldcat_wa-seltext_m = 'Year From'.
d_fieldcat_wa-col_pos = 5.
append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.
d_fieldcat_wa-fieldname = 'GJAHRH'.
d_fieldcat_wa-seltext_m = 'YearTo'.
d_fieldcat_wa-col_pos = 5.
append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.
DATA: DISVARIANT LIKE DISVARIANT.
DISVARIANT-REPORT = SY-REPID.
DISVARIANT-USERNAME = SY-UNAME.
perform build_layout.
perform build_sort.
data : gd_repid like sy-repid.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = gd_repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT = gd_layout
IT_FIELDCAT = d_fieldcat
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT = isort
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = 'X'
IS_VARIANT =
IT_EVENTS = t_eve
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP = 0
I_HTML_HEIGHT_END = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = itab_final
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
&----
*& Form build_layout
&----
text
----
--> p1 text
<-- p2 text
----
FORM build_layout .
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-subtotals_text = 'Revenue'.
*gd_layout-subtotals_text = 'Expenses'.
gd_layout-totals_text = 'Gross Margin'.
ENDFORM. " build_layout
&----
*& Form build_sort
&----
text
----
--> p1 text
<-- p2 text
----
FORM build_sort .
wsort-spos = 1.
wsort-fieldname = 'KATYP'.
wsort-group = 'UL'.
wsort-subtot = 'X'.
wsort-down = 'X'.
append wsort to isort.
clear wsort.
*if itab_final-katyp = '11' or itab_final-katyp = '12'.
*wsort-subtot = 'X'.
*wsort-group = 'UL'.
*wsort-down = 'X'.
*gd_layout-subtotals_text = 'Revenue'.
*append wsort to isort.
*
*elseif itab_final-katyp = '01'.
*wsort-subtot = 'X'.
*wsort-group = 'UL'.
*wsort-down = 'X'.
*gd_layout-subtotals_text = 'Expense'.
*append wsort to isort.
*
*
*elseif itab_final-katyp <> '11' or itab_final-katyp <> '12' or itab_final-katyp <> '01'.
*wsort-subtot = 'X'.
*wsort-group = 'UL'.
*wsort-down = 'X'.
*gd_layout-subtotals_text = 'Allocated Cost'.
*
*endif.
ENDFORM. " build_sort
&----
*& Form Top_of_page
&----
text
----
--> p1 text
<-- p2 text
----
form top_of_page.
data : uline like sy-uline.
data : wa_header1 type slis_listheader.
uline = sy-uline.
wa_header-typ = 'S'.
wa_header-info = 'Inputs'.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-info = uline.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-key = 'Controlling Area:'.
wa_header-info = itab_final-ca.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-key = ' Year '.
concatenate itab_final-gjahrl 'to' itab_final-gjahrh
into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-key = 'Company Code '.
concatenate itab_final-ccl 'to' itab_final-cch
into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-key = ' Profit Center Group '.
concatenate itab_final-pgl 'to' itab_final-pgh
into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-key = 'Profit Center '.
concatenate itab_final-pcl 'to' itab_final-pch
into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-key = 'Cost Element Group '.
concatenate itab_final-kul 'to' itab_final-kuh
into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-key = ' Internal Order '.
concatenate itab_final-orl 'to' itab_final-orh
into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
wa_header-typ = 'S'.
wa_header-info = uline.
append wa_header to t_header.
clear wa_header.
wa_header1-key = 'TillPeriod '.
concatenate itab_final-periol 'To'
itab_final-perioh into wa_header1-info separated by space.
wa_header-typ = 'S'.
concatenate 'From Period ' itab_final-periol
space wa_header1 into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = t_header
I_LOGO =
I_END_OF_LIST_GRID =
I_ALV_FORM =
.
refresh t_header.
endform. "top_of_page