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: 

i need simple example for alv grid

laxman_sankhla3
Participant
0 Kudos
404

hi

i need code for simple example for alv grid.

thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
105

HI,

see this example.

REPORT ZBHALV_LIST_GRID2.

TABLES:MARA.

DATA:BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

ERSDA LIKE MARA-ERSDA,

ERNAM LIKE MARA-ERNAM,

MBRSH LIKE MARA-MBRSH,

END OF ITAB.

TYPE-POOLS:SLIS.

DATA:FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

DATA:EVE TYPE SLIS_T_EVENT WITH HEADER LINE.

DATA:HEAD TYPE SLIS_T_LISTHEADER WITH HEADER LINE.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_INTERNAL_TABNAME = 'ITAB'

  • I_STRUCTURE_NAME = 'ITAB'

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = SY-REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = FIELDCAT1.

EVE-NAME = 'TOP_OF_PAGE'.

EVE-FORM = 'HEADER'.

APPEND EVE.

EVE-NAME = 'END_OF_LIST'.

EVE-FORM = 'LISTEND'.

APPEND EVE.

EVE-NAME = 'TOP_OF_LIST'.

EVE-FORM = 'LISTTOP'.

APPEND EVE.

SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE ITAB UP TO 20 ROWS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

  • I_STRUCTURE_NAME = 'ITAB'

IT_FIELDCAT = FIELDCAT1

I_DEFAULT = 'X'

I_SAVE = 'A'

IT_EVENTS = EVE[]

TABLES

T_OUTTAB = ITAB.

FORM HEADER.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'GENERAL MATERIAL DATA'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[].

ENDFORM.

FORM LISTEND.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'END OF THE LIST'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[].

ENDFORM.

FORM LISTTOP.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'TOP OF THE LIST'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[].

ENDFORM.

**********************************************************

this is simple alv grid with out fieldcat

<b>REPORT ZBHALV_LIST_GRID1.

TABLES:MARA.

DATA ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT * FROM MARA INTO TABLE ITAB UP TO 25 ROWS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_STRUCTURE_NAME = 'MARA'

I_GRID_TITLE = 'GENERAL MATERIAL DATA'

TABLES

T_OUTTAB = ITAB.</b>

reward if helpful

rgds,

bharat.

8 REPLIES 8

Former Member
0 Kudos
106

HI,

see this example.

REPORT ZBHALV_LIST_GRID2.

TABLES:MARA.

DATA:BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

ERSDA LIKE MARA-ERSDA,

ERNAM LIKE MARA-ERNAM,

MBRSH LIKE MARA-MBRSH,

END OF ITAB.

TYPE-POOLS:SLIS.

DATA:FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

DATA:EVE TYPE SLIS_T_EVENT WITH HEADER LINE.

DATA:HEAD TYPE SLIS_T_LISTHEADER WITH HEADER LINE.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_INTERNAL_TABNAME = 'ITAB'

  • I_STRUCTURE_NAME = 'ITAB'

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = SY-REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = FIELDCAT1.

EVE-NAME = 'TOP_OF_PAGE'.

EVE-FORM = 'HEADER'.

APPEND EVE.

EVE-NAME = 'END_OF_LIST'.

EVE-FORM = 'LISTEND'.

APPEND EVE.

EVE-NAME = 'TOP_OF_LIST'.

EVE-FORM = 'LISTTOP'.

APPEND EVE.

SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE ITAB UP TO 20 ROWS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

  • I_STRUCTURE_NAME = 'ITAB'

IT_FIELDCAT = FIELDCAT1

I_DEFAULT = 'X'

I_SAVE = 'A'

IT_EVENTS = EVE[]

TABLES

T_OUTTAB = ITAB.

FORM HEADER.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'GENERAL MATERIAL DATA'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[].

ENDFORM.

FORM LISTEND.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'END OF THE LIST'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[].

ENDFORM.

FORM LISTTOP.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'TOP OF THE LIST'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[].

ENDFORM.

**********************************************************

this is simple alv grid with out fieldcat

<b>REPORT ZBHALV_LIST_GRID1.

TABLES:MARA.

DATA ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT * FROM MARA INTO TABLE ITAB UP TO 25 ROWS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_STRUCTURE_NAME = 'MARA'

I_GRID_TITLE = 'GENERAL MATERIAL DATA'

TABLES

T_OUTTAB = ITAB.</b>

reward if helpful

rgds,

bharat.

0 Kudos
105

hi bharat,

this is report with most of the functionality.

report zus_alv_demo_grid .

tables: ekko.

type-pools: slis.

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,

line_color(4) type c, "Used to store row color

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.

  • Data declaration for EVENT and PRINT PARAMETER.

data: gt_events type slis_t_event,

gd_prntparams type slis_print_alv.

  • data declaration for sorting.

data : it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.

data : i_list_comments type slis_t_listheader.

start-of-selection.

perform data_retrieval.

  • perform user_command.

perform build_fieldcatalog.

perform build_layout.

perform build_events.

perform build_print_params.

perform build_sortcat.

perform display_alv_report.

end-of-selection.

*TOP-OF-PAGE.

  • PERFORM top-of-page.

end-of-page.

*&----


*& Form build_fieldcatalog

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form build_fieldcatalog.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = '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.

fieldcatalog-do_sum = 'X'.

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

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • Set layout field for row attributes(i.e. color)

gd_layout-info_fieldname = 'LINE_COLOR'.

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for

*when double

  • "click(press f2)*

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

endform. " build_layout

*&----


*& Form data_retrieval

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form data_retrieval.

data: ld_color(1) type c.

select ebeln ebelp statu aedat matnr menge meins netpr

peinh from ekpo into table it_ekko.

*Populate field with color attributes

loop at it_ekko into wa_ekko.

  • Populate color variable with colour properties

  • Char 1 = C (This is a color property)

  • Char 2 = 3 (Color codes: 1 - 7)

  • Char 3 = Intensified on/off ( 1 or 0 )

  • Char 4 = Inverse display on/off ( 1 or 0 )

  • i.e. wa_ekko-line_color = 'C410'

ld_color = ld_color + 1.

  • Only 7 colours so need to reset color value

if ld_color = 8.

ld_color = 1.

endif.

concatenate 'C' ld_color '10' into wa_ekko-line_color.

  • wa_ekko-line_color = 'C410'.

modify it_ekko from wa_ekko.

endloop.

endform. " data_retrieval

*&----


*& Form display_alv_report

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

is_layout = gd_layout

i_callback_top_of_page = 'TOP-OF-PAGE'

i_callback_user_command = 'USER_COMMAND'

i_callback_pf_status_set = 'SET_PF_STATUS'

it_event = gt_events

is_print = gd_prntparams

it_fieldcat = fieldcatalog[]

it_sort = it_sortcat

i_save = 'X'

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 user_command

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


*&----


*& Form top-of-page

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form top-of-page.

*ALV Header declarations

data: t_header type slis_t_listheader,

wa_header type slis_listheader,

t_line like wa_header-info,

ld_lines type i,

ld_linesc(10) type c.

  • Title

wa_header-typ = 'H'.

wa_header-info = 'EKKO Table Report'.

append wa_header to t_header.

clear wa_header.

  • Date

wa_header-typ = 'S'.

wa_header-key = 'Date: '.

concatenate sy-datum+6(2) '.'

sy-datum+4(2) '.'

sy-datum(4) into wa_header-info."todays date

append wa_header to t_header.

clear: wa_header.

  • Total No. of Records Selected

describe table it_ekko lines ld_lines.

ld_linesc = ld_lines.

concatenate 'Total No. of Records Selected: ' ld_linesc

into t_line separated by space.

wa_header-typ = 'A'.

wa_header-info = t_line.

append wa_header to t_header.

clear: wa_header, t_line.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = t_header

i_logo = 'GANESH_LOGO'.

endform. " top-of-page

----


  • FORM user_command *

----


  • ........ *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case r_ucomm.

when '&IC1'.

if rs_selfield-fieldname = 'EBELN'.

read table it_ekko into wa_ekko index rs_selfield-tabindex.

set parameter id 'BES' field wa_ekko-ebeln.

call transaction 'ME23N' and skip first screen.

endif.

when 'ULHAS'.

if rs_selfield-fieldname = 'EBELN'.

read table it_ekko into wa_ekko index rs_selfield-tabindex.

set parameter id 'BES' field wa_ekko-ebeln.

call transaction 'ME23N' and skip first screen.

endif.

endcase.

endform.

----


  • FORM set_pf_status *

----


  • ........ *

----


  • --> RT_EXTAB *

----


form set_pf_status using rt_extab type slis_t_extab.

set pf-status 'ZNEWSTATUS'.

endform.

&----


*& Form build_events

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_events.

data: ls_event type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = gt_events[]

  • 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 gt_events with key name = slis_ev_end_of_page

into ls_event.

if sy-subrc = 0.

move 'END_OF_PAGE' to ls_event-form.

append ls_event to gt_events.

endif.

read table gt_events with key name = slis_ev_end_of_list

into ls_event.

if sy-subrc = 0.

move 'END_OF_LIST' to ls_event-form.

append ls_event to gt_events.

endif.

endform. " build_events

&----


*& Form build_print_params

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_print_params.

gd_prntparams-reserve_lines = '3'. "Lines reserved for footer

gd_prntparams-no_coverpage = 'X'.

endform. " build_print_params

----


  • FORM END_OF_PAGE *

----


  • ........ *

----


form end_of_page.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

write: sy-uline(50).

skip. write:/40 'Page:', sy-pagno .

endform.

----


  • FORM END_OF_LIST *

----


  • ........ *

----


form end_of_list.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

skip. write:/40 'Page:', sy-pagno .

endform.

&----


*& Form build_sortcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_sortcat.

wa_sort-spos = 1.

wa_sort-fieldname = 'EBELN'.

append wa_sort to it_sortcat.

wa_sort-spos = 2.

wa_sort-fieldname = 'EBELP'.

append wa_sort to it_sortcat.

endform. " build_sortcat

Rewards if helpfull

regards

vijay dwivedi

Former Member
0 Kudos
105

hi,

there are lots of sample programs, search for BCALV and you will get a list.

Regards

Subbu

Former Member
0 Kudos
105

hi,

REPORT ZZABCTEST2.

TABLES: MARA,

MAKT.

TYPE-POOLS: SLIS.

TYPES: BEGIN OF TY_MARA,

MATNR TYPE MATNR,

MTART TYPE MTART,

MATKL TYPE MATKL,

BRGEW TYPE BRGEW,

END OF TY_MARA,

BEGIN OF TY_MAKT,

MATNR TYPE MATNR,

SPRAS TYPE SPRAS,

MAKTX TYPE MAKTX,

END OF TY_MAKT,

BEGIN OF TY_FINAL,

MATNR TYPE MATNR,

MAKTX TYPE MAKTX,

MTART TYPE MTART,

MATKL TYPE MATKL,

BRGEW TYPE BRGEW,

TOTBW TYPE BRGEW,

END OF TY_FINAL.

CONSTANTS: C_X VALUE 'X',

C_H VALUE 'H',

C_S VALUE 'S'.

DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA INITIAL SIZE 0,

IT_MAKT TYPE STANDARD TABLE OF TY_MAKT INITIAL SIZE 0,

IT_FINAL TYPE STANDARD TABLE OF TY_FINAL INITIAL SIZE 0,

WA_MARA TYPE TY_MARA,

WA_MAKT TYPE TY_MAKT,

WA_FINAL TYPE TY_FINAL,

G_TOTAL TYPE BRGEW,

G_SNO TYPE I.

  • DECLARATION FOR ALV.

DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV,

LAYOUT TYPE SLIS_LAYOUT_ALV,

TOPPAGE TYPE SLIS_T_LISTHEADER,

ALVSORT TYPE SLIS_T_SORTINFO_ALV.

                    • INITIALIZATION BLOCK ****************************

INITIALIZATION.

                          • SELECTION SCREEN *****************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_MAT FOR MARA-MATNR.

SELECTION-SCREEN END OF BLOCK B1.

                      • START OF SELECTION ******************************

START-OF-SELECTION.

PERFORM DATA_RETRIVAL.

IF IT_FINAL[] IS NOT INITIAL.

PERFORM BUILD_FIELDCAT.

PERFORM BUILD_LAYOUT.

PERFORM BUILD_HEADER.

PERFORM ALV_SORT.

PERFORM DISPLAY_OUTPUT.

ENDIF.

***********END OF SEL;ECTION ********************************

END-OF-SELECTION.

CLEAR: IT_MARA,

IT_MAKT,

IT_FINAL.

&----


*& Form DATA_RETRIVAL

&----


FORM DATA_RETRIVAL .

SELECT MATNR MTART MATKL BRGEW

FROM MARA

INTO TABLE IT_MARA

WHERE MATNR IN S_MAT.

IF IT_MARA[] IS NOT INITIAL.

SELECT MATNR SPRAS MAKTX

FROM MAKT

INTO TABLE IT_MAKT

FOR ALL ENTRIES IN IT_MARA

WHERE MATNR EQ IT_MARA-MATNR

  • AND SPRAS BETWEEN L_SPRAS AND H_SPRAS.

AND SPRAS EQ SY-LANGU.

ENDIF.

CLEAR G_SNO.

CLEAR G_TOTAL.

LOOP AT IT_MARA INTO WA_MARA WHERE MATNR IS NOT INITIAL.

READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MARA-MATNR BINARY SEARCH.

WA_FINAL-MATNR = WA_MARA-MATNR.

WA_FINAL-MAKTX = WA_MAKT-MAKTX.

WA_FINAL-MTART = WA_MARA-MTART.

WA_FINAL-MATKL = WA_MARA-MATKL.

WA_FINAL-BRGEW = WA_MARA-BRGEW.

  • ON CHANGE OF WA_FINAL-MTART.

WA_FINAL-TOTBW = WA_FINAL-BRGEW.

  • ENDON.

  • ON CHANGE OF WA_FINAL-MTART.

  • G_TOTAL = WA_FINAL-BRGEW + G_TOTAL.

  • WA_FINAL-BRGEW = G_TOTAL.

  • ENDON.

APPEND WA_FINAL TO IT_FINAL.

CLEAR WA_FINAL.

ENDLOOP.

SORT IT_FINAL BY MTART.

ENDFORM. " DATA_RETRIVAL

&----


*& Form BUILD_FIELDCAT

&----


FORM BUILD_FIELDCAT .

DATA: L_POS TYPE I,

WA_FLDCAT TYPE SLIS_FIELDCAT_ALV.

WA_FLDCAT-FIELDNAME = 'MATNR'.

WA_FLDCAT-TABNAME = 'IT_FINAL'.

WA_FLDCAT-SELTEXT_M = TEXT-002.

WA_FLDCAT-OUTPUTLEN = 10.

WA_FLDCAT-KEY = C_X.

WA_FLDCAT-COL_POS = L_POS.

APPEND WA_FLDCAT TO FLDCAT.

CLEAR WA_FLDCAT.

L_POS = L_POS + 1.

WA_FLDCAT-FIELDNAME = 'MAKTX'.

WA_FLDCAT-TABNAME = 'IT_FINAL'.

WA_FLDCAT-SELTEXT_M = TEXT-003.

WA_FLDCAT-OUTPUTLEN = 40.

  • WA_FLDCAT-KEY = C_X.

  • WA_FLDCAT-EMPHASIZE = C_X.

WA_FLDCAT-COL_POS = L_POS.

APPEND WA_FLDCAT TO FLDCAT.

CLEAR WA_FLDCAT.

L_POS = L_POS + 1.

WA_FLDCAT-FIELDNAME = 'MTART'.

WA_FLDCAT-TABNAME = 'IT_FINAL'.

WA_FLDCAT-SELTEXT_M = TEXT-004.

WA_FLDCAT-OUTPUTLEN = 4.

  • WA_FLDCAT-KEY = C_X.

WA_FLDCAT-COL_POS = L_POS.

APPEND WA_FLDCAT TO FLDCAT.

CLEAR WA_FLDCAT.

L_POS = L_POS + 1.

WA_FLDCAT-FIELDNAME = 'MATKL'.

WA_FLDCAT-TABNAME = 'IT_FINAL'.

WA_FLDCAT-SELTEXT_M = TEXT-005.

  • WA_FLDCAT-KEY = C_X.

WA_FLDCAT-OUTPUTLEN = 9.

WA_FLDCAT-COL_POS = L_POS.

APPEND WA_FLDCAT TO FLDCAT.

CLEAR WA_FLDCAT.

L_POS = L_POS + 1.

WA_FLDCAT-FIELDNAME = 'TOTBW'.

WA_FLDCAT-TABNAME = 'IT_FINAL'.

WA_FLDCAT-SELTEXT_M = TEXT-005.

  • WA_FLDCAT-KEY = C_X.

WA_FLDCAT-OUTPUTLEN = 13.

WA_FLDCAT-DO_SUM = 'X'.

WA_FLDCAT-COL_POS = L_POS.

APPEND WA_FLDCAT TO FLDCAT.

CLEAR WA_FLDCAT.

L_POS = L_POS + 1.

ENDFORM. " BUILD_FIELDCAT

&----


*& Form BUILD_LAYOUT

&----


FORM BUILD_LAYOUT .

LAYOUT-ZEBRA = C_X.

LAYOUT-COLWIDTH_OPTIMIZE = C_X.

ENDFORM. " BUILD_LAYOUT

&----


*& Form BUILD_HEADER

&----


FORM BUILD_HEADER .

DATA: L_TP TYPE SLIS_LISTHEADER.

L_TP-TYP = C_H.

L_TP-INFO = TEXT-006.

APPEND L_TP TO TOPPAGE.

L_TP-TYP = C_S.

L_TP-INFO = TEXT-007.

APPEND L_TP TO TOPPAGE.

ENDFORM. " BUILD_HEADER

&----


*& Form BUILD_COMMENTRY

&----


FORM BUILD_COMMENTRY .

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = TOPPAGE.

ENDFORM.

&----


*& Form DISPLAY_OUTPUT

&----


FORM DISPLAY_OUTPUT .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_TOP_OF_PAGE = 'BUILD_COMMENTRY'

IT_SORT = ALVSORT

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FLDCAT[]

I_SAVE = C_X

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.

ENDFORM. " DISPLAY_OUTPUT

&----


*& Form ALV_SORT

&----


FORM ALV_SORT .

DATA: WA_SORT TYPE SLIS_SORTINFO_ALV.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'MTART'.

WA_SORT-SPOS = C_X.

WA_SORT-SUBTOT = C_X.

WA_SORT-UP = C_X.

APPEND WA_SORT TO ALVSORT.

CLEAR WA_SORT.

ENDFORM.

Rewards points if it is useful.

Former Member
0 Kudos
105

please check with the following code...

&----


*& Report ZTESTDEMO_INTERACTIVE_LIST_2

*&

&----


*&

*&

&----


REPORT ZTESTDEMO_INTERACTIVE_LIST_2.

TABLES: MARA,MARC,MARD.

  • internal table itab_mara 3 fields matnr, ernam,mtart

DATA: BEGIN OF ITAB_MARA OCCURS 0,

MATNR LIKE MARA-MATNR, " material number

ERNAM LIKE MARA-ERNAM, " name of person who create

MTART LIKE MARA-MTART, " Material Type

END OF ITAB_MARA.

  • internal table itab_marc 3 fields matnr, werks,lvorm

DATA: BEGIN OF ITAB_MARC OCCURS 0,

MATNR LIKE MARC-MATNR,

WERKS LIKE MARC-WERKS, " Plant

LVORM LIKE MARC-LVORM, " Flag Material for Deletion at Plant Level

END OF ITAB_MARC.

  • internal table itab_mard 2 fields

DATA: BEGIN OF ITAB_MARD OCCURS 0,

MATNR LIKE MARD-MATNR,

LGORT LIKE MARD-LGORT, " Storage Location

END OF ITAB_MARD.

SELECT-OPTIONS: S_MTART FOR MARA-MTART.

INITIALIZATION.

S_MTART-LOW = 'HALB'.

S_MTART-HIGH = 'HAWA'.

S_MTART-OPTION = 'BT'.

APPEND S_MTART.

START-OF-SELECTION.

SELECT MATNR ERNAM MTART FROM MARA INTO TABLE ITAB_MARA WHERE MTART IN

S_MTART.

PERFORM DISPLAY.

TOP-OF-PAGE.

WRITE:/2(15) 'MATERIAL NO',20(20) 'CREATED BY',45(15) 'MATERIAL TYPE'.

FORM DISPLAY.

LOOP AT ITAB_MARA.

WRITE:/ ITAB_MARA-MATNR UNDER 'MATERIAL NO' HOTSPOT ON,ITAB_MARA-ERNAM

UNDER 'CREATED BY',ITAB_MARA-MTART UNDER 'MATERIAL TYPE'.

HIDE: ITAB_MARA-MATNR.

ENDLOOP.

ENDFORM.

AT LINE-SELECTION.

CASE SY-LSIND.

WHEN 1.

SELECT MATNR WERKS LVORM FROM MARC INTO TABLE ITAB_MARC WHERE MATNR =

ITAB_MARA-MATNR.

PERFORM DISPLAY1.

WHEN 2.

SELECT MATNR LGORT FROM MARD INTO TABLE ITAB_MARD WHERE MATNR =

ITAB_MARC-MATNR.

PERFORM DISPLAY2.

when 3.

sy-lsind = 0.

ENDCASE.

FORM DISPLAY1.

LOOP AT ITAB_MARC.

WRITE:/ ITAB_MARC-MATNR HOTSPOT ON, ITAB_MARC-WERKS,ITAB_MARC-LVORM.

HIDE: ITAB_MARC-MATNR.

ENDLOOP.

WRITE:/ SY-LSIND.

ENDFORM.

FORM DISPLAY2.

LOOP AT ITAB_MARD.

WRITE:/ ITAB_MARD-MATNR, ITAB_MARD-LGORT.

ENDLOOP.

WRITE:/ SY-LSIND.

ENDFORM.

Former Member
0 Kudos
105

Hi

Hi

chk this sample programs

report zkiran .

  • Global ALV Data Declarations

type-pools: slis.

  • Internal Tables

data: begin of ialv occurs 0,

test1(10) type c,

test2(10) type c,

end of ialv.

data: fieldcat type slis_t_fieldcat_alv.

start-of-selection.

perform get_data.

perform call_alv.

*********************************************************************

  • Form GET_DATA

*********************************************************************

form get_data.

ialv-test1 = 'ABC'.

ialv-test2 = 'DEF'.

append ialv.

ialv-test1 = 'GHI'.

ialv-test2 = 'JKL'.

append ialv.

ialv-test1 = '123'.

ialv-test2 = '456'.

append ialv.

endform. "GET_DATA

************************************************************************

  • CALL_ALV

************************************************************************

form call_alv.

perform build_field_catalog.

  • Call ABAP List Viewer (ALV)

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

it_fieldcat = fieldcat

tables

t_outtab = ialv.

endform. "CALL_ALV

************************************************************************

  • BUILD_FIELD_CATALOG

************************************************************************

form build_field_catalog.

clear: fieldcat. refresh: fieldcat.

data: tmp_fc type slis_fieldcat_alv.

tmp_fc-reptext_ddic = 'Test1'.

tmp_fc-fieldname = 'TEST1'.

tmp_fc-tabname = 'IALV'.

tmp_fc-outputlen = '10'.

append tmp_fc to fieldcat.

tmp_fc-reptext_ddic = 'Test2'.

tmp_fc-fieldname = 'TEST2'.

tmp_fc-tabname = 'IALV'.

tmp_fc-outputlen = '10'.

append tmp_fc to fieldcat.

endform. "BUILD_FIELD_CATALOG

reward points to all helpful answers

kiran.M

Former Member
0 Kudos
105

Hi,

I have attached a very simple ALV code. This report takes 100 records of only two fields MATNR (Material Number) and MTART (Material Type) from table MARA. This will surely help u to understand about ALV Report.

Report ZRS_SIMPLE_ALV .

tables mara.

type-pools slis.

data: itab like mara occurs 0 with header line,

it_fc type slis_t_fieldcat_alv,

wa_fc type slis_fieldcat_alv.

start-of-selection.

select * from mara into table itab up to 100 rows.

end-of-selection.

clear wa_fc.

wa_fc-col_pos = 1.

wa_fc-tabname = 'ITAB'.

wa_fc-fieldname = 'MATNR'.

wa_fc-reptext_ddic = 'Material'.

wa_fc-outputlen = 20.

wa_fc-edit = 'X'.

append wa_fc to it_fc.

clear wa_fc.

wa_fc-col_pos = 2.

wa_fc-tabname = 'ITAB'.

wa_fc-fieldname = 'MTART'.

wa_fc-reptext_ddic = 'Mattype'.

wa_fc-outputlen = 10.

wa_fc-edit = 'X'.

append wa_fc to it_fc.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = sy-repid

it_fieldcat = it_fc

