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: 

Example of a Simple ALV Report using Function Modules (not OO)

Former Member
0 Kudos

Hi,

I am new to ABAP. Where can I get a proper Example of a Simple ALV Report using Function Modules? I searched the forum but did not find a proper solution. Kindly help.

Smruthi.

Edited by: Smruthi Acharya on Jan 29, 2009 7:13 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

If you are aware what a Package means and if you have access to a SAP system, you will find loads of examples related to ALV programming with excellent explanation in the package SLIS. Goto t-code se80 and select "Package" from the dropdown in the object navigator and enter SLIS and press enter.

This package not only explains the ALV reporting using function modules , but also using OOPS. That is how most of us have learnt about ALV and I would suggest you follow the same path.

By any chance you dont have access to the system, go to the SCN's WIKI section and type "ALV" in the search field you will find a plethora of examples.

regards,

Advait

6 REPLIES 6

former_member156446
Active Contributor
0 Kudos

check BCALV in se38

Former Member
0 Kudos

Hi,

Check this link [ALV|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=alvgriddisplayusingFunction+Module&adv=false&sortby=cm_rnd_rankvalue]

Former Member
0 Kudos

> I searched the forum but did not find a proper solution.

I think you are unaware what a Function Module is.!

Initially as a beginner, to know what are all the function modules available for ALV,

goto Tcode - SE37, type REUSE_ALV* and press F4. It will give all the function modules.

With this, search here in SDN.

For sample programs:

Goto SE38, type BCALV* and press F4, it will give all the examples.

Most commonly used Function Module in ALV is REUSE_ALV_GRID_DISPLAY

some std demo programs, u can check out are:

BCALV_TEST_GRID

BCALV_TEST_LIST

BALVSD02_GRID

BALVST02_GRID

BALVST03_GRID

BCALV_FULLSCREEN_DEMO

All the Best.

Padmashree

Edited by: Padmashree RamMaghenthar on Jan 29, 2009 7:40 PM

former_member206439
Contributor
0 Kudos

Hi

under Wiki (SDN)section you can find many program in ALV

I355602
Advisor
Advisor
0 Kudos

Hi,

Use this demo code:-


REPORT  z_alv01 MESSAGE-ID zmsg.
*&---------------------------------------------------------------------*
*          TABLES
*&---------------------------------------------------------------------*
TABLES : ekpo.

*&---------------------------------------------------------------------*
*          TYPE POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.

*&---------------------------------------------------------------------*
*          TYPE DECLARATION
*&---------------------------------------------------------------------*
TYPES : BEGIN OF t_ekpo,
          ebeln TYPE ekpo-ebeln,
          ebelp TYPE ekpo-ebelp,
          matnr TYPE ekpo-matnr,
          werks TYPE ekpo-werks,
          menge TYPE ekpo-menge,
        END OF t_ekpo.

*&---------------------------------------------------------------------*
*          PARAMETERS
*&---------------------------------------------------------------------*
PARAMETERS : s_var TYPE disvariant-variant.

*&---------------------------------------------------------------------*
*          DATA DECLARATION
*&---------------------------------------------------------------------*
*VARIABLES
DATA : check(1),
       rep_id TYPE sy-repid.

*INTERNAL TABLE TYPE OF ZEKPO
DATA : it_ekpo TYPE STANDARD TABLE OF t_ekpo WITH HEADER LINE.

*FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv,
       wa_field TYPE slis_fieldcat_alv.

*SORTING
DATA : it_sort TYPE slis_t_sortinfo_alv,
       wa_sort TYPE slis_sortinfo_alv.

*FOR TOP OF THE PAGE
DATA : it_top TYPE slis_t_listheader,
       wa_top TYPE slis_listheader.

*FOR END OF THE PAGE
DATA : it_end TYPE slis_t_listheader,
       wa_end TYPE slis_listheader.

*TO CAPTURE EVENTS AND HANDLE
DATA : it_event TYPE slis_t_event,
       wa_event TYPE slis_alv_event.

*FOR GRID TITLE
DATA : wa_title TYPE lvc_title.

*FOR LAYOUT
DATA : wa_layout TYPE slis_layout_alv.

*FOR EXCLUDING STANDARD BUTTON FROM ALV TOOLBAR
DATA : it_exclude TYPE slis_t_extab,
       wa_exclude TYPE slis_extab.

*FOR VARIANT
DATA : wa_variant TYPE disvariant.

*&---------------------------------------------------------------------*
*          INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.
  check = 'X'.
  rep_id = sy-repid.
  wa_variant-report = sy-repid.
*GET DEFUALT ON THE SELECTION SCREEN FOR DEFAULT DISPLAY
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = wa_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc = 0.               " IF DEFAULT VARIANT FOUND
    s_var = wa_variant-variant.  " PASS THE DEFAULT VARIANT TO THE SELECTION SCREEN FIELD
  ENDIF.

*&---------------------------------------------------------------------*
*          AT-SELECTION SCREEN ON VALUE REQUEST
*&---------------------------------------------------------------------*
*          TO GET THE F4 HELP FOR VARIANT
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_var.

  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant                = wa_variant
*   I_TABNAME_HEADER          =
*   I_TABNAME_ITEM            =
*   IT_DEFAULT_FIELDCAT       =
     i_save                    = 'A'
*   I_DISPLAY_VIA_GRID        = ' '
   IMPORTING
*   E_EXIT                    =
     es_variant                = wa_variant
   EXCEPTIONS
     not_found                 = 1
     program_error             = 2
     OTHERS                    = 3.
  IF sy-subrc = 0.
    s_var = wa_variant-variant. " PASS THE SELECTED VARIANT TO THE SELECTION SCREEN FIELD
  ENDIF.

*&---------------------------------------------------------------------*
*          AT-SELECTION SCREEN
*&---------------------------------------------------------------------*
*          TO CHECK THE EXISTENCE FOR VARIANT
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
  wa_variant-variant = s_var.
  CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = wa_variant
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc <> 0.
    MESSAGE w001.
  ENDIF.

*&---------------------------------------------------------------------*
*          START OF SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  SELECT ebeln
         ebelp
         matnr
         werks
         menge
         FROM ekpo
         INTO TABLE it_ekpo.

*&---------------------------------------------------------------------*
*          FIELD CATALOG
*&---------------------------------------------------------------------*
  wa_field-fieldname = 'EBELN'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'PO #'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'EBELP'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'Line Item'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'MATNR'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 15.
  wa_field-seltext_l = 'Material'.
*  wa_field-input = check.
*  wa_field-edit = check.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'WERKS'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 6.
  wa_field-seltext_l = 'Plant'.
*  wa_field-input = check.
*  wa_field-edit = check.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'MENGE'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'Qty.'.
*  wa_field-input = check.
*  wa_field-edit = check.
  wa_field-do_sum = check.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

*&---------------------------------------------------------------------*
*          SORT W.R.T. PURCHASE ORDER NUMBER
*&---------------------------------------------------------------------*
  wa_sort-spos = 1.
  wa_sort-fieldname = 'EBELN'.
  wa_sort-tabname = 'IT_EKPO'.
  wa_sort-up = check.
  wa_sort-subtot = check.
  APPEND wa_sort TO it_sort.
  CLEAR wa_sort.

*&---------------------------------------------------------------------*
*          FOR GRID TITLE
*&---------------------------------------------------------------------*
  wa_title = 'Hello'.

*&---------------------------------------------------------------------*
*          FOR LAYOUT
*&---------------------------------------------------------------------*
  wa_layout-zebra = check.

*&---------------------------------------------------------------------*
*          FOR EXCLUDING STANDARD BUTTONS FROM ALV TOOLBAR
*&---------------------------------------------------------------------*
  wa_exclude-fcode = '&OUP'.
  APPEND wa_exclude TO it_exclude.
  CLEAR wa_exclude.

  wa_exclude-fcode = '&ODN'.
  APPEND wa_exclude TO it_exclude.
  CLEAR wa_exclude.

  wa_exclude-fcode = '&OAD'.
  APPEND wa_exclude TO it_exclude.
  CLEAR wa_exclude.

*  wa_exclude-fcode = '&AVE'.
*  APPEND wa_exclude TO it_exclude.
*  CLEAR wa_exclude.

  wa_exclude-fcode = '&INFO'.
  APPEND wa_exclude TO it_exclude.
  CLEAR wa_exclude.

*&---------------------------------------------------------------------*
*          POPULATE ALL EVENTS INTO INTERNAL TABLE
*&---------------------------------------------------------------------*
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = it_event
    EXCEPTIONS
      list_type_wrong = 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.

  READ TABLE it_event INTO wa_event WITH KEY name = 'END_OF_LIST'.
  wa_event-form = 'END'.
  MODIFY it_event FROM wa_event INDEX sy-tabix.
  CLEAR wa_event.

