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

sample code ALV report using methods

Former Member
0 Likes
5,825

can anyone send me a sample ALV report using methods

my requirement is do subtotals and top of page.

please help me..

4 REPLIES 4
Read only

Former Member
0 Likes
5,733

HI,

See the below Example programs in SAP

<b>BCALV_EDIT_01</b> This report illustrates the simplest case of using an editable/noneditable ALV Grid Control.

<b>BCALV_EDIT_02</b> This report illustrates how to set chosen cells of an ALV Grid Control editable.

<b>BCALV_EDIT_03</b> In this example the user may change values of fields SEATSOCC (occupied seats) and/or PLANETYPE.

The report checks the input value(s) semantically and provides protocol messages in case of error

<b>BCALV_EDIT_04</b> This report illustrates how to add and remove lines to a table using the ALV Grid Control and how to

implement the saving of the new data.

<b>BCALV_EDIT_05</b> This example shows how to use checkboxes within an ALV Grid Control. You learn:

(1) how to define a column for editable checkboxes for an attribute of your list

(2) how to evaluate the checked checkboxes

(3) how to switch between editable and non-editable checkboxes

<b>BCALV_EDIT_06</b> This example shows how to define a dropdown listbox for all cells of one column in an editable ALV

Grid Control.

<b>BCALV_EDIT_07</b> This example shows how to define dropdown listboxes for particular cells of your output table.

<b>BCALV_EDIT_08</b> This report implements an ALV Grid Control with an application specific F4 help. The following aspects

are dealt with:

(1) how to replace the standard f4 help

(2) how to pass the selected value to the ALV Grid Control

(3) how to build an f4 help, whose value range depend on a value of another cell.

Regards

Sudheer

Read only

Former Member
0 Likes
5,733

Hi,

try this simple program

report yalv2 .

                                        • declare data areas for listviewer******************

type-pools:slis.

data:g_repid like sy-repid,

gs_layout type slis_layout_alv,

gt_fieldcat type slis_t_fieldcat_alv,

fieldcat_ln type slis_fieldcat_alv,

gt_sort type slis_t_sortinfo_alv,

gs_sort type slis_sortinfo_alv,

gt_events type slis_t_event,

gs_event type slis_alv_event,

gt_list_top_of_page type slis_t_listheader,

gs_line type slis_listheader,

col_pos type i.

data:begin of itab,

field1(5) type c,

field2(5) type c,

field3(5) type p decimals 2,

end of itab.

data:begin of itab1 occurs 0.

include structure itab.

data:end of itab1.

data:begin of itab_fieldcat occurs 0.

include structure itab.

data:end of itab_fieldcat.

initialization.

g_repid = sy-repid.

start-of-selection.

move 'test1' to itab1-field1.

move 'test1' to itab1-field2.

move '10.00' to itab1-field3.

append itab1.

move 'test2' to itab1-field1.

move 'test2' to itab1-field2.

move '20.00' to itab1-field3.

append itab1.

do 200 times.

append itab1.

enddo.

end-of-selection.

perform build_fieldcat.

perform build_sortcat.

perform build_eventcat changing gt_events.

perform build_commentcat changing gt_list_top_of_page.

perform call_alv.

*&----


*

*& Form build_fieldcat

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form build_fieldcat . "data field catalog, explain field desc

"to alv

fieldcat_ln-fieldname = 'FIELD1'.

fieldcat_ln-tabname = 'ITAB1'.

fieldcat_ln-key = ' '. "subtotal key

fieldcat_ln-no_out = ' '.

fieldcat_ln-seltext_l = 'HEAD1'.

append fieldcat_ln to gt_fieldcat.

fieldcat_ln-fieldname = 'FIELD2'.

fieldcat_ln-tabname = 'ITAB1'.

fieldcat_ln-no_out = ' '.

fieldcat_ln-seltext_l = 'HEAD2'.

append fieldcat_ln to gt_fieldcat.

fieldcat_ln-fieldname = 'FIELD3'.

fieldcat_ln-tabname = 'ITAB1'.

fieldcat_ln-ref_tabname = 'MSEG'.

fieldcat_ln-ref_fieldname = 'MENGE'.

fieldcat_ln-no_out = ' '.

fieldcat_ln-do_sum = 'X'. "sum upon display

append fieldcat_ln to gt_fieldcat.

endform. " build_fieldcat

*&----


*

*& Form build_sortcat

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form build_sortcat . "data sorting and displaying subtotal

clear gs_sort.

gs_sort-fieldname = 'FIELD1'.

gs_sort-spos = '1'.

gs_sort-up = 'X'.

append gs_sort to gt_sort.

clear gs_sort.

gs_sort-fieldname = 'FIELD2'.

gs_sort-spos = '2'.

gs_sort-up = 'X'.

append gs_sort to gt_sort.

endform. " build_sortcat

*&----


*

*& Form build_eventcat

*&----


*

  • text

*----


*

  • <--P_GT_EVENTS text

*----


*

form build_eventcat changing lt_events type slis_t_event.

constants:

gc_formname_top_of_page type slis_formname value 'TOP-OF-PAGE'.

call function 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = lt_events

.

read table lt_events with key name = slis_ev_top_of_page into gs_event.

if sy-subrc = 0.

move gc_formname_top_of_page to gs_event-form.

append gs_event to lt_events.

endif.

endform. " build_eventcat

&----


*& Form build_commentcat

&----


  • text

----


  • <--P_GT_LIST_TOP_OF_PAGE text

----


form build_commentcat changing gt_top_of_page type slis_t_listheader.

clear gs_line.

gs_line-typ = 'H'.

gs_line-info = 'HEADER 1'.

append gs_line to gt_top_of_page.

clear gs_line.

gs_line-typ = 'S'.

gs_line-key = 'STATUS 1'.

gs_line-info = 'INFO 1'.

append gs_line to gt_top_of_page.

clear gs_line.

gs_line-typ = 'S'.

gs_line-key = 'STATUS 2'.

gs_line-info = 'INFO 2'.

append gs_line to gt_top_of_page.

endform. " build_commentcat

form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = gt_list_top_of_page.

write: sy-datum, 'Page no', sy-pagno left-justified.

endform.

form end-of-page.

write at (sy-linsz) sy-pagno centered.

endform.

&----


*& Form call_alv

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form call_alv .

call function 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = g_repid

I_STRUCTURE_NAME = 'ITAB1'

IS_LAYOUT = gs_layout

IT_FIELDCAT = gt_fieldcat

IT_SORT = gt_sort

IT_EVENTS = gt_events

tables

t_outtab = ITAB1

.

endform. " call_alv

regards,

sowjanya

Read only

Former Member
0 Likes
5,733

Hi Alekhya,

Just go through these documents.It will help you in learning ALV using Object Oriented technology.

http://esnips.com/doc/b708766f-a934-42a1-8064-c4de75b48fc4/Sample-Program-of-alv-using-oops.ppt

http://esnips.com/doc/2d953590-e8c5-490c-a607-d1ab7cf517d7/ALV.pdf

<u>related document</u>

http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt

<b>Award points if found useful.</b>

Regards,

SP.