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: 

simple Grid display

Former Member
0 Kudos

hi experts,

help me how to create simple ALV grid display

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi nitin,

see the below link and it will automatically generates the ALV grid

www.alvrobot.ar.com

reward if its useful

11 REPLIES 11

Former Member
0 Kudos

hi nitin,

see the below link and it will automatically generates the ALV grid

www.alvrobot.ar.com

reward if its useful

former_member404244
Active Contributor
0 Kudos

Hi,

check the below link

http://www.sapdev.co.uk/reporting/alv/alvgrid.htm

Regards,

Nagaraj

Former Member
0 Kudos

Hi,

check out this code.

type-POOLs: slis.

--


ALV Related Variables--

DATA: lt_fcat TYPE slis_t_fieldcat_alv,

lw_fcat TYPE slis_fieldcat_alv,

lv_variant TYPE disvariant,

lv_layout TYPE slis_layout_alv,

lt_sort type slis_t_sortinfo_alv,

lw_sort type slis_sortinfo_alv.

types: begin of ty_vbap,

vbeln type vbap-vbeln,

posnr type vbap-posnr,

zmeng type vbap-zmeng,

umzin type vbap-umzin,

end of ty_vbap.

data: lt_vbap type table of ty_vbap.

start-of-selection.

select vbeln posnr zmeng umzin

from vbap

into table lt_vbap.

sort lt_vbap descending.

clear lw_fcat.

lw_fcat-fieldname = 'VBELN'.

lw_fcat-seltext_l = 'Sales document'.

append lw_fcat to lt_fcat.

clear lw_fcat.

lw_fcat-fieldname = 'POSNR'.

lw_fcat-seltext_l = 'Sales document'.

append lw_fcat to lt_fcat.

clear lw_fcat.

lw_fcat-fieldname = 'ZMENG'.

lw_fcat-seltext_l = 'Sales document'.

lw_fcat-do_sum = 'X'.

append lw_fcat to lt_fcat.

clear lw_fcat.

lw_fcat-fieldname = 'UMZIN'.

lw_fcat-seltext_l = 'Sales document'.

lw_fcat-do_sum = 'X'.

append lw_fcat to lt_fcat.

*lw_sort-spos = 1.

*lw_sort-fieldname = 'VBELN'.

*LW_SORT-Up = 'X'.

*append lw_sort to lt_sort.

clear lw_sort.

lw_sort-spos = 2.

lw_sort-fieldname = 'ZMENG'.

LW_SORT-Up = 'X'.

lw_sort-subtot = 'X'.

append lw_sort to lt_sort.

clear lw_sort.

lw_sort-spos = 3.

lw_sort-fieldname = 'UMZIN'.LW_SORT-Up = 'X'.

lw_sort-subtot = 'X'.

append lw_sort to lt_sort.

lv_layout-totals_text = 'Santosh'.

lv_layout-subtotals_text = 'Thorat'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

  • I_CALLBACK_PROGRAM = ' '

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = lv_layout

