Skip to Content
author's profile photo Former Member
Former Member

Display Total in ALV-List-urgent

Hi,

I have an ALV-List with an amount column...I have to show the total at the end of the list..Calculation of total can be done in the internal table but how to display it neatly just below the itab-amount with a tag Total : 29000000 .Kindly help.

Thanks..

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Posted on Dec 04, 2007 at 09:46 AM

    Renu,

    Select the field of which you want to get the total and the press ctrl+f 6 or the Summation button in the ALV tool bar.

    K.Kiran.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 09:49 AM

    see this below example

    REPORT yktest.

    &----


    *& TABLES DECLARATION *

    &----


    TABLES : ekko, ekpo, t001w, t161t, lfa1.

    &----


    *& INTERNAL TABLE DECLARATION *

    &----


    TYPES : BEGIN OF tp_itab1,

    bukrs TYPE ekko-bukrs,

    lifnr TYPE ekko-lifnr,

    ebeln TYPE ekko-ebeln,

    waers TYPE ekko-waers,

    bsart TYPE ekko-bsart,

    ekorg TYPE ekko-ekorg,

    ekgrp TYPE ekko-ekgrp,

    ebelp TYPE ekpo-ebelp,

    txz01 TYPE ekpo-txz01,

    matnr TYPE ekpo-matnr,

    werks TYPE ekpo-werks,

    menge TYPE ekpo-menge,

    meins TYPE ekpo-meins,

    netpr TYPE ekpo-netpr,

    netwr TYPE ekpo-netwr,

    name1 TYPE t001w-name1,

    header_text(132),

    chk TYPE c,

    END OF tp_itab1.

    DATA : t_itab1 TYPE STANDARD TABLE OF tp_itab1,

    wa_itab1 TYPE tp_itab1,

    ws_name1 TYPE t001w-name1.

    DATA : f_itab1 TYPE STANDARD TABLE OF tp_itab1,

    wa_fitab1 TYPE tp_itab1.

    DATA : f_itab2 TYPE STANDARD TABLE OF tp_itab1,

    wa_fitab2 TYPE tp_itab1.

    TYPES : BEGIN OF tp_name1,

    werks TYPE t001w-werks,

    name1 TYPE t001w-name1,

    END OF tp_name1.

    DATA : t_name1 TYPE STANDARD TABLE OF tp_name1,

    wa_name1 TYPE tp_name1.

    DATA : t_lfa1 TYPE STANDARD TABLE OF lfa1,

    wa_lfa1 TYPE lfa1.

    DATA: hold_tabix TYPE sy-tabix.

    DATA : t_tlinetab TYPE STANDARD TABLE OF tline,

    wa_tlinetab TYPE tline.

    DATA: ws_name TYPE thead-tdname,

    ws_repid TYPE sy-repid VALUE 'YKTEST'.

    DATA : repid TYPE sy-repid.

    DATA : total TYPE p DECIMALS 2,

    quantity TYPE p DECIMALS 3.

    CONSTANTS : ws_id TYPE thead-tdid VALUE 'F01',

    ws_object TYPE thead-tdobject VALUE 'EKKO',

    lc_view(1) TYPE c VALUE 'F',

    lc_form(10) TYPE c VALUE 'YK_FORM'.

    &----


    *& ALV DECLARATION *

    &----


    TYPE-POOLS : slis.

    DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,

    lf_fieldcat TYPE slis_fieldcat_alv.

    DATA: lh_index LIKE lf_fieldcat-col_pos.

    DATA: l_layout TYPE slis_layout_alv.

    DATA : l_sort TYPE slis_t_sortinfo_alv,

    w_sort TYPE slis_sortinfo_alv.

    &----


    *& SELECTION-SCREEN *

    &----


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

    SELECTION-SCREEN SKIP 2.

    SELECT-OPTIONS: s_bukrs FOR ekko-bukrs OBLIGATORY.

    SELECT-OPTIONS: s_lifnr FOR ekko-lifnr OBLIGATORY.

    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.

    PARAMETERS: p_bsart TYPE ekko-bsart.

    SELECT-OPTIONS: s_matnr FOR ekpo-matnr.

    SELECT-OPTIONS: s_ekorg FOR ekko-ekorg.

    SELECT-OPTIONS: s_ekgrp FOR ekko-ekgrp.

    SELECTION-SCREEN SKIP 2.

    SELECTION-SCREEN END OF BLOCK a1.

    &----


    *& START-OF-SELECTION *

    &----


    START-OF-SELECTION.

    • FETCHING DATA

    PERFORM fetch_data.

    • BUILD FIELD CATALOG

    PERFORM build_fieldcatalog.

    • BUILD LAYOUT

    PERFORM build_layout.

    • SORT LAYOUT

    PERFORM sort_layout.

    &----


    *& END-OF-SELECTION. *

    &----


    END-OF-SELECTION.

    *DISPLAY GRID

    PERFORM display_grid.

    &----


    *& Form fetch_data *

    &----


    FORM fetch_data.

    IF p_bsart IS INITIAL.

    SELECT ekko~bukrs

    ekko~lifnr

    ekko~ebeln

    ekko~waers

    ekko~bsart

    ekko~ekorg

    ekko~ekgrp

    ekpo~ebelp

    ekpo~txz01

    ekpo~matnr

    ekpo~werks

    ekpo~menge

    ekpo~meins

    ekpo~netpr

    ekpo~netwr

    INTO TABLE t_itab1 FROM

    ekko INNER JOIN ekpo ON ekkoebeln = ekpoebeln

    WHERE ekko~ebeln IN s_ebeln AND

    ekko~bukrs IN s_bukrs AND

    ekko~lifnr IN s_lifnr AND

    ekko~ekorg IN s_ekorg AND

    ekko~ekgrp IN s_ekgrp AND

    ekpo~matnr IN s_matnr.

    ELSE.

    SELECT ekko~bukrs

    ekko~lifnr

    ekko~ebeln

    ekko~waers

    ekko~bsart

    ekko~ekorg

    ekko~ekgrp

    ekpo~ebelp

    ekpo~txz01

    ekpo~matnr

    ekpo~werks

    ekpo~menge

    ekpo~meins

    ekpo~netpr

    ekpo~netwr

    INTO TABLE t_itab1 FROM

    ekko INNER JOIN ekpo ON ekkoebeln = ekpoebeln

    WHERE ekko~ebeln IN s_ebeln AND

    ekko~bukrs IN s_bukrs AND

    ekko~lifnr IN s_lifnr AND

    ekko~ekorg IN s_ekorg AND

    ekko~ekgrp IN s_ekgrp AND

    ekpo~matnr IN s_matnr AND

    ekko~bsart = p_bsart.

    ENDIF.

    IF NOT t_itab1[] IS INITIAL.

    • FETCHING NAME1

    SELECT werks

    name1

    FROM t001w

    INTO TABLE t_name1

    FOR ALL ENTRIES IN t_itab1

    WHERE werks = t_itab1-werks.

    SORT t_itab1 BY werks.

    SORT t_name1 BY werks.

    IF sy-subrc = 0.

    LOOP AT t_itab1 INTO wa_itab1.

    hold_tabix = sy-tabix.

    READ TABLE t_name1 INTO wa_name1 WITH KEY werks = wa_itab1-werks

    BINARY SEARCH.

    IF sy-subrc = 0.

    wa_itab1-name1 = wa_name1-name1.

    MODIFY t_itab1 INDEX hold_tabix FROM wa_itab1.

    ENDIF.

    • FETCHING HEADER TEXT

    MOVE wa_itab1-ebeln TO ws_name.

    CALL FUNCTION 'READ_TEXT'

    EXPORTING

    id = ws_id

    language = sy-langu

    name = ws_name

    object = ws_object

    TABLES

    lines = t_tlinetab

    EXCEPTIONS

    id = 1

    language = 2

    name = 3

    not_found = 4

    object = 5

    reference_check = 6

    wrong_access_to_archive = 7

    OTHERS = 8.

    IF sy-subrc = 0.

    LOOP AT t_tlinetab INTO wa_tlinetab.

    wa_itab1-header_text = wa_tlinetab-tdline.

    MODIFY t_itab1 FROM wa_itab1.

    ENDLOOP.

    ENDIF. " IF sy-subrc = 0.

    CLEAR : wa_itab1,

    hold_tabix,

    wa_name1.

    ENDLOOP.

    ENDIF.

    ENDIF. " IF NOT t_itab1[] IS INITIAL.

    IF t_itab1[] IS INITIAL.

    MESSAGE i000(zg) WITH text-008.

    ENDIF.

    SORT : t_itab1 BY bukrs lifnr ebeln ebelp.

    ENDFORM. " fetch_data

    &----


    *& Form build_fieldcatalog *

    &----


    FORM build_fieldcatalog .

    • COMPANY CODE

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'BUKRS'.

    lf_fieldcat-ref_tabname = 'EKKO'.

    lf_fieldcat-ref_fieldname = 'BUKRS'.

    lf_fieldcat-fix_column = 'X'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • VENDOR

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'LIFNR'.

    lf_fieldcat-ref_tabname = 'EKKO'.

    lf_fieldcat-ref_fieldname = 'LIFNR'.

    lf_fieldcat-fix_column = 'X'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • PURCHASING DOCUMENT NUMBER

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'EBELN'.

    lf_fieldcat-ref_tabname = 'EKKO'.

    lf_fieldcat-ref_fieldname = 'EBELN'.

    • lf_fieldcat-key = 'X'.

    lf_fieldcat-do_sum = 'X'.

    lf_fieldcat-fix_column = 'X'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • ITEM NUMBER OF PURCHASING DOCUMENT

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'EBELP'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'EBELP'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • SHORT TEXT

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'TXZ01'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'TXZ01'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • MATERIAL NUMBER

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'MATNR'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'MATNR'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • PLANT

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'WERKS'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'WERKS'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • NAME

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'NAME1'.

    lf_fieldcat-ref_tabname = 'T001W'.

    lf_fieldcat-ref_fieldname = 'NAME1'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • PURCHASE ORDER QUANTITY

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'MENGE'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'MENGE'.

    lf_fieldcat-do_sum = 'X'.

    lf_fieldcat-qfieldname = 'MEINS'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • UNIT

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'MEINS'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'MEINS'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • NET PRICE IN PURCHASING DOCUMENT

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'NETPR'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'NETPR'.

    lf_fieldcat-cfieldname = 'WAERS'.

    lf_fieldcat-do_sum = 'X'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • NET ORDER VALUE IN PO CURRENCY

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'NETWR'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'NETWR'.

    lf_fieldcat-cfieldname = 'WAERS'.

    lf_fieldcat-do_sum = 'X'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • CURRENCY

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'WAERS'.

    lf_fieldcat-ref_tabname = 'EKKO'.

    lf_fieldcat-ref_fieldname = 'WAERS'.

    APPEND lf_fieldcat TO lt_fieldcat.

    • HEADER TEXT

    CLEAR lf_fieldcat.

    lf_fieldcat-fieldname = 'HEADER_TEXT'.

    lf_fieldcat-seltext_m = 'Header Text'.

    APPEND lf_fieldcat TO lt_fieldcat.

    ENDFORM. " build_fieldcatalog

    &----


    *& Form display_grid *

    &----


    FORM display_grid.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = ws_repid

    i_callback_pf_status_set = 'PF_STATUS'

    i_callback_user_command = 'USER_COMMAND'

    is_layout = l_layout

    it_fieldcat = lt_fieldcat

    it_sort = l_sort

    i_save = 'X'

    • IMPORTING

    TABLES

    t_outtab = t_itab1

    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_grid

    &----


    *& Form build_layout *

    &----


    FORM build_layout .

    l_layout-colwidth_optimize = 'X'.

    l_layout-zebra = 'X'.

    l_layout-box_fieldname = 'CHK'.

    l_layout-box_tabname = 'T_ITAB1' .

    ENDFORM. " build_layout

    &----


    *& Form sort_layout *

    &----


    FORM sort_layout .

    CLEAR w_sort.

    w_sort-fieldname = 'BUKRS'.

    w_sort-tabname = 'T_ITAB1'.

    w_sort-spos = 1.

    w_sort-up = 'X'.

    w_sort-subtot = 'X'.

    APPEND w_sort TO l_sort.

    CLEAR w_sort.

    w_sort-fieldname = 'EBELN'.

    w_sort-tabname = 'T_ITAB1'.

    w_sort-spos = 1.

    w_sort-up = 'X'.

    w_sort-subtot = 'X'.

    APPEND w_sort TO l_sort.

    ENDFORM. " sort_layout

    &----


    *& Form PF_STATUS

    &----


    FORM pf_status USING rt_extab TYPE slis_t_extab.

    SET PF-STATUS 'STANDARD1' EXCLUDING rt_extab.

    ENDFORM. " PF_STATUS

    &----


    *& Form user_command

    &----


    FORM user_command USING s_ucomm TYPE sy-ucomm

    rs_selfield TYPE slis_selfield.

    CLEAR wa_itab1.

    READ TABLE t_itab1 INTO wa_itab1 INDEX rs_selfield-tabindex.

    CASE s_ucomm.

    WHEN 'POD'.

    SET PARAMETER ID 'BES' FIELD wa_itab1-ebeln.

    CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.

    CLEAR wa_itab1.

    WHEN 'MAT'.

    SET PARAMETER ID 'MAT' FIELD wa_itab1-matnr.

    CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

    WHEN '&IC1'.

    IF rs_selfield-fieldname = 'MATNR'.

    SET PARAMETER ID 'MAT' FIELD wa_itab1-matnr.

    CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

    ELSEIF rs_selfield-fieldname = 'EBELN'.

    SET PARAMETER ID 'BES' FIELD wa_itab1-ebeln.

    CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.

    ENDIF.

    WHEN 'PRINT'.

    PERFORM multiple_sel.

    PERFORM call_form.

    CLEAR : f_itab1, f_itab2.

    WHEN 'SMART'.

    PERFORM multiple_sel.

    PERFORM call_smartform.

    ENDCASE.

    ENDFORM. "user_command

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 09:54 AM

    wa_fieldcat-do_sum = 'X'.

    Thanks,

    Sankar M

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 09:56 AM

    just use this in field catalog.

    line_fieldcat-fieldname = 'PRD12'.

    line_fieldcat-seltext_m = '331-365'.

    line_fieldcat-col_pos = 19.

    line_fieldcat-outputlen = 12.

    line_fieldcat-hotspot = 'X'.

    line_fieldcat-do_sum = 'X'.

    append line_fieldcat to fieldcatalog.

    clear line_fieldcat.

    plz reward point sif helps.

    regards,

    rahul

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 09:56 AM

    Hi Renu,

    I was also facing the same problem which u have mentioned.Below is the simple ALV code ,in which i have sumed the total net price .

    Only change to be made is in the fieldcatalog where u want the amount to be sumed.Just add this field

    lf_fieldcat-do_sum = 'X'.

    below is the sample code.JUst copy paste and run on your system ,it will show the net price sumed.For logic make change in fieldcatalog as mentioned above

    Please do reward if useful

    Thankx.

    report zhalv2.

    tables:ekpo.

    *data itab_ekpo type ekpo occurs 100 with header line.

    types: begin of itab_new,

    ebeln type ekpo-ebeln,

    matnr type ekpo-matnr,

    netpr type ekpo-netpr,

    end of itab_new.

    data itab1 type standard table of itab_new initial size 0.

    type-pools: slis.

    data: lt_fieldcat type slis_t_fieldcat_alv, lf_fieldcat type slis_fieldcat_alv.

    data: ws_repid type sy-repid value 'ZHALV2'.

    selection-screen begin of block block1 with frame title text-111.

    select-options : s_ebeln for ekpo-ebeln.

    selection-screen end of block block1.

    initialization.

    start-of-selection.

    select ebeln matnr netpr from ekpo into table itab1 up to 10 rows where ebeln in s_ebeln.

    perform build_fieldcatalog.

    perform get_details.

    end-of-selection.

    &----


    *& Form build_fieldcatalog

    &----


    • text

    ----


    form build_fieldcatalog .

    • PURCHASING DOCUMENT NUMBER

    clear lf_fieldcat.

    lf_fieldcat-fieldname = 'EBELN'.

    lf_fieldcat-ref_tabname = 'EKKO'.

    lf_fieldcat-ref_fieldname = 'EBELN'.

    append lf_fieldcat to lt_fieldcat.

    • MATERIAL NUMBER

    clear lf_fieldcat.

    lf_fieldcat-fieldname = 'MATNR'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'MATNR'.

    append lf_fieldcat to lt_fieldcat.

    • NET PRICE IN PURCHASING DOCUMENT

    clear lf_fieldcat.

    lf_fieldcat-fieldname = 'NETPR'.

    lf_fieldcat-ref_tabname = 'EKPO'.

    lf_fieldcat-ref_fieldname = 'NETPR'.

    *lf_fieldcat-cfieldname = 'WAERS'.

    lf_fieldcat-do_sum = 'X'.

    append lf_fieldcat to lt_fieldcat.

    endform. " build_fieldcatalog

    &----


    *& Form GET_DETAILS

    &----


    • text

    ----


    form get_details.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_callback_program = ws_repid

    it_fieldcat = lt_fieldcat

    tables

    t_outtab = itab1

    exceptions

    program_error = 1

    others = 2.

    .

    if sy-subrc <> 0.

    write: 'SY-SUBRC: ', sy-subrc .

    endif.

    endform.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 10:25 AM

    in ur coding add this

    fieldcatalog-do_sum = 'X'.

    like this

    fieldcatalog-fieldname = 'G_MENGE'.

    fieldcatalog-seltext_m = 'Qty Inv W.Time'.

    fieldcatalog-col_pos = 11.

    <b> fieldcatalog-do_sum = 'X'.</b>

    APPEND fieldcatalog TO fieldcatalog.

    CLEAR fieldcatalog.

    fieldcatalog-fieldname = 'G_INVAL'.

    fieldcatalog-seltext_m = 'Val Inv W.Time'.

    fieldcatalog-col_pos = 12.

    <b> fieldcatalog-do_sum = 'X'.</b>

    APPEND fieldcatalog TO fieldcatalog.

    CLEAR fieldcatalog.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 11:16 AM

    Hi,

    While building the fieldcatalog, you have use do_sum = 'X' for the field for which you need to have summation.

    Thanks,

    Sriram Ponna.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 11:26 AM

    u can use this logic for total.

    l_wa_fieldcat-do_sum = 'X'.

    WHEN 'ANSW_GJA'.

    l_wa_fieldcat-do_sum = 'X'.

    WHEN 'ZDIFF'.

    l_wa_fieldcat-do_sum = 'X'.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.