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

ALV total

Former Member
0 Likes
926

hi gurus,

Kindly help me on how to display the total using ALV list. Below is my code, I've used already the DO_SUM in the field where i want to get the total but it still doesn't work...

Kindly help me with this points will be awarded to helpful advice.

type-pools: slis.

tables: zstore_prod, zprod_stan.

types: begin of itab,

prodnum like zstore_prod-prodnum,

prodname like zstore_prod-prodname,

prodmanuf like zstore_prod-prodmanuf,

class like zstore_prod-class,

mandat like zprod_stan-mandat,

typpak like zprod_stan-typpak,

tprc like zmytable-tprc,

LINE_COLOR(4) TYPE C,

end of itab.

data: t_tab type standard table of itab initial size 0,

wa_tab type itab.

data: GD_LAYOUT TYPE SLIS_LAYOUT_ALV,

GD_REPID TYPE SY-REPID,

fieldcat type slis_fieldcat_alv,

t_fieldcat type slis_t_fieldcat_alv.

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

select-options: prodnum for zstore_prod-prodnum.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

PERFORM DATA_RETRIEVAL.

PERFORM BLD_FLDCAT.

PERFORM BDL_LAYOUT.

PERFORM DISPLAY_ALV_REPORT.

FORM BLD_FLDCAT.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'PRODNUM'.

fieldcat-seltext_l = 'Product Number'.

fieldcat-col_pos = 1.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'PRODNAME'.

fieldcat-seltext_l = 'Product Name'.

fieldcat-col_pos = 2.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'PRODMANUF'.

fieldcat-seltext_l = 'Product Manufacturer'.

fieldcat-col_pos = 3.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'CLASS'.

fieldcat-seltext_l = 'Product Class'.

fieldcat-col_pos = 4.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'MANDAT'.

fieldcat-seltext_l = 'Product Manufacturing Date'.

fieldcat-col_pos = 5.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'TYPPAK'.

fieldcat-seltext_l = 'Product Type of Packaging'.

fieldcat-col_pos = 6.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'TPRC'.

fieldcat-seltext_l = 'Total Price'.

fieldcat-do_sum = 'X'.

fieldcat-col_pos = 7.

append fieldcat to t_fieldcat.

ENDFORM.

FORM BDL_LAYOUT.

GD_LAYOUT-NO_INPUT = 'X'.

GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

GD_LAYOUT-WINDOW_TITLEBAR = 'LIST DISPLAY'.

GD_LAYOUT-CONFIRMATION_PROMPT = 'X'.

ENDFORM.

FORM DATA_RETRIEVAL.

data: LD_COLOR(1) type c.

select aprodnum aprodname aprodmanuf aclass bmandat btyppak

c~tprc from zstore_prod as a left outer join zprod_stan as b on

aprodnum = bprodnum inner join zmytable as c on a~prodnum =

cprodnum into table t_tab where aprodnum in prodnum.

LOOP AT t_tab INTO wa_tab.

LD_COLOR = LD_COLOR + 1.

IF LD_COLOR = 3.

LD_COLOR = 1.

ENDIF.

CONCATENATE 'C' LD_COLOR '10' INTO wa_tab-LINE_COLOR.

MODIFY t_tab FROM wa_tab.

ENDLOOP.

ENDFORM.

FORM DISPLAY_ALV_REPORT.

GD_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = GD_REPID

I_CALLBACK_TOP_OF_PAGE = slis_ev_top_of_page

IS_LAYOUT = GD_LAYOUT

IT_FIELDCAT = t_fieldcat

TABLES

T_OUTTAB = t_tab.

ENDFORM.

FORM top_of_page.

data: 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.

wa_header-typ = 'H'.

wa_header-info = 'My First ALV Program'.

append wa_header to header.

wa_header-typ = 'A'.

wa_header-info = 'Date:'.

CONCATENATE sy-datum6(2)'/' sy-datum4(2)'/' sy-datum(4) into

wa_header-info.

append wa_header to header.

describe table t_tab lines ld_lines.

ld_linesc = ld_lines.

CONCATENATE 'Total Nos. of Record:' ld_linesc into

t_line separated by space.

wa_header-typ = 'A'.

wa_header-info = t_line.

append wa_header to header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = header.

  • i_logo = 'ENJOYSAP_LOGO'.

*

