2014 Apr 30 11:55 AM
My ALV works and displays correct output. However, I am struggling to display the text 'Total' on position in the last row of the grid. The total is for the salary. My code is below..
I have looked on numerous sites and forums for assistance.
*&---------------------------------------------------------------------*
*& Report ZALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZALV.
TABLES: ZCONTACT.
TYPE-POOLS: slis. "slis contains all of the ALV data types.
DATA: "fieldcatALOG TYPE slis_t_fieldcat_alv WITH HEADER LINE,
it_zcontact TYPE TABLE OF zcontact,"declares an internal table of type ZCONTACT
alv_prog_name LIKE sy-repid,
g_variant TYPE disvariant,
gx_variant TYPE disvariant,
g_save TYPE c VALUE 'X',
it_fieldcat TYPE slis_t_fieldcat_alv,"declares field catalog table of line type alv
wa_fieldcat TYPE slis_fieldcat_alv, "declares the work area of the field catalog
it_list_top_of_page TYPE slis_t_listheader,
izontact TYPE TABLE OF zcontact,
h1(10) TYPE c VALUE 'Toatall',
"i_logo TYPE OT.
gt_events TYPE slis_t_event,
gd_prntparams TYPE slis_print_alv,
text(40) type c,
wa_layout TYPE slis_layout_alv.
**Selection Screen details
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: variant like disvariant-variant.
SELECTION-SCREEN END OF BLOCK B1.
**Getting default variant
INITIALIZATION.
gx_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = G_SAVE
CHANGING
CS_VARIANT = GX_VARIANT
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 0.
VARIANT = GX_VARIANT-VARIANT.
ENDIF.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_FIELDCATALOG.
PERFORM DISPLAY_ALV_REPORT.
"PERFORM build_alv_header
FORM BUILD_FIELDCATALOG.
*Build field catalog
wa_fieldcat-fieldname = 'ID'.
wa_fieldcat-seltext_m = 'ID'.
wa_fieldcat-col_pos = 0.
wa_fieldcat-outputlen = 10.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
*
wa_fieldcat-fieldname = 'LASTNAME'.
wa_fieldcat-seltext_m = 'LASTNAME'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
*
wa_fieldcat-fieldname = 'FIRSTNAME'.
wa_fieldcat-seltext_m = 'FIRSTNAME'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
*
wa_fieldcat-fieldname = 'DOB'.
wa_fieldcat-seltext_m = 'DOB'.
wa_fieldcat-col_pos = 3.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
*
wa_fieldcat-fieldname = 'TEL'.
wa_fieldcat-seltext_m = 'Tel'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ADDRESS'.
wa_fieldcat-seltext_m = 'ADDRESS'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'OCCUPATION'.
wa_fieldcat-seltext_m = 'OCCUPATION'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
**
wa_fieldcat-fieldname = 'WEIGHT'.
wa_fieldcat-seltext_m = 'WEIGHT'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
*
wa_fieldcat-fieldname = 'AGE'.
wa_fieldcat-seltext_m = 'AGE'.
wa_fieldcat-do_sum = 'X'. "Display column total
APPEND wa_fieldcat TO it_fieldcat.
"CLEAR wa_fieldcat.
*
wa_fieldcat-fieldname = 'SALARY'.
wa_fieldcat-seltext_m = 'SALARY'.
wa_fieldcat-do_sum = 'X'.
wa_fieldcat-cfieldname = 'CURRENCYKEY'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'CURRENCY'.
wa_fieldcat-seltext_s = 'CURRENCY'.
APPEND wa_fieldcat TO it_fieldcat.
"CLEAR wa_fieldcat.
ENDFORM. "BUILDING THE FIELD CATALOG
**FORM layout.
*wa_layout-colwidth_optimize = 'X'.
*wa_layout-totals_text ='TOTAL'.
*wa_layout-zebra = 'X'.
*ENDFORM.
"ls_layout-cell_merge = 'X'.
FORM DISPLAY_ALV_REPORT.
alv_prog_name = sy-repid.
*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = it_fieldcat[]
i_callback_program = alv_prog_name
is_layout = wa_layout
i_callback_top_of_page = 'TOP_OF_PAGE'
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'ZCONTACT'
i_save = 'X'
it_events = gt_events
is_print = gd_prntparams
is_variant = g_variant
"is_layout = ls_layout
TABLES
t_outtab = it_zcontact
EXCEPTIONS
program_error = 1
OTHERS = 2.
WRITE: H1 UNDER 'SALARY'.
ENDFORM.
**Fetch data from the database
FORM DATA_RETRIEVAL.
SELECT * FROM zcontact INTO TABLE it_zcontact.
ENDFORM.
*
FORM top_of_page.
*ALV Header declarations
DATA: it_listheader TYPE slis_t_listheader,
wa_listheader TYPE slis_listheader,
t_line like wa_listheader-info,
ld_lines TYPE I,
ld_linesc(10) TYPE C.
wa_listheader-typ = 'H'.
wa_listheader-info = 'Contact Details'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-info = sy-repid.
wa_listheader-key = 'Program Name:'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-info = sy-uname.
wa_listheader-key = 'User Name:'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-key = 'Run Date :'.
CONCATENATE sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO wa_listheader-info
SEPARATED BY '/'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-key = 'Time :'.
CONCATENATE sy-uzeit(2)
sy-uzeit+2(2)
sy-uzeit+4(2)
INTO wa_listheader-info
SEPARATED BY ':'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_listheader[]
i_logo = 'KLOGO'.
ENDFORM. "top_of_page
2014 Apr 30 12:03 PM
Hi,
you cannot edit the standard totals performed in an ALV.
Also if you put your own line of total in the Internal table and user clicks on total it will consider this total also and will give wrong result.
So Ideally speaking it is not possible to edit the line of standard ALV totals / Sub totals.
Regards
2014 Apr 30 12:03 PM
Hi,
you cannot edit the standard totals performed in an ALV.
Also if you put your own line of total in the Internal table and user clicks on total it will consider this total also and will give wrong result.
So Ideally speaking it is not possible to edit the line of standard ALV totals / Sub totals.
Regards
2014 Apr 30 12:08 PM
Thanks for the prompt response..Not editing the totals..having a text/label in a row labelled 'Total.' for example at the beginning of the last row.
2014 Apr 30 12:16 PM
That's what ... The last row is from standard and you cannot modify it.
2014 Apr 30 12:27 PM
To change final display of an ALV grid you need to handle event after_refresh of class cl_gui_alv_grid (*) or similar event for latest salv tables classes.
If you are asking on a total subtotal line, you can use method get_subtotals in the previous event to get some reference to total lines and update some fields (**), and then force (only once using a global flag) redisplay with method refresh_table_display with paramether i_soft_refresh set.
If you want to change the value in an initial field of the displayed record, use the same event, get the sort criteria with method get_sort_criteria, identify the last record, update it and redisplay the grid the same way.
But, frankly, I do not see much relevance in your request, just define a field as summed and ALV will add a total line for almost no cost ?
Regards,
Raymond
(*) Of course using this good old REUSE_ALV_GRID_DISPLAY FM was not the best idea if you need to change the standard behavior, not without playing with GET_GLOBALS_FROM_SLVC_FULLSCR..
(**) But, in your case, field for AGE must allow input of 'TOTAL' text.
2014 May 12 8:29 AM
Actually, you CAN modify the totals row, if you use the OO ALV.
2014 May 12 8:40 AM
Thank you! so i'll have to change the structure of my program to be OO not a simple standard ALV? So il have to use Modules and CALL SCREEN to display output etc.. then Thank you..I've been biting myself for that one issue.
2014 May 12 8:49 AM
Well, it's a bit of work, so I would suggest you first should weigh up if it's really worth it to invest extra work just to display the word "Total" in the totals row.
2014 Apr 30 12:26 PM
Hi Ten,
In order to display the 'Total' text, you need to use the below code and populate LS_LAYOUT to importing parameter is_layout of FM REUSE_ALV_GRID_DISPLAY.
DATA: LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
LS_LAYOUT-TOTALS_TEXT = 'TOTAL'.
**FORM layout.
*wa_layout-colwidth_optimize = 'X'.
*wa_layout-totals_text ='TOTAL'.
*wa_layout-zebra = 'X'.
*ENDFORM.
It has been observed from your code that you have already used code but commented it seems.
Uncomment this code and try.
Regards
Gangadhar
2014 Apr 30 1:33 PM
Hi Ten,
You have to create a custom row at last index of your output table.
After filling your output table loop through your output table and sum all the values that you want to add and append it into your output table with custom text 'Total'. Make sure your first column in ALV is character type and capable of holding value Total.
Mark if helpful.
Regards,
Nooruddin Bohra
2014 May 02 7:58 AM
hello,
Thank you for your response.
i have tried again and again, but i cant get the total field to display, I did change the ID column in my data dictionary to CHAR and specified this in my alv catalog. i also added a new text row of length 10 then i looped(loop at itt_zcontact into wat_zcontact.)..please take a look and let me know. I appreciate it. its the last part of what im doing. basically im 90% done. i only have to show the 'total' text label in the last row..
PS iv even tried saying WRITE 'TOTAL' UNDER 'ID'...but that did not work.
code below:
*&---------------------------------------------------------------------*
*& Report ZALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZALV.
TABLES: ZCONTACT.
TYPE-POOLS: slis. "slis contains all of the ALV data types.
TYPES: BEGIN OF t_zcontact,
mandt TYPE mandt,
id TYPE zcontactid,
lastname type zcontactlname,
firstname TYPE zcontactfname,
dob TYPE zdateofbirth,
tel TYPE ztel,
address TYPE zaddress,
occupation TYPE zoccup,
weight type zweight,
age TYPE zage,
salary TYPE zsalary,
ecurrency TYPE curcy,
TEXT(10) TYPE c,
END OF t_zcontact.
DATA: itt_zcontact TYPE STANDARD TABLE OF t_zcontact INITIAL SIZE 0,
wat_zcontact TYPE t_zcontact.
DATA: "it_zcontact TYPE TABLE OF zcontact,"declares an internal table of type ZCONTACT
gd_repid LIKE sy-repid,
g_variant TYPE disvariant,
gx_variant TYPE disvariant,
g_save TYPE c VALUE 'X',
fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,"declares field catalog table of line type alv
gd_tab_group type slis_t_sp_group_alv,
gd_prntparams TYPE slis_print_alv,
"fieldcatalog TYPE slis_fieldcat_alv, "declares the work area of the field catalog
it_list_top_of_page TYPE slis_t_listheader,
izontact TYPE TABLE OF zcontact,
"h1(10) TYPE c VALUE 'Toatall',
"i_logo TYPE OT.
gt_events TYPE slis_t_event,
gd_layout TYPE slis_layout_alv.
data: it_sortcat type slis_sortinfo_alv occurs 1,
wa_sort like line of it_sortcat.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_FIELDCATALOG.
PERFORM DISPLAY_ALV_REPORT.
PERFORM BUILD_LAYOUT.
perform build_sortcat.
"PERFORM build_alv_header
*
*DATA: gd_layout TYPE slis_layout_alv.
* gd_layout-totals_text = 'TOTAL'.
**Selection Screen details
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: variant like disvariant-variant.
SELECTION-SCREEN END OF BLOCK B1.
**Getting default variant
INITIALIZATION.
gx_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = G_SAVE
CHANGING
CS_VARIANT = GX_VARIANT
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 0.
VARIANT = GX_VARIANT-VARIANT.
ENDIF.
FORM BUILD_FIELDCATALOG.
*Build field catalog
fieldcatalog-fieldname = 'ID'.
fieldcatalog-seltext_m = 'ID'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-datatype = 'CHAR'.
"fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'LASTNAME'.
fieldcatalog-seltext_m = 'LASTNAME'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
*
fieldcatalog-fieldname = 'FIRSTNAME'.
fieldcatalog-seltext_m = 'FIRSTNAME'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'DOB'.
fieldcatalog-seltext_m = 'DOB'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'TEL'.
fieldcatalog-seltext_m = 'Tel'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ADDRESS'.
fieldcatalog-seltext_m = 'ADDRESS'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'OCCUPATION'.
fieldcatalog-seltext_m = 'OCCUPATION'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
**
fieldcatalog-fieldname = 'WEIGHT'.
fieldcatalog-seltext_m = 'WEIGHT'.
"fieldcatalog-do_sum = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'AGE'.
fieldcatalog-seltext_m = 'AGE'.
"fieldcatalog-do_sum = 'X'. "Display column total
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'SALARY'.
fieldcatalog-seltext_m = 'SALARY'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype ='CURR'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
"fieldcatalog-fieldname = 'ECURRENCY'.
"fieldcatalog-seltext_s = 'ECURRENCY'.
"APPEND fieldcatalog TO fieldcatalog.
"CLEAR fieldcatalog.
fieldcatalog-fieldname = 'TEXT'.
fieldcatalog-seltext_m = 'Totals'.
fieldcatalog-tech = 'X'.
fieldcatalog-no_out = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
ENDFORM. "BUILDING THE FIELD CATALOG
FORM BUILD_LAYOUT.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-no_totalline = 'X'.
ENDFORM.
"ls_layout-cell_merge = 'X'.
*&----------------------------------------------------------*
*& Form build_sortcat
*&----------------------------------------------------------*
* Build Sort catalog
*-----------------------------------------------------------*
FORM build_sortcat .
wa_sort-spos = 1.
wa_sort-fieldname = 'TEXT'.
wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field
wa_sort-up = 'X'.
APPEND wa_sort TO it_sortcat.
ENDFORM. " build_sortcat
FORM DISPLAY_ALV_REPORT.
gd_repid = sy-repid.
*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fieldcatalog[]
it_sort = it_sortcat
i_callback_program = gd_repid
is_layout = gd_layout
i_callback_top_of_page = 'TOP_OF_PAGE'
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'ZCONTACT'
i_save = 'X'
it_events = gt_events
is_print = gd_prntparams
is_variant = g_variant
"is_layout = ls_layout
TABLES
t_outtab = itt_zcontact
EXCEPTIONS
program_error = 1
OTHERS = 2.
"WRITE: 'TOTAL' UNDER 'ID'.
"IF SY-SUBRC <> 0.
"ENDIF.
"LEAVE LIST-PROCESSING.
ENDFORM.
**Fetch data from the database
FORM DATA_RETRIEVAL.
DATA: ld_subtot(1) type c.
SELECT * FROM zcontact INTO TABLE itt_zcontact.
*Populate field with text value
loop at itt_zcontact into wat_zcontact.
* Populate color variable with colour properties
ld_subtot = ld_subtot + 1.
wat_zcontact-text = ld_subtot.
modify itt_zcontact from wat_zcontact.
endloop.
ENDFORM.
*
FORM top_of_page.
*ALV Header declarations
DATA: it_listheader TYPE slis_t_listheader,
wa_listheader TYPE slis_listheader,
t_line like wa_listheader-info,
ld_lines TYPE I,
ld_linesc(10) TYPE C.
wa_listheader-typ = 'H'.
wa_listheader-info = 'Contact Details'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-info = sy-repid.
wa_listheader-key = 'Program Name:'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-info = sy-uname.
wa_listheader-key = 'User Name:'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-key = 'Run Date :'.
CONCATENATE sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO wa_listheader-info
SEPARATED BY '/'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-key = 'Time :'.
CONCATENATE sy-uzeit(2)
sy-uzeit+2(2)
sy-uzeit+4(2)
INTO wa_listheader-info
SEPARATED BY ':'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_listheader[]
i_logo = 'KLOGO'.
ENDFORM. "top_of_page
2014 May 12 8:19 AM
I did this but still i cant display the total text..I have reposted my code. please assist. Im only missing that total label
*&---------------------------------------------------------------------*
*& Report ZALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZALV.
TABLES: ZCONTACT.
TYPE-POOLS: slis. "slis contains all of the ALV data types.
TYPES: BEGIN OF t_zcontact,
text(40) TYPE c, "storing the total text
mandt TYPE mandt,
id TYPE zcontactid,
lastname type zcontactlname,
firstname TYPE zcontactfname,
dob TYPE zdateofbirth,
tel TYPE ztel,
address TYPE zaddress,
occupation TYPE zoccup,
weight type zweight,
age TYPE zage,
salary TYPE zsalary,
ecurrency TYPE curcy,
END OF t_zcontact.
TYPES: BEGIN OF wa_zcontact,
mandt TYPE mandt,
id TYPE zcontactid,
lastname type zcontactlname,
firstname TYPE zcontactfname,
dob TYPE zdateofbirth,
tel TYPE ztel,
address TYPE zaddress,
occupation TYPE zoccup,
weight type zweight,
age TYPE zage,
salary TYPE zsalary,
ecurrency TYPE curcy,
END OF wa_zcontact.
TYPES:
i_zcontact TYPE STANDARD TABLE OF t_zcontact." INITIAL SIZE 0.
DATA: itt_zcontact TYPE STANDARD TABLE OF wa_zcontact INITIAL SIZE 0,
wat_zcontact TYPE wa_zcontact.
DATA: "it_zcontact TYPE TABLE OF zcontact,"declares an internal table of type ZCONTACT
gd_repid LIKE sy-repid,
g_variant TYPE disvariant,
gx_variant TYPE disvariant,
g_save TYPE c VALUE 'X',
fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,"declares field catalog table of line type alv
gd_tab_group type slis_t_sp_group_alv,
gd_prntparams TYPE slis_print_alv,
fieldcat TYPE slis_fieldcat_alv, "declares the work area of the field catalog
it_list_top_of_page TYPE slis_t_listheader,
i_zcontact TYPE TABLE OF zcontact,
"h1(10) TYPE c VALUE 'Toatall',
"i_logo TYPE OT.
gt_events TYPE slis_t_event,
gd_layout TYPE slis_layout_alv."work area for the alv layout
data: it_sortcat type slis_sortinfo_alv occurs 1,
wa_sort LIKE LINE OF it_sortcat.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_FIELDCATALOG.
PERFORM DISPLAY_ALV_REPORT.
PERFORM BUILD_LAYOUT.
perform build_sortcat.
PERFORM sub_add_text.
"PERFORM build_events.
PERFORM top-of-page.
"PERFORM build_alv_header.
END-OF-SELECTION.
*
*DATA: gd_layout TYPE slis_layout_alv.
* gd_layout-totals_text = 'TOTAL'.
**Selection Screen details
*SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
*PARAMETERS: variant like disvariant-variant.
*SELECTION-SCREEN END OF BLOCK B1.
*
***Getting default variant
*INITIALIZATION.
*gx_variant-report = sy-repid.
*CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
*EXPORTING
* I_SAVE = G_SAVE
* CHANGING
* CS_VARIANT = GX_VARIANT
* EXCEPTIONS
* NOT_FOUND = 2.
*IF SY-SUBRC = 0.
* VARIANT = GX_VARIANT-VARIANT.
* ENDIF.
FORM BUILD_FIELDCATALOG.
*Build field catalog
fieldcatalog-fieldname = 'ID'.
fieldcatalog-seltext_m = 'ID'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 10.
fieldcatalog-datatype = 'CHAR'.
"fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'LASTNAME'.
fieldcatalog-seltext_m = 'LASTNAME'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
*
fieldcatalog-fieldname = 'FIRSTNAME'.
fieldcatalog-seltext_m = 'FIRSTNAME'.
fieldcatalog-col_pos = 4.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'DOB'.
fieldcatalog-seltext_m = 'DOB'.
fieldcatalog-col_pos = 5.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'TEL'.
fieldcatalog-seltext_m = 'Tel'.
fieldcatalog-col_pos = 6.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'ADDRESS'.
fieldcatalog-seltext_m = 'ADDRESS'.
fieldcatalog-col_pos = 7.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'OCCUPATION'.
fieldcatalog-seltext_m = 'OCCUPATION'.
fieldcatalog-col_pos = 8.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
**
fieldcatalog-fieldname = 'WEIGHT'.
fieldcatalog-seltext_m = 'WEIGHT'.
"fieldcatalog-do_sum = 'X'.
fieldcatalog-col_pos = 9.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'AGE'.
fieldcatalog-seltext_m = 'AGE'.
"fieldcatalog-do_sum = 'X'. "Display column total
fieldcatalog-col_pos = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'SALARY'.
fieldcatalog-seltext_m = 'SALARY'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype ='CURR'.
fieldcatalog-col_pos = 11.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
"fieldcatalog-fieldname = 'ECURRENCY'.
"fieldcatalog-seltext_s = 'ECURRENCY'.
"APPEND fieldcatalog TO fieldcatalog.
"CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'TEXT'.
fieldcatalog-col_pos = 0.
"fieldcatalog-seltext_m = 'TEXT'.
fieldcatalog-tech = 'X'.
fieldcatalog-no_out = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
ENDFORM.
*&----------------------------------------------------------*
*& Form build_sortcat
*&----------------------------------------------------------*
* Build Sort catalog
*-----------------------------------------------------------*
FORM build_sortcat .
"wa_sort-spos = 1.
wa_sort-fieldname = 'TEXT'.
"wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field
wa_sort-up = 'X'.
APPEND wa_sort TO it_sortcat.
CLEAR wa_sort.
ENDFORM. " build_sortcat
FORM BUILD_LAYOUT.
*gd_layout-no_input = 'X'.
*gd_layout-colwidth_optimize = 'X'.
*gd_layout-totals_text = 'Totals'(201).
*"gd_LAYOUT-coltab_fieldname = 'SALARY'.
gd_layout-no_totalline = 'X'.
ENDFORM.
*IF sy-subrc = 0.
*
* LOOP AT fieldcatalog INTO fieldcat.
*
* IF fieldcat-fieldname = 'WEIGHT' OR
* fieldcat-fieldname = 'AGE'.
** Summation for WEIGHT & AGE
* fieldcat-do_sum = 'X'.
* MODIFY fieldcatalog FROM fieldcat TRANSPORTING do_sum.
*
* ENDIF.
*
* IF fieldcat-fieldname = 'TEXT'.
** Hide this field so that it can display it's content i.e.
** Total text in Subtotal level
* fieldcat-tech = 'X'.
* fieldcat-no_out = 'X'.
* MODIFY fieldcatalog FROM fieldcat TRANSPORTING tech no_out.
*
* ENDIF.
* CLEAR fieldcat.
* ENDLOOP.
* ENDIF.
*ENDFORM. "BUILDING THE FIELD CATALOG
*form build_events.
* data: ls_event type slis_alv_event.
*
* call function 'REUSE_ALV_EVENTS_GET'
* exporting
* i_list_type = 0
* importing
* et_events = gt_events[].
* read table gt_events with key name = slis_ev_top_of_page
* into ls_event.
* if sy-subrc = 0.
* move 'TOP-OF-PAGE' to ls_event-form.
* append ls_event to gt_events.
* endif.
*
* read table gt_events with key name = slis_ev_end_of_list
* into ls_event.
* if sy-subrc = 0.
* move 'END_OF_LIST' to ls_event-form.
* append ls_event to gt_events.
* endif.
*endform. " BUILD_EVENTS
"ls_layout-cell_merge = 'X'.
FORM DISPLAY_ALV_REPORT.
gd_repid = sy-repid.
*Pass data and field catalog to ALV function module to display ALV list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fieldcatalog[]
it_sort = it_sortcat
i_callback_program = gd_repid
is_layout = gd_layout
i_callback_top_of_page = 'TOP-OF-PAGE'
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'ZCONTACT'
i_save = 'X'
it_events = gt_events
is_print = gd_prntparams
is_variant = g_variant
"is_layout = ls_layout
TABLES
t_outtab = itt_zcontact
EXCEPTIONS
program_error = 1
OTHERS = 2.
"WRITE: 'TOTAL' UNDER 'ID'.
ENDFORM.
**Fetch data from the database
FORM DATA_RETRIEVAL.
"DATA: ld_subtot(1) type c.
SELECT * FROM zcontact INTO TABLE itt_zcontact UP TO 10 ROWS.
ENDFORM.
FORM sub_add_text.
*Populate field with text value
DATA:
wt_zcontact TYPE t_zcontact,
last TYPE zcontact-ID,
l_text(40) type c,
num type n.
loop at itt_zcontact into wat_zcontact.
* Populate final table
wt_zcontact-TEXT = 'Total salary: '.
"ld_subtot = ld_subtot + 1.
"wat_zcontact-text = ld_subtot.
modify itt_zcontact FROM wat_zcontact.
clear wat_zcontact.
"APPEND wat_zcontact TO itt_zcontact.
endloop.
ENDFORM.
*
FORM top-of-page.
*ALV Header declarations
DATA: it_listheader TYPE slis_t_listheader,
wa_listheader TYPE slis_listheader,
t_line like wa_listheader-info,
ld_lines TYPE I,
ld_linesc(10) TYPE C.
wa_listheader-typ = 'H'.
wa_listheader-info = 'Contact Details'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-info = sy-repid.
wa_listheader-key = 'Program Name:'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-info = sy-uname.
wa_listheader-key = 'User Name:'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-key = 'Run Date :'.
CONCATENATE sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO wa_listheader-info
SEPARATED BY '/'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
wa_listheader-typ = 'S'.
wa_listheader-key = 'Time :'.
CONCATENATE sy-uzeit(2)
sy-uzeit+2(2)
sy-uzeit+4(2)
INTO wa_listheader-info
SEPARATED BY ':'.
APPEND wa_listheader TO it_listheader.
CLEAR wa_listheader.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_listheader[]
i_logo = 'KLOGO'.
ENDFORM. "top_of_page