‎2006 Mar 17 4:13 PM
I have created a report that has various cols and then the detail lines sorted by customer, I have also created a static top of page section for the report, The analyst wants a header with specific info that will change for each customer followed by the detail lines. How do I create a dynamic header that will change with each customer using ALV?
Thanks
‎2006 Mar 17 4:18 PM
George,
Welcome to SDN Forums,
I am not clear, if you are writinf something while showing the ALV grid or you want this only in print preivew / print.
If you are looking to display the data along with the grid,
Function :
You can use the RESUE_ALV_COMMENTARY_WRITE.
Controls :
You will have to use the Split container and then write some thing in the top container.
If you are looking for TOP_OF_PAGE, then you will have to activate the events TOP OF PAGE event of the grid.
regards,
Ravi
Note : Please reward the helpful posts.
‎2006 Mar 17 4:22 PM
Look at this sample code.
REPORT zad_test_alv
NO STANDARD PAGE HEADING
MESSAGE-ID zcs_cs_001.
************************************************************************
DATA DECLARATIONS
************************************************************************
************************************************************************
Table Declarations:
************************************************************************
TABLES: mara.
************************************************************************
Internal Tables:
************************************************************************
DATA: i_fieldcat TYPE lvc_t_fcat,
i_fieldrows TYPE lvc_t_row,
i_output TYPE STANDARD TABLE OF mara,
************************************************************************
Work Areas:
************************************************************************
w_fieldrows LIKE LINE OF i_fieldrows,
w_output TYPE mara.
************************************************************************
Constants Declarations:
************************************************************************
CONSTANTS: c_x TYPE c VALUE 'X'.
----
SELECTION SCREEN FIELDS
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b_0 WITH FRAME TITLE text-000.
SELECT-OPTIONS: s_mara FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK b_0.
----
CLASS DECLARATIONS *
----
INCLUDE <icon>.
Predefine a local class for event handling to allow the
declaration of a reference variable before the class is defined.
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA : o_alvgrid TYPE REF TO cl_gui_alv_grid ,
o_dockingcontainer TYPE REF TO cl_gui_docking_container ,
o_eventreceiver TYPE REF TO lcl_event_receiver,
v_split TYPE REF TO cl_gui_easy_splitter_container,
v_contnr_top TYPE REF TO cl_gui_container,
v_contnr_bot TYPE REF TO cl_gui_container,
v_grid_02 TYPE REF TO cl_gui_alv_grid,
v_html TYPE REF TO cl_dd_document,
v_text01(255) TYPE c VALUE 'This is the heading',
v_font(50) TYPE c VALUE '30',
----
Work Area
----
w_layout TYPE lvc_s_layo ,
w_variant TYPE disvariant.
----
Constants
----
CONSTANTS : c_a(1) TYPE c VALUE 'A' . " All Layouts
----
CLASS lcl_event_receiver DEFINITION
----
........ *
----
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
Hot Spot Click
handle_hotspot
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id
e_column_id
es_row_no,
handle_print_top_of_page
FOR EVENT print_top_of_page OF
cl_gui_alv_grid,
handle_top_of_page
FOR EVENT top_of_page OF
cl_gui_alv_grid.
ENDCLASS.
Implementation
CLASS lcl_event_receiver IMPLEMENTATION.
&----
*& Method handle_hotspot
&----
This method is called when the user clicks on a hotspot to drill down.
The following types are exported from the ALV
LVC_S_ROW
LVC_S_COL
LVC_S_ROID
&----
METHOD handle_hotspot.
The hotspot processing coded in the form below.
PERFORM f9802_handle_hotspot USING e_row_id
e_column_id
es_row_no.
ENDMETHOD.
METHOD handle_print_top_of_page.
IF sy-pagno = 1.
PERFORM f9803_top_of_page.
ENDIF.
ENDMETHOD.
METHOD handle_top_of_page.
PERFORM f9803_top_of_page.
ENDMETHOD.
ENDCLASS.
***********************************************************************
START-OF-SELECTION
***********************************************************************
START-OF-SELECTION.
PERFORM f5000_get_data.
************************************************************************
END-OF-SELECTION
************************************************************************
END-OF-SELECTION.
************************************************************************
IF NOT i_output[] IS INITIAL.
CALL SCREEN 9001.
ELSE.
MESSAGE i001 WITH text-051.
" No documents were found for the selection
LEAVE LIST-PROCESSING.
ENDIF.
----
FORMS *
----
This part has the various forms used in the program
************************************************************************
&----
*& Form f5000_get_totals
&----
To get Data
----
FORM f5000_get_data.
SELECT *
INTO TABLE i_output UP TO 5 ROWS
FROM mara.
ENDFORM. " f5000_get_data
&----
*& Form f9000_objects_create
&----
text
----
--> p1 text
<-- p2 text
----
FORM f9000_objects_create.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
CREATE OBJECT o_dockingcontainer
EXPORTING
ratio = '95'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
IF sy-subrc NE 0.
MESSAGE i001 WITH text-e01."Error in creating Docking container
LEAVE LIST-PROCESSING.
ENDIF.
CREATE OBJECT v_split
EXPORTING
parent = o_dockingcontainer
ORIENTATION = 0
sash_position = 25
with_border = 0
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
others = 3.
IF sy-subrc NE 0.
MESSAGE i000 WITH text-e01."Error in creating Docking container
LEAVE LIST-PROCESSING.
ENDIF.
Get the containers of the splitter control
v_contnr_top = v_split->top_left_container.
v_contnr_bot = v_split->bottom_right_container.
CREATE OBJECT o_alvgrid
EXPORTING
i_parent = o_dockingcontainer.
Create an instance of alv control
CREATE OBJECT o_alvgrid
EXPORTING i_parent = v_contnr_bot.
Object for display of selection parameters in HTML top container
CREATE OBJECT v_html
EXPORTING
style = 'ALV_GRID'.
Must be after the SET HANDLER for TOP_OF_PAGE and foreground only
CALL METHOD o_alvgrid->list_processing_events
EXPORTING i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = v_html.
CLEAR v_text01.
v_text01 = 'Heading'.
v_font = 'HEADING'.
CALL METHOD v_html->add_gap
EXPORTING
width = 120.
CALL METHOD v_html->add_text
EXPORTING
text = v_text01
sap_style = v_font.
CALL METHOD v_html->new_line.
Display the data
CALL METHOD v_html->display_document
EXPORTING
parent = v_contnr_top.
Handle the event
CALL METHOD o_alvgrid->list_processing_events
EXPORTING i_event_name = 'PRINT_TOP_OF_PAGE'.
ENDIF.
IF Program Running in Background, place a container.
IF sy-batch = 'X'.
CREATE OBJECT o_alvgrid
EXPORTING
i_parent = o_dockingcontainer.
ENDIF.
ENDFORM. " f9000_objects_create
&----
*& Form f9001_build_field_cat
&----
text
----
-->P_I_FIELDCAT text
-->P_0021 text
----
FORM f9001_build_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat
USING value(p_structure).
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_structure
CHANGING
ct_fieldcat = p_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE i001 WITH text-e05."Error in ALV field catalogue creation
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " f9001_build_field_cat
&----
*& Form f9002_modify_field_cat
&----
text
----
-->P_I_FIELDCAT text
----
FORM f9002_modify_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat.
FIELD-SYMBOLS : <lfs_fieldcat> TYPE lvc_s_fcat.
ENDFORM. " f9002_modify_field_cat
&----
*& Form f9003_layout
&----
text
----
-->P_SY_TITLE text
-->P_0030 text
-->P_0031 text
-->P_0032 text
----
FORM f9003_layout USING value(ptitle)
value(pzebra)
value(pmode)
value(pwidth).
w_layout-grid_title = ptitle.
w_layout-zebra = pzebra.
w_layout-sel_mode = pmode.
w_layout-cwidth_opt = pwidth.
w_variant-report = sy-repid.
ENDFORM. " f9003_layout
&----
*& Form f9004_display_data
&----
text
----
-->P_I_OUTPUT text
-->P_I_FIELDCAT text
----
FORM f9004_display_data TABLES p_output
p_fieldcat.
IF sy-batch = 'X'.
CREATE OBJECT o_eventreceiver.
SET HANDLER o_eventreceiver->handle_print_top_of_page FOR o_alvgrid.
ENDIF.
CALL METHOD o_alvgrid->set_table_for_first_display
EXPORTING
is_variant = w_variant
i_save = c_a
is_layout = w_layout
CHANGING
it_outtab = p_output[]
it_fieldcatalog = p_fieldcat[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE i128 WITH text-e06."Error in ALV report display
LEAVE LIST-PROCESSING.
ENDIF.
IF sy-batch NE 'X'.
CREATE OBJECT o_eventreceiver.
SET HANDLER o_eventreceiver->handle_print_top_of_page FOR o_alvgrid.
SET HANDLER o_eventreceiver->handle_top_of_page FOR o_alvgrid.
ENDIF.
ENDFORM. " f9004_display_data
&----
*& Form f9005_free_objects
&----
text
----
-->P_O_ALVGRID text
-->P_0056 text
-->P_TEXT_E02 text
----
FORM f9005_free_objects USING pobject
value(ptype)
value(ptext).
CASE ptype.
WHEN 'ALV'.
DATA lobjectalv TYPE REF TO cl_gui_alv_grid.
lobjectalv = pobject.
IF NOT ( lobjectalv IS INITIAL ).
CALL METHOD lobjectalv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject ,
lobjectalv.
PERFORM f9006_error_handle USING ptext.
ENDIF.
WHEN 'DOCKING'.
DATA lobjectdock TYPE REF TO cl_gui_docking_container.
lobjectdock = pobject.
IF NOT ( lobjectdock IS INITIAL ).
CALL METHOD lobjectdock->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject ,
lobjectdock.
PERFORM f9006_error_handle USING ptext.
ENDIF.
WHEN 'CONTAINER'.
DATA lobjectcontainer TYPE REF TO cl_gui_container.
lobjectcontainer = pobject.
IF NOT ( lobjectcontainer IS INITIAL ).
CALL METHOD lobjectcontainer->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject ,
lobjectcontainer.
PERFORM f9006_error_handle USING ptext.
ENDIF.
WHEN OTHERS.
sy-subrc = 1.
PERFORM f9006_error_handle USING text-e04.
ENDCASE.
ENDFORM. " f9005_free_objects
&----
*& Form f9006_error_handle
&----
text
----
-->P_PTEXT text
----
FORM f9006_error_handle USING value(ptext).
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-e03
txt2 = sy-subrc
txt1 = ptext.
ENDIF.
ENDFORM. " f9006_error_handle
&----
*& Form f9802_handle_hotspot
&----
text
----
-->P_E_ROW_ID text
-->P_E_COLUMN_ID text
-->P_ES_ROW_NO text
----
FORM f9802_handle_hotspot USING p_row_id
p_column_id
p_row_no.
ENDFORM. " f9802_handle_hotspot
&----
*& Form f9803_top_of_page
&----
TOP-OF-PAGE
----
FORM f9803_top_of_page.
List heading
WRITE:/ v_text01.
ENDFORM. " f9803_top_of_page
----
INCLUDE ZCSGM_MFRECON_SUMMRPT_LD_SCRN *
************************************************************************
&----
*& Module STATUS_1001 OUTPUT
&----
This performs PBO
----
MODULE status_9001 OUTPUT.
IF o_dockingcontainer IS INITIAL.
SET PF-STATUS 'ZSTATUS'.
SET TITLEBAR 'ZTITLE'.
Creating Object
PERFORM f9000_objects_create.
Building the field catalog
PERFORM f9001_build_field_cat TABLES i_fieldcat
USING 'MARA'.
ENDIF.
Modifying the field catalog
PERFORM f9002_modify_field_cat TABLES i_fieldcat.
For Layout
PERFORM f9003_layout USING sy-title 'X' 'B' 'X' .
To display output
PERFORM f9004_display_data TABLES i_output
i_fieldcat.
Set handlers for events
SET HANDLER o_eventreceiver->handle_hotspot FOR o_alvgrid.
ENDMODULE. " STATUS_9001 OUTPUT
*&----
*& Module USER_COMMAND_9001 INPUT
*&----
This performs PAI
----
MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
PERFORM f9005_free_objects :
USING o_alvgrid 'ALV' text-e02 ,
USING o_dockingcontainer 'DOCKING' text-e01.
LEAVE PROGRAM.
WHEN 'BACK'.
PERFORM f9005_free_objects :
USING o_alvgrid 'ALV' text-e02 ,
USING o_dockingcontainer 'DOCKING' text-e01.
SET SCREEN '0'.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_9001 INPUT
‎2006 Mar 17 4:36 PM
‎2006 Mar 17 4:40 PM
Sorry Leon, I have not worked with SALV extensively yet.
Have you gone through the sample programs, they are pretty good. You can search for them SE38 with SALVDEMO.
Regards,
Ravi
‎2006 Mar 17 4:44 PM
hehe I'm deep into it already...I think there is a bug in CL_SALV_FORM_LAYOUT_GRID...maybe Thomas would help
‎2006 Mar 17 5:03 PM
So will this change the header for each new customer I.E when scrolling through the list with each new customer the customer name, number and payment terms etc should show up in the header
‎2006 Mar 17 8:07 PM
Anyone have any other idea's I am in a bit of a crunch here. O have the report working fine It is just I cannot get the header to change when a new customer detail line is scrolled to
‎2006 Mar 17 8:29 PM
Hi George.. How about making a page break for every new customer? you could still use top_of_page event
Jesus
‎2006 Mar 17 8:32 PM
Hi
That sounds like a possibility do you have an sa,ple of a page break?
Thanks
‎2006 Mar 17 8:38 PM
‎2006 Mar 17 9:23 PM
Here is the problem, The report works fine it is the header I cannot figure out
Header
_________________________________________________________
For Customer var1
Doc date var2
Cust number var3
cust name var4 Pay terms var5
_________________________________________________________
Detail lines
cust num 001 doc num other stuff
cust num 001 doc num other stuff
cust num 002 doc num other stuff
For every change of cust # I need the variables in the header to change. I have tried the spli container but could not get it to work. I have tried page break but the info did not change in the headr after the page break. I am new with ALV grid so if anyone has a fairly well explained example or suggestion I would appreciate it
Thanks
‎2007 Apr 16 10:52 AM
Dear George,
I too have same type of problem as u had. Hope by this time you might had solved it. I wish that u can share your solution with me. Please mail me at sacsap@gmail.com. Its urgent.
Regards