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: 

interactive ALV

Former Member
0 Kudos

Hi everyone

i have created a normal ALV display.

now my requirement is changed and i have to make it interactive can anyone gv me sample code of interactive ALV or guide me with the events or FM's please...

its very urgent

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ,

Check the code below it will help you.

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

*&----


*

*& Report ZSAND_SUBTOTAL *

*& *

&----


*& *

*& *

&----


REPORT ZSAND_SUBTOTAL LINE-COUNT 65 .

*&----


*& Report ZALV_LIST

*&

*&----


*&

*&

*&----


TABLES : mseg.

TYPE-POOLS : slis.

DATA : BEGIN OF itab OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

menge LIKE mseg-menge,

line_color(4) TYPE c,

END OF itab.

DATA : BEGIN OF itab1 OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

menge LIKE mseg-menge,

line_color(4) TYPE c,

END OF itab1.

data: it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.

DATA: it_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader.

data: var1(1).

DATA var2.

data:mytabix like sy-tabix.

data:wtab1 like line of itab,

wtab2 like line of itab.

DATA : t_fcat TYPE slis_t_fieldcat_alv,

t_eve TYPE slis_t_event,

t_subtot TYPE slis_t_sortinfo_alv,

subtot LIKE LINE OF t_subtot,

wa_fcat LIKE LINE OF t_fcat,

gd_layout TYPE slis_layout_alv.

DATA : gt_menge LIKE mseg-menge,

st_menge LIKE mseg-menge.

data:it_extab type SLIS_t_EXTAB,

wa_extab like line of it_extab.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : doc FOR mseg-mblnr.

SELECTION-SCREEN : END OF BLOCK blk1.

START-OF-SELECTION.

PERFORM build_cat USING t_fcat.

PERFORM build_layout.

PERFORM build_eve.

perform fill_sort.

PERFORM get_data.

PERFORM display.

*&----


*& Form build_cat

*&----


*text

*----


*-->TEMP_FCAT text

*----


FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MBLNR'.

wa_fcat-seltext_m = 'Material Doc.'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-seltext_m = 'Material'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'WERKS'.

wa_fcat-seltext_m = 'Plant'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MENGE'.

wa_fcat-seltext_m = 'Quantity'.

wa_fcat-do_sum = 'Y'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

ENDFORM. "build_cat

*&----


*& Form build_eve

*&----


*text

*----


FORM build_eve.

DATA : wa_eve TYPE slis_alv_event.

data:mytabix type sy-tabix.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = t_eve

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 t_eve into wa_eve WITH KEY name = slis_ev_top_of_page.

*INTO wa_eve.

IF sy-subrc = 0.

mytabix = sy-tabix.

MOVE 'TOP_OF_PAGE' TO wa_eve-form.

append wa_eve to t_eve.

*modify t_eve from wa_eve index mytabix transporting form.

ENDIF.

READ TABLE t_eve into wa_eve WITH KEY name = slis_ev_end_of_page.

*INTO wa_eve.

IF sy-subrc = 0.

mytabix = sy-tabix.

MOVE 'END_OF_PAGE' TO wa_eve-form.

append wa_eve to t_eve.

*modify t_eve from wa_eve index mytabix transporting form.

ENDIF.

ENDFORM. "build_eve

*&----


*& Form build_layout

*&----


*text

*----


FORM build_layout.

*gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-info_fieldname = 'LINE_COLOR'.

gd_layout-subtotals_text = 'SUBTOTAL'.

*gd_layout-totals_text = 'TOTAL'.

gd_layout-EDIT = 'X'.

ENDFORM. " BUILD_LAYOUT

*&----


*& Form get_data

*&----


*text

*----


FORM get_data.

SELECT mblnr matnr werks menge FROM mseg INTO CORRESPONDING FIELDS OF

TABLE itab

WHERE mblnr IN doc.

SORT itab BY mblnr.

sort itab by mblnr matnr.

read table itab into wtab1 index 1.

mytabix = 1.

loop at itab into wtab2 from 2.

if wtab1-mblnr = wtab2-mblnr and wtab1-matnr = wtab2-matnr.

wtab1-menge = wtab1-menge + wtab2-menge.

modify itab from wtab1 index mytabix.

else.

modify itab from wtab1 index mytabix.

clear wtab1.

mytabix = sy-tabix.

move wtab2 to wtab1.

