Anda di halaman 1dari 5

Report zvenkat_alv_subtot_text.

"Types
types:
begin of t_pa0001,
pernr type pa0001-pernr,
end of t_pa0001,
begin of t_pa0008,
pernr type pa0008-pernr,
lga01 type pa0008-lga01,
bet01 type pa0008-bet01,
end of t_pa0008.
"Work areas
data:
w_pa0008 type t_pa0008,
w_pa0001 type t_pa0001.
"Internal tables
data:
i_pa0008 type standard table of t_pa0008,
i_pa0001 type standard table of t_pa0001.
*&---------------------------------------------------------------------*
" ALV Declarations
*----------------------------------------------------------------------*
" Types Pools
type-pools:
slis.
" Types
types:
t_fieldcat
type slis_fieldcat_alv,
t_events
type slis_alv_event,
t_layout
type slis_layout_alv,
t_sort
type slis_sortinfo_alv,
t_keyinfo
type slis_keyinfo_alv.
" Workareas
data:
w_fieldcat
type t_fieldcat,
w_events
type t_events,
w_sort
type t_sort,
w_layout
type t_layout,
w_keyinfo
type t_keyinfo.
" Internal Tables
data:
i_fieldcat
type standard table of t_fieldcat,
i_events
type standard table of t_events,
i_sort
type standard table of t_sort.
start-of-selection.
perform get_data.
end-of-selection.
w_layout-colwidth_optimize = 'X'.

perform build_fieldcatalog.
perform build_events.
perform build_sort_tab.
perform build_relation_structure.
Item table
perform display_data.

"Fieldcatalog
"Events table
"To sort table and get subtotal
"Making relationship between header and

*&---------------------------------------------------------------------*
*&
Form get_data
*&---------------------------------------------------------------------*
form get_data.
data:l_0008 type pa0008 occurs 0 with header line.
select pernr
from pa0001
into corresponding fields of table i_pa0001
up to 50 rows
where begda le sy-datum
and endda
ge sy-datum.
if i_pa0001[] is not initial.
select pernr lga01 bet01
from pa0008
into corresponding fields of l_0008
for all entries in i_pa0001
where pernr = i_pa0001-pernr
and begda le sy-datum
and endda ge sy-datum.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga01.
w_pa0008-bet01 = l_0008-bet01.
append w_pa0008 to i_pa0008.
clear w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga02.
w_pa0008-bet01 = l_0008-bet02.
append w_pa0008 to i_pa0008.
clear w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga03.
w_pa0008-bet01 = l_0008-bet03.
append w_pa0008 to i_pa0008.
clear w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga04.
w_pa0008-bet01 = l_0008-bet04.
append w_pa0008 to i_pa0008.
clear w_pa0008.

endselect.
endif.

endform.
"get_data
*&---------------------------------------------------------------------*
*&
Form build_fieldcatalog
*&---------------------------------------------------------------------*
form build_fieldcatalog.
perform build_fcat using:
"Field
Int.Table
Text
'PERNR' 'I_PA0008'
'PERNR', "Remove this if u dont want in the item table
as well as it is there in the header table
'LGA01' 'I_PA0008'
'LGA01',
'BET01' 'I_PA0008'
'BET01'.
endform.
"build_fieldcatalog
*&---------------------------------------------------------------------*
*&
Form build_events
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form build_events.
clear:
w_events, i_events[].
w_events-name = 'TOP_OF_PAGE'.
w_events-form = 'TOP_OF_PAGE'.
append w_events to i_events.
clear w_events.
w_events-name = 'SUBTOTAL_TEXT'.
w_events-form = 'SUBTOTAL_TEXT'.
append w_events to i_events.
clear w_events.
endform.
"build_events
*&---------------------------------------------------------------------*
*&
Form build_relation_structure
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form build_relation_structure.
w_keyinfo-header01 = 'PERNR'.
w_keyinfo-item01
= 'PERNR'.
endform.
"build_relation_structure
*&---------------------------------------------------------------------*
*&
Form display_data

*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form display_data.
data:
l_program type sy-repid value sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = l_program
it_fieldcat
= i_fieldcat
it_events
= i_events
it_sort
= i_sort
tables
t_outtab
= i_pa0008.
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 build_fcat
*&---------------------------------------------------------------------*
form build_fcat using l_field l_tab l_text.
w_fieldcat-fieldname = l_field.
w_fieldcat-tabname
= l_tab.
w_fieldcat-seltext_m = l_text.
if l_field = 'BET01'.
w_fieldcat-do_sum = 'X'.
endif.
append w_fieldcat to i_fieldcat.
clear w_fieldcat.
endform.

" build_fcat

*&---------------------------------------------------------------------*
*&
Form top_of_page
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form top_of_page.
data :
i_header type slis_t_listheader,
w_header like line of i_header.
data:l_date1 type datum,
l_date2 type datum.
w_header-typ = 'S'.

w_header-info = sy-title.
append w_header to i_header.
clear w_header.
w_header-typ = 'H'.
w_header-info = sy-repid.
append w_header to i_header.
clear w_header.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_header
i_logo
= 'ENJOYSAP_LOGO'.
endform.
"top_of_page
*&---------------------------------------------------------------------*
*&
Form BUILD_sort_tab
*&---------------------------------------------------------------------*
form build_sort_tab .
clear :i_sort[],w_sort.
w_sort-spos
= 1.
w_sort-fieldname = 'PERNR'.
w_sort-tabname
= 'I_PA0008'. "header table
w_sort-up
= 'X'.
w_sort-subtot
= 'X'.
append w_sort to i_sort.
clear w_sort.
endform.
" BUILD_sort_tab
*&---------------------------------------------------------------------*
*&
Form subtotal_text
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_TOTAL
text
*
-->P_SUBTOT_TEXT text
*----------------------------------------------------------------------*
form subtotal_text changing
p_total type any
p_subtot_text type slis_subtot_text.
if p_subtot_text-criteria = 'PERNR'.
p_subtot_text-display_text_for_subtotal = 'Employee Salary'.
endif.
endform.

"subtotal_text

Anda mungkin juga menyukai