Application Development and Automation 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: 
Read only

ALV Grid

Former Member
0 Likes
934

Hi Friends,

I have data in final table,

How to pass the data to ALV grid plz code with declaration or any sample program.

Thanx in advance,

Venu.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
911

hi venu,

If it helpful reward points.

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

Regards

Alfred

Hi Friends,

I have data in final table,

How to pass the data to ALV grid plz code with declaration or any sample program.

Thanx in advance,

Venu.

8 REPLIES 8
Read only

anversha_s
Active Contributor
0 Likes
911

hi,

&----


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

<b>tables

t_outtab = it_ekko</b>

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.

<b>select ebeln ebelp statu aedat matnr menge meins netpr peinh

up to 10 rows

from ekpo

into table it_ekko.</b>endform. " DATA_RETRIEVAL

rgds

anver

if hlped mark points

Message was edited by: Anversha s

Read only

Former Member
0 Likes
912

hi venu,

If it helpful reward points.

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

Regards

Alfred

Read only

Former Member
0 Likes
911

After getting data to final internaltable u have to decalre field catlog.

U can follow the following example.

report z_example.

TYPE-POOLS slis.

TABLES : qals.

DATA : BEGIN OF t_out OCCURS 0,

matnr LIKE qals-matnr, "MATERIAL

werk LIKE qals-werk, "PLANT

art like qals-art, "Inspaction Lot Type

objnr like qals-objnr, "Object Number

END OF t_out.

DATA : i_fieldcat TYPE slis_t_fieldcat_alv,

i_layout TYPE slis_layout_alv,

gs_layout TYPE lvc_s_layo,

g_repid TYPE sy-repid,

ls_fieldcat TYPE slis_fieldcat_alv.

SELECT-OPTIONS:s_prflos FOR qals-prueflos.

INITIALIZATION.

g_repid = sy-repid.

i_layout-zebra = 'X'.

i_layout-colwidth_optimize = 'X'.

START-OF-SELECTION.

PERFORM fetch_data.

END-OF-SELECTION.

PERFORM fill_fieldcat.

PERFORM display_alv.

FORM fetch_data .

SELECT matnr werk art objnr

FROM qals

INTO TABLE t_out

WHERE prueflos IN s_prflos.

ENDFORM. " FETCH_DATA

FORM fill_fieldcat .

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = g_repid

i_internal_tabname = 'T_OUT'

i_inclname = g_repid

CHANGING

ct_fieldcat = i_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

ENDFORM. " FILL_FIELDCAT

FORM display_alv .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid

is_layout = i_layout

it_fieldcat = i_fieldcat[]

TABLES

t_outtab = t_out

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDFORM. " display_alv

Regards

Read only

baskaran00
Active Participant
0 Likes
911

Hi Venu,

You can try with the following code.

Here if u want to add field catalog u can add in the FCAT.

data : itab like table of MARA with header line.

data : FCAT TYPE slis_t_fieldcat_alv,

WA TYPE slis_fieldcat_alv.

WA-seltext_l = 'Material No'.

WA-FIELDNAME = 'MATNR'.

WA-outputlen = '20'.

APPEND WA TO FCAT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = sy-repid

IT_FIELDCAT = FCAT

TABLES

T_OUTTAB = itab.

---Router

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
911
Read only

anversha_s
Active Contributor
0 Likes
911

hi venu,

pls chk these links also.

ALV

1. 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

rgds

anver

pls mark hlpful asnwers

Message was edited by: Anversha s

Read only

Former Member
0 Likes
911

Hi

this example will help u.

TABLES: SPFLI.

TYPE-POOLS: SLIS.

DATA: BEGIN OF TAB OCCURS 0,

CARRID LIKE SPFLI-CARRID,

CONNID LIKE SPFLI-CONNID,

CITYFROM LIKE SPFLI-CITYFROM,

CITYTO LIKE SPFLI-CITYFROM,

END OF TAB.

DATA: NAME1 TYPE SY-REPID,

NAME2 TYPE SY-DYNNR,

REPID TYPE SY-REPID.

DATA: I_FCAT TYPE TABLE OF SLIS_FIELDCAT_ALV..

PARAMETERS: P_CARRID LIKE SPFLI-CARRID,

P_CONNID LIKE SPFLI-CONNID,

CITYFROM LIKE SPFLI-CITYFROM.

START-OF-SELECTION.

REPID = SY-REPID.

SELECT CARRID CONNID CITYFROM CITYTO FROM SPFLI

INTO TABLE TAB

WHERE CARRID = P_CARRID AND CONNID = P_CONNID.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = REPID

I_INTERNAL_TABNAME = 'TAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

ct_fieldcat = I_FCAT[]

  • 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.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = REPID

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

IT_FIELDCAT = I_FCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_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

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = TAB

  • 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.

Read only

Former Member
0 Likes
911

hi this example will help u.

TABLES: SPFLI.

TYPE-POOLS: SLIS.

DATA: BEGIN OF TAB OCCURS 0,

CARRID LIKE SPFLI-CARRID,

CONNID LIKE SPFLI-CONNID,

CITYFROM LIKE SPFLI-CITYFROM,

CITYTO LIKE SPFLI-CITYFROM,

END OF TAB.

DATA: NAME1 TYPE SY-REPID,

NAME2 TYPE SY-DYNNR,

REPID TYPE SY-REPID.

DATA: I_FCAT TYPE TABLE OF SLIS_FIELDCAT_ALV..

PARAMETERS: P_CARRID LIKE SPFLI-CARRID,

P_CONNID LIKE SPFLI-CONNID,

CITYFROM LIKE SPFLI-CITYFROM.

START-OF-SELECTION.

REPID = SY-REPID.

SELECT CARRID CONNID CITYFROM CITYTO FROM SPFLI

INTO TABLE TAB

WHERE CARRID = P_CARRID AND CONNID = P_CONNID.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = REPID

I_INTERNAL_TABNAME = 'TAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

ct_fieldcat = I_FCAT[]

  • 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.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = REPID

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

IT_FIELDCAT = I_FCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_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

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = TAB

  • 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.