Skip to Content

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

&—-


  •       text

—-


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_BUFFER_ACTIVE              =

      I_STRUCTURE_NAME             = ‘SFLIGHT’

  •     I_CLIENT_NEVER_DISPLAY       = ‘X’

      I_BYPASSING_BUFFER           = ‘X’

  •     I_INTERNAL_TABNAME           =

    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

  •    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.                 ” STATUS_0100  OUTPUT

</textarea>

Here is the output of my report.

image

Now, let us create a implementation of the BADI in SE18 / SE19 transactions.

image

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

.

image

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.

image

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.

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

      1. Suresh Datti
        Ravi,

        We are still on 620, so can’t check this .. but can you verify if we can assign a diff pf-status or manipulate the buttons, uisng this BAdI?

        Regards,

        Suresh Datti

        (0) 
        1. Ravikumar Allampallam Post author
          Suresh,

          Unfortunately, I don’t think we can change the PF-STATUS. However, there are quite few other parameters which can be changed. Will try and find out what are the things that can be used.

          Regards,
          Ravi

          (0) 
  1. Ravikumar Allampallam Post author
    Thanks Rich.

    I think its available only from WAS 6.40. I looked into our SAP R/3 4.7 and that class is not available. The system that I was working on is on WAS 6.40 SP14.

    Regards,
    Ravi

    (0) 
    1. Anonymous
      hi ravi,

      how can i put entries in table TALV_GRID? is it in sm30 or somewhere else? i need to know since i cannot set my own program in the defined filters section of my implementation

      additionally, is there a badi defined to enhance the methods of CL_GUI_ALV_TREE or the tree and node ALV?

      thanks

      (0) 
    1. Ravikumar Allampallam Post author
      Thanks Abdul.
      I don’t think it will be possible in 4.6C, as the BADI is does not exist even on R/3 4.7. So, unless SAP provides the BADI, we will not be able to do anything.

      Regards,
      Ravi

      (0) 
  2. Anonymous
    Ravi,

    Great weblog.  Do you know if there is any way to change the structure of CT_OUTTAB?

    For example I passed in a table with two fields, and I want to add a third field within the BADI.  However CT_OUTTAB has the original structure and I can’t seem to change it.

    Thanks,

    Chris

    (0) 
    1. Ravikumar Allampallam Post author
      Chris,

      This is the same thing that has been troubling since the day I worked with this BADI. I haven’t been successful in adding fields to and existing internal table. What I tried was delete the incoming table and pass another table to CT_OUTTAB with a different stucture. But it was taking the old table. However, I was successful in adding entries to the fieldcat, so in the change layout option those showed up.

      If you find a way to add more fields to internal table at runtime, please let me know.

      regards,
      Ravi

      (0) 
    2. Dragos Mihai Florescu
      That is my experience as well. One can’t change the structure of ct_outtab (so, no chance to dinamically add fields). If I am mistaken, someone please correct me!

      There may be an workaround, if the table is built based on a DDIC structure: append a z-structure to the initial DDIC object and inside the BAdI implementation fill accordingly the empty fields. But I wouldn’t use it if the original strucutre is widely used (for instance, if ct_outtab is a TABLE OF resb), because it affects the performace of all existing programs.

      (0) 
  3. Emanuel Klenner
    Hi Ravi !

    Unfortunately you won’t be able to extend any SAP delivered ALV using the technique described above. You can only use the BAdI ALV_GRID_XT if the standard developer was kind enough to deliver an entry in table TALV_GRID AND include that grid ID in the create object statement.

    It was my intention, when creating the BAdI, that it would be easier for customers to change the ALV.

    Currently SAP’s insurance claims processing solution is the only application that provides the grid ID’s and creates the objects with reference to the class cl_alv_grid_xt.

    The BAdI is available starting with WAS 6.40

    Best regards.

    Emanuel Klenner – SAP
    Insurance Claims Development 

    (0) 
  4. Dragos Mihai Florescu
    As people already found out, there is no way to dinamically change ct_outtab inside the BADI method, to fit specific needs (for instance, to display icons for various flags instead of Xs and Spaces).

    However, a solution exist, but it requires cooperation from the initial developer.

    The trick is to use, for defining the field catalog, not the heavily-used SAP-delivered DDIC structure, but instead a new structure, specific only to the program. This new structure can be enhanced via APPENDs, and therefore there is no need to modify the structure of CT_OUTTAB. Well, of course, the fields are not populated yet…

    In Ravi’s case, he should not use SFLIGHT, but a new structure /DEVNAMESPACE/ALVXT_SFLIGHT, which initially contains only an .INCLUDE SFLIGHT line.
    In a subsequent system, one may create an APPEND-structure, /CUSTNAMESPACE/SFLIGHT_EXT, containing the additional fields he needs. In the BADI implementation, these additional fields must be populated accordingly.

    The reason for the additional structure is that noone want to mess up SFLIGHT by adding APPEND-fields, thus affecting all the programs that rely on it (alright, SFLIGHT might be ok, but MARA or VBAK are definitely not!).

    I have tried this solution and it works. In my case, I displayed a grid based on DIRECTORY_LIST_FILES and then I enhanced the output, displaying an additional icon for the folders.

    (0) 

Leave a Reply