tables

t_outtab = itab

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.

<b>Please reward points for useful answers.</b>

Former Member
0 Kudos
105

&----


*& Report ZALV_FIELD_GRID1

*&

&----


*&

*&

&----


REPORT ZALV_FIELD_GRID1

NO STANDARD PAGE HEADING.

TABLES MARA.

type-pools :slis.

TYPES : BEGIN OF TMARA ,

MATNR LIKE MARA-MATNR,

MEINS LIKE MARA-MEINS,

ERSDA LIKE MARA-ERSDA,

color(4) type c,

SEL type c,

LIGHT TYPE C,

END OF TMARA.

TYPES: BEGIN OF TMAKT,

MATNR LIKE MAKT-MATNR,

MAKTX LIKE MAKT-MAKTX,

MAKTG LIKE MAKT-MAKTG,

SEL TYPE C,

COLOR(4),

END OF TMAKT.

DATA: ITAB TYPE TMARA OCCURS 0 WITH HEADER LINE,

ITAB1 TYPE TMAKT OCCURS 0 WITH HEADER LINE,

wa_fieldcat type slis_fieldcat_alv,

fieldcat type slis_fieldcat_alv occurs 0,

i_layout type slis_layout_alv,

WA_LISTHEADER TYPE SLIS_LISTHEADER,

i_LISTHEADER TYPE SLIS_LISTHEADER OCCURS 0,

V_EVENTS TYPE SLIS_T_EVENT ,

WA_EVENT TYPE SLIS_ALV_EVENT,

I_TITLE_MARA TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED',

I_TITLE_MAKT TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED',

SORT TYPE slis_t_sortinfo_alv WITH HEADER LINE,

PRINT_CONT type slis_print_alv.

*----


  • SELECTION SCREE

*----


selection-screen begin of block screen1 with frame title TEXT-001.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT /32(35) COMM1.

SELECTION-SCREEN ULINE /27(35).

SELECTION-SCREEN SKIP.

SELECT-OPTIONS MATNR FOR MARA-MATNR.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN ULINE.

SELECTION-SCREEN COMMENT /30(50) COMM2.

SELECTION-SCREEN ULINE /27(40).

SELECTION-SCREEN SKIP.

SELECT-OPTIONS ERSDA FOR MARA-ERSDA.

SELECTION-SCREEN SKIP.

selection-screen end of block screen1.

*----


  • INITIALIZATION

*----


INITIALIZATION.

MATNR-low = '23'.

MATNR-high = '1000'.

MATNR-option = 'BT'.

MATNR-sign = 'I'.

APPEND MATNR.

ERSDA-low = '20030124'.

ERSDA-high = '20050302' .

APPEND ERSDA.

PERFORM FILLFIELD.

PERFORM FILLLAYOUT.

PERFORM build_print_params.

PERFORM FILL_SORT.

PERFORM EVENT_CALL.

PERFORM POPULATE_EVENT.

*----


  • SELECTION-SCREEN OUTPUT

*----


AT SELECTION-SCREEN OUTPUT.

comm1 ='SELECT MATERIAL NUMBER RANGE'.

comm2 ='SELECT MATERIAL CREATION DATE'.

*----


  • START-OF-SELECTION

*----


START-OF-SELECTION.

PERFORM READDATA.

PERFORM POPDATA.

&----


*& Form READDATA

&----


  • text

----


FORM READDATA .

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = MATNR-LOW

IMPORTING

OUTPUT = MATNR-LOW.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = MATNR-HIGH

IMPORTING

OUTPUT = MATNR-HIGH.

SELECT MATNR

ERSDA

MEINS

FROM MARA

INTO CORRESPONDING FIELDS OF

TABLE ITAB

WHERE MATNR IN MATNR AND ERSDA IN ERSDA.

LOOP AT ITAB.

data id_color type i VALUE 1.

data id_colors(2) type c.

IF ITAB-MATNR < '000000000000000100'.

ITAB-LIGHT = '1'.

ELSEIF ITAB-MATNR < '000000000000000150' AND ITAB-MATNR >

'000000000000000100' .

ITAB-LIGHT = '2'.

ELSE.

ITAB-LIGHT = '3'.

ENDIF.

id_color = id_color + 1.

if id_color > 7.

id_color = 1.

endif.

id_colors = id_color.

concatenate 'C' id_colors '10' into itab-color.

modify itab.

CLEAR ITAB.

endloop.

ENDFORM. " READDATA

----


  • Form FILLFIELD

----


FORM FILLFIELD .

WA_FIELDCAT-FIELDNAME = 'MATNR'.

WA_FIELDCAT-KEY = 'X'.

WA_FIELDCAT-COL_POS = '1'.

WA_FIELDCAT-outputlen = 20.

WA_FIELDCAT-HOTSPOT = 'X'.

wa_fieldcat-seltext_m = 'MATERIAL NUMBER'.

*WA_FIELDCAT-EMPHASIZE = 'C210'.

APPEND WA_FIELDCAT TO FIELDCAT.

clear wa_fieldcat.

WA_FIELDCAT-FIELDNAME = 'MEINS'.

