Skip to Content
0
Former Member
Dec 13, 2006 at 05:05 PM

Subtotals in ALV

34 Views

Hi

SAP Guru s

I am facing a dump when i pass the Gt_sort in reuse alv display FM

I am tryingto display the subtotals on the kunnr for dollars and count via ALV

following is the code

ur advice is highly appreciated

thanks

report orders .

*----


  • DICTIONARY TABLES

*----


tables: vbak, "Sales Document: Header Data

vbpa, "Sales Document: Partner

vbuk, "Sales Document: Header Status and Administrative Data

adrc.

----


  • ALV Declarations *

----


type-pools: slis, kkblo.

data: g_repid like sy-repid,

gs_layout type slis_layout_alv,

gt_fieldcat type slis_t_fieldcat_alv,

fieldcat_in like line of gt_fieldcat,

cos_pos type i,

gt_events type slis_t_event,

gt_sort type slis_t_sortinfo_alv,

months like komp-anz_monate.

data: g_anzlines type i.

data : t_list_top_of_page type slis_t_listheader.

data : t_list_end_of_list type slis_t_listheader.

data : t_events type slis_t_event.

*----


  • DATA

*----


data: gv_netwr like vbak-netwr,

gv_netwr0 like vbak-netwr,

zvbeln like vbak-vbeln,

gv_count(6) type n,

gv_count0(6) type n,

erdat1 like vbak-erdat,

temp like vbak-erdat,

temp1(10),

erdat2 like vbak-erdat,

vkorg like vbak-vkorg,

erdat(25),

hyphen(3) value '---',

p_name1 like adrc-name1,

zlines type i,

g_tabix like sy-tabix,

month_nme(10),

zline type i,

gv_tot like vbak-netwr,

gv_kcount type i,

gv_ktot like vbak-netwr,

l_tabix like sy-tabix.

*----


  • INTERNAL TABLES

*----


data: begin of zvbak occurs 0,

vbeln like vbak-vbeln, "order no

erdat like vbak-erdat,

vgbel like vbak-vgbel, "reference doc num

netwr like vbak-netwr, " amount

end of zvbak.

data: zvbak0 like zvbak occurs 0 with header line.

data: begin of zvbpa occurs 0,

name1 like adrc-name1,

month(2),

vbeln like vbpa-vbeln,

parvw like vbpa-parvw, " partner function

kunnr like vbpa-kunnr,

adrnr like vbpa-adrnr,

netwr like vbak-netwr,

erdat like vbak-erdat,

end of zvbpa.

data: zvbpa0 like zvbpa occurs 0 with header line.

data: alv_dat like zvbpa occurs 0 with header line,

alv_data0 like zvbpa occurs 0 with header line.

data: begin of alv0 occurs 0,

kunnr like vbak-kunnr,

name1 like adrc-name1,

count type i,

dollars like vbak-netwr ,

kcount type i,

kdollars like vbak-netwr,

month_nme(10),

erdat like vbak-erdat,

netwr like vbak-netwr,

vbeln like vbpa-vbeln,

end of alv0.

data: begin of zvbuk occurs 0,

vbeln like vbak-vbeln,

netwr like vbak-netwr,

erdat like vbak-erdat,

end of zvbuk.

data: begin of ztab_period occurs 0,

sindex like scscp_period_str-sindex,

datuv like scscp_period_str-datuv,

datub like scscp_period_str-datub,

id like scscp_period_str-id,

name(10) type c,

end of ztab_period.

data: begin of ztab_perio0 occurs 0,

sindex like scscp_period_str-sindex,

datuv like scscp_period_str-datuv,

id like scscp_period_str-id,

name(10) type c,

end of ztab_perio0.

*----


  • SELECTION SCREEN

*----


selection-screen begin of block b with frame title text-001 .

select-options: s_erdat for vbak-erdat obligatory,

s_vkorg for vbak-vkorg obligatory.

selection-screen end of block b.

----


*INITIALIZATION.