endif.

clear wtab2.

endloop.

delete ADJACENT DUPLICATES from itab comparing mblnr matnr.

ENDFORM. "get_data

*&----


*& Form display

*&----


*text

*----


FORM display.

*

wa_extab-fcode = '&ETA'.

append wa_extab to it_extab.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = 'ZSAND_SUBTOTAL'

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'USERCOMMAND'

  • I_CALLBACK_TOP_OF_PAGE = '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 = gd_layout

IT_FIELDCAT = t_fcat

IT_EXCLUDING = it_extab

  • IT_SPECIAL_GROUPS =

IT_SORT = it_sortcat

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = t_eve[]

  • IT_EVENT_EXIT = 'BUILD_EVE'

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

ENDFORM. "display

*

**&----


***& Form top_of_page

*&----


*

*text

*----


FORM top_of_page.

if var1 is initial.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = it_header

I_LOGO = 'HR_LOGO'

  • I_END_OF_LIST_GRID =

.

var1 = 'X'.

endif.

ENDFORM. "top_of_page

FORM end_of_page.

if var2 is initial.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = it_header

I_LOGO = 'HR_LOGO'

  • I_END_OF_LIST_GRID =

.

var2 = 'X'.

endif.

ENDFORM. "top_of_page

&----


*& Form fill_sort

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fill_sort .

wa_sort-spos = 1.

wa_sort-fieldname = 'MBLNR'.

wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

wa_sort-spos = 2.

wa_sort-fieldname = 'MATNR'.

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

endform. " fill_sort

FORM status USING rt_extab TYPE slis_t_extab.

set pf-status 'ZSTANDARD'.

endform.

form USERCOMMAND USING R_UCOMM type sy-ucomm

rselfield type slis_selfield .

set parameter id 'MAT' field rselfield-value .

call transaction 'MM03' and skip first screen.

endform.

I hope this wuill help you.

Help children of U.N World Food Program by rewarding points and encourage others to answer your queries.

5 REPLIES 5

Former Member
0 Kudos

Former Member
0 Kudos

Hi Ravi,

Please check this link

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

Best regards,

raam

huseyindereli
Active Contributor
0 Kudos

Hi ,

Check this link ;

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/samplecodeforDynamicALV+generation

GauthamV
Active Contributor
0 Kudos

hi,

check BALV* in se38 u will get lots of alv interactive reports.

Former Member
0 Kudos

Hi ,

Check the code below it will help you.

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

*&----


*

*& Report ZSAND_SUBTOTAL *

*& *

&----


*& *

*& *

&----


REPORT ZSAND_SUBTOTAL LINE-COUNT 65 .

*&----


*& Report ZALV_LIST

*&

*&----


*&

*&

*&----


TABLES : mseg.

TYPE-POOLS : slis.

DATA : BEGIN OF itab OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

menge LIKE mseg-menge,

line_color(4) TYPE c,

END OF itab.

DATA : BEGIN OF itab1 OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

menge LIKE mseg-menge,

line_color(4) TYPE c,

END OF itab1.

data: it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.

DATA: it_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader.

data: var1(1).

DATA var2.

data:mytabix like sy-tabix.

data:wtab1 like line of itab,

wtab2 like line of itab.

DATA : t_fcat TYPE slis_t_fieldcat_alv,

t_eve TYPE slis_t_event,

t_subtot TYPE slis_t_sortinfo_alv,

subtot LIKE LINE OF t_subtot,

wa_fcat LIKE LINE OF t_fcat,

gd_layout TYPE slis_layout_alv.

DATA : gt_menge LIKE mseg-menge,

st_menge LIKE mseg-menge.

data:it_extab type SLIS_t_EXTAB,

wa_extab like line of it_extab.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : doc FOR mseg-mblnr.

SELECTION-SCREEN : END OF BLOCK blk1.

START-OF-SELECTION.

PERFORM build_cat USING t_fcat.

PERFORM build_layout.

PERFORM build_eve.

perform fill_sort.

PERFORM get_data.

PERFORM display.

*&----


*& Form build_cat

*&----


*text

*----


*-->TEMP_FCAT text

*----


FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MBLNR'.

wa_fcat-seltext_m = 'Material Doc.'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-seltext_m = 'Material'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'WERKS'.

wa_fcat-seltext_m = 'Plant'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB'.