IT_FIELDCAT = lt_fcat[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = lt_sort[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • 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 = lt_vbap

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.

regards,

Santosh Thorat

former_member200338
Active Contributor
0 Kudos

Check this website.

http://www.geocities.com/mpioud/Abap_programs.html

Reward points if useful,

Regards,

Niyaz

Former Member
0 Kudos

Have a look at below links. It contains sample code for alv grid.

http://www.erpgenie.com/abap/controls/alvgrid.htm#Complete%20code%20for%20the%20ALV%20grid%20example

http://www.sap-img.com/abap/sample-programs-on-alv-grid.htm

http://sap.niraj.tripod.com/id64.html

Also have a look at below for OO alv grid:

http://help.sap.com/saphelp_erp2004/helpdata/en/0a/b5533cd30911d2b467006094192fe3/frameset.htm

-->REUSE_ALV_GRID _DISPLAY

Heirarchial

Here is a simple example of such an ALV.

code

report zrich_0001.

type-pools: slis.

data: begin of head occurs 0,

matnr type afpo-matnr,

maktx type makt-maktx,

EXPAND type c,

end of head.

data: begin of detail occurs 0,

aufnr type afpo-aufnr,

matnr type afpo-matnr,

werks type aufk-werks,

pwerk type afpo-pwerk,

psmng type afpo-psmng,

end of detail.

start-of-selection.

select * into corresponding fields of table detail

from afpo

inner join aufk

on afpo~aufnr = aufk~aufnr

inner join afko

on afpo~aufnr = afko~aufnr

up to 500 rows

where aufk~auart = 'PP01'.

if not detail[] is initial.

sort detail ascending by matnr.

select distinct * into corresponding fields of table head

from makt

for all entries in detail

where matnr = detail-matnr

and spras = sy-langu.

endif.

perform call_alv.

-


FORM call_alv *

-


........ *

-


form call_alv.

data: gt_fieldcat type slis_t_fieldcat_alv,

gs_keyinfo type slis_keyinfo_alv,

gs_layout type slis_layout_alv.

.

data: ls_fieldcat type slis_fieldcat_alv.

clear gs_keyinfo.

gs_keyinfo-header01 = 'MATNR'.

gs_keyinfo-item01 = 'MATNR'.

clear ls_fieldcat.

ls_fieldcat-fieldname = 'MATNR'.

ls_fieldcat-reptext_ddic = 'Material'.

ls_fieldcat-tabname = 'HEAD'.

ls_fieldcat-outputlen = 18.

append ls_fieldcat to gt_fieldcat.

clear ls_fieldcat.

ls_fieldcat-fieldname = 'MAKTX'.

ls_fieldcat-reptext_ddic = 'Description'.

ls_fieldcat-tabname = 'HEAD'.

ls_fieldcat-outputlen = 40.

append ls_fieldcat to gt_fieldcat.

clear ls_fieldcat.

ls_fieldcat-fieldname = 'AUFNR'.

ls_fieldcat-reptext_ddic = 'Production Order'.

ls_fieldcat-tabname = 'DETAIL'.

ls_fieldcat-outputlen = 12.

append ls_fieldcat to gt_fieldcat.

clear ls_fieldcat.

ls_fieldcat-fieldname = 'WERKS'.

ls_fieldcat-reptext_ddic = 'Production Plant'.

ls_fieldcat-tabname = 'DETAIL'.

ls_fieldcat-outputlen = 4.

append ls_fieldcat to gt_fieldcat.

clear ls_fieldcat.

ls_fieldcat-fieldname = 'PWERK'.

ls_fieldcat-reptext_ddic = 'Planning Plant'.

ls_fieldcat-tabname = 'DETAIL'.

ls_fieldcat-outputlen = 4.

append ls_fieldcat to gt_fieldcat.

clear ls_fieldcat.

ls_fieldcat-fieldname = 'PSMNG'.

ls_fieldcat-reptext_ddic = 'Quantity'.

ls_fieldcat-tabname = 'DETAIL'.

ls_fieldcat-outputlen = 20.

append ls_fieldcat to gt_fieldcat.

gs_layout-expand_fieldname = 'EXPAND'.

call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

exporting

it_fieldcat = gt_fieldcat[]

is_layout = gs_layout

i_tabname_header = 'HEAD'

i_tabname_item = 'DETAIL'

is_keyinfo = gs_keyinfo

tables

t_outtab_header = head

t_outtab_item = detail.

endform.

[/code]

-->

ABAP List Viewer

The common features of report are column alignment, sorting, filtering, subtotals, totals etc. To implement these, a lot of coding and logic is to be put. To avoid that we can use a concept called ABAP List Viewer (ALV).

This helps us to implement all the features mentioned very effectively.

Using ALV, We can have three types of reports:

1. Simple Report

2. Block Report

3. Hierarchical Sequential Report

There are some function modules which will enable to produce the above reports without much effort.

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

1. SIMPLE REPORT.

The important function modules are

a. Reuse_alv_list_display

b. Reuse_alv_fieldcatalog_merge

c. Reuse_alv_events_get

d. Reuse_alv_commentary_write

e. Reuse_alv_grid_display

A. REUSE_ALV_LIST_DISPLAY : This is the function module which prints the data.

The important parameters are :

I. Export :

i. I_callback_program : report id

ii. I_callback_pf_status_set : routine where a user can set his own pf status or change the functionality of the existing pf status

iii. I_callback_user_command : routine where the function codes are handled

iv. I_structure name : name of the dictionary table

v. Is_layout : structure to set the layout of the report

vi. It_fieldcat : internal table with the list of all fields and their attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE

vii. It_events : internal table with a list of all possible events of ALV and their corresponding form names.

II. Tables :

i. t_outtab : internal table with the data to be output

B. REUSE_ALV_FIELDCATALOG_MERGE : This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it.

The Important Parameters are :

I. Export :

i. I_program_name : report id

ii. I_internal_tabname : the internal output table

iii. I_inclname : include or the report name where all the dynamic forms are handled.

II Changing

ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is

declared in the type pool SLIS.

C. REUSE_ALV_EVENTS_GET : Returns table of possible events for a list type

Parameters :

I. Import :

Et_Events : The event table is returned with all possible CALLBACK events

for the specified list type (column 'NAME'). For events to be processed by Callback, their 'FORM' field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field 'FORM' filled and the entry modified using constants from the type pool SALV.

II. Export :

I_List_type :

0 = simple list REUSE_ALV_LIST_DISPLAY

1 = hierarchcal-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY

2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND

3 = hierarchical-sequential block list

REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list.

Parameters :

I. it_list_commentary : internal table with the headings of the type slis_t_listheader.

This internal table has three fields :

Typ : ‘H’ – header, ‘S’ – selection , ‘A’ - action

Key : only when typ is ‘S’.

Info : the text to be printed

E. REUSE_ALV_GRID_DISPLAY : A new function in 4.6 version, to display the results in grid rather than as a preview.

Parameters : same as reuse_alv_list_display

This is an example for simple list.

2. BLOCK REPORT

This is used to have multiple lists continuously.

The important functions used in this report are:

A. REUSE_ALV_BLOCK_LIST_INIT

B. REUSE_ALV_BLOCK_LIST_APPEND

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_BLOCK_LIST_DISPLAY

A. REUSE_ALV_BLOCK_LIST_INIT

Parameters:

I. I_CALLBACK_PROGRAM

II. I_CALLBACK_PF_STATUS_SET

III. I_CALLBACK_USER_COMMAND

This function module is used to set the default gui status etc.

B. REUSE_ALV_BLOCK_LIST_APPEND

Parameters :

Export :

I. is_layout : layout settings for block

II. it_fieldcat : field catalog

III. i_tabname : internal table name with output data

IV. it_events : internal table with all possible events

Tables :

i. t_outtab : internal table with output data.

This function module adds the data to the block.

Repeat this function for all the different blocks to be displayed one after the other.

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

This function module is used for hierarchical sequential blocks.

D. REUSE_ALV_BLOCK_LIST_DISPLAY

Parameters : All the parameters are optional.

This function module display the list with data appended by the above function.

Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.

3. Hierarchical reports :

Hierarchical sequential list output.

The function module is

A. REUSE_ALV_HIERSEQ_LIST_DISPLAY

Parameters:

I. Export:

i. I_CALLBACK_PROGRAM

ii. I_CALLBACK_PF_STATUS_SET

iii. I_CALLBACK_USER_COMMAND

iv. IS_LAYOUT

v. IT_FIELDCAT

vi. IT_EVENTS

vii. i_tabname_header : Name of the internal table in the program containing the

output data of the highest hierarchy level.

viii. i_tabname_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

ix. is_keyinfo : This structure contains the header and item table field

names which link the two tables (shared key).

II. Tables

i. t_outtab_header : Header table with data to be output

ii. t_outtab_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

slis_t_fieldcat_alv : This internal table contains the field attributes. This internal table can be populated automatically by using ‘REUSE_ALV_FIELDCATALOG_MERGE’.

Important Attributes :

A. col_pos : position of the column

B. fieldname : internal fieldname

C. tabname : internal table name

D. ref_fieldname : fieldname (dictionary)

E. ref_tabname : table (dictionary)

F. key(1) : column with key-color

G. icon(1) : icon

H. symbol(1) : symbol

I. checkbox(1) : checkbox

J. just(1) : (R)ight (L)eft (C)ent.

K. do_sum(1) : sum up

L. no_out(1) : (O)blig.(X)no out

M. outputlen : output length

N. seltext_l : long key word

O. seltext_m : middle key word

P. seltext_s : short key word

Q. reptext_ddic : heading (ddic)

R. ddictxt(1) : (S)hort (M)iddle (L)ong

S. datatype : datatype

T. hotspot(1) : hotspot

Simple ALV report

http://www.sapgenie.com/abap/controls/alvgrid.htm

http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox

ALV

1. Please give me general info on ALV.

http://www.sapfans.com/forums/viewtopic.php?t=58286

http://www.sapfans.com/forums/viewtopic.php?t=76490

http://www.sapfans.com/forums/viewtopic.php?t=20591

http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.

2. How do I program double click in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=11601

http://www.sapfans.com/forums/viewtopic.php?t=23010

3. How do I add subtotals (I have problem to add them)...

http://www.sapfans.com/forums/viewtopic.php?t=20386

http://www.sapfans.com/forums/viewtopic.php?t=85191

http://www.sapfans.com/forums/viewtopic.php?t=88401

http://www.sapfans.com/forums/viewtopic.php?t=17335

4. How to add list heading like top-of-page in ABAP lists?

http://www.sapfans.com/forums/viewtopic.php?t=58775

http://www.sapfans.com/forums/viewtopic.php?t=60550

http://www.sapfans.com/forums/viewtopic.php?t=16629

5. How to print page number / total number of pages X/XX in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)

6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.

http://www.sapfans.com/forums/viewtopic.php?t=64320

http://www.sapfans.com/forums/viewtopic.php?t=44477

7. How can I set the cell color in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=52107

8. How do I print a logo/graphics in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=81149

http://www.sapfans.com/forums/viewtopic.php?t=35498

http://www.sapfans.com/forums/viewtopic.php?t=5013

9. How do I create and use input-enabled fields in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=84933

http://www.sapfans.com/forums/viewtopic.php?t=69878

10. How can I use ALV for reports that are going to be run in background?

http://www.sapfans.com/forums/viewtopic.php?t=83243

http://www.sapfans.com/forums/viewtopic.php?t=19224

11. How can I display an icon in ALV? (Common requirement is traffic light icon).

http://www.sapfans.com/forums/viewtopic.php?t=79424

http://www.sapfans.com/forums/viewtopic.php?t=24512

12. How can I display a checkbox in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=88376

http://www.sapfans.com/forums/viewtopic.php?t=40968

http://www.sapfans.com/forums/viewtopic.php?t=6919

Go thru these programs they may help u to try on some hands on

ALV Demo program

BCALV_DEMO_HTML

BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode

BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode

BCALV_GRID_DEMO Simple ALV Control Call Demo Program

BCALV_TREE_DEMO Demo for ALV tree control

BCALV_TREE_SIMPLE_DEMO

BC_ALV_DEMO_HTML_D0100

Reward If useful

former_member386202
Active Contributor
0 Kudos

Hi,

Goto SE38 give BCALV* and press F4 it will display the list of all standard alv programs just refer that n also refer this code

&----


*& Form sub_field_catalog

&----


  • text

----


FORM sub_field_catalog .

it_fieldcat-fieldname = 'BELNR'.

it_fieldcat-seltext_m = text-003.

it_fieldcat-col_pos = 0.

it_fieldcat-outputlen = 10.

it_fieldcat-key = 'X'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'BLART'.

it_fieldcat-seltext_m = text-002.

it_fieldcat-col_pos = 1.

it_fieldcat-outputlen = 2.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'BLDAT'.

it_fieldcat-seltext_m = text-004.

it_fieldcat-col_pos = 2.

it_fieldcat-outputlen = 8.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'BUDAT'.

it_fieldcat-seltext_m = text-005.

it_fieldcat-col_pos = 3.

it_fieldcat-outputlen = 8.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'LIFNR'.

it_fieldcat-seltext_m = text-006.

it_fieldcat-col_pos = 4.

it_fieldcat-outputlen = 10.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'NAME1'.

it_fieldcat-seltext_m = text-007.

it_fieldcat-col_pos = 5.

it_fieldcat-outputlen = 35.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'XREF3'.

it_fieldcat-seltext_m = text-008.

it_fieldcat-col_pos = 6.

it_fieldcat-outputlen = 20.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'ZUONR'.

it_fieldcat-seltext_m = text-009.

it_fieldcat-col_pos = 7.

it_fieldcat-outputlen = 18.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'DMBTR'.

it_fieldcat-seltext_m = text-010.

it_fieldcat-col_pos = 8.

it_fieldcat-outputlen = 13.

it_fieldcat-do_sum = 'X'.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'EBELN'.

it_fieldcat-seltext_m = text-011.

it_fieldcat-col_pos = 9.

it_fieldcat-outputlen = 10.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'TXZ01'.

it_fieldcat-seltext_m = text-012.

it_fieldcat-col_pos = 10.

it_fieldcat-outputlen = 40.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'ERFMG'.

it_fieldcat-seltext_m = text-013.

it_fieldcat-col_pos = 11.

it_fieldcat-outputlen = 13.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'MENGE'.

it_fieldcat-seltext_m = text-014.

it_fieldcat-col_pos = 12.

it_fieldcat-outputlen = 13.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

it_fieldcat-fieldname = 'MBLNR'.

it_fieldcat-seltext_m = text-015.

it_fieldcat-col_pos = 13.

it_fieldcat-outputlen = 10.

APPEND it_fieldcat TO it_fieldcat.

CLEAR it_fieldcat.

ENDFORM. " sub_field_catalog

&----


*& Form sub_display_data

&----


  • text

----


FORM sub_display_data .

*--Local Variables

DATA : lv_repid LIKE sy-repid.

*--Pass the Report name

lv_repid = sy-repid.

wa_layout-colwidth_optimize = 'X'.

IF NOT it_final[] IS INITIAL.

*--Call the function module to display the ALV report

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = lv_repid

is_layout = wa_layout

it_fieldcat = it_fieldcat[]

i_default = 'X'

i_save = 'A'

i_callback_user_command = 'USER_COMMAND'

  • is_variant = wa_variant

it_events = it_events

  • is_print = wa_print

  • it_sort = li_sort

TABLES

t_outtab = it_final

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.

ELSE.

*--No data found for the given selection criteria.

MESSAGE text-016 TYPE 'I'.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " sub_display_data.

Regards,

Prashant

Former Member
0 Kudos

The FM used is: "REUSE_ALV_GRID_DISPLAY"

1. prepare your final internal table with all your data eg: gt_output as shown in the below FM.

2. prepare the field catalog for the structure to be displayed as. Repeat the below code for every output

field to be displayed.

clear gwa_fieldcat.

gwa_fieldcat-fieldname = 'WERKS'.

gwa_fieldcat-tabname = 'GT_OUTPUT'.

gwa_fieldcat-seltext_l = 'PLANT'.

append gwa_fieldcat to gt_fieldcat.

type-pools : slis.

data: gt_fieldcat type slis_t_fieldcat_alv

gwa_fieldcat type slis_fieldcat_alv.

There are other parameters in the FM like Variant, SORt, SAVE, LAYOUT etc. which you can explore further on your own. This is simple ALV GRID DISPLAY.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = sy-repid

it_fieldcat = gt_fieldcat[]

tables

t_outtab = gt_output.

hope this helps.

Former Member
0 Kudos

Hi

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

Former Member
0 Kudos

Hi Nitin,

First of all I would like to explain you the various ways of creating an ALV grid for displayng purposes.

1) It can be prepared using ABAP Objects.