----


initialization.

g_repid = sy-repid.

----


*START-OF-SELECTION.

----


start-of-selection.

data:t_index like sy-tabix.

perform select_orders tables alv_data0.

loop at alv_data0.

t_index = sy-tabix.

move alv_data0-erdat+4(2) to alv_data0-month.

modify alv_data0 index t_index transporting month.

clear alv_data0.

endloop.

sort alv_data0 by name1 month.

loop at alv_data0.

if alv_data0-name1 = space.

delete alv_data0.

endif.

move alv_data0-kunnr to alv0-kunnr.

at new name1.

move: alv_data0-name1 to alv0-name1.

endat.

gv_netwr = alv_data0-netwr + gv_netwr.

gv_count = gv_count + 1.

at end of month.

call function 'MONTH_TO_MONTHNAME'

exporting

monthnum = alv_data0-month

importing

monthname = month_nme.

move month_nme to alv0-month_nme.

move gv_count to alv0-count.

move gv_netwr to alv0-dollars.

append alv0.

clear: alv0, gv_netwr, gv_count.

endat.

endloop.

*----


**END-OF-SELECTION.

*----


end-of-selection.

loop at alv0 .

gv_tot = gv_tot + alv0-dollars.

endloop.

describe table alv0 lines g_anzlines.

if g_anzlines gt 0.

perform display_list.

endif.

&----


*& Form select_orders

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form select_orders tables alv_dat structure zvbpa.

data: gv_index like sy-tabix,

ztab like ztab_period,

erdath like vbak-erdat,

erdat_h like vbak-erdat.

erdat1 = s_erdat-low(8).

erdath = s_erdat-high(8).

concatenate erdat1 hyphen erdat_h erdath into erdat.

vkorg = s_vkorg+3(4).

*calculate the no of orders and dollars month wise from the selection

*date

call function 'CSCP_PARA1_GET_PERIODS'

exporting

i_datuv = s_erdat-low

i_datub = s_erdat-high

i_timeunit = 'D'

tables

et_dates = ztab_period.

clear ztab_period.

clear gv_index.

describe table ztab_period lines zlines.

loop at ztab_period.

move-corresponding ztab_period to ztab_perio0.

append ztab_perio0.

clear ztab_perio0.

endloop.

sort ztab_perio0 by datuv.

loop at ztab_perio0.

if zlines = 2 and ztab_perio0-sindex = 1.

delete ztab_perio0.

clear ztab_perio0.

exit.

endif.

endloop.

*always delete first and last records in the internal table

loop at ztab_perio0.

if ( ztab_perio0-sindex = 1 ) .

delete ztab_perio0.

endif.

endloop.

*Assign Month name and calculate no of orders

clear gv_index.

clear: ztab, ztab_perio0.

describe table ztab_perio0 lines zline.

loop at ztab_perio0 into ztab.

gv_index = sy-tabix.

if ( ( ztab-datuv+4(2) = '01' ) or

( ztab-datuv+4(2) = '02' ) or

( ztab-datuv+4(2) = '03' ) or

( ztab-datuv+4(2) = '04' ) or

( ztab-datuv+4(2) = '05' ) or

( ztab-datuv+4(2) = '06' ) or

( ztab-datuv+4(2) = '07' ) or

( ztab-datuv+4(2) = '08' ) or

( ztab-datuv+4(2) = '09' ) or

( ztab-datuv+4(2) = '10' ) or

( ztab-datuv+4(2) = '11' ) or

( ztab-datuv+4(2) = '12' ) ).

erdat1 = ztab-datuv.

perform cal_no_of_orders tables alv_dat

using erdat1

changing gv_count0 gv_netwr0.

clear : erdat1 , ztab.

endif.

clear ztab.

endloop.

endform. " select_orders

*&----


*

*& Form DISPLAY_LIST

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form display_list.

g_repid = sy-repid.

  • sort alv0 by kunnr.

  • loop at alv0.

  • gv_ktot = gv_ktot + alv0-dollars.

  • gv_kcount = gv_kcount + alv0-count.

