‎2007 Feb 06 4:24 PM
Hi All,
I am trying to develop a generic function module which can be used in different programs for displaying ALV.
I am able to display the ALV but unable to get the header for it.
Please suggest.
This is the code -
function zhrca_show_itab_in_alv.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(V_REPID) TYPE SY-REPID DEFAULT SY-REPID
*" TABLES
*" ITAB
*" ITAB_NAMES
*" I_ALV OPTIONAL
*" EXCEPTIONS
*" DATA_TABLE_EMPTY
*" HEADER_TABLE_EMPTY
*"----
l_repid = v_repid.
describe table itab lines l_lines.
if l_lines eq 0.
raise data_table_empty.
endif.
describe table itab_names lines l_lines.
if l_lines eq 0.
raise header_table_empty.
endif.
perform fill_layout changing l_layout.
PERFORM easy_alv_build_fcat TABLES itab
itab_names
CHANGING fcat error.
***************************
field-symbols: <f_line> type any.
clear fcat.
refresh fcat.
error = 0.
l_index = 0.
clear fcat.
refresh fcat.
Read the structure of the incoming Internal table and then
create the field catalog ,assigning the user defined texts
sent in the table P_ITAB_NAMES
assign local copy of initial line of itab to <f_line>.
describe field <f_line> into td.
read table td-types index 1 into typed.
if typed-from = 0 and typed-to = 0.
error = 10. exit.
endif.
read table itab_names index l_index.
itab_names1[] = itab_names[].
loop at td-types into wa_types from typed-from to typed-to.
l_index = l_index + 1.
read table td-names into wa_name index wa_types-idx_name.
wa_fcat-fieldname = wa_name-name.
if not wa_name-continue is initial.
idx = wa_types-idx_name + 1.
read table td-names into wa_name index idx.
For local struct no more than 30 chars are allowed so there is no need
to loop at td-name to get more than 2 pieces of the name
concatenate wa_fcat-fieldname wa_name-name
into wa_fcat-fieldname.
endif.
READ TABLE itab_names INDEX l_index.
read table itab_names1 index l_index.
wa_fcat-reptext_ddic = itab_names1-title.
wa_fcat-inttype = wa_types-type.
wa_fcat-outputlen = wa_types-output_length.
textlen = strlen( wa_fcat-fieldname ).
if wa_fcat-outputlen < textlen.
wa_fcat-outputlen = textlen.
endif.
wa_fcat-decimals_out = wa_types-decimals.
append wa_fcat to fcat.
endloop.
***************************
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_eventcat
EXCEPTIONS
list_type_wrong = 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.
*
CLEAR l_event.
READ TABLE i_eventcat WITH KEY name = slis_ev_top_of_page INTO l_event.
IF sy-subrc = 0.
MOVE 'ZF_TOP_OF_PAGE' TO l_event-form.
APPEND l_event TO i_eventcat.
ENDIF.
*perform event.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = l_repid
i_callback_top_of_page = 'ALV_TOP_OF_PAGE'
i_callback_pf_status_set = ' '
i_callback_user_command = ' '
is_layout = l_layout
it_fieldcat = fcat
it_events = i_eventcat
i_default = 'X'
i_save = 'A'
is_variant = l_variant
tables
t_outtab = itab
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.
endfunction.
----
***INCLUDE LZHRCA_UEMAILSF02 .
----
&----
*& Form FILL_LAYOUT
&----
form fill_layout changing c_f_layout type slis_layout_alv.
Call module to set values for optimize width etc
call function 'FM_ALV_LAYOUT'
changing
c_f_layout = c_f_layout.
c_f_layout-key_hotspot = ' '.
endform. " FILL_LAYOUT
*&----
**& Form event
*&----
text
*----
--> p1 text
<-- p2 text
*----
*FORM event .
*
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_eventcat
EXCEPTIONS
list_type_wrong = 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.
*
CLEAR l_event.
READ TABLE i_eventcat WITH KEY name = slis_ev_top_of_page INTO l_event.
IF sy-subrc = 0.
MOVE 'ZF_TOP_OF_PAGE' TO l_event-form.
APPEND l_event TO i_eventcat.
ENDIF.
*
*
*
*ENDFORM. " event
&----
*& Form alv_top_of_page
&----
text
----
form alv_top_of_page.
data: l_listheader type slis_listheader.
refresh i_listheader.
clear l_listheader.
l_listheader-typ = 'H'.
l_listheader-key = 'Program'.
l_listheader-info = l_repid.
append l_listheader to i_listheader.
clear l_listheader.
l_listheader-typ = 'S'.
l_listheader-key = 'Run Date'.
l_listheader-info = sy-datum.
append l_listheader to i_listheader.
clear l_listheader.
l_listheader-typ = 'S'.
l_listheader-key = 'Run BY'.
l_listheader-info = sy-uname.
append l_listheader to i_listheader.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_listheader.
endform. " ALV_TOP_OF_PAGE
Points will be rewarded.
Thanks,
Amit Khare
Anym Suggestion from anyone.
Message was edited by:
Amit Khare
‎2007 Feb 06 11:28 PM
Hi,
Do this change at starting of your FM..
l_repid = <b>sy-repid</b>.
Since you are assigning the program name that calls this function module...But the subroutine 'ALV_TOP_OF_PAGE' is available inside your function module..
So this should work..
Thanks,
Naren
‎2007 Feb 06 9:28 PM
Hi Amit,
Try the following:
function zhrca_show_itab_in_alv.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(V_REPID) TYPE SY-REPID DEFAULT SY-REPID
*" TABLES
*" ITAB
*" ITAB_NAMES
*" I_ALV OPTIONAL
*" EXCEPTIONS
*" DATA_TABLE_EMPTY
*" HEADER_TABLE_EMPTY
*"----
l_repid = v_repid.
describe table itab lines l_lines.
if l_lines eq 0.
raise data_table_empty.
endif.
describe table itab_names lines l_lines.
if l_lines eq 0.
raise header_table_empty.
endif.
perform fill_layout changing l_layout.
PERFORM easy_alv_build_fcat TABLES itab
itab_names
CHANGING fcat error.
***************************
field-symbols: <f_line> type any.
clear fcat.
refresh fcat.
error = 0.
l_index = 0.
clear fcat.
refresh fcat.
Read the structure of the incoming Internal table and then
create the field catalog ,assigning the user defined texts
sent in the table P_ITAB_NAMES
assign local copy of initial line of itab to <f_line>.
describe field <f_line> into td.
read table td-types index 1 into typed.
if typed-from = 0 and typed-to = 0.
error = 10. exit.
endif.
read table itab_names index l_index.
itab_names1[] = itab_names[].
loop at td-types into wa_types from typed-from to typed-to.
l_index = l_index + 1.
read table td-names into wa_name index wa_types-idx_name.
wa_fcat-fieldname = wa_name-name.
if not wa_name-continue is initial.
idx = wa_types-idx_name + 1.
read table td-names into wa_name index idx.
For local struct no more than 30 chars are allowed so there is no need
to loop at td-name to get more than 2 pieces of the name
concatenate wa_fcat-fieldname wa_name-name
into wa_fcat-fieldname.
endif.
READ TABLE itab_names INDEX l_index.
read table itab_names1 index l_index.
wa_fcat-reptext_ddic = itab_names1-title.
wa_fcat-inttype = wa_types-type.
wa_fcat-outputlen = wa_types-output_length.
textlen = strlen( wa_fcat-fieldname ).
if wa_fcat-outputlen < textlen.
wa_fcat-outputlen = textlen.
endif.
wa_fcat-decimals_out = wa_types-decimals.
append wa_fcat to fcat.
endloop.
***************************
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_eventcat
EXCEPTIONS
list_type_wrong = 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.
*
CLEAR l_event.
READ TABLE i_eventcat WITH KEY name = slis_ev_top_of_page INTO l_event.
IF sy-subrc = 0.
MOVE 'ZF_TOP_OF_PAGE' TO l_event-form.
APPEND l_event TO i_eventcat.
ENDIF.
<b>perform event.</b>
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = l_repid
i_callback_top_of_page = 'ALV_TOP_OF_PAGE'
i_callback_pf_status_set = ' '
i_callback_user_command = ' '
is_layout = l_layout
it_fieldcat = fcat
it_events = i_eventcat
i_default = 'X'
i_save = 'A'
is_variant = l_variant
tables
t_outtab = itab
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.
endfunction.
----
***INCLUDE LZHRCA_UEMAILSF02 .
----
&----
*& Form FILL_LAYOUT
&----
form fill_layout changing c_f_layout type slis_layout_alv.
Call module to set values for optimize width etc
call function 'FM_ALV_LAYOUT'
changing
c_f_layout = c_f_layout.
c_f_layout-key_hotspot = ' '.
endform. " FILL_LAYOUT
*&----
**& Form event
*&----
text
*----
--> p1 text
<-- p2 text
*----
<b>FORM event .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_eventcat
EXCEPTIONS
list_type_wrong = 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.
CLEAR l_event.
READ TABLE i_eventcat WITH KEY name = slis_ev_top_of_page INTO l_event.
IF sy-subrc = 0.
MOVE 'ZF_TOP_OF_PAGE' TO l_event-form.
APPEND l_event TO i_eventcat.
ENDIF.
ENDFORM. " event</b>
&----
*& Form alv_top_of_page
&----
text
----
form alv_top_of_page.
data: l_listheader type slis_listheader.
refresh i_listheader.
clear l_listheader.
l_listheader-typ = 'H'.
l_listheader-key = 'Program'.
l_listheader-info = l_repid.
append l_listheader to i_listheader.
clear l_listheader.
l_listheader-typ = 'S'.
l_listheader-key = 'Run Date'.
l_listheader-info = sy-datum.
append l_listheader to i_listheader.
clear l_listheader.
l_listheader-typ = 'S'.
l_listheader-key = 'Run BY'.
l_listheader-info = sy-uname.
append l_listheader to i_listheader.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_listheader.
endform. " ALV_TOP_OF_PAGE
Hope it helps.
Regards,
Gilberto Li
‎2007 Feb 06 11:23 PM
Thanks for reply,
but you may find the same suggestion existing in the code and commented out, as it is not working too.
Amit
‎2007 Feb 06 11:28 PM
Hi,
Do this change at starting of your FM..
l_repid = <b>sy-repid</b>.
Since you are assigning the program name that calls this function module...But the subroutine 'ALV_TOP_OF_PAGE' is available inside your function module..
So this should work..
Thanks,
Naren