ENDFORM.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
902

Hi,

You have add another statemet as datatype:

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'TPRC'.

fieldcat-seltext_l = 'Total Price'.

fieldcat-do_sum = 'X'.

fieldcat_datatype = 'CURR'

fieldcat-col_pos = 7.

append fieldcat to t_fieldcat.

Thanks,

Sriram Ponna.

hi gurus,

Kindly help me on how to display the total using ALV list. Below is my code, I've used already the DO_SUM in the field where i want to get the total but it still doesn't work...

Kindly help me with this points will be awarded to helpful advice.

type-pools: slis.

tables: zstore_prod, zprod_stan.

types: begin of itab,

prodnum like zstore_prod-prodnum,

prodname like zstore_prod-prodname,

prodmanuf like zstore_prod-prodmanuf,

class like zstore_prod-class,

mandat like zprod_stan-mandat,

typpak like zprod_stan-typpak,

tprc like zmytable-tprc,

LINE_COLOR(4) TYPE C,

end of itab.

data: t_tab type standard table of itab initial size 0,

wa_tab type itab.

data: GD_LAYOUT TYPE SLIS_LAYOUT_ALV,

GD_REPID TYPE SY-REPID,

fieldcat type slis_fieldcat_alv,

t_fieldcat type slis_t_fieldcat_alv.

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

select-options: prodnum for zstore_prod-prodnum.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

PERFORM DATA_RETRIEVAL.

PERFORM BLD_FLDCAT.

PERFORM BDL_LAYOUT.

PERFORM DISPLAY_ALV_REPORT.

FORM BLD_FLDCAT.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'PRODNUM'.

fieldcat-seltext_l = 'Product Number'.

fieldcat-col_pos = 1.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'PRODNAME'.

fieldcat-seltext_l = 'Product Name'.

fieldcat-col_pos = 2.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'PRODMANUF'.

fieldcat-seltext_l = 'Product Manufacturer'.

fieldcat-col_pos = 3.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'CLASS'.

fieldcat-seltext_l = 'Product Class'.

fieldcat-col_pos = 4.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'MANDAT'.

fieldcat-seltext_l = 'Product Manufacturing Date'.

fieldcat-col_pos = 5.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'TYPPAK'.

fieldcat-seltext_l = 'Product Type of Packaging'.

fieldcat-col_pos = 6.

append fieldcat to t_fieldcat.

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'TPRC'.

fieldcat-seltext_l = 'Total Price'.

fieldcat-do_sum = 'X'.

fieldcat-col_pos = 7.

append fieldcat to t_fieldcat.

ENDFORM.

FORM BDL_LAYOUT.

GD_LAYOUT-NO_INPUT = 'X'.

GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

GD_LAYOUT-WINDOW_TITLEBAR = 'LIST DISPLAY'.

GD_LAYOUT-CONFIRMATION_PROMPT = 'X'.

ENDFORM.

FORM DATA_RETRIEVAL.

data: LD_COLOR(1) type c.

select aprodnum aprodname aprodmanuf aclass bmandat btyppak

c~tprc from zstore_prod as a left outer join zprod_stan as b on

aprodnum = bprodnum inner join zmytable as c on a~prodnum =

cprodnum into table t_tab where aprodnum in prodnum.

LOOP AT t_tab INTO wa_tab.

LD_COLOR = LD_COLOR + 1.

IF LD_COLOR = 3.

LD_COLOR = 1.

ENDIF.

CONCATENATE 'C' LD_COLOR '10' INTO wa_tab-LINE_COLOR.

MODIFY t_tab FROM wa_tab.

ENDLOOP.

ENDFORM.

FORM DISPLAY_ALV_REPORT.

GD_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = GD_REPID

I_CALLBACK_TOP_OF_PAGE = slis_ev_top_of_page

IS_LAYOUT = GD_LAYOUT

IT_FIELDCAT = t_fieldcat

TABLES

T_OUTTAB = t_tab.

ENDFORM.

FORM top_of_page.

data: 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.

wa_header-typ = 'H'.

wa_header-info = 'My First ALV Program'.

append wa_header to header.

wa_header-typ = 'A'.

wa_header-info = 'Date:'.

CONCATENATE sy-datum6(2)'/' sy-datum4(2)'/' sy-datum(4) into

wa_header-info.

append wa_header to header.

