Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

what is structure of ALV

Former Member
0 Kudos

what is structure of ALV

4 REPLIES 4

Former Member
0 Kudos

Hi,

Important Function Modules

• Reuse_alv_list_display

• Reuse_alv_fieldcatalog_merge

• Reuse_alv_events_get

• Reuse_alv_commentary_write

• Reuse_alv_grid_display

All the definitions of internal tables, structures and Constants are declared in a type-pool called SLIS.

regards,

kiran kumar k

Former Member
0 Kudos

hi Nagaraju,

for alv use type pools 'SLIS'

regards,

Navneeth.K

Former Member
0 Kudos

1. First we prepare a outputlist which we want to display .

2.WE made a fieldcatalog table which will say the display of the columns.

Ex: position of columns, heading, length etc.

3. Then we prepare a layout structure which contain the layout informations.

4. we call a FM ( ex: RUSE_ALV_GRID_DISPLY or REUSE_ALV_LIST_DISPLAY)

ex:


*&---------------------------------------------------------------------*
*& 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.                   

You can also prepare alv display by using class.

ex:

STEPS:

1. Call a screen.

2. Go to the screen layout and add a custom control .

3. Go to attribute and give a name to the custom control (Ex: 'CUSTOM_CONTROL').

4. Give a name to the ok_code ( Ex: ok_code) in the attribute of the screen.

5. Data Declaration section:

I. Data declaration for ALV

a. Declare a object type cl_gui_alv_grid for ALV Grid instance referance

b. Declare a object type cl_gui_custom_container for Custom container instance referance

c. Declare Name of the custom control added to the screen

d. Declare field catalog table of type lvc_t_fcat.

e. Declare layout of type lvc_s_layo.

II. Data declaration for fetching data as input

III. Declare variables for ok_code.

6. Set pf-status and titlebar for the screen.

7. Write PBO. IN PBO do the following:

i. Check whether gr_alvgrid is initial.

a. If yes do the following.

• Create instance for custom container (gr_container) by passing the container name.

• Create instance for ALV grid by passing the custom control instance reference.

• select the material data from database

• Build field ctalog

• Build layout

• Call method ‘set_table_for_first_display’ for the object gr_alvgrid(alv grid instance reference) with passing layout, input table and field catalog.

b. If NO do the following.

• Call method ‘refresh_table_display for the object gr_alvgrid(alv grid instance reference).

ii.

8. Write PAI. IN PAI do the following:

Check the ok_code, if ‘Exit’ then leave from program.

All the user commands where user do any actions in the screen will be code here . For this purpose check the value of ok_code and according that ok_code, code the functionality for the particular user actions.

REPORT  zdemoab.


************************************
*DATA DECLARATION
*************************************
*---Global data deckaration for alv
*--ALV Grid instance referance
DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid,
*--Name of the custom control added to the screen
      gc_custom_control_name TYPE scrfname VALUE 'CUSTOM_CONTROL',
*--Custom container instance referance
      gr_container TYPE REF TO cl_gui_custom_container,
*--Field catalog table
      gt_fieldcat TYPE lvc_t_fcat,
*--Layout structure
      gs_layout TYPE lvc_s_layo.

DATA: ok_code LIKE sy-ucomm,
      save_ok LIKE sy-ucomm.


*---Input table
TYPES: BEGIN OF t_mara,
        matnr TYPE mara-matnr,
        mtart TYPE mara-mtart,
        matkl TYPE mara-matkl,
        meins TYPE mara-meins,
      END OF t_mara.
TYPES: t_mara_table TYPE STANDARD TABLE OF t_mara.

DATA: gt_mara TYPE STANDARD TABLE OF t_mara.

************************************
*MAIN
*************************************
CALL SCREEN 101.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0101  OUTPUT
*&---------------------------------------------------------------------*

MODULE status_0101 OUTPUT.
  SET PF-STATUS 'STATUS-0101'.
  SET TITLEBAR 'TITLE'.

ENDMODULE.                 " STATUS_0101  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  display_alv  OUTPUT
*&---------------------------------------------------------------------*

MODULE display_alv OUTPUT.

  IF gr_alvgrid IS INITIAL.
*----Create custom container instance
    CREATE OBJECT gr_container
      EXPORTING
        container_name              = gc_custom_control_name
      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.

