Skip to Content

ALV Programming has undergone a major change over the last couple of years. First we had the function module approach – where the data to be displayed is passed to a function module like REUSE_ALV_LIST_DISPLAY. Then with the introduction of the OO concepts in 46C we had classes like CL_GUI_ALV_GRID and CL_GUI_ALV_TREE which changed ALV
Programming quite a bit. Most (almost all ?) ABAPers today use these classes to program their ALV.

If you were asked to name one improvement to this approach based on classes, what would that be? I would say that it is still a bit painful to create a screen and put a custom control container and then place this ALV Grid in that , all by myself. Especially when I want to create some test programs to answer the questions in the ABAP Forum :-)!
Wouldn’t it be great if I could worry less about these and concentrate more on imporving the functionality of my ALV Grid?

This is precisely what you can do from Basis 640. You can now program an ALV in various modes (Fullscreen, Regular and List Mode), all using a single class (and without even having to create a screen ! ).

So without further ado, let me introduce you what’s called  the ALV Object Model. Now, what’s that ?

START-OF-SELECTION.

  CALL FUNCTION ‘NAMETAB_GET’

    EXPORTING

      langu   = sy-langu

      tabname = tab_name

    TABLES

      nametab = dyntab. “dyntab now contains the field names

  • FILLING THE CATALOG OF NEW DYNAMIC INTERNAL TABLE

  LOOP AT dyntab INTO wa_dyntab.

    wa_fcat-fieldname = wa_dyntab-fieldname.

    wa_fcat-ref_field = wa_dyntab-fieldname.

    wa_fcat-ref_table = wa_dyntab-tabname.

    APPEND wa_fcat TO i_fcat .

  ENDLOOP.

  • CREATING A POINTER (FIELD SYMBOL) TO THE INTERNAL TABLE

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog = i_fcat

    IMPORTING

      ep_table        = dref.

  ASSIGN  dref->* TO .

  • SELECT the data from the table SPFLI. If you want a

  • different table, then just use a different value

  • than SPFLI in the data declarations part. Or better

  • still, use a PARAMETERS to take the name of the

  • table name as input from the selection-screen.

  SELECT *

    FROM (tab_name)

    INTO TABLE

  • Instead of if_salv_c_bool_sap=>false, you can pass the

  • value if_salv_c_bool_sap=>true to this method to

  • see your ALV as a list.

  TRY.

      CALL METHOD cl_salv_table=>factory

        EXPORTING

          list_display   = if_salv_c_bool_sap=>false

        IMPORTING

          r_salv_table   = gr_table

        CHANGING

          t_table        =

To report this post you need to login first.

12 Comments

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

  1. Former Member
    Hello Poornanand,
                      Your weblog based on ALV using classes helped me a lot. Thanks from all SDN’ians.

    Regards,
    Dilip
       

    (0) 
  2. Hi,… Create Instance<br/>  TRY.<br/>      CALL METHOD cl_salv_table=>factory<br/>        IMPORTING<br/>          r_salv_table = gr_table<br/>        CHANGING<br/>          t_table      = <newtab>.<br/><br/>    CATCH cx_salv_msg.<br/>  ENDTRY.<br/><br/>Display table<br/>  gr_table->display( ).<br/><br/>Here in the above code, you can also specify your own internal type (defined in your report) with fields of ABAP dictionary type like:<br/><br/><br/>TYPES:<br/>     BEGIN OF my_own_type,<br/>       sample_field_1 TYPE spfli-carrid,<br/>       sample_field_2 TYPE spfli-connid,<br/>     END   OF my_own_type.<br/><br/>linetype ?= cl_abap_typedescr=>describe_by_name( ‘MY_OWN_TYPE’ ).<br/><br/><br/><br/>The cl_salv_table=>factory method will automatically pickup the field descriptions from the ABAP Dictionary.<br/><br/>Of course, you can also define your headings using the other methods of the SALV classes.<br/><br/>More information about the RTTS can be found in the class documentations. These are really useful when you have to create dynamic tables using your own types defined in your report.<br/>

    (0) 
    1. Hello Anand,

      I agree with what you’ve said about reating a dynamic internal table. However, it was not the purpose of this weblog to explain how RTTI (Run-Tyime-Type-Identificaton) can be used in Generic Programming. I had just wanted to show another way of programming an ALV.

      Regards,
      Anand Mandalika.

      (0) 
  3. Former Member
    I need to have the functions to modify and save variants.  The status I have has the function but doesn’t appear.
    I’m trying to add the function but I have the “CX_SALV_METHOD_NOT_SUPPORTED” error.
    This is my code:
      gr_table->set_screen_status(
        pfstatus      =  ‘STANDARD’
        report        =  ”SAPLKKBL’
        set_functions = gr_table->c_functions_all ).

      CALL METHOD gr_table->get_functions
        RECEIVING
          value = lt_functions.

      TRY.
          CALL METHOD lt_functions->add_function
            EXPORTING
              name     = ‘&AVE’
    *         icon     =
    *         text     =
              tooltip  = ‘Grabar’
              position = ‘1’
              .
        CATCH cx_salv_existing .
        CATCH cx_salv_wrong_call .
      ENDTRY.

      gr_table->display( ).

    Thanks for your help

    (0) 

Leave a Reply