*

  • at end of kunnr.

  • move gv_ktot to alv0-kdollars.

  • move gv_kcount to alv0-kcount.

  • append alv0.

  • clear: alv0, gv_kcount, gv_ktot.

  • endat.

*

  • endloop.

*

perform fillevents.

perform comment_build using t_list_top_of_page.

perform create_layout.

perform create_fieldcat.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = g_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

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

is_layout = gs_layout

it_fieldcat = gt_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

it_sort = gt_sort[] ===========================>[ a dump is created here

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = 'A'

  • IS_VARIANT =

it_events = t_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_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = alv0

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

&----


*& Form comment_build

&----


  • text

----


  • -->P_t_list_top_of_page text

----


form comment_build using t_list_top_of_page type slis_t_listheader.

data : ls_line type slis_listheader.

data : ldate(10),hdate(10).

data : lv_dat(20).

clear lv_dat.

refresh : t_list_top_of_page.

clear ls_line.

ls_line-info = sy-repid.

ls_line-typ = 'H'.

ls_line-info = 'ORDERS AND DOLLARS REPORT'.

append ls_line to t_list_top_of_page.

write sy-datum to ldate using edit mask '__.__.____' .

clear ls_line.

ls_line-typ = 'A'.

concatenate 'Run Date :' ldate

into ls_line-info separated by space.

append ls_line to t_list_top_of_page.

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'User ID :'.

ls_line-info+12 = sy-uname.

append ls_line to t_list_top_of_page.

  • clear ls_line.

  • ls_line-typ = 'A'.

  • ls_line-info = 'No OF ORDERS :'.

  • ls_line-info+17 = gv_count.

  • append ls_line to t_list_top_of_page.

*

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'TOTAL dOLLAR AMOUNT :'.

ls_line-info+25 = gv_tot.

append ls_line to t_list_top_of_page.

clear ls_line.

concatenate s_erdat3(8) '----' s_erdat11(8) into lv_dat.

ls_line-typ = 'A'.

ls_line-info = 'Date Range for Documents :'.

ls_line-info+25 = lv_dat.

append ls_line to t_list_top_of_page.

clear ls_line.

ls_line-typ = 'A'.

ls_line-info = 'Sales Organization :'.

ls_line-info+25 = vkorg.

append ls_line to t_list_top_of_page.

endform. " comment_build

&----


*& Form fillevents

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fillevents.

data l_events type line of slis_t_event.

clear l_events.

l_events-name = 'TOP_OF_PAGE'.

l_events-form = 'TOP_OF_PAGE'.

append l_events to t_events.

*perform top-of-page1.

endform. " fillevents

&----


*& Form create_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form create_fieldcat.

perform fill_fieldcat using:

'NAME1' 'ALV0' 'NAME' '1' '',

'MONTH_NME' 'ALV0' 'EDIMONTH' '2' '',

'DOLLARS' 'ALV0' 'DOLLARS' '3' '',

'COUNT' 'ALV0' 'COUNT' '4' ''.

endform. " create_fieldcat

&----


*& Form create_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form create_layout.

gs_layout-colwidth_optimize = 'X'.

gs_layout-zebra = 'X'.

gs_layout-no_totalline = 'X'.

endform. " create_layout

&----


*& Form fill_fieldcat

&----


  • text

----


  • -->P_0564 text

  • -->P_0565 text

  • -->P_0566 text

  • -->P_0567 text

  • -->P_0568 text

----


form fill_fieldcat using p_fname

p_tabname

p_seltext

p_colpos

p_do_sum.

clear fieldcat_in.

fieldcat_in-fieldname = p_fname.

fieldcat_in-tabname = p_tabname.

fieldcat_in-seltext_m = p_seltext.

fieldcat_in-col_pos = p_colpos.

fieldcat_in-do_sum = p_do_sum.

append fieldcat_in to gt_fieldcat.

clear fieldcat_in.

fieldcat_in-fieldname = 'DOLLARS'.

fieldcat_in-tabname = 'ALV0'.

fieldcat_in-no_out = ' '.

fieldcat_in-do_sum = 'X'. "SUM UPON DISPLAY

append fieldcat_in to gt_fieldcat.

clear fieldcat_in.

fieldcat_in-fieldname = 'COUNT'.

fieldcat_in-tabname = 'ALV0'.

fieldcat_in-no_out = ' '.

fieldcat_in-do_sum = 'X'. "SUM UPON DISPLAY

append fieldcat_in to gt_fieldcat.

  • data sorting and subtotal

data: gs_sort type slis_sortinfo_alv.

clear gs_sort.

gs_sort-tabname = 'ALV0'.

gs_sort-fieldname = 'KUNNR'.

gs_sort-spos = 1.

gs_sort-up = 'X'.

gs_sort-subtot = 'X'.

append gs_sort to gt_sort.

gs_sort-tabname = 'ALV0'.

gs_sort-fieldname = 'DOLLARS'.

gs_sort-spos = 3.

gs_sort-up = 'X'.

gs_sort-subtot = 'X'.

append gs_sort to gt_sort.

gs_sort-tabname = 'ALV0'.

gs_sort-fieldname = 'COUNT'.

gs_sort-spos = 4.

gs_sort-up = 'X'.

gs_sort-subtot = 'X'.

append gs_sort to gt_sort.

Gs_layout-cell_merge = 'X'.

*

endform. " fill_fieldcat

&----


*& Form TOP_OF_PAGE

----


form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

i_logo = 'ENJOYSAP_LOGO'

it_list_commentary = t_list_top_of_page.

endform.

.

&----


*& Form cal_no_of_orders

&----


  • text

----


  • -->P_ALV_dat text

  • -->P_ERDAT1 text

  • <--P_KUNNR text

  • <--P_GV_COUNT text

  • <--P_GV_NETWR text

  • <--P_GV_NAME1 text

----


form cal_no_of_orders tables alv_tab structure zvbpa

using p_erdat1

changing p_gv_count

p_gv_netwr.

clear: alv_tab, p_gv_count, p_gv_netwr, g_tabix, zvbak, zvbpa.

refresh: zvbak, zvbpa.

data: g_tabix like sy-tabix,

gv_index like sy-tabix.

data: av_tab like zvbpa occurs 0 with header line.

*Select Orders Processed

select vbeln erdat netwr vgbel from vbak

into corresponding fields of table zvbak where

erdat = p_erdat1 and

vkorg in s_vkorg and

auart = 'ZEDI' and

( ( bsark = 'DFUA' ) or

( bsark = 'DFUE' ) or

( bsark = 'DFUI' ) ).

if sy-subrc = 0.

clear sy-subrc .

sort zvbak by vbeln.

select vbeln parvw kunnr adrnr from vbpa

into corresponding fields of table zvbpa

for all entries in zvbak

where vbeln = zvbak-vbeln

and parvw = 'AG'.

if sy-subrc = 0.

clear zvbpa.

loop at zvbpa.

g_tabix = sy-tabix.

read table zvbak with key vbeln = zvbpa-vbeln binary search.

if sy-subrc eq 0.

move :zvbak-netwr to zvbpa-netwr,

zvbak-erdat to zvbpa-erdat.

modify zvbpa index g_tabix.

endif.

select single name1 into (p_name1 )

from adrc

where addrnumber = zvbpa-adrnr.

if sy-subrc = 0.

move p_name1 to zvbpa-name1.

modify zvbpa index g_tabix.

endif.

endloop.

endif.

endif.

  • move Processed Orders to ALV display table

clear zvbpa.

loop at zvbpa.

move-corresponding zvbpa to alv_tab.

append alv_tab.

clear alv_tab.

endloop.

endform. " cal_no_of_orders<i></i>

Message was edited by:

sap learner