2) It can be done through Standard Predefined Type Pools avaliable to us.

There are few other ways also, but putting down the simplest of all for you.

Out of these two the second option is the easiest one according to me.

I will explain you the steps you need to follow in creating an ALV grid using an Executable program / Report Program.

1) Create a Report Program

2) Define an Intialization event in your Report program to Define all your variables, types and type-pools.

( Here you need to mention your type pool: SLIS.)

3) Now comes your validations if required in your application. This can be done using At Selection-Screen event.

4) Next is your Start-Of-Selection Event where in you populate the data in to your internal table which will be defined in your Initialization event.

5) Here in this event you need to populate the Field-Catalog also for ALV recognition purpose.

6) Atlast comes your End-Of-Selection Event. Here you will call the ALV function module "REUSE_ ALV_GRID_DISPLAY"

Former Member
0 Kudos

Hi,

Please refer to the link below :

http://www.sapdev.co.uk/reporting/alv/alvgrid_basic.htm

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Hi,

see the following example...

report zalvtest.

type-pools: slis.

tables zprod.

data: begin of product occurs 0,

pno like zprod-pno,

pname like zprod-pname,

qty like zprod-qty,

rate like zprod-rate1,

end of product.

data: fldhead type slis_t_fieldcat_alv,

fldwa type slis_fieldcat_alv.

product-pno = 10.

product-pname = 'xxx'.

product-qty = 3.

product-rate = 100.

append product to product.

product-pno = 20.

product-pname = 'yyy'.

product-qty = 3.

product-rate = 10.

append product to product.

fldwa-fieldname = 'PNO'.

fldwa-seltext_l = 'Prod No'.

append fldwa to fldhead.

clear fldwa.

fldwa-fieldname = 'PNAME'.

fldwa-seltext_l = 'Prod Name'.

append fldwa to fldhead.

clear fldwa.

fldwa-fieldname = 'QTY'.

fldwa-seltext_l = 'Qty'.

append fldwa to fldhead.

clear fldwa.

fldwa-fieldname = 'RATE'.

fldwa-seltext_l = 'Rate'.

append fldwa to fldhead.

clear fldwa.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = sy-repid

it_fieldcat = fldhead

tables

t_outtab = product

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.

Regards,

Shanthi. P

      • Reward points if useful ***