Alv Saptech
Alv Saptech
Alv Saptech
This is a simple tutorial which shows how to insert hyperlinks in the ALV Grid. On clicking the
hyperlink, a web browser will open up which will point to the URL which has been configured
programmatically.
Besides the regular steps for ALV grid some additional steps needs to be followed to populate
hyperlinks into the ALV grid.
Steps to create hyperlink in ALV:
1.
Create additional fields for the hyperlink handles in your type declaration for the final
table(the table that is passed to the it_output parameter of the method
set_table_for_first_display)
2.
3.
Assign an appropriate handle number and URL for a particular column and populate the internal
table with this data and pass this internal table to the it_hyperlink parameter of the method
set_table_for_first_display.
4.
Pass the appropriate handle number while populating the list data.
Code:
*&------------------------------------------------------------------*& Report YALV_HYPERLINK
*&
*&-------------------------------------------------------------------
REPORT yalv_hyperlink.
TYPE char100,
START-OF-SELECTION.
PERFORM f_fill_data.
PERFORM f_fill_fieldcat.
PERFORM f_fill_hyperlink.
*&------------------------------------------------------------------*&
Form F_FILL_DATA
*&------------------------------------------------------------------*
*--------------------------------------------------------------------
FORM f_fill_data .
CLEAR e_data.
MOVE : 'iPhone' TO e_data-product,
'iPhone5' TO e_data-variant,
'$599'
TO e_data-price,
'1'
TO e_data-pd_handle,
'2'
TO e_data-vr_handle.
CLEAR e_data.
MOVE : 'iPhone' TO e_data-product,
'iPhone 4S' TO e_data-variant,
'$399'
TO e_data-price,
'1'
TO e_data-pd_handle,
'2'
TO e_data-vr_handle.
CLEAR e_data.
MOVE : 'iPhone' TO e_data-product,
'iPhone 4' TO e_data-variant,
'$299'
TO e_data-price,
'1'
TO e_data-pd_handle,
'2'
TO e_data-vr_handle.
ENDFORM.
" F_FILL_DATA
*&------------------------------------------------------------------*&
Form F_FILL_FIELDCAT
*&------------------------------------------------------------------*
*-------------------------------------------------------------------FORM f_fill_fieldcat .
FREE ts_fcat.
CLEAR : e_fcat.
TO e_fcat-col_pos,
TO e_fcat-indx_field,
20
TO e_fcat-outputlen,
'Product' TO e_fcat-coltext,
'PD_HANDLE' TO e_fcat-web_field.
CLEAR : e_fcat.
TO e_fcat-col_pos,
TO e_fcat-indx_field,
20
TO e_fcat-outputlen,
'Variant' TO e_fcat-coltext,
'VR_HANDLE' TO e_fcat-web_field.
TO e_fcat-col_pos,
TO e_fcat-indx_field,
20
TO e_fcat-outputlen,
'Price' TO e_fcat-coltext,
*"
*"
*"
value here.
''
TO e_fcat-web_field.
ENDFORM.
" F_FILL_FIELDCAT
*&------------------------------------------------------------------*&
*&------------------------------------------------------------------*
= 'CONT'
EXCEPTIONS
cntl_error
=1
cntl_system_error
=2
create_error
=3
lifetime_error
=4
lifetime_dynpro_dynpro_link = 5
OTHERS
= 6.
IF sy-subrc EQ 0.
ENDIF.
i_parent
= ref_grid
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS
= 5.
IF sy-subrc <> 0.
ENDIF.
= ts_hype
CHANGING
it_outtab
= ts_data
it_fieldcatalog
= ts_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error
=2
too_many_lines
=3
OTHERS
= 4.
IF sy-subrc <> 0.
ENDIF.
ENDMODULE.
*&------------------------------------------------------------------*&
*&------------------------------------------------------------------*
CASE ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
*&------------------------------------------------------------------*&
Form F_FILL_HYPERLINK
*&------------------------------------------------------------------*
*-------------------------------------------------------------------FORM f_fill_hyperlink .
FREE ts_hype.
CLEAR e_hype.
MOVE : '1' TO e_hype-handle,
'http://www.apple.com' TO e_hype-href.
APPEND e_hype TO ts_hype.
CLEAR e_hype.
MOVE : '2' TO e_hype-handle,
'http://www.apple.com/iphone' TO e_hype-href.
APPEND e_hype TO ts_hype.
ENDFORM.
" F_FILL_HYPERLINK
Final Internal table should have the field rowcolor to differentiate the last row color
2.
3.
4.
Fill the field cat, layout and Call the ALV Grid function module
5.
Output
STEP1 -> Final Internal table should have the field rowcolor to differentiate the last row color
STEP4-> Fill the field cat and Layout and Call the ALV Grid function module
Since already we have calculated the sum, just pass the parameter no_sum = X for all the fields
STEP5-> Output
The challenge in this scenario is, the 3 ALV grids built using OOPS concept cannot be sent to Spool
directly
in
foreground.
For
sending
the
3
ALV
grids
to
spool,
FMREUSE_ALV_BLOCK_LIST_APPEND has been used. The foreground mode uses both the normal
ALV grid display methods of OOPS to display the three ALVs in foreground and then uses
REUSE_ALV_BLOCK_LIST_APPEND FM to send the report to spool as list. The background mode
uses only REUSE_ALV_BLOCK_LIST_APPEND to send the report to spool.
Step1: Creating screen for foreground display
Go to Screen painter Transaction Code SE51.
Create a screen with no 100.
Provide description for the screen and click on the Layout Button.
Place 3 Custom container UI elements and give names as G_CONTAINER1 , G_CONTAINER2 and
G_CONTAINER3 .The screen 100 will have 3 custom containers as shown below. Activate the
Object.
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
ENDMODULE.
*&---------------------------------------------------------------------*
*&
Form sub_pf_status
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM sub_pf_status.
*Set PF status
SET PF-STATUS 'ZSTATUS_0100' EXCLUDING lt_excl.
ENDFORM.
SUB_PF_STATUS
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_FIRSTALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_I_FIELDCATALOG1 text
-->P_I_ORDERS1 text
*----------------------------------------------------------------------*
FORM sub_display_firstalv USING fp_i_fieldcatalog1 TYPE lvc_t_fcat
fp_i_orders1
DATA:
TYPE ty_t_orders1.
IF g_custom_container1 IS INITIAL.
= g_custom_container1
*Top of page
PERFORM sub_top_of_page.
= i_exclude
= li_layout
= lx_print
CHANGING
it_outtab
it_fieldcatalog
= fp_i_orders1
= fp_i_fieldcatalog1
EXCEPTIONS
invalid_parameter_combination = 1
program_error
=2
too_many_lines
=3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDFORM.
SUB_DISPLAY_FIRSTALV
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_SECONDALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_I_FIELDCATALOG2 text
-->P_I_ORDERS2 text
*----------------------------------------------------------------------*
FORM sub_display_secondalv USING fp_i_fieldcatalog2 TYPE lvc_t_fcat
fp_i_orders2
TYPE ty_t_orders2.
IF g_custom_container2 IS INITIAL.
= i_exclude
= li_layout
= lx_print
CHANGING
it_outtab
it_fieldcatalog
= fp_i_orders2
= fp_i_fieldcatalog2
EXCEPTIONS
invalid_parameter_combination = 1
program_error
=2
too_many_lines
=3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
ENDFORM.
SUB_DISPLAY_SECONDALV
*&---------------------------------------------------------------------*
*&
Form SUB_DISPLAY_THIRDALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_I_FIELDCATALOG3 text
-->P_I_INVSTATUS text
*----------------------------------------------------------------------*
FORM sub_display_thirdalv USING fp_i_fieldcatalog3 TYPE lvc_t_fcat
fp_i_invstatus TYPE ty_t_invstatus.
text-013
c_x
c_cellstyle
CHANGING li_layout.
* Use Flush
CALL METHOD cl_gui_cfw=>flush.
IF g_custom_container3 IS INITIAL.
= i_exclude
= li_layout
= lx_print
CHANGING
it_outtab
= fp_i_invstatus
it_fieldcatalog
= fp_i_fieldcatalog3
EXCEPTIONS
invalid_parameter_combination = 1
program_error
=2
too_many_lines
=3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDFORM.
SUB_DISPLAY_THIRDALV
*&---------------------------------------------------------------------*
*&
Form SUB_PREPARE_LAYOUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_LI_LAYOUT text
*----------------------------------------------------------------------*
FORM sub_prepare_layout USING fp_c_x
fp_title
TYPE xfeld
TYPE lvc_title
fp_li_layout-zebra
= fp_c_x.
fp_li_layout-grid_title = fp_title.
fp_li_layout-smalltitle = fp_smalltitle.
fp_li_layout-stylefname = fp_stylename.
ENDFORM.
SUB_PREPARE_LAYOUT
Subroutine for Report header, which will be created dynamically based on the fields selected by
the User for a User selected report layout.
*&---------------------------------------------------------------------*
*&
Form SUB_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_top_of_page.
= text-014
* Adding Line
CALL METHOD g_document->new_line.
* Adding Line
CALL METHOD g_document->new_line.
* Sold-to customer
IF s_kunnr-high IS NOT INITIAL.
CONCATENATE s_kunnr-low 'to' s_kunnr-high INTO l_text SEPARATED BY ' '.
ELSE.
l_text = s_kunnr-low.
ENDIF.
= text-015
EXPORTING
width = '15'.
CLEAR: l_text.
* Change date
* Converting date format
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = s_erdat-low
IMPORTING
date_external = l_datel.
= text-016
CLEAR: l_text.
IF NOT s_vkorg IS INITIAL.
* Sales Organization
IF s_vkorg-high IS NOT INITIAL.
CONCATENATE s_vkorg-low 'to' s_vkorg-high INTO l_text SEPARATED BY ' '.
ELSE.
l_text = s_vkorg-low.
ENDIF.
= text-017
CLEAR : l_text.
IF NOT s_bsark IS INITIAL.
* PO Type
IF s_bsark-high IS NOT INITIAL.
CONCATENATE s_bsark-low 'to' s_bsark-high INTO l_text SEPARATED BY ' '.
ELSE.
l_text = s_bsark-low.
ENDIF.
= text-018
ENDFORM.
SUB_TOP_OF_PAGE
The ALV output is first send to spool request, then the spool is converted to PDF and then the
PDF attachment is sent to Email.
a)
*&---------------------------------------------------------------------*
*&
Form SUB_CONVERT_SPOOL_TO_PDF
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_convert_spool_to_pdf CHANGING fp_size
fp_i_mess_att TYPE ty_t_mess_att.
DATA: lv_buffer
TYPE string,
TYPE i
no_dialog
= space
dst_device
IMPORTING
pdf_bytecount
TABLES
pdf
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob
err_no_permission
=2
=3
err_conv_not_possible = 4
err_bad_destdevice
=5
user_cancelled
=6
err_spoolerror
=7
err_temseerror
=8
err_btcjob_open_failed = 9.
IF sy-subrc EQ 0.
LOOP AT li_pdf_output INTO lw_pdf_output.
TRANSLATE lw_pdf_output USING c_col1.
CONCATENATE lv_buffer lw_pdf_output INTO lv_buffer.
CLEAR :lw_pdf_output.
ENDLOOP.
TRANSLATE lv_buffer USING c_col2.
DO.
lw_mess_att = lv_buffer.
APPEND lw_mess_att TO fp_i_mess_att.
SHIFT lv_buffer LEFT BY c_255 PLACES.
IF lv_buffer IS INITIAL.
EXIT.
ENDIF.
CLEAR lw_mess_att.
ENDDO.
ENDIF.
ENDFORM.
SUB_CONVERT_SPOOL_TO_PDF
The email addresses of the receivers are populated in table I_EMAIL which is passed in the
below subroutine as FP_I_EMAIL.
*&---------------------------------------------------------------------*
*&
Form SUB_SEND_PDF_TO_MAIL
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_send_pdf_to_mail USING fp_size
TYPE i
DATA: l_ref_bcs
TYPE so_obj_des,
lv_data
TYPE bcsy_text,
TYPE ty_email,
TRY.
* Create persistent send request
l_ref_bcs = cl_bcs=>create_persistent ( ).
* Mail subject
lv_text = text-021.
APPEND text-021 TO lv_data.
* Create document
l_ref_document = cl_document_bcs=>create_document (
i_type = c_raw
i_text = lv_data
i_subject = lv_text).
= 'E'.
* Send E-mail
CALL METHOD l_ref_bcs->send (
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result
= sent_to_all).
IF sent_to_all = 'X'.
* E-mail sent successfully
MESSAGE i028 WITH text-020.
ENDIF.
ENDLOOP.
COMMIT WORK.
ENDFORM.
SUB_SEND_PDF_TO_MAIL
REUSE_ALV_BLOCK_LIST_INIT
b) REUSE_ALV_BLOCK_LIST_APPEND
c)
REUSE_ALV_BLOCK_LIST_DISPLAY
The three field catalogs are built for this and the field catalog names are: LI_FIELDCAT1,
LI_FIELDCAT2 and LI_FIELDCAT3.
The header of the three ALVs in the spool is created as follows by using the below code:
PERFORM sub_header_list CHANGING li_events_1
li_events_2
li_events_3.
*&---------------------------------------------------------------------*
*&
Form SUB_HEADER_LIST
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_LI_EVENTS_1 text
<--P_LI_EVENTS_2 text
<--P_LI_EVENTS_3 text
*----------------------------------------------------------------------*
FORM sub_header_list CHANGING fp_li_events_1 TYPE slis_t_event
fp_li_events_2 TYPE slis_t_event
fp_li_events_3 TYPE slis_t_event.
lw_events-name = 'TOP_OF_PAGE'.
lw_events-form = 'TOP_OF_PAGE_1'."Subroutine name
APPEND lw_events TO fp_li_events_1.
CLEAR lw_events.
lw_events-name = 'TOP_OF_PAGE'.
lw_events-form = 'TOP_OF_PAGE_2'."Subroutine name
APPEND lw_events TO fp_li_events_2.
CLEAR lw_events.
lw_events-name = 'TOP_OF_PAGE'.
lw_events-form = 'TOP_OF_PAGE_3'."Subroutine name
APPEND lw_events TO fp_li_events_3.
CLEAR lw_events.
ENDFORM.
SUB_HEADER_LIST
lv_repid = sy-repid.
= lv_layout
it_fieldcat
= li_fieldcat1
i_tabname
it_events
= 'I_ORDERS1'
= li_events_1[]
TABLES
t_outtab
= i_orders1
EXCEPTIONS
program_error
=1
maximum_of_appends_reached = 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
= lv_layout
it_fieldcat
= li_fieldcat2
i_tabname
it_events
= 'I_ORDERS2'
= li_events_2
TABLES
t_outtab
= i_orders2
EXCEPTIONS
program_error
=1
maximum_of_appends_reached = 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
EXPORTING
is_layout
= lv_layout
it_fieldcat
= li_fieldcat3
i_tabname
it_events
= 'I_INVSTATUS'
= li_events_3
TABLES
t_outtab
= i_invstatus
EXCEPTIONS
program_error
=1
maximum_of_appends_reached = 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
= lx_print
EXCEPTIONS
program_error
OTHERS
=1
= 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.
COMMIT WORK.
NEW-PAGE PRINT OFF.
*&---------------------------------------------------------------------*
*&
Form SUB_GET_PRINT_PARAMETERS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM sub_get_print_parameters.
DATA: lv_valid.
= 'X'
line_size
= '255'
line_count
layout
= '65'
= 'X_65_255'
destination = 'LP01'
IMPORTING
out_parameters = x_params
valid
= lv_valid
EXCEPTIONS
OTHERS
= 1.
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.
SUB_GET_PRINT_PARAMETERS
The above spool output is finally sent as a PDF attachment to email addresses of multiple
persons.
Radio Buttons in the output of an ALV
As per business need there was a scenario for an ALV Report Output, It must have functionality
selecting only one row at a time. It is possible with Radio buttons.
NOTE: Here we have two types of Radio buttons Icons i.e. icon_wd_radio_button_empty (Empty
Radio Button) and icon_radiobutton (Selected Radio button)
Below are the steps to display Radio Buttons in the output of an ALV.
a)
Include ICONS.
INCLUDE <icons>.
b) Declare an internal table with the required fields and additional field called RADIO of type
CHAR of size 4.
c) Define a class to handle an even HOTSPOT_CLICK o trigger when we click on the radio
button icon. Definition as coded below.
* Handles the Even when user clicks on any row.
METHODS: handle_hotspot_click FOR EVENT hotspot_click
OF cl_gui_alv_grid
IMPORTING e_row_id.
d) Do the implementation for the same class to handle the event i.e. if we select a radio button,
then the already selected radio button should be deselect and new radio button should be
selected. Code as follows.
*&--------------------------------------------------------------*
*& METHOD handle_hotspot_click.
*&--------------------------------------------------------------*
*& On double clicking a particulat row
*&--------------------------------------------------------------*
METHOD handle_hotspot_click .
CLEAR : gs_emp.
READ TABLE gt_emp INTO gs_emp
CLEAR gs_emp .
READ TABLE gt_emp INTO gs_emp INDEX e_row_id.
IF gs_emp-radio = icon_radiobutton.
gs_emp-radio = icon_wd_radio_button_empty.
MODIFY gt_emp INDEX e_row_id FROM gs_emp
TRANSPORTING radio.
ELSE.
gs_emp-radio = icon_radiobutton.
MODIFY gt_emp INDEX e_row_id FROM gs_emp
TRANSPORTING radio.
ENDIF.
ELSE .
gs_emp-radio = icon_wd_radio_button_empty.
MODIFY gt_emp INDEX sy-tabix FROM gs_emp
TRANSPORTING radio.
CLEAR gs_emp.
READ TABLE gt_emp INTO gs_emp INDEX e_row_id .
IF sy-subrc = 0.
gs_emp-radio = icon_radiobutton.
MODIFY gt_emp INDEX e_row_id FROM gs_emp
TRANSPORTING radio.
ENDIF.
ENDIF .
EXPORTING
new_code = 'REFRESH'
*
IMPORTING
rc
.
ENDMETHOD.
e)
"handle_hotspot_click
Update the RADIO button with empty radio button in the internal table. Code as follows.
= 'X'.
"Icons
ls_fieldcat-hotspot = 'X'.
"Hotspot(Hand Symbol)
ls_fieldcat-col_pos = '1'.
g) Refresh the grid, Perform REFRESH action when the radio button is selected.
* Define local data
DATA:ls_stable TYPE lvc_s_stbl.
ls_stable-row = abap_true.
ls_stable-col = abap_true.
h)
Provide description for the screen and click on the Layout Button.
Place a Custom container UI element and give name as CCONTAINER now you will have a screen
with custom container as below screen shot. Activate the Object.
Step 3: Report
Go to SE38 and create a program in Z name space and paste the following code snippet.
*&---------------------------------------------------------------------*
*& Report ZPC_CONTAINER_CONTROL
*&---------------------------------------------------------------------*
REPORT zpc_container_control.
*Declaration
DATA: Splitter_1
Splitter_2
Container
Grid2
Grid3
*&---------------------------------------------------------------------*
*& Module STATUS_9010 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_9010 OUTPUT.
SET PF-STATUS 'TEST'.
*creating object reference for container
CREATE OBJECT container
EXPORTING
container_name = 'CCONTAINER'. Pass name of container created in Screen no 9010
*splitting the main container into 1 row & 2 coloum
CREATE OBJECT splitter_1
EXPORTING
Parent
= container
Rows
=1
Columns = 2.
*getting the reference for the splited container (row 1 & col 1 container)
CALL METHOD splitter_1->get_container
EXPORTING
Row
=1
Column = 1
RECEIVING
Container = container_1.
*getting the reference for the splited container (row 1 & col 2 container)
CALL METHOD splitter_1->get_container
EXPORTING
Row
=1
Column = 2
RECEIVING
Container = container_2.
*splitting the 2nd coloum container in to 2 rows & 1 coloum
CREATE OBJECT splitter_2
EXPORTING
Parent
= container_2
Rows
=2
Columns = 1.
*getting the reference for the splited container2 (row 1 & col 2 container)
CALL METHOD splitter_2->get_container
EXPORTING
Row
=1
Column = 1
RECEIVING
Container = container_2.
*getting the reference for the splited container2 (row 2 & col 1 container)
CALL METHOD splitter_2->get_container
EXPORTING
Row
=2
Column = 1
RECEIVING
Container = container_3.
*populating first internal table to the container
CREATE OBJECT container
EXPORTING
container_name = g_container.
CREATE OBJECT grid1
EXPORTING
i_parent = container_1.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = gt_sflight_1.
*populating second internal table
CREATE OBJECT container
EXPORTING
container_name = g_container.
CREATE OBJECT grid2
EXPORTING
i_parent = container_2.
CALL METHOD grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = gt_sflight_2.
*populating third internal table
CREATE OBJECT container
EXPORTING
container_name = g_container.
CREATE OBJECT grid3
EXPORTING
i_parent = container_3.
CALL METHOD grid3->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = gt_sflight_3.
ENDMODULE. STATUS_9010 OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
MODULE exit INPUT.
*free the container memory when exit
CALL METHOD container->free.
LEAVE PROGRAM.
ENDMODULE. EXIT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9010 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_9010 INPUT.
CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'BACK'.
LEAVE SCREEN.
WHEN 'CANCEL'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. USER_COMMAND_9010 INPUT
Output
The purpose of this document is to provide an option of word wrap to ALV functionality. Other
options may be possible; however, they only work around and doesnt provide end user the
flexibility to view the texts in single instance. Few of the other alternatives are listed below
You can make the column text as link and show truncated text so that even if the whole
text in a column is not seen, the user can see the entire text on mouse over.
You can implement functionality where in on clicking on the required cell, a popup
comes with the entire text.
However, in the above alternatives, incase end user needs to take print out of the report output,
he will miss out the truncated texts.
Dependencies/Pre-requisites/Assumption
Basic understanding of ALV, ABAP Programming is required to understand the flow and concept
of ALV reporting.
Technical Process
Limitations in Standard output of ALV
For demonstration purpose, I have used 2 columns Employee ID (width of Character
10) and Employee Name (width of Character 20). However, Employee Name field contains
values which are more than 20 characters.
Report output truncates the value after character 21
In case of Invoice printing/ Deliver document scenarios, this becomes as a challenge if
the long text gets truncated. Truncated texts wont make any sense to the end user and he
wont be able to take printouts!!!
Identify the length to which the column needs to be wrapped and define a field of same
length. Different columns can be wrapped to different length, and hence logic needs to be
modified accordingly.
Usually, for ALV output, data records internal table is defined to populate output. In
order to implement wrap functionality, we need to declare another internal table with the
desired wrapped length. This internal table will contain wrapped texts for the column.
Internal table will need to have first column as identifier to match each record of parent
internal table.
Standard Function Module RKD_WORD_WRAP is used to wrap the desired text.
IMPORT Parameters
1.
2.
3.
OUTPUTLEN (Optional) - Maximum output line width. Default value is set to 35.
TABLES
1.
OUT_LINES (Optional) - All output lines after wrapping get stored as table
REUSE_ALV_EVENTS_GET is called to get the list of all active events for particular ALV
report output.
Populate appropriate FORM name for the event AFTER_LINE_OUTPUT.
Call function module REUSE_ALV_LIST_DISPLAY to populate report output. ALV List is
used for demonstration; however, ALV Grid can also be used.
Implement AFTER_LINE_OUTPUT event among other events for the ALV. Below
snapshot shows the logic that is required to trigger multiple lines.
REPORT ZTEST_WRAP.
TYPE-POOLS: SLIS.
TYPES: BEGIN OF TY_DATA,
EMP
TYPE CHAR10,
DO 4 TIMES.
COUNT = COUNT + 1.
CASE COUNT.
WHEN 1.
WATAB-EMP = '10'.
WATAB-EMP_NAME = 'Purpose of this tutorial is to provide an easy
and quick reference which may be used as a
guide'.
APPEND WATAB TO I_DATA.
CLEAR WATAB.
WHEN 2.
WATAB-EMP = '20'.
WATAB-EMP_NAME = 'Coding is done for ALV List Display'.
APPEND WATAB TO I_DATA.
CLEAR WATAB.
WHEN 3.
WATAB-EMP = '30'.
WATAB-EMP_NAME = 'Same functionality can be implemented for ALV
Grid Display also'.
APPEND WATAB TO I_DATA.
CLEAR WATAB.
ENDCASE.
ENDDO.
REPORT_ID = SY-REPID.
CLEAR WA_FLD.
WA_FLD-FIELDNAME = 'EMP'.
WA_FLD-REF_TABNAME = 'I_DATA'.
WA_FLD-SELTEXT_L = 'EMP. ID'.
WA_FLD-REF_FIELDNAME = 'EMP'.
APPEND WA_FLD TO IT_FLD.
CLEAR WA_FLD.
WA_FLD-FIELDNAME = 'EMP_NAME1'.
WA_FLD-INTTYPE = 'CHAR'.
WA_FLD-OUTPUTLEN = 20.
WA_FLD-INTLEN = 20.
WA_FLD-SELTEXT_L = 'EMP. NAME'.
WA_FLD-DDICTXT = 'L'.
APPEND WA_FLD TO IT_FLD.
* Word Wrap the text in multiple lines
LOOP AT I_DATA INTO WATAB.
V_TABIX = SY-TABIX.
CLEAR: IT_SENTENCE [].
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
TEXTLINE
OUTPUTLEN
= WATAB-EMP_NAME
= C_LEN
TABLES
OUT_LINES
= IT_SENTENCE
EXCEPTIONS
OUTPUTLEN_TOO_LARGE
OTHERS
.
=2
=1
IF SY-SUBRC eq 0.
IF NOT IT_SENTENCE IS INITIAL.
READ TABLE IT_SENTENCE INTO WA_WORD INDEX 1.
WATAB-EMP_NAME1 = WA_WORD-EMP.
MODIFY I_DATA FROM WATAB INDEX V_TABIX.
ENDIF.
ENDIF.
ENDLOOP.
* Get event. We will handle BEFORE and AFTER line output
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
ET_EVENTS = IT_EVT.
READ TABLE IT_EVT INTO WA_EVT WITH KEY NAME = SLIS_EV_AFTER_LINE_OUTPUT.
WA_EVT-FORM = SLIS_EV_AFTER_LINE_OUTPUT.
MODIFY IT_EVT FROM WA_EVT INDEX SY-TABIX.
WA_LAY-EDIT = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPORT_ID
IS_LAYOUT
IT_FIELDCAT
IT_EVENTS
= WA_LAY
= IT_FLD
= IT_EVT
TABLES
T_OUTTAB
= I_DATA
EXCEPTIONS
PROGRAM_ERROR
=1
OTHERS
= 2.
IF SY-SUBRC <> 0.
* Exceptions will be handled as per requirement
ENDIF.
*---------------------------------------------------------------------*
* FORM AFTER_LINE_OUTPUT
*---------------------------------------------------------------------*
FORM AFTER_LINE_OUTPUT USING RS_LINEINFO TYPE SLIS_LINEINFO.
CLEAR: IT_SENTENCE, WATAB.
READ TABLE I_DATA INTO WATAB INDEX RS_LINEINFO-TABINDEX.
CHECK SY-SUBRC = 0.
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
TEXTLINE = WATAB-EMP_NAME
OUTPUTLEN = C_LEN
TABLES
OUT_LINES = IT_SENTENCE.
DESCRIBE TABLE IT_SENTENCE LINES V_TABIX.
CHECK V_TABIX > 1.
LOOP AT IT_SENTENCE INTO WA_WORD FROM 2.
WRITE: / SY-VLINE,
12 SY-VLINE,
13 WA_WORD-EMP,
33 SY-VLINE.
ENDLOOP.
ENDFORM. "after_line_output
Benefits
Desired Columns can be wrapped and shown in the same report output.
Multiple columns can be wrapped as per requirement. Also, different columns can be
wrapped to different lengths, and hence logic needs to be modified accordingly.
Wrap length can be set dynamically and changed during run time as per desired
functionality.
Even though string gets wrapped into multiple lines, however its treated as one line
item. This provides an advantage incase HOTSPOT functionality is required over line
items.
No hassles or logic is required to ensure that line gets split at words instead of in
between the words as standard SAP function modules are used to achieve the same. Also,
we can set custom delimiters for wrap functionality. Hence, CSV file can be wrapped
at comma.
Print output will also show wrapped output and hence, word wrap functionality is quite
helpful in scenarios like Invoice printing, Delivery Document.
Conclusion
Though SAP doesnt provide Wrap functionality along with ALV standard features,
however, we can achieve this though custom logic and coding.
This document can be referred by technical consultants to understand how wrap
functionality can be implemented for ALV. This document doesnt explain about ALV
Events functionality.
The code can be reused with minimal changes as per requirement.
ALV - Consistency Check
Problem:
Often for our ALV Programs output, we initially get a short dump or no data display or dump
during sorting and rearrangement of columns. These things generally results from wrong design
of Field catalog, Layout or Sorting Tables.
Tracking the error and rectifying the code definitely takes some good amount of efforts incase its
a complex ALV Report.
Solution:
SAP provides quite a simple and convenient way to trace out these errors and eases the task of
debugging by providing a detailed description of the errors and probable solutions.
To use this, press SHIFT + (Double Right Click) on any empty section of the ALV output screen of
the Report as shown below in the output of the sample Report:
The below SAP standard analysis screen opens up. This screen gives a detailed technical report
of the ALV Grid control used in the Report program.
It has different tabs for FieldCatalog, Layout, Sort etc. which when clicked gives individual
analysis report.
Example sample:
The example here displays 3 errors in the Report program in the initial display. This screen
basically shows a summary of errors initially. When the buttons for Fcat or Layout are clicked
above, individual errors are displayed then.
The short description of these errors is available along with a long description of selected errors.
Also it displays in tabular format the detailed design of the Fcat, Layout and other tables used to
build up the ALV display. For example, below table shows how I have build my layout in the
program.
Correction of errors:
This analysis report helps us to easily correct any kind of errors as done below.
Let us look into the 2nd displayed error:
From the error description it is quite evident that we have used a Data Element in the Fcat, which
basically doesnt exist in the Data Dictionary. When we look into the Fcat code in the program, we
find:
Activate and run the Report and submit for analysis by using SHIFT+Double Right click. Below is
the result. The errors got reduced to 2.
Since it points out that field PLANT has a wrong value which means that the declaration of PLANT
in the main Internal table, where values of PLANT are stored, might be wrong. We look into the
declaration part of the Internal table. The PLANT field is declared with a wrong Data Type
WERKS in the Table. It should be WERKS_D.
Correction of Error:
Before change:
After change
Activate and run the Report and submit for analysis again. This is what we get as the analysis
result now:
Apart from this a lot of other information can be collected from this SAP standard analysis result.
Hence we can conclude that this is quite a handy tool for analyzing the consistency of our ALV
report generated. We can declare the ALV Grid error free only if no inconsistencies are found in
this result.
Displaying ALV using a Docking Container
Objective
This program is used to display Docking Container. Sometimes we get the requirement to place
the container at any corner as resizable Ex: ALV and selection parameters in same Screen. To
serve purpose we will go for docking container.
Introduction
As we know that a SAP Container is a control that accommodates other controls, such as the SAP
Tree Control, SAP Picture Control, SAP Text edit Control, SAP Splitter Control, and so on. It
manages these controls logically in a collection, and provides a physical area in which they are
displayed. All controls live in a container. Since containers are themselves controls, you can nest
them. There are five kinds of SAP Containers:
SAP Custom Container: display controls in an area defined on a normal screen using the Screen
Painter. Class: CL_GUI_CUSTOM_CONTAINER
SAP Dialog Box Container: display controls in a modal dialog box or full screen.
Class: CL_GUI_DIALOGBOX_CONTAINER
SAP Docking Container: The SAP Docking Container allows you to attach a control to any of the
four edges of a screen as a resizable screen area. You can also detach it so that it becomes an
independent modal dialog box. Class: CL_GUI_DOCKING_CONTAINER
SAP Splitter Container: to display more than one control in a given area by dividing it into cells.
Class: CL_GUI_SPLITTER_CONTAINER
SAP Easy Splitter Container: this container allows us to divide an area into two cells with a
control in each. The cells are separated by a moveable splitter bar.
Class: CL_GUI_EASY_SPLITTER_CONTAINER.
Here we display the functionality of docking container.
SAP Docking container can be attached on or more areas of screen. To reattach the docking
container to a different edge of the screen we use DOCK_AT method. To switch the status of the
Docking Container between fixed (docking) and free (floating) we use the method FLOAT.
We can use docking container in web Dynpro and sub screen also.
Below is the Example of Docking Container.
Code Snippet
REPORT z75_docking MESSAGE-ID yxnmc.
TABLES: mara.
*---------------------------------------------------------------------*
*
WORK AREAS
*---------------------------------------------------------------------*
DATA:
* Material Data
BEGIN OF wa_mara,
matnr TYPE mara-matnr,
END OF wa_mara,
* Field Catalog
*---------------------------------------------------------------------*
*
INTERNAL TABLES
*---------------------------------------------------------------------*
DATA:
* For Material Data
t_mara LIKE STANDARD TABLE OF wa_mara,
* For Field Catalog
t_fieldcat TYPE lvc_t_fcat.
*---------------------------------------------------------------------*
*
WORK VARIABLES
*---------------------------------------------------------------------*
DATA:
* User Command
ok_code TYPE sy-ucomm,
* Reference Variable for Docking Container
r_dock_container TYPE REF TO cl_gui_docking_container,
* Reference Variable for alv grid
r_grid TYPE REF TO cl_gui_alv_grid.
*---------------------------------------------------------------------*
*
START OF SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
* To Display the Data
PERFORM display_output.
*&--------------------------------------------------------------------*
*&
Form display_output
*&--------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine.*
*---------------------------------------------------------------------*
FORM display_output .
* To fill the Field Catalog
PERFORM fill_fieldcat USING :
'MATNR' 'T_MARA'
'Material No.',
'MTART' 'T_MARA'
'Material Type',
'BISMT' 'T_MARA'
'MATKL' 'T_MARA'
'Material Group',
'MEINS' 'T_MARA'
'BRGEW' 'T_MARA'
'Gross Weight',
'NTGEW' 'T_MARA'
'Net Weight',
'GEWEI' 'T_MARA'
'Weight Unit'.
" Display_output
*&--------------------------------------------------------------*
*&
Form FILL_FIELDCAT
*&--------------------------------------------------------------*
*
*---------------------------------------------------------------*
* Three Parameters are passed
* pv_field TYPE any for Field
*
*
wa_fieldcat-fieldname = pv_field.
wa_fieldcat-tabname = pv_tabname.
wa_fieldcat-coltext = pv_coltext.
" FILL_FIELDCAT
*
*
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_0500 OUTPUT.
ENDMODULE.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE create_objects OUTPUT.
* Create a Docking container and dock the control at right side of screen
CHECK r_dock_container IS INITIAL.
CREATE OBJECT r_dock_container
EXPORTING
side
extension
= cl_gui_docking_container=>dock_at_right
= 780
caption
= 'Materials'
EXCEPTIONS
cntl_error
=1
cntl_system_error
=2
create_error
=3
lifetime_error
=4
lifetime_dynpro_dynpro_link = 5
OTHERS
= 6.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
= r_dock_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS
= 5.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
= t_mara
it_fieldcatalog
= t_fieldcat
it_sort
it_filter
EXCEPTIONS
invalid_parameter_combination = 1
program_error
=2
too_many_lines
=3
OTHERS
=4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
To Fetch the Material Data & Refresh Table after get User Command*
*----------------------------------------------------------------------*
MODULE user_command_0500 INPUT.
CASE ok_code.
WHEN 'EXECUTE'.
SELECT matnr
mtart
bismt
matkl
meins
brgew
ntgew
gewei
FROM mara
INTO TABLE t_mara
WHERE mtart = mara-mtart.
IF sy-subrc <> 0.
ENDIF.
" IF sy-subrc EQ 0.
Application Toolbar
Screen 500.
Output
Creating dynamic ALV with dynamic editable columns and dynamic colors to the columns based
on condition
This Program will help to create dynamic ALV with dynamic editable columns and dynamic
colors to the columns based on condition.
*&---------------------------------------------------------------------*
*& Report YSHU_SAI_ALV_DYNAMIC
*&---------------------------------------------------------------------*
REPORT YSHU_SAI_ALV_DYNAMIC.
TYPE-POOLS : ABAP.
FIELD-SYMBOLS: <LINE> TYPE STANDARD TABLE,
<WA> TYPE ANY.
DATA: DYN_TABLE
DYN_LINE
TYPE SY-UCOMM.
START-OF-SELECTION.
* Create dynamic table stricture..
PERFORM GET_TABLE_STRUCTURE.
*&---------------------------------------------------------------------*
*&
Form get_table_structure
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM GET_TABLE_STRUCTURE.
DATA : REF_TABLE_DESCR TYPE REF TO CL_ABAP_STRUCTDESCR,
IT_TABDESCR TYPE ABAP_COMPDESCR_TAB,
WA_TABDESCR TYPE ABAP_COMPDESCR,
LV_NO_DAYS TYPE P,
LV_DATE
TYPE SY-DATUM,
TYPE TEXT40,
TYPE SY-TFILL,
C_REM
= SY-DATUM
IMPORTING
NUMBER_OF_DAYS = LV_NO_DAYS.
* get no of lines..
DESCRIBE TABLE IT_FIELDCAT LINES LIN .
LV_DATUM
= SY-DATUM.
LV_DATUM+6(2)
= 1.
WA_FIELDCAT-COL_POS = LIN.
* fill dynamic field into fields cate..
DO LV_NO_DAYS TIMES.
LV_DATE = LV_DATUM + SY-INDEX - 1.
CALL FUNCTION 'DATE_TO_DAY'
EXPORTING
DATE = LV_DATE
IMPORTING
WEEKDAY = LV_WEEK_DAY.
ENDFORM.
"get_table_structure
*&---------------------------------------------------------------------*
*&
Form create_itab_dynamically
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM CREATE_ITAB_DYNAMICALLY.
* Create dynamic internal table and assign to Field-Symbol
CLEAR WA_FIELDCAT.
*move fields from IT_FIELDCAT into IT_FIELDCAT_1.
IT_FIELDCAT_1 = IT_FIELDCAT.
* Use ref table CALENDAR_TYPE and ref field 'COLTAB'
WA_FIELDCAT-FIELDNAME = 'CELLCOLOR'.
WA_FIELDCAT-REF_TABLE = 'CALENDAR_TYPE'.
WA_FIELDCAT-REF_FIELD = 'COLTAB'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
= DYN_TABLE.
ENDFORM.
"create_itab_dynamically
*&---------------------------------------------------------------------*
*&
Form get_data
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM GET_DATA.
TYPE P,
IF <WA_FIELDCAT>-FIELDNAME+8(2) = '_R'.
LV_MOD_DATE = <WA_FIELDCAT>-FIELDNAME+0(8).
L_DAY_P = LV_MOD_DATE MOD 7.
IF L_DAY_P > 1.
L_DAY_P = L_DAY_P - 1.
ELSE.
L_DAY_P = L_DAY_P + 6.
ENDIF.
IF L_DAY_P = 6 OR L_DAY_P = 7.
PERFORM MODIFY_CELL_COLOR USING <WA_FIELDCAT>-FIELDNAME
CHANGING IT_CELLCOLOR.
<FS_COLOR> = IT_CELLCOLOR.
ENDFORM.
"get_data
*&---------------------------------------------------------------------*
*&
Form modify_cell_color
*&---------------------------------------------------------------------*
*
-->P_FIELDNAME text
-->PT_CELLCOLOR text
*----------------------------------------------------------------------*
FORM MODIFY_CELL_COLOR USING P_FIELDNAME TYPE LVC_FNAME
CHANGING PT_CELLCOLOR TYPE TABLE.
IF DAY_P > 1.
DAY_P = DAY_P - 1.
ELSE.
DAY_P = DAY_P + 6.
ENDIF.
IF DAY_P = 6 OR DAY_P = 7.
IF P_FIELDNAME+8(2) = '_R'.
L_CELLCOLOR-COLOR-COL = 7.
" Red.
L_CELLCOLOR-COLOR-INT = 0.
L_CELLCOLOR-COLOR-INV = 0.
ELSE.
L_CELLCOLOR-COLOR-COL = 7.
" Red.
L_CELLCOLOR-COLOR-INT = 1.
L_CELLCOLOR-COLOR-INV = 1.
ENDIF.
L_CELLCOLOR-FNAME = P_FIELDNAME.
APPEND L_CELLCOLOR TO PT_CELLCOLOR.
ELSE.
CLEAR L_CELLCOLOR.
ENDIF.
IF P_FIELDNAME+0(8) = SY-DATUM.
L_CELLCOLOR-FNAME = P_FIELDNAME.
L_CELLCOLOR-COLOR-COL = 3.
" Red.
L_CELLCOLOR-COLOR-INT = 1.
L_CELLCOLOR-COLOR-INV = 1.
APPEND L_CELLCOLOR TO PT_CELLCOLOR.
CONCATENATE P_FIELDNAME '_R' INTO L_CELLCOLOR-FNAME .
L_CELLCOLOR-COLOR-COL = 3.
" Red.
L_CELLCOLOR-COLOR-INT = 1.
L_CELLCOLOR-COLOR-INV = 1.
APPEND L_CELLCOLOR TO PT_CELLCOLOR.
ENDIF.
ENDFORM.
" MODIFY_CELL_COLOR
*&---------------------------------------------------------------------*
*&
Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG USING P_IT_FIELDCAT TYPE
LVC_T_FCAT."SLIS_T_FIELDCAT_ALV .
** ALV Function module to build field catalog from SAP table structure
I_STRUCTURE_NAME
= 'ZDYNAMIC_ALV_STR'
* I_CLIENT_NEVER_DISPLAY
* I_BYPASSING_BUFFER
= 'X'
=
* I_INTERNAL_TABNAME
CHANGING
CT_FIELDCAT
= P_IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE
PROGRAM_ERROR
OTHERS
=1
=2
=3
.
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.
" BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&
Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT.
DATA :G_GRID_I
GS_LAYOUT-COL_OPT
= 'X'.
GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
GS_LAYOUT-STYLEFNAME = 'CELLSTYLE'.
= GS_LAYOUT
IT_TOOLBAR_EXCLUDING = LT_EXCLUDE[]
CHANGING
IT_FIELDCATALOG
IT_OUTTAB
= IT_FIELDCAT_1
= <LINE>.
ENDFORM.
" DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_2000 INPUT.
CASE OK_CODE.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
SET PF-STATUS 'STATUS_2000'.
* SET TITLEBAR 'xxx'.
ENDMODULE.
*&---------------------------------------------------------------------*
*&
Form EDITABLE_CELL
*&---------------------------------------------------------------------**
-->P_IT_CELLSTYLE text
*----------------------------------------------------------------------*
FORM EDITABLE_CELL USING
= CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
ENDFORM.
Output:
Output:
" EDITABLE_CELL
The output shows current month calendar with all the Saturday and Sundays dynamically red
color will apply and for the current date yellow color with Editable fields.
Printing a line after Subtotaling in an ALV
REPORT ztest_alv.
*---type pools
TYPE-POOLS: slis.
*---internal tables
DATA: BEGIN OF it_flight OCCURS 0,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
END OF it_flight,
*--internal tables for alv
it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF it_fieldcat,
layout TYPE slis_layout_alv,
it_sort type slis_t_sortinfo_alv,
wa_sort like line of it_sort.
*---start-of-selection .
START-OF-SELECTION.
= sy-repid
i_internal_tabname
= 'IT_FLIGHT'
i_inclname
= sy-repid
CHANGING
ct_fieldcat
= it_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error
= 2.
*----get data
SELECT carrid
connid
fldate
seatsmax
seatsocc
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE it_flight
UP TO 20 ROWS.
.
wa_fcat-do_sum = 'X'.
MODIFY it_fieldcat FROM wa_fcat TRANSPORTING do_sum
WHERE fieldname = 'SEATSOCC' .
wa_sort-fieldname = 'CARRID'.
wa_sort-group = 'UL'.
wa_sort-up = 'X'.
= layout
it_fieldcat
= it_fieldcat
it_sort
= it_sort
TABLES
t_outtab
= it_flight
EXCEPTIONS
program_error
= 1.
TYPE-POOLS:slis.
DATA : t_node TYPE snodetext.
DATA : it_node LIKE TABLE OF t_node,
wa_node LIKE t_node.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
fs_fieldcat TYPE slis_fieldcat_alv.
DATA:w_repid LIKE sy-repid.
*Internal Table declarations
DATA: BEGIN OF fs_scarr,
carrid LIKE scarr-carrid,
END OF fs_scarr.
DATA:BEGIN OF fs_spfli,
carrid LIKE spfli-carrid,
connid LIKE spfli-connid,
END OF fs_spfli.
DATA:BEGIN OF fs_sflight,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
END OF fs_sflight.
DATA:BEGIN OF fs_sbook,
carrid LIKE sbook-carrid,
connid LIKE sbook-connid,
fldate LIKE sbook-fldate,
bookid LIKE sbook-bookid,
END OF fs_sbook.
Form get_data
*&----------------------------------------------------------------*
FORM get_data .
SELECT carrid
FROM scarr
INTO TABLE t_scarr.
SELECT carrid
connid
FROM spfli
INTO TABLE t_spfli
FOR ALL ENTRIES IN t_scarr
WHERE carrid EQ t_scarr-carrid.
ENDFORM.
" get_data
*&----------------------------------------------------------------*
*&
Form build_tree
*&----------------------------------------------------------------*
FORM build_tree .
CLEAR: it_node,
wa_node.
SORT: t_scarr BY carrid,
t_spfli BY carrid connid,
t_sflight BY carrid connid fldate,
t_sbook BY carrid connid fldate bookid.
wa_node-type = 'T'.
wa_node-name = 'Flight Details'.
wa_node-tlevel = '01'.
wa_node-nlength = '15'.
wa_node-color = '4'.
wa_node-text = 'Flight'.
wa_node-tlength ='20'.
wa_node-tcolor = 3.
APPEND wa_node TO it_node.
CLEAR wa_node.
LOOP AT t_scarr INTO fs_scarr.
wa_node-type = 'P'.
wa_node-name = 'CARRID'.
wa_node-tlevel = '02'.
wa_node-nlength = '8'.
wa_node-color = '1'.
wa_node-text = fs_scarr-carrid.
wa_node-tlength ='20'.
wa_node-tcolor = 4.
APPEND wa_node TO it_node.
CLEAR wa_node.
LOOP AT t_spfli INTO fs_spfli WHERE carrid EQ fs_scarr-carrid.
wa_node-type = 'P'.
wa_node-name = 'CONNID'.
wa_node-tlevel = '03'.
wa_node-nlength = '8'.
wa_node-color = '1'.
wa_node-text = fs_spfli-connid.
wa_node-tlength ='20'.
wa_node-tcolor = 4.
APPEND wa_node TO it_node.
CLEAR wa_node.
ENDLOOP.
ENDLOOP.
ENDFORM.
" build_tree
*&----------------------------------------------------------------*
*&
Form display_tree
*&----------------------------------------------------------------*
FORM display_tree .
CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
nodetab = it_node.
w_repid = sy-repid.
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
callback_program
= w_repid
callback_user_command = 'USER_COMMAND'
callback_gui_status = 'SET_PF'.
ENDFORM.
" display_tree
*&----------------------------------------------------------------*
*&
Form pick
*&----------------------------------------------------------------*
*
-->COMMAND text
-->NODE
text
*-----------------------------------------------------------------*
FORM user_command TABLES pt_nodes
STRUCTURE seucomm
USING pv_command
CHANGING pv_exit
TYPE c
TYPE c
pv_list_refresh TYPE c.
pv_list_refresh = 'X'.
IF pt_nodes-tlevel = '03'.
CLEAR t_fieldcat[].
SELECT carrid
connid
fldate
FROM sflight
INTO TABLE t_sflight
WHERE connid EQ pt_nodes-text.
fs_fieldcat-col_pos = 1.
fs_fieldcat-fieldname = 'CARRID'.
fs_fieldcat-seltext_m = 'Airlinecarrier'.
fs_fieldcat-key = 'X'.
fs_fieldcat-hotspot = 'X'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.
fs_fieldcat-col_pos = 2.
fs_fieldcat-fieldname = 'CONNID'.
fs_fieldcat-seltext_m = 'Connection No'.
fs_fieldcat-key = 'X'.
fs_fieldcat-hotspot = 'X'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.
fs_fieldcat-col_pos = 3.
fs_fieldcat-fieldname = 'FLDATE'.
fs_fieldcat-seltext_m = 'Flight Date'.
fs_fieldcat-key = 'X'.
fs_fieldcat-hotspot = 'X'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.
w_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = w_repid
it_fieldcat
= t_fieldcat[]
TABLES
t_outtab
= t_sflight.
ENDIF.
ENDFORM.
"pick
*&----------------------------------------------------------------*
*&
Form set_pf
*&----------------------------------------------------------------*
*
text
*-----------------------------------------------------------------*
FORM set_pf.
SET PF-STATUS 'MYPF'.
ENDFORM.
Primary Screen:
"set_pf
OUTPUT:
Secondary screen:
Field1
A
A
B
C
Field2
B
A
C
D
Field3
10
10
10
10
Field4
10
10
10
10
Field2
B
A
C
D
Field3
10
10
10
10
40
Code:
*&----------------------------------------------------------------*
*& Report Z_ALV_DEMO_TOTAL_TEXT
*&
*&----------------------------------------------------------------*
*&
*&
*&----------------------------------------------------------------*
REPORT z_alv_demo_total_text.
* Type declaration for final table to display the output
TYPES: BEGIN OF ty_mara,
srno TYPE char40, " Storing the total text
matnr TYPE matnr, " Material
ersda TYPE ersda, " Creation date
ernam TYPE ernam, " Created by
laeda TYPE laeda, " Last change date
aenam TYPE aenam, " Last change by
vpsta TYPE vpsta, " Maintenance status
brgew TYPE brgew, " Gross weight
ntgew TYPE ntgew, " Net weight
gewei TYPE gewei, " Weight Unit
Field4
10
10
10
10
40
END OF ty_mara.
* Type declaration for table storing temp. data
TYPES: BEGIN OF ty_mara_tmp,
matnr TYPE matnr, " Material
ersda TYPE ersda, " Creation date
ernam TYPE ernam, " Created by
laeda TYPE laeda, " Last change date
aenam TYPE aenam, " Last change by
vpsta TYPE vpsta, " Maintenance status
brgew TYPE brgew, " Gross weight
ntgew TYPE ntgew, " Net weight
gewei TYPE gewei, " Weight Unit
END OF ty_mara_tmp.
* Internal table for storing final data
DATA: i_mara TYPE STANDARD TABLE OF ty_mara INITIAL SIZE 0.
* Work area for final table
DATA: w_mara TYPE ty_mara.
* Internal table for storing temp. data
DATA: i_mara_tmp TYPE STANDARD TABLE OF ty_mara_tmp INITIAL SIZE 0.
* Work area for temp. table
DATA: w_mara_tmp TYPE ty_mara_tmp.
* Object variable for ALV grid
DATA: oref1 TYPE REF TO cl_gui_alv_grid.
* Field catalog table for ALV grid
DATA: fieldcat TYPE lvc_t_fcat.
* Workarea for field catalog table
TYPE lvc_s_sort.
TYPE lvc_s_layo.
START-OF-SELECTION.
* Fetch data
SELECT matnr " Material
ersda " Creation date
ernam " Created by
laeda " Last change date
aenam " Last change by
vpsta " Maintenance status
brgew " Gross weight
ntgew " Net weight
gewei " Weight Unit
FROM mara
INTO TABLE i_mara_tmp
UP TO 100 ROWS.
CHECK sy-subrc = 0.
* Populate final table
LOOP AT i_mara_tmp INTO w_mara_tmp.
* Storing the Total text need to be displayed in
* ALV
*&----------------------------------------------------------------*
*
*-----------------------------------------------------------------*
MODULE status_0100 OUTPUT.
IF oref1 IS INITIAL.
* Create ALV grid object
* In this case we have not created any custom container in the screen,
* Instead of that dummy container name is passed
* ADVANTAGE: we can run this report in background without any problem
CREATE OBJECT oref1
EXPORTING
i_parent
= cl_gui_custom_container=>screen0
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS
=5
.
CHECK sy-subrc = 0.
* Preparing the field catalog
* ZDEMO: Defined in DDIC, it's structure is same as TYPE ty_mara
* defined in the program
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name
= 'ZDEMO'
CHANGING
ct_fieldcat
= fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error
OTHERS
=2
= 3.
IF sy-subrc = 0.
LOOP AT fieldcat INTO w_field.
IF w_field-fieldname = 'BRGEW' OR
w_field-fieldname = 'NTGEW'.
* Populate Sort table with SRNO field so that we can display the total
* text in it's subtotal level
wa_sort2-spos = 1.
wa_sort2-fieldname = 'SRNO'.
wa_sort2-up = 'X'.
wa_sort2-subtot = 'X'.
APPEND wa_sort2 TO i_sort2.
* Hide the total line
wa_layout-no_totline = 'X'.
* Display the ALV grid
CALL METHOD oref1->set_table_for_first_display
EXPORTING
is_layout
= wa_layout
CHANGING
it_outtab
= i_mara[]
it_fieldcatalog
= fieldcat
it_sort
= i_sort2
EXCEPTIONS
invalid_parameter_combination = 1
program_error
=2
too_many_lines
=3
OTHERS
= 4.
IF sy-subrc <> 0.
ENDIF.
* Set the focus on the grid
CALL METHOD cl_gui_alv_grid=>set_focus
EXPORTING
control
= oref1
EXCEPTIONS
cntl_error
=1
cntl_system_error = 2
OTHERS
= 3.
IF sy-subrc <> 0.
ENDIF.
ENDIF.
ENDMODULE.
Output:
" ST
*******************************************************************
TYPE-POOLS: slis.
*******************************************************************
* INTERNAL TABLES/WORK AREAS/VARIABLES
*******************************************************************
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
w_field TYPE slis_fieldcat_alv,
p_table LIKE dd02l-tabname,
dy_table TYPE REF TO data,
dy_tab TYPE REF TO data,
*******************************************************************
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa> TYPE ANY,
<dyn_field> TYPE ANY,
<dyn_tab_temp> TYPE STANDARD TABLE.
*******************************************************************
* SELECTION SCREEN
*******************************************************************
PARAMETERS: tabname(30) TYPE c,
lines(5) TYPE n.
*******************************************************************
* START-OF-SELECTION
*******************************************************************
START-OF-SELECTION.
* Storing table name
p_table = tabname.
* Create internal table dynamically with the stucture of table name
* entered in the selection screen
CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_table->* TO <dyn_table>.
IF sy-subrc <> 0.
MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'.
LEAVE TO LIST-PROCESSING.
ENDIF.
* Create workarea for the table
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
* Create another temp. table
CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_tab->* TO <dyn_tab_temp>.
SORT i_fieldcat BY col_pos.
* Select data from table
SELECT * FROM (p_table)
INTO TABLE <dyn_table>
UP TO lines ROWS.
REFRESH <dyn_tab_temp>.
* Display report
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program
i_structure_name
= sy-repid
= p_table
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
TABLES
t_outtab
= <dyn_table>
EXCEPTIONS
program_error
OTHERS
IF sy-subrc <> 0.
=1
= 2.
ENDIF.
*&-----------------------------------------------------------------*
*&
Form SET_PF_STATUS
*&-----------------------------------------------------------------*
*
*------------------------------------------------------------------*
*
*------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'Z_STANDARD'.
ENDFORM.
"SET_PF_STATUS
*&----------------------------------------------------------------*
*&
Form user_command
*&-----------------------------------------------------------------*
*
*------------------------------------------------------------------*
*
-->R_UCOMM
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* Local data declaration
DATA: li_tab TYPE REF TO data,
l_line TYPE REF TO data.
* Local field-symbols
FIELD-SYMBOLS:<l_tab> TYPE table,
= 'Z_DEMO_PDF_JG'
i_structure_name
= p_table
CHANGING
ct_fieldcat
= i_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error
=2
OTHERS
= 3.
IF sy-subrc = 0.
*
= p_table
= i_fieldcat
i_screen_start_column = 10
i_screen_start_line = 15
i_screen_end_column = 200
i_screen_end_line
= 20
TABLES
t_outtab
= <l_tab>
EXCEPTIONS
program_error
OTHERS
=1
= 2.
IF sy-subrc = 0.
*
action
IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
<dyn_wa> = <l_wa>.
i_index = rs_selfield-tabindex.
APPEND i_index.
ENDIF.
ENDIF.
ENDIF.
mode_rstable = 'E'
tabname
= p_table
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS
= 3.
IF sy-subrc = 0.
*
= p_table.
ENDIF.
ENDCASE.
rs_selfield-refresh = 'X'.
ENDFORM.
Selection screen:
Selection screen:
"user_command
Output: