Enterprise Resource
Planning Portal

 

Advertise | Founder BLOG

ERPGenie.COM ABAP Tips and Tricks Database

THE ultimate
ERP website

 

Forums | Vote for us |

Google    Other Search Options

Login

Login to view more content!!!





Lost Password?
No account yet? Register

Registered Access

Poll

What area of ABAP are you interested in?
 
Home arrow Sample Code arrow ABAP Reports arrow ALV Grid Using Function Modules
ALV Grid Using Function Modules PDF Print E-mail
User Rating: / 1
PoorBest 
Written by H Franks   
Saturday, 07 March 2009
This simple example shows how to create an ALV grid report using function modules.
REPORT zhfnk_alvtest.


TYPES:
BEGIN OF t_makt,
matnr LIKE makt-matnr,
maktx LIKE makt-maktx,
END OF t_makt.

DATA:
it_makt TYPE STANDARD TABLE OF t_makt,
wa_makt TYPE t_makt.

******************************************************************'
* Data declarations for the ALV grid
******************************************************************'
DATA: r_grid TYPE REF TO cl_gui_alv_grid.

DATA: alv_fieldcat TYPE slis_t_fieldcat_alv,
wa_alv_fieldcat TYPE slis_fieldcat_alv,
alv_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.

******************************************************************'

START-OF-SELECTION.
PERFORM alv_setup.
PERFORM read_data.
END-OF-SELECTION.
  PERFORM display_alv.

*&---------------------------------------------------------------------*
*& Form read_data
*&---------------------------------------------------------------------*

FORM read_data.
SELECT matnr maktx
FROM makt
INTO TABLE it_makt
WHERE spras = 'E'.
ENDFORM. " read_data

*&---------------------------------------------------------------------*
*& Form alv_setup
*&---------------------------------------------------------------------*
*
* Setup of the columns in the ALV grid
*
*----------------------------------------------------------------------*
FORM alv_setup.

CLEAR wa_alv_fieldcat.
REFRESH alv_fieldcat.

* Matnr field
wa_alv_fieldcat-key = 'X'. "This is a key column
wa_alv_fieldcat-fieldname = 'MATNR'. "Name of the table field
wa_alv_fieldcat-seltext_s = 'Matnr'. "Short column heading
wa_alv_fieldcat-seltext_m = 'Material nr.'. "Medium column heading
wa_alv_fieldcat-seltext_l = 'Material number'. "Long column heading
APPEND wa_alv_fieldcat TO alv_fieldcat.

* Mat text field
wa_alv_fieldcat-key = ''. "This is not a key column
wa_alv_fieldcat-fieldname = 'MAKTX'.
wa_alv_fieldcat-seltext_s = 'Mat. txt'.
wa_alv_fieldcat-seltext_m = 'Material txt'.
wa_alv_fieldcat-seltext_l = 'Material text'.
APPEND wa_alv_fieldcat TO alv_fieldcat.
ENDFORM. " alv_setup
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* Display data in the ALV grid
*
*----------------------------------------------------------------------*
FORM display_alv.

gd_repid = sy-repid.

* Configure layout of screen
alv_layout-colwidth_optimize = 'X'.
alv_layout-zebra = 'X'.
alv_layout-no_min_linesize = 'X'.

* Now call display function
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP_OF_PAGE_SETUP' "Ref to form
is_layout = alv_layout
it_fieldcat = alv_fieldcat
* i_grid_title = text-005
TABLES
t_outtab = it_makt
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
*&---------------------------------------------------------------------*
*& Form top_of_page_setup
*&---------------------------------------------------------------------*
*
* Set-up what to display at the top of the ALV pages
* Note that the link to this form is in the
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' parameter
* i_callback_top_of_page = 'TOP_OF_PAGE' in form display_alv
*----------------------------------------------------------------------*
FORM top_of_page_setup.

DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader.


wa_header-typ = 'H'.
wa_header-info = 'This is a test of the ALV grid'.
APPEND wa_header TO t_header.

CLEAR wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
ENDFORM. " top_of_page_setup
The resulting report:


Related Items:

 
< Prev   Next >

Google Search

Statistics

Contribution Activity
Utilities: 41
Tips and Tricks: 362
Sample Code: 174
Total Contributions: 592

Member Activity
Members: 6795 since 2/1/2007!
New: 2 since yesterday!
Visitors: 2164012
We have 2 guests online

Newest Members

Welcome our newest members:

Google Ads