*&---------------------------------------------------------------------*
*          DISPLAY RECORDS IN ALV GRID
*&---------------------------------------------------------------------*
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   i_callback_program                = rep_id
*   i_callback_pf_status_set          = 'PF'
   i_callback_user_command           = 'COMMAND'
   i_callback_top_of_page            = 'TOP'
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
   i_grid_title                      = wa_title
*   I_GRID_SETTINGS                   =
   is_layout                         = wa_layout
   it_fieldcat                       = it_field
   it_excluding                      = it_exclude
*   IT_SPECIAL_GROUPS                 =
   it_sort                           = it_sort
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
   i_save                            = 'A'
   is_variant                        = wa_variant
   it_events                         = it_event
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
    TABLES
      t_outtab                          = it_ekpo
 EXCEPTIONS
   program_error                     = 1
   OTHERS                            = 2.

  IF sy-subrc <> 0.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  top
*&---------------------------------------------------------------------*
*       TO WRITE THE HEADER
*----------------------------------------------------------------------*
FORM top.

  REFRESH it_top.
  wa_top-typ = 'S'.
  wa_top-key = text-001.
  wa_top-info = rep_id.
  APPEND wa_top TO it_top.
  CLEAR wa_top.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = it_top
*   I_LOGO                   =
*   I_END_OF_LIST_GRID       =
*   I_ALV_FORM               =
            .

ENDFORM.                    "top

*&---------------------------------------------------------------------*
*&      Form  end
*&---------------------------------------------------------------------*
*       TO WRITE THE FOOTER
*----------------------------------------------------------------------*
FORM end.

  REFRESH it_end.
  wa_end-typ = 'S'.
  wa_end-key = text-001.
  wa_end-info = rep_id.
  APPEND wa_end TO it_end.
  CLEAR wa_end.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = it_end
*   I_LOGO                   =
*   I_END_OF_LIST_GRID       =
*   I_ALV_FORM               =
            .

ENDFORM.                    "end

*&---------------------------------------------------------------------*
*&      Form  pf
*&---------------------------------------------------------------------*
*       FOR PF-STATUS WITH USER DEFINED BUTTONS
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM pf USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZTG_PF_ALV'.
ENDFORM.                    "pf

*&---------------------------------------------------------------------*
*&      Form  command
*&---------------------------------------------------------------------*
*       TO HANDLE USER ACTIONS AGAINST PF-STATUS
*----------------------------------------------------------------------*
*      -->UCOMM      text
*      -->SELFIELD   text
*----------------------------------------------------------------------*
FORM command USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.
  DATA : ok_code TYPE sy-ucomm.
  ok_code = ucomm.
  CASE ok_code.
    WHEN 'T_DOWN'.
      CALL FUNCTION 'POPUP_TO_INFORM'
        EXPORTING
          titel = 'HELLO'
          txt1  = 'USER COMMAND'
          txt2  = 'TOTAL DOWN'.

    WHEN 'DOWN'.
      CALL FUNCTION 'POPUP_TO_INFORM'
        EXPORTING
          titel = 'HELLO'
          txt1  = 'USER COMMAND'
          txt2  = 'DOWN'.

    WHEN 'UP'.
      CALL FUNCTION 'POPUP_TO_INFORM'
        EXPORTING
          titel = 'HELLO'
          txt1  = 'USER COMMAND'
          txt2  = 'UP'.

    WHEN 'T_UP'.
      CALL FUNCTION 'POPUP_TO_INFORM'
        EXPORTING
          titel = 'HELLO'
          txt1  = 'USER COMMAND'
          txt2  = 'TOTAL UP'.

  ENDCASE.
ENDFORM.                    "command

Hope this helps you.

Thanks & Regards,

Tarun Gambhir

Former Member
0 Kudos

Hi,

If you are aware what a Package means and if you have access to a SAP system, you will find loads of examples related to ALV programming with excellent explanation in the package SLIS. Goto t-code se80 and select "Package" from the dropdown in the object navigator and enter SLIS and press enter.

This package not only explains the ALV reporting using function modules , but also using OOPS. That is how most of us have learnt about ALV and I would suggest you follow the same path.

By any chance you dont have access to the system, go to the SCN's WIKI section and type "ALV" in the search field you will find a plethora of examples.

regards,

Advait