Have you scratched your head to do minor modifications (change the appearance of a column), add more fields to your output of an existing standard ALV report? I know most of us would have encountered this situation and finally ended up cloning the standard program and struggled with the changes to be done to get your requirements done.
Now, there is a way and the good thing is you do NOT have to copy the standard program. SAP has been kind of enough to provide a BADI which can be used just for this purpose. The BADI
ALV_GRID_XT
can be used to alter the output of the report. I will explain below how I have done the same with a quick flight example. In this example, I have take a custom made report and altered the output of the same without actually changing the fields. My basic report displays nothing but the data from the SFLIGHTS table.
So here is the code for my basic report.
&----
*& Report Y_RAVI_ALV_GRID_BADI
*&
&----
*&
*&
&----
REPORT Y_RAVI_ALV_GRID_BADI.
DATA : T_DATA TYPE TABLE OF SFLIGHT,
T_FIELDCAT TYPE LVC_T_FCAT.
DATA : W_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
W_GRID TYPE REF TO cl_alv_grid_xt.
START-OF-SELECTION.
SELECT * FROM SFLIGHT INTO TABLE T_DATA.
END-OF-SELECTION.
CALL SCREEN 0100.
INCLUDE Y_RAVI_ALV_GRID_BADI_STATUSO01.
INCLUDE Y_RAVI_ALV_GRID_BADI_USER_CI01.
----
***INCLUDE Y_RAVI_ALV_GRID_BADI_STATUSO01 .
----
&----
*& Module STATUS_0100 OUTPUT
&----
----
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ZALV_BADI'.
SET TITLEBAR 'ZALV_BADI_TITLE'.
IF CL_GUI_ALV_GRID=>OFFLINE( ) IS INITIAL.
CREATE OBJECT W_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = 'ALV_BADI'.
CREATE OBJECT W_GRID
EXPORTING
I_PARENT = W_CUSTOM_CONTAINER
I_GRID_ID = 'Y_RAVI_GRID_XT'.
ENDIF.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
I_BYPASSING_BUFFER = 'X'
CHANGING
CT_FIELDCAT = T_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 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.
CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = T_DATA
IT_FIELDCATALOG = T_FIELDCAT
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. " STATUS_0100 OUTPUT
</textarea>
Here is the output of my report.
Now, let us create a implementation of the BADI in SE18 / SE19 transactions.
And here is the code in my implementation. Once I do this I activate the BADI. Here I am taking a simple case of just changing the colour of o`e singli column
.
While creating the BADI implemenation make sure you mention the filter conditions so that the implementation works only for your report and for everyone else's.
This BADI fires just before the
SET_TABLE_FOR_FIRST_DISPLAY
and
REFRESH_TABLE_DISPLAY
methods and all the parameters that are generally available for these methods, are available at the BADI level also so that you can modify anything that you want.