wa_fcat-fieldname = 'MENGE'.

wa_fcat-seltext_m = 'Quantity'.

wa_fcat-do_sum = 'Y'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

ENDFORM. "build_cat

*&----


*& Form build_eve

*&----


*text

*----


FORM build_eve.

DATA : wa_eve TYPE slis_alv_event.

data:mytabix type sy-tabix.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = t_eve

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 t_eve into wa_eve WITH KEY name = slis_ev_top_of_page.

*INTO wa_eve.

IF sy-subrc = 0.

mytabix = sy-tabix.

MOVE 'TOP_OF_PAGE' TO wa_eve-form.

append wa_eve to t_eve.

*modify t_eve from wa_eve index mytabix transporting form.

ENDIF.

READ TABLE t_eve into wa_eve WITH KEY name = slis_ev_end_of_page.

*INTO wa_eve.

IF sy-subrc = 0.

mytabix = sy-tabix.

MOVE 'END_OF_PAGE' TO wa_eve-form.

append wa_eve to t_eve.

*modify t_eve from wa_eve index mytabix transporting form.

ENDIF.

ENDFORM. "build_eve

*&----


*& Form build_layout

*&----


*text

*----


FORM build_layout.

*gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-info_fieldname = 'LINE_COLOR'.

gd_layout-subtotals_text = 'SUBTOTAL'.

*gd_layout-totals_text = 'TOTAL'.

gd_layout-EDIT = 'X'.

ENDFORM. " BUILD_LAYOUT

*&----


*& Form get_data

*&----


*text

*----


FORM get_data.

SELECT mblnr matnr werks menge FROM mseg INTO CORRESPONDING FIELDS OF

TABLE itab

WHERE mblnr IN doc.

SORT itab BY mblnr.

sort itab by mblnr matnr.

read table itab into wtab1 index 1.

mytabix = 1.

loop at itab into wtab2 from 2.

if wtab1-mblnr = wtab2-mblnr and wtab1-matnr = wtab2-matnr.

wtab1-menge = wtab1-menge + wtab2-menge.

modify itab from wtab1 index mytabix.

else.

modify itab from wtab1 index mytabix.

clear wtab1.

mytabix = sy-tabix.

move wtab2 to wtab1.

endif.

clear wtab2.

endloop.

delete ADJACENT DUPLICATES from itab comparing mblnr matnr.

ENDFORM. "get_data

*&----


*& Form display

*&----


*text

*----


FORM display.

*

wa_extab-fcode = '&ETA'.

append wa_extab to it_extab.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = 'ZSAND_SUBTOTAL'

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'USERCOMMAND'

  • I_CALLBACK_TOP_OF_PAGE = '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 = gd_layout

IT_FIELDCAT = t_fcat

IT_EXCLUDING = it_extab

  • IT_SPECIAL_GROUPS =

IT_SORT = it_sortcat

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = t_eve[]

  • IT_EVENT_EXIT = 'BUILD_EVE'

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

ENDFORM. "display

*

**&----


***& Form top_of_page

*&----


*

*text

*----


FORM top_of_page.

if var1 is initial.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = it_header

I_LOGO = 'HR_LOGO'

  • I_END_OF_LIST_GRID =

.

var1 = 'X'.

endif.

ENDFORM. "top_of_page

FORM end_of_page.

if var2 is initial.

wa_header-typ = 'H'.

wa_header-info = 'SANDY is Great'.

append wa_header to it_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = it_header

I_LOGO = 'HR_LOGO'

  • I_END_OF_LIST_GRID =

.

var2 = 'X'.

endif.

ENDFORM. "top_of_page

&----


*& Form fill_sort

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fill_sort .

wa_sort-spos = 1.

wa_sort-fieldname = 'MBLNR'.

wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

wa_sort-spos = 2.

wa_sort-fieldname = 'MATNR'.

  • gd_sortcat-tabname

APPEND wa_sort TO it_sortcat.

endform. " fill_sort

FORM status USING rt_extab TYPE slis_t_extab.

set pf-status 'ZSTANDARD'.

endform.

form USERCOMMAND USING R_UCOMM type sy-ucomm

rselfield type slis_selfield .

set parameter id 'MAT' field rselfield-value .

call transaction 'MM03' and skip first screen.

endform.

I hope this wuill help you.

Help children of U.N World Food Program by rewarding points and encourage others to answer your queries.