Google Search - Blog...........

ABAP - ALV With Page Numbers & Subtotals.

Here is the code for alv with page nos and subtotal.

If you click any one of the line it will displays the list .


report ztests .

* ALV

type-pools: slis.



*--------------------------------------------------------------------

* G L O B A L I N T E R N A L T A B L E S

*--------------------------------------------------------------------

data: gt_fieldcat type slis_t_fieldcat_alv,

gs_layout type slis_layout_alv,

gt_events type slis_t_event.

data: it_sort type slis_t_sortinfo_alv ,

wa_sort type slis_sortinfo_alv .

data: gs_print type slis_print_alv.



data: begin of it_sflight occurs 0,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

price like sflight-price,

planetype like sflight-planetype,

seatsmax like sflight-seatsmax,

seatsocc like sflight-seatsocc,

paymentsum like sflight-paymentsum,

end of it_sflight.



*DATA: GI_SFLIGHT LIKE STANDARD TABLE OF ST_SFLIGHT.

data: g_repid like sy-repid.

data: gt_list_top_of_page type slis_t_listheader.

data: v_total(5).



start-of-selection.

g_repid = sy-repid.



perform init_fieldcat using gt_fieldcat[].

perform build_eventtab using gt_events[].

perform build_comment using gt_list_top_of_page[].

perform get_data.

perform set_layout using gs_layout.



* SORTING

clear wa_sort.

wa_sort-fieldname = 'CARRID'.

wa_sort-up = 'X'.

wa_sort-group = '*'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.



clear wa_sort.

wa_sort-fieldname = 'CONNID'.

wa_sort-up = 'X'.

wa_sort-group = 'UL'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.



* DISPLAY LIST

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_interface_check = ' '

i_callback_program = g_repid

i_callback_user_command = 'USER_COMMAND'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

it_sort = it_sort[]

it_events = gt_events

is_print = gs_print

tables

t_outtab = it_sflight

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.





*&---------------------------------------------------------------------*

*& Form INIT_FIELDCAT

*&---------------------------------------------------------------------*

form init_fieldcat using p_gt_fieldcat type slis_t_fieldcat_alv.

data: ls_fieldcat type slis_fieldcat_alv,

l_index type sy-tabix.



data :rep like sy-repid.

rep = sy-repid.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = rep

i_internal_tabname = 'IT_SFLIGHT'

i_inclname = rep

changing

ct_fieldcat = gt_fieldcat

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0.

message id sy-msgid type 'S' number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-subrc.

endif.

sort gt_fieldcat by col_pos.

loop at gt_fieldcat into ls_fieldcat.

l_index = sy-tabix.

if ls_fieldcat-fieldname = 'PRICE'.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-sp_group = 'X'.

modify gt_fieldcat from ls_fieldcat index l_index .

endif.

endloop.



endform. " INIT_FIELDCAT



*&---------------------------------------------------------------------*

*& Form BUILD_EVENTTAB

*&---------------------------------------------------------------------*

form build_eventtab using p_gt_events type slis_t_event.

data: ls_event type slis_alv_event.



clear ls_event.

ls_event-name = slis_ev_top_of_page.

ls_event-form = 'XTOP_OF_PAGE'.

append ls_event to p_gt_events.

clear ls_event.

ls_event-name = slis_ev_top_of_list.

ls_event-form = 'XTOP_OF_LIST'.

append ls_event to p_gt_events.

clear ls_event.

clear ls_event.

ls_event-name = slis_ev_end_of_page.

ls_event-form = 'XEND_OF_PAGE'.

append ls_event to p_gt_events.

ls_event-name = slis_ev_end_of_list.

ls_event-form = 'XEND_OF_LIST'.

append ls_event to p_gt_events.

clear ls_event.



endform. " BUILD_EVENTTAB



*&---------------------------------------------------------------------*

*& Form BUILD_COMMENT

*&---------------------------------------------------------------------*

form build_comment using p_gt_list_top_of_page type slis_t_listheader.

data: ls_line type slis_listheader.

ls_line-typ = 'H'." = Header, S = Selection, A = Action

ls_line-key = 'KEY'.

ls_line-info = 'INFO'.

append ls_line to p_gt_list_top_of_page.



endform. " BUILD_COMMENT





*&---------------------------------------------------------------------*

*& Form SELECTION

*&---------------------------------------------------------------------*

form get_data..

data: l_rows type i value 3.

* Read data from table SFLIGHT

select carrid

connid

fldate

price

planetype

seatsmax

seatsocc

paymentsum

from sflight

into table it_sflight.

** up to l_rows rows.

sort it_sflight.

endform. " SELECTION



*&---------------------------------------------------------------------*

*& Form SET_LAYOUT

*&---------------------------------------------------------------------*

form set_layout using p_gs_layout type slis_layout_alv.



* * P_GS_LAYOUT-F2CODE = P_F2CODE.

p_gs_layout-zebra = 'X'.

p_gs_layout-colwidth_optimize = 'X'.

p_gs_layout-no_input = 'X'.

p_gs_layout-no_colhead = space.

p_gs_layout-totals_text = 'Total Price'.

p_gs_layout-subtotals_text = 'Sub Total'.

p_gs_layout-totals_only = 'X'.

p_gs_layout-key_hotspot = 'X'.

p_gs_layout-detail_popup = 'X'.

p_gs_layout-no_subtotals = space.

p_gs_layout-expand_all = 'X'.

p_gs_layout-group_buttons = 'X'."space.

endform. " SET_LAYOUT



*---------------------------------------------------------------------*

* FORM XTOP_OF_PAGE *

*---------------------------------------------------------------------*

form xtop_of_page.

data : lv_page(5),

lv_text(20).

MOVE SY-PAGNO TO LV_PAGE.

write:/ 'X_TOP_OF_PAGE'.

.

endform. "xtop_of_page

*---------------------------------------------------------------------*

* FORM XTOP_OF_LIST *

*---------------------------------------------------------------------*

form xtop_of_list.

write:/ 'X_TOP_OF_LIST'.

endform. "xtop_of_list

*---------------------------------------------------------------------*

* FORM XEND_OF_PAGE *

*---------------------------------------------------------------------*

form xend_of_page.

write:/ 'X_END_OF_PAGE'.

endform. "xend_of_page

*---------------------------------------------------------------------*

* FORM XEND_OF_LIST *

*---------------------------------------------------------------------*

form xend_of_list.

write:/ 'X_END_OF_LIST'.

data : lv_page(5),

lv_text(20).

data : l_lines type i,

l_line type i.



clear v_total.



write sy-pagno to v_total left-justified.

* export v_total to memory id 'V_TOTAL'.

do sy-pagno times.

lv_page = sy-index.

concatenate 'Page' lv_page 'of' v_total

into lv_text separated by space.

if sy-index = 1.

read line 2 of page sy-index.

else.

read line 1 of page sy-index.



endif.

sy-lisel+60(20) = lv_text.

modify current line .

enddo.



endform. "xend_of_list



*---------------------------------------------------------------------*

* USER_COMMAND *

*---------------------------------------------------------------------*

form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.



case r_ucomm.

when 'EXIT'.

leave to screen 0.

when '&IC1'.

data: text(256),text1(6),text2(5).

move rs_selfield-tabindex to text1.

move rs_selfield-sumindex to text2.

concatenate 'Double clicked on (field:'

rs_selfield-fieldname

'Value:'

rs_selfield-value

','

text1

','

text2

' ) '

into text

separated by space.



call function 'POPUP_TO_DISPLAY_TEXT'

exporting

textline1 = text.



endcase.

endform. "user_command

\

ALSO READ:

- Footer Functionality In ALV Reports.

- Calling One ALV From Other ALV Report Program.

- Capture Single & Multiple Row Selction In ALV Report Program.

- Coloring A Row & Column In ALV Display Using OOPS Concept.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


No comments:

Post a Comment