In previous post I mentioned about the function modules that can be used to display the selection options on the header of the report. Here I am going to give an example of the actual use of these function modules. I am going to start with the ALV report template that I have mentioned. I will be creating a private method to the class LCL_REPORT called BUILD_HEADER. This can display the header in either ALV or normal list output. I am going to read the KNA1 table and display the address of the customers. BTW there is a very good FM that will show the address if you pass the address number to it, the address is returned in a format that can be printed on a label. The function module is ADDRESS_INTO_PRINTFORM.
The class CL_SALV_FORM_LAYOUT_GRID will be used to define the layout and will be attached to the ALV object (class CL_SALV_TABLE) as top of list element. The function module that does the main work for us here is PRINT_SELECTIONS. It will return a table filed with preformatted lines. Here is screen shot of the table values from the debugger.
Now all we have to do is strip out unwanted lines and match the label against the values. The class CL_SALV_FORM_LAYOUT_GRID has 2 methods for this label and text creation, which are used in this case.
The selection screen of the report is:
In a list output it looks like this:
And in ALV output it looks like this.
Declaration of the method BUILD_HEADER:
METHODS:build_header IMPORTING i_alv_table TYPE REF TO cl_salv_table.
And the code for the method BUILD_HEADER:
METHOD build_header.TYPES:BEGIN OF l_ty_info,flag(1),olength(1) TYPE x,line TYPE infoline,END OF l_ty_info.DATA:l_t_info TYPE TABLE OF l_ty_info,l_s_info TYPE l_ty_info,l_row TYPE i,l_o_uie TYPE REF TO cl_salv_form_layout_grid,l_o_any TYPE REF TO object,l_selection_flag,l_label_flag,l_str_report_by TYPE string,l_flag_report_by TYPE boolean.IF sy-repi2 IS INITIAL.sy-repi2 = sy-repid.ENDIF.CREATE OBJECT l_o_uie.CALL METHOD l_o_uie->create_header_informationEXPORTINGrow = 1column = 1text = sy-titleRECEIVINGr_value = l_o_any.CALL FUNCTION 'PRINT_SELECTIONS'EXPORTINGrname = sy-repi2rvariante = sy-slsetmode = 'TABLE'TABLESinfotab = l_t_info.DELETE l_t_info WHERE LINE = c_last_line.DELETE l_t_info WHERE LINE IS INITIAL.LOOP AT l_t_info INTO l_s_info.IF l_s_info-line+1(77) = c_last_line.EXIT.ENDIF.IF l_s_info-flag = 'D'. " prg run Date and timel_row = sy-tabix.CALL METHOD l_o_uie->create_labelEXPORTINGrow = l_rowcolumn = 1text = l_s_info-line+1(77)RECEIVINGr_value = l_o_any.l_row = l_row + 1.CALL METHOD l_o_uie->create_labelEXPORTINGrow = l_rowcolumn = 1text = c_last_line+1(20)RECEIVINGr_value = l_o_any.ENDIF.IF l_s_info-flag <> 'H'. " Header not encountered so farIF l_selection_flag IS INITIAL. " Wait for itCONTINUE.ELSE.* write textENDIF.ELSE. " We have header so set the flagl_selection_flag = abap_true. " Set the flag
CONTINUE. " Data is in the next lineENDIF.IF l_s_info-line+3(1) <> space. " This is the Labell_label_flag = abap_true.l_row = l_row + 1.CONDENSE l_s_info-line+1(32).CALL METHOD l_o_uie->create_labelEXPORTINGrow = l_rowcolumn = 1* colspan = 30text = l_s_info-line+1(32)RECEIVINGr_value = l_o_any.IF l_s_info-line+1(32) = 'Report by'.l_flag_report_by = abap_true.ENDIF.ELSE. " This is the ValueIF l_label_flag = abap_true.l_label_flag = abap_false.ELSE.l_row = l_row + 1.ENDIF.CONDENSE l_s_info-line+1(77).IF l_flag_report_by = abap_true.l_s_info-line+1(77) = l_str_report_by.l_flag_report_by = abap_false.ENDIF.CALL METHOD l_o_uie->create_textEXPORTINGrow = l_rowcolumn = 2text = l_s_info-line+1(77)* TOOLTIP =RECEIVINGr_value = l_o_any.ENDIF.ENDLOOP.CALL METHOD l_o_uie->create_labelEXPORTINGrow = l_rowcolumn = 1text = c_last_line+1(20)RECEIVINGr_value = l_o_any.CALL METHOD i_alv_table->set_top_of_listEXPORTINGvalue = l_o_uie.ENDMETHOD. "build_header
2 comments:
Hi,
good posts..i have just added your site to http://social.sapdocs.info/abap/
Best
Eddai
Thanks. You are doing a fine job yourself! And welcome to the world of SAP!
Post a Comment