*----Create ALV grid instance
    CREATE OBJECT gr_alvgrid
      EXPORTING
        i_parent          = gr_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.

* select the material data from database
    PERFORM get_input CHANGING gt_mara..
* prepare field catalog
    PERFORM prepare_fieldcatalog CHANGING gt_fieldcat.
* prepare layout
    PERFORM prepare_layout CHANGING gs_layout.


    CALL METHOD gr_alvgrid->set_table_for_first_display
      EXPORTING
        is_layout                     = gs_layout
      CHANGING
        it_outtab                     = gt_mara[]
        it_fieldcatalog               = gt_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.
  ELSE.
    CALL METHOD gr_alvgrid->refresh_table_display
      EXCEPTIONS
        finished = 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.


  ENDIF.
ENDMODULE.                 " display_alv  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  get_input
*&---------------------------------------------------------------------*
FORM get_input CHANGING gt_mara_table TYPE t_mara_table.
  SELECT matnr mtart matkl meins INTO TABLE gt_mara_table
                                 FROM mara UP TO 10 ROWS.
ENDFORM.                    " get_input
*&---------------------------------------------------------------------*
*&      Form  prepare_fieldcatalog
*&---------------------------------------------------------------------*

FORM prepare_fieldcatalog  CHANGING gt_fieldcat_table TYPE lvc_t_fcat.

  DATA: ls_fcat TYPE lvc_s_fcat,
        l_col_no TYPE i.

  CLEAR: ls_fcat,
         l_col_no .

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MATNR'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 18.
  ls_fcat-coltext   = 'Material No'.
  ls_fcat-seltext   = 'Material No'.
  APPEND ls_fcat TO gt_fieldcat_table.

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MTART'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 4.
  ls_fcat-coltext   = 'Material type'.
  ls_fcat-seltext   = 'Material type'.
  APPEND ls_fcat TO gt_fieldcat_table.

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MATKL'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 9.
  ls_fcat-coltext   = 'Material group'.
  ls_fcat-seltext   = 'Material group'.
  APPEND ls_fcat TO gt_fieldcat_table.

  l_col_no = l_col_no + 1.
  ls_fcat-fieldname = 'MEINS'.
  ls_fcat-ref_table = 'MARA'.
  ls_fcat-col_pos   = l_col_no.
  ls_fcat-outputlen = 3.
  ls_fcat-coltext   = 'Unit'.
  ls_fcat-seltext   = 'Unit'.
  APPEND ls_fcat TO gt_fieldcat_table.

  CLEAR: ls_fcat,
         l_col_no .

ENDFORM.                    " prepare_fieldcatalog
*&---------------------------------------------------------------------*
*&      Form  prepare_layout
*&---------------------------------------------------------------------*
FORM prepare_layout  CHANGING p_gs_layout TYPE lvc_s_layo.

  p_gs_layout-zebra = 'X'.
  p_gs_layout-grid_title = 'Material'.
  p_gs_layout-smalltitle = 'X'.

ENDFORM.                    " prepare_layout
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0101  INPUT
*&---------------------------------------------------------------------*

MODULE user_command_0101 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'EXIT'.
      PERFORM exit_program.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0101  INPUT
*&---------------------------------------------------------------------*
*&      Form  exit_program
*&---------------------------------------------------------------------*
FORM exit_program .
  LEAVE PROGRAM.
ENDFORM.                    " exit_program

Former Member
0 Kudos

hi nagaraju,

the very basic structure of alv consists of

*table name.

tables:mara. "for eg.

data: itab type table of mara.

*declaration of type-pools.

type-pools : slis.

data: fieldcatalog type slis_t_fieldcat_alv,

wa_mara type slis_t_fieldcat_alv.

SELECT-OPTIONS

-


SELECT * -


WHERE-----

END-OF-SELECTION

perform fieldcatalog.

PERFORM DISPLAY.

FORM FIELDCATALOG.

call function 'REUSE_FIELD_CATALOG'

-


-


-


ENDFORM.

FORM DISPLAY.

CALL FUNCTION 'REUSE_GRID_DISPLAY'

-


-


ENDFORM

ANUJ

AWARD POINT FOR EVERY HELPFUL ANSWERS