WA_FIELDCAT-COL_POS = '2'.

*WA_FIELDCAT-EMPHASIZE = 'C510'.

WA_FIELDCAT-outputlen = 10.

wa_fieldcat-seltext_m = 'UNIT'.

APPEND WA_FIELDCAT TO FIELDCAT.

clear wa_fieldcat.

WA_FIELDCAT-FIELDNAME = 'ERSDA'.

WA_FIELDCAT-COL_POS = '3'.

WA_FIELDCAT-outputlen = 15.

*WA_FIELDCAT-EDIT_MASK = 'DD.MM.YYYY'.

*WA_FIELDCAT-EMPHASIZE = 'C710'.

wa_fieldcat-seltext_m = 'CREAT DATE'.

APPEND WA_FIELDCAT TO FIELDCAT.

clear wa_fieldcat.

ENDFORM. "FILLFIELD

&----


  • Setup print parameters

----


form build_print_params.

PRINT_CONT-reserve_lines = '3'. "Lines reserved for footer

PRINT_CONT-no_coverpage = 'X'.

endform. " BUILD_PRINT_PARAMS

----


  • Form POPDATA

----


FORM POPDATA .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = sy-repid

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'USER-COMMAND'

I_CALLBACK_TOP_OF_PAGE = 'TOPPAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

I_GRID_TITLE = I_TITLE_MARA

  • I_GRID_SETTINGS =

IS_LAYOUT = I_LAYOUT

IT_FIELDCAT = fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = SORT[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = V_EVENTS

  • IT_EVENT_EXIT =

IS_PRINT = PRINT_CONT

TABLES

T_OUTTAB = ITAB

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

ENDFORM. " POPDATA

----


  • Form TOPPAGE

----


FORM TOPPAGE.

REFRESH I_LISTHEADER.

DATA: ld_lines type i,

ld_linesc(10) type c,

I_DATE(10) TYPE C,

I_INFO LIKE WA_LISTHEADER-INFO.

WA_LISTHEADER-TYP = 'H'.

WA_LISTHEADER-INFO = 'MATERIAL DETAIL'.

APPEND WA_LISTHEADER TO I_LISTHEADER.

CLEAR WA_LISTHEADER.

WA_LISTHEADER-TYP = 'S'.

WA_LISTHEADER-KEY = 'DATE :'.

CONCATENATE SY-DATUM+6(2) '.'

SY-DATUM+4(2) '.'

SY-DATUM(4) INTO I_DATE.

WA_LISTHEADER-INFO = I_datE.

APPEND WA_LISTHEADER TO I_LISTHEADER.

CLEAR WA_LISTHEADER.

describe table ITAB lines ld_lines.

ld_linesc = ld_lines.

concatenate 'TOTAL NUMBER OF RECORD SELECTED: ' ld_linesc

into I_INFO separated by space.

WA_LISTHEADER-TYP = 'A'.

WA_LISTHEADER-INFO = I_INFO.

append WA_LISTHEADER to I_LISTHEADER.

clear: WA_LISTHEADER , I_INFO.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = I_LISTHEADER

I_LOGO = 'ENJOYSAP_LOGO'.

ENDFORM. "TOPPAGE

----


  • Form FILLLAYOUT

----


FORM FILLLAYOUT .

i_layout-zebra = 'X'.

i_layout-info_fieldname = 'COLOR'.

i_layout-box_fieldname = 'SEL'.

I_LAYOUT-lights_fieldname = 'LIGHT'.

I_LAYOUT-EDIT ='X'.

I_LAYOUT-colwidth_optimize = 'X'.

I_LAYOUT-window_titlebar = 'EXAMPLE FOR ALV GRID'.

I_LAYOUT-no_totalline = 'X'.

ENDFORM. "FILLLAYOUT

----


  • Form FILL_SORT

----


FORM FILL_SORT .

SORT-DOWN = 'X'.

SORT-SPOS = 1.

SORT-FIELDNAME = 'MATNR'.

SORT-tabname = 'MARA'.

APPEND SORT.

ENDFORM. " FILL_SORT

----


  • Form EVENT_CALL

----


FORM EVENT_CALL .

DATA: I_EVENT LIKE V_EVENTS.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = V_EVENTS.

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. " EVENT_CALL

----


  • Form POPULATE_EVENT

----


FORM POPULATE_EVENT .

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.

IF SY-SUBRC EQ 0.

WA_EVENT-FORM = 'USER_COMMAND'.

MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =

WA_EVENT-NAME.

READ TABLE V_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE

INTO WA_EVENT.

IF SY-SUBRC = 0.

move 'END_OF_PAGE' to WA_EVENT-FORM.

MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =

WA_EVENT-NAME.

endif.

ENDIF.

ENDFORM. "POPULATE_EVENT

*----


FORM END_OF_PAGE.

write: sy-uline(50).

skip.

write:/40 'Page:', sy-pagno .

ENDFORM.

&----


*& Form USER_COMMAND

----


FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

CASE R_UCOMM.

WHEN '&IC1'.

CASE RS_SELFIELD-FIELDNAME.

when 'MATNR'.

read table itab with key matnr = RS_SELFIELD-VALUE.

if sy-subrc = 0.

PERFORM DATA_RETRIEVAL_MAKT USING RS_SELFIELD-VALUE.

PERFORM BUILD_FIELDCATLOG_MAKT.

PERFORM FILLLAYOUT_MAKT.

PERFORM DISPLAY_ALV_MAKT.

CLEAR RS_SELFIELD.

ENDIF.

ENDCASE.

ENDCASE.

ENDFORM. "user_command

----


  • Form DATA_RETRIEVAL_MAKT

----


FORM DATA_RETRIEVAL_MAKT USING TMATNR .

SELECT MATNR

MAKTX

MAKTG

UP TO 100 ROWS

FROM MAKT

INTO TABLE ITAB1

WHERE SPRAS = 'EN' AND MATNR = TMATNR.

LOOP AT ITAB1.

data id_color type i VALUE 1.

data id_colors(2) type c.

id_color = id_color + 1.

if id_color > 7.

id_color = 1.

endif.

id_colors = id_color.

concatenate 'C' id_colors '10' into itab1-color.

modify itab1.

CLEAR ITAB1.

ENDLOOP.

ENDFORM. "DATA_RETRIEVAL_MAKT

----


  • Form FILLLAYOUT_MAKT

----


FORM FILLLAYOUT_MAKT .

CLEAR I_LAYOUT.

i_layout-zebra = 'X'.

i_layout-info_fieldname = 'COLOR'.

i_layout-box_fieldname = 'SEL'.

I_LAYOUT-EDIT ='X'.

I_LAYOUT-colwidth_optimize = 'X'.

I_LAYOUT-window_titlebar = 'EXAMPLE FOR ALV GRID'.

ENDFORM. " LAYOUT_MAKT

----


  • Form BUILD_FIELDCATLOG_MAKT

----


FORM BUILD_FIELDCATLOG_MAKT .

REFRESH FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MATNR'.

WA_FIELDCAT-KEY = 'X'.

WA_FIELDCAT-COL_POS = '1'.

*WA_FIELDCAT-EDIT_MASK = 'DD.MM.YYYY'.

WA_FIELDCAT-EMPHASIZE = 'C510'.

wa_fieldcat-seltext_m = 'MATERIAL NUMBER'.

APPEND WA_FIELDCAT TO FIELDCAT.

clear wa_fieldcat.

WA_FIELDCAT-FIELDNAME = 'MAKTX'.

WA_FIELDCAT-COL_POS = '2'.

WA_FIELDCAT-EMPHASIZE = 'C710'.

wa_fieldcat-seltext_m = 'MATERIAL DESCRIPTION'.

APPEND WA_FIELDCAT TO FIELDCAT.

clear wa_fieldcat.

WA_FIELDCAT-FIELDNAME = 'MAKTG'.

WA_FIELDCAT-COL_POS = '3'.

WA_FIELDCAT-EMPHASIZE = 'C210'.

wa_fieldcat-seltext_m = 'MATERIAL DESCRIPTION'.

APPEND WA_FIELDCAT TO FIELDCAT.

clear wa_fieldcat.

ENDFORM. " BUILD_FIELDCATLOG_MAKT

----


  • Form DISPLAY_ALV_MAKT

----


FORM TOP-OF-PAGE.

REFRESH I_LISTHEADER.

DATA: ld_lines type i,

ld_linesc(10) type c,

I_DATE(10) TYPE C,

I_INFO LIKE WA_LISTHEADER-INFO.

WA_LISTHEADER-TYP = 'H'.

WA_LISTHEADER-INFO = 'MATERIAL DESCRIPTION FOR SELECTED NUMBER'.

APPEND WA_LISTHEADER TO I_LISTHEADER.

CLEAR WA_LISTHEADER.

WA_LISTHEADER-TYP = 'S'.

WA_LISTHEADER-KEY = 'DATE :'.

CONCATENATE SY-DATUM+6(2) '.'

SY-DATUM+4(2) '.'

SY-DATUM(4) INTO I_DATE.

WA_LISTHEADER-INFO = I_datE.

APPEND WA_LISTHEADER TO I_LISTHEADER.

CLEAR WA_LISTHEADER.

describe table ITAB1 lines ld_lines.

ld_linesc = ld_lines.

concatenate 'TOTAL NUMBER OF RECORD SELECTED: ' ld_linesc

into I_INFO separated by space.

WA_LISTHEADER-TYP = 'A'.

WA_LISTHEADER-INFO = I_INFO.

append WA_LISTHEADER to I_LISTHEADER.

clear: WA_LISTHEADER , I_INFO.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = I_LISTHEADER

I_LOGO = 'ENJOYSAP_LOGO'.

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

ENDFORM. "TOP-OF-PAGE

&----


*& Form DISPLAY_ALV_MAKT

&----


  • text

----


FORM DISPLAY_ALV_MAKT .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE'

I_GRID_TITLE = I_TITLE_MAKT

IS_LAYOUT = I_LAYOUT

IT_FIELDCAT = fieldcat

TABLES

T_OUTTAB = ITAB1

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_MAKT

reward points to all helpful answers