Application Development 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: 

regd : alv

Former Member
0 Kudos
163

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

1 ACCEPTED SOLUTION

former_member402443
Contributor
0 Kudos
111

Hi Vinutha,

I go thru your code. Its working fine and at the end it also display the subtotal.

I want to know that on which field you want to display the subtotal.

Regards,

Manoj Kumar

6 REPLIES 6

former_member402443
Contributor
0 Kudos
112

Hi Vinutha,

I go thru your code. Its working fine and at the end it also display the subtotal.

I want to know that on which field you want to display the subtotal.

Regards,

Manoj Kumar

0 Kudos
111

hi,

at each costelement type i am getting subtotal value.i wan't to include subtotal text for this...please help me out.

0 Kudos
111

are the other layout options working fine?

0 Kudos
111

hi,

i have used layout also.

gd_layout-subtotals_text = 'Revenue'.

but it not getting displayed in the output.

0 Kudos
111

hi,

ya facing same problem, its not working in my case also...

U have to do manually like,

SORT itab BY mblnr.

LOOP AT itab.

AT NEW mblnr.

LOOP AT itab WHERE mblnr = itab-mblnr.

st_menge = st_menge + itab-menge.

itab1-mblnr = itab-mblnr.

itab1-matnr = itab-matnr.

itab1-werks = itab-werks.

itab1-menge = itab-menge.

APPEND itab1.

ENDLOOP.

itab1-mblnr = 'Sub_Total'.

itab1-matnr = ''.

itab1-werks = ''.

itab1-menge = st_menge.

itab1-line_color = 'C710'.

APPEND itab1.

itab1-line_color = ''.

CLEAR st_menge.

ENDAT.

ENDLOOP.

LOOP AT itab.

gt_menge = gt_menge + itab-menge.

ENDLOOP.

itab1-mblnr = 'Total'.

itab1-matnr = ''.

itab1-werks = ''.

itab1-menge = gt_menge.

itab1-line_color = 'C310'.

APPEND itab1.

reward if useful...

Former Member
0 Kudos
111

hi Vinutha,

This is kiran kumar.G.I will check ur code.The code u writeen is correct.I will send some sample code according to ur requirement.plz check it once.plz copy the below code and execite in ur system.

code:

EPORT yalv_subtotal .

----


  • Type Pools

----


TYPE-POOLS:slis.

----


  • Tables

----


TABLES: vbak, "Sales Document: Header Data

vbap. "Sales Document: Item Data

----


  • Global Structures

----


DATA:gt_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv,

gt_sortcat TYPE slis_t_sortinfo_alv,

wa_sortcat LIKE LINE OF gt_sortcat.

----


  • Internal Table

----


DATA: BEGIN OF gt_salesorder OCCURS 0,

vbeln LIKE vbak-vbeln, " Sales Document Number

posnr LIKE vbap-posnr, " Sales Doc Item

netwr LIKE vbap-netwr, " Net Value

END OF gt_salesorder.

----


  • SELECT OPTIONS

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. " Sales Document Number.

SELECTION-SCREEN END OF BLOCK b1.

----


  • Initialization

----


INITIALIZATION.

PERFORM initialization.

----


  • Start Of Selection

----


START-OF-SELECTION.

PERFORM field_catalog. "For Structure Creation

PERFORM fetch_data. "Get the Data From DB Table

PERFORM sorting USING gt_sortcat.

----


  • End Of Selection

----


END-OF-SELECTION.

PERFORM display_data.

&----


*& Form initialization

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM initialization .

s_vbeln-sign = 'I'.

s_vbeln-option = 'BT'.

s_vbeln-low = '4969'.

s_vbeln-high = '5000'.

APPEND s_vbeln.

ENDFORM. " initialization

&----


*& Form field_catalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM field_catalog .

REFRESH : gt_fieldcat.

CLEAR : wa_fieldcat.

wa_fieldcat-col_pos = '1'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table

wa_fieldcat-fieldname = 'VBELN'. "Field Name

wa_fieldcat-key = 'X'. "Blue Color

wa_fieldcat-seltext_m = 'Sales Doc No'. "Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '2'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table Name

wa_fieldcat-fieldname = 'POSNR'. "Field Name

wa_fieldcat-seltext_m = 'Sales Doc Item'."Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

*SubTotal on the Field NETWR

wa_fieldcat-col_pos = '3'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table

wa_fieldcat-fieldname = 'NETWR'. "Field Name

wa_fieldcat-do_sum = 'X'. "Sum

wa_fieldcat-seltext_m = 'Net Value'. "Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " field_catalog

&----


*& Form sorting

&----


  • text

----


  • -->P_IT_SORTCAT text

----


FORM sorting USING p_it_sortcat TYPE slis_t_sortinfo_alv.

clear wa_sortcat.

wa_sortcat-fieldname = 'VBELN'.

wa_sortcat-up ='X'.

wa_sortcat-subtot = 'X'.

APPEND wa_sortcat TO p_it_sortcat.

ENDFORM. " sorting

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = SY-REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_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 =

it_fieldcat = gt_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

it_sort = gt_sortcat

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • 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

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = gt_salesorder

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.

ENDFORM. " display_data

&----


*& Form fetch_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fetch_data .

refresh : gt_salesorder.

clear : gt_salesorder.

SELECT a~vbeln

posnr

b~netwr

FROM vbak AS a

INNER JOIN vbap AS b ON avbeln = bvbeln

INTO TABLE gt_salesorder

WHERE a~vbeln IN s_vbeln.

ENDFORM. " fetch_data

Award points if helpful.

kiran kumar.G