5 Replies Latest reply: Dec 11, 2007 6:48 AM by newbie82 c RSS

ALV report using the field catalog

newbie82 c
Currently Being Moderated

which is the quickest way to generate an ALV report using the field catalog merge.  without needing to build the field catalog manually .

 

is it easier to create a structure and passe it in the field catalog merge .  if yes can i have an example plzzzz

  • Re: ALV report using the field catalog
    Prashant Patil
    Currently Being Moderated

    Hi,

     

    Refer tyhis code

     

    data :  wa_fieldcat TYPE slis_fieldcat_alv."Work area for fieldcatalog

                i_fieldcat TYPE slis_t_fieldcat_alv..

     

    &----


    *&      Form  sub_field_catalogmerge                                   *

    &----


    • This form builds the fieldcatalog using REUSE_ALV_FIELDCATALOG_MERGE*

    • function module                                                     *

    ----


    FORM sub_field_catalogmerge.

     

      CONSTANTS : lc_long_text(1) TYPE c VALUE 'L'.

     

    *--Pass the Report name

      v_repid = sy-repid.

     

    *--Call funtion module to build the field catalog

      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

        EXPORTING

          i_program_name         = v_repid

          i_internal_tabname     = 'I_FINAL'

          i_client_never_display = c_chk

          i_inclname             = v_repid

        CHANGING

          ct_fieldcat            = i_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.

     

      LOOP AT i_fieldcat INTO wa_fieldcat.

     

        CASE wa_fieldcat-fieldname.

     

          WHEN 'FELDV'.

            wa_fieldcat-ddictxt   = lc_long_text.

            wa_fieldcat-seltext_l = text-014.

            MODIFY i_fieldcat FROM wa_fieldcat INDEX sy-tabix

              TRANSPORTING ddictxt seltext_l.

    *--Clear

            CLEAR wa_fieldcat.

     

          WHEN 'VERPR'.

            wa_fieldcat-ddictxt   = lc_long_text.

            wa_fieldcat-seltext_l = text-013.

            MODIFY i_fieldcat FROM wa_fieldcat INDEX sy-tabix

              TRANSPORTING ddictxt seltext_l.

    *--Clear

            CLEAR wa_fieldcat.

     

          WHEN 'EINME'.

            wa_fieldcat-ddictxt   = lc_long_text.

            wa_fieldcat-seltext_l = text-015.

            MODIFY i_fieldcat FROM wa_fieldcat INDEX sy-tabix

              TRANSPORTING ddictxt seltext_l.

    *--Clear

            CLEAR wa_fieldcat.

     

          WHEN 'TVAL'.

            wa_fieldcat-ddictxt   = lc_long_text.

            wa_fieldcat-seltext_l = text-016.

            wa_fieldcat-do_sum = 'X'.

            MODIFY i_fieldcat FROM wa_fieldcat INDEX sy-tabix

              TRANSPORTING ddictxt seltext_l do_sum.

    *--Clear

            CLEAR wa_fieldcat.

     

        ENDCASE.                              " CASE lwa_catlog-fieldname

     

      ENDLOOP.                          "loop at i_fieldcat into wa_fieldcat

     

    ENDFORM.                                  "sub_field_catalogmerge

     

     

    Regards,

    PRashant

  • Re: ALV report using the field catalog
    manjari kotta
    Currently Being Moderated

    Hi,

      If u create the structure then their is no neeed for filling the fieldcatalog table,

      so it is easy to populate the alv grid using by creating the structure.

      plzz reward points if it helps

  • Re: ALV report using the field catalog
    Currently Being Moderated

    function REUSE_ALV_FIELDCATALOG_MERGE

    An example :-

     

    Please note that structure ZSTOCK is a custom table and iline looks as follow :-

     

    data: iline type table of zstock with header line.

    data: gt_fieldcat         type slis_t_fieldcat_alv.

     

      perform setup-fieldcatalog using gt_fieldcat[].

     

    form setup-fieldcatalog using fieldcat type slist_fieldcat_alv.

      data: ls_fieldcat type slis_fieldcat_alv.

     

      call function 'REUSE_ALV_FIELDCATALOG_MERGE'

           exporting

                i_internal_tabname = 'ILINE'

                i_structure_name   = 'ZSTOCK'

           changing

                ct_fieldcat        = _fieldcat.

     

      loop at fieldcat into lsfieldcat.

        case ls_fieldcat-fieldname.

          when 'DEPT'.

            ls_fieldcat-no_out    = 'X'.

           when 'DESCR'.

            ls_fieldcat-no_out    = 'X'.

          when 'GOOD_PRD'.

            ls_fieldcat-do_sum    = 'X'.

        endcase.

     

        modify fieldcat from lsfieldcat.

      endloop.

     

    endform.                    " FIELDCATALOG

  • Re: ALV report using the field catalog
    Currently Being Moderated

    hI

     

    Supports the creation of the field catalog for the ALV function modules

    based either on a structure or table defined in the ABAP Data

    Dictionary, or a program-internal table.

     

    The program-internal table must either be in a TOP Include or its

    Include must be specified explicitly in the interface.

     

    The variant based on a program-internal table should only be used for

    rapid prototyping since the following restrictions apply:

     

    o Performance is affected since the code of the table definition must

    always be read and interpreted at runtime.

     

    o Dictionary references are only considered if the keywords LIKE or

    INCLUDE STRUCTURE (not TYPE) are used.

     

    If the field catalog contains more than 90 fields, the first 90 fields

    are output in the list by default whereas the remaining fields are only

    available in the field selection.

     

    If the field catalog is passed with values, they are merged with the

    'automatically' found information.

     

    Below is an example ABAP program which will populate a simple internal table(it_ekpo) with data and

    display it using the basic ALV grid functionality(including column total). The example details the main

    sections of coding required to implement the ALV grid functionality:

                             Data declaration

                             Data retrieval

                             Build fieldcatalog

                             Build layout setup

     

    *&---------------------------------------------------------------------*
    *& Report  ZDEMO_ALVGRID                                               *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *&                                                                     *
    *& Example of a simple ALV Grid Report                                 *
    *& ...................................                                 *
    *&                                                                     *
    *& The basic requirement for this demo is to display a number of       *
    *& fields from the EKKO table.                                         *
    *&---------------------------------------------------------------------*
    REPORT  zdemo_alvgrid                 .
    
    TABLES:     ekko.
    
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    *----------------
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
     END OF t_ekko.
    
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    
    
    ************************************************************************
    *Start-of-selection.
    START-OF-SELECTION.
    
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform display_alv_report.
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCATALOG
    *&---------------------------------------------------------------------*
    *       Build Fieldcatalog for ALV Report
    *----------------------------------------------------------------------*
    form build_fieldcatalog.
    
    * There are a number of ways to create a fieldcat.
    * For the purpose of this example i will build the fieldcatalog manualy
    * by populating the internal table fields individually and then
    * appending the rows. This method can be the most time consuming but can
    * also allow you  more control of the final product.
    
    * Beware though, you need to ensure that all fields required are
    * populated. When using some of functionality available via ALV, such as
    * total. You may need to provide more information than if you were
    * simply displaying the result
    *               I.e. Field type may be required in-order for
    *                    the 'TOTAL' function to work.
    
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    *  fieldcatalog-do_sum      = 'X'.
    *  fieldcatalog-no_zero     = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.        "Display column total
      fieldcatalog-datatype     = 'CURR'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_LAYOUT
    *&---------------------------------------------------------------------*
    *       Build layout for ALV grid report
    *----------------------------------------------------------------------*
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    *  gd_layout-totals_only        = 'X'.
    *  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
    *                                         "click(press f2)
    *  gd_layout-zebra             = 'X'.
    *  gd_layout-group_change_edit = 'X'.
    *  gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_ALV_REPORT
    *&---------------------------------------------------------------------*
    *       Display report using ALV grid
    *----------------------------------------------------------------------*
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
    *            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
    *            i_callback_user_command = 'USER_COMMAND'
    *            i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
    *            it_special_groups       = gd_tabgroup
    *            IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
    *            is_variant              = z_template
    
           tables
                t_outtab                = it_ekko
           exceptions
                program_error           = 1
                others                  = 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.
    endform.                    " DISPLAY_ALV_REPORT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    *       Retrieve data form EKPO table and populate itab it_ekko
    *----------------------------------------------------------------------*
    form data_retrieval.
    
    select ebeln ebelp statu aedat matnr menge meins netpr peinh
     up to 10 rows
      from ekpo
      into table it_ekko.
    endform.                    " DATA_RETRIEVAL

     

Actions