describe table t_tab lines ld_lines.

ld_linesc = ld_lines.

CONCATENATE 'Total Nos. of Record:' ld_linesc into

t_line separated by space.

wa_header-typ = 'A'.

wa_header-info = t_line.

append wa_header to header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = header.

  • i_logo = 'ENJOYSAP_LOGO'.

*

ENDFORM.

7 REPLIES 7
Read only

former_member386202
Active Contributor
0 Likes
902

Hi,

Its should work, check the type of field 'TPRC' it should be quant curr .

Regards,

Prashant

Read only

0 Likes
902

hi,

what do you mean by quant. curr??

do i have to specify the currency?? since im using a custumized database table..

Read only

Former Member
0 Likes
902

hi,

see the below link is usful how to generate a alv report

www.alvrobot.ar.com

reward if it is useful

Read only

Former Member
0 Likes
902

Jose,

First Sort your fields on what base you want total.Not only

Ex: based on district or vendor like.....

DATA : wa_sort1 TYPE slis_t_sortinfo_alv,

wa_sort2 TYPE slis_sortinfo_alv.

wa_sort2-spos = '07'. " Column position

wa_sort2-up = 'X'.

wa_sort2-fieldname = 'ZZVENDOR'.

APPEND wa_sort2 TO wa_sort1.

CLEAR wa_sort2.

wa_sort2-spos = '08'. " Column position

wa_sort2-up = 'X'.

wa_sort2-subtot = 'X'.

wa_sort2-fieldname = 'TYPBZ'.

APPEND wa_sort2 TO wa_sort1.

CLEAR wa_sort2.

wa_sort2-spos = '09'. " Column position

wa_sort2-up = 'X'.

wa_sort2-subtot = 'X'.

wa_sort2-fieldname = 'DISTRICT'.

APPEND wa_sort2 TO wa_sort1.

CLEAR wa_sort2.

Then add wa_sort1 to FM

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = ws_repid

i_callback_pf_status_set = 'GUI_STAT1'

i_callback_user_command = 'STAT'

is_layout = gs_layout

it_fieldcat = i_fieldcat[]

it_sort = wa_sort1

TABLES

t_outtab = i_zaw_pol_plan.

IN preparation of fields catelog add "do_sum" to fields(Ex : vendor,district ,) on which base your are sorting and fields to which fields you want to do total(Ex : amount fields etc.)

w_fieldcat-tabname = c_tabname.

w_fieldcat-fieldname = c_fldname1.

w_fieldcat-do_sum = c_x.

Now it wil work,

Don't forget to reward if useful.......

Read only

Former Member
0 Likes
902

Hi,

Check the datatype of field 'TPRC'. It should be either 'QUANT' or 'CURR'. Then only u will get the TOTALS in ALV output.

Regards,

Srinivas Ch.

Read only

Former Member
0 Likes
903

Hi,

You have add another statemet as datatype:

fieldcat-tabname = 'ITAB'.

fieldcat-fieldname = 'TPRC'.

fieldcat-seltext_l = 'Total Price'.

fieldcat-do_sum = 'X'.

fieldcat_datatype = 'CURR'

fieldcat-col_pos = 7.

append fieldcat to t_fieldcat.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
902

Hi,

see the following code which i developed.

fieldcat1-fieldname = 'LFIMG'.

i_fieldcat1-seltext_m = 'ACTUAL QUANTITY'.

i_fieldcat1-do_sum = 'X'.

APPEND i_fieldcat1 TO i_fieldcat1.

CLEAR i_fieldcat1.

i_fieldcat1-fieldname = 'NTGEW'.

i_fieldcat1-seltext_m = 'NET WEIGHT'.

i_fieldcat1-do_sum = 'X'.

APPEND i_fieldcat1 TO i_fieldcat1.

CLEAR i_fieldcat1.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = repid

it_fieldcat = i_fieldcat1[]

i_callback_top_of_page = 'TOP_OF_PAGE'

i_callback_user_command = 'USER_COMMAND1'

it_events = i_events

TABLES

t_outtab = i_vbup1

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.

CLEAR i_vbup1.

after append the fields catalog u have to use clear statement then u have update the same into the function module..

u have to pass the above values if ur forget to pass any of above try to forward that values. u will get that sum..

if it is use full answer reward me a points..

praveen