ALV grid total  or based on two key fields

Hello experts,
I have ALV grid with  vendor, g/l account and amount field.
I want to have sum or total of each vendor, and if vendor having mutliple g/l accounts i want to have sum for each g/l account.
ex:  vendor   g/l account    amount.
        10           aa                  100
        10           bb                  200
        11           cc                   300
olp   :   10      aa   100
            10      bb   200
            11      cc   300
ex2 :   vendor g/ account   amount
           10       aa                 100
            10       aa                200
            11        cc               300
o/p       10   aa   300.
            11  cc    300.
Could you please help me and any suggestions
<<Text removed>>
Thanks
reddy.
Edited by: Matt on Jul 27, 2011 9:21 AM

Hello Reddy,
Try using the sort functionality of ALV grid
    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_save                                           = 'A'
        is_layout                                      = lwa_layout
        it_toolbar_excluding                    = i_excl_func
        i_default                                      = c_x
      CHANGING
        it_outtab                                     = i_outtab[]
        it_fieldcatalog                             = i_fieldcat[]
        it_sort                                         = li_sort[]            "use this functionality as per your requirement
      EXCEPTIONS
        invalid_parameter_combination  = 1
        program_error                            = 2
        too_many_lines                          = 3
        OTHERS                                      = 4.
Hope this may be helpful.
Sharin

Similar Messages

  • ALV grid total line customizing

    Dear Masters,
    I need a solution for my problem. I need to modify sorting of subtotal and grand total based on currency which criteria i create  myself. The standard alv output sort total by currency based on alpahabetical order, e.g: AUD,  EUR, IDR, USD. I need to change the sorting into IDR, USD, AUD, EUR. How can i do it in alv grid?
    I also like to add new line after grand total line, which is grand total in Local Currency, in this case, in IDR, which rate given. I can get the figure of subtotal, but i don't know how to append new line after grand total line output in alv standard.
    Need your suggestion.
    Many thanks,
    Tiara

    Hi,
    I have used object oriented ALV. You can remove final total line and have sub total lines. Code below can help you.
    1) Fieldcatalog you can do sum for currency values
    2) Sort Build you can have sub totals.
    3) layout_init you can remove final total line.
    4) CALL METHOD grid->set_table_for_first_display you can pass above structure for excepted Result.
    fieldcatalog_init
    FORM fieldcatalog_init USING lt_fieldcatalog TYPE lvc_t_fcat
                           value(field_name) value(field_type) value(field_text) value(field_key).
      DATA: ls_fieldcatalog TYPE lvc_s_fcat.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname = field_name.
      ls_fieldcatalog-datatype  = field_type.
      ls_fieldcatalog-reptext   = field_text.
      ls_fieldcatalog-coltext   = field_text.
      ls_fieldcatalog-seltext   = field_text.
      ls_fieldcatalog-tooltip   = field_text.
      ls_fieldcatalog-key       = field_key.
      IF field_type = 'CURR'.
        ls_fieldcatalog-do_sum    = 'X'.
      ENDIF.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ENDFORM.                    "fieldcatalog_init
    sort_build
    FORM sort_build USING lt_sort TYPE lvc_t_sort.
      DATA: ls_sort TYPE lvc_s_sort.
      ls_sort-fieldname = 'BUKRS'. "Fieldname on which to sort
      ls_sort-subtot    = 'X'.
      ls_sort-up        = 'X'.     "Sort Ascending
      APPEND ls_sort TO lt_sort.
      IF p_comp <> 'X'.
        ls_sort-fieldname = 'LIFNR'. "Fieldname on which to sort
        ls_sort-subtot    = 'X'.
        ls_sort-up        = 'X'.     "Sort Ascending
        APPEND ls_sort TO lt_sort.
      ENDIF.
      ls_sort-fieldname = 'WAERS'. "Fieldname on which to sort
      ls_sort-subtot    = 'X'.
      ls_sort-up        = 'X'.     "Sort Ascending
      APPEND ls_sort TO lt_sort.
    ENDFORM.                    "sort_build
    layout_init
    FORM layout_init USING ls_layout TYPE lvc_s_layo.
      DATA lv_date(10) TYPE c.
      WRITE sy-datum TO lv_date.
      IF p_line = 'X'.
        CONCATENATE 'Line Item wise Report as on' lv_date INTO w_string2 SEPARATED BY space.
      ELSEIF p_vend = 'X'.
        CONCATENATE 'Vendor Summary Report as on' lv_date INTO w_string2 SEPARATED BY space.
      ELSEIF p_comp = 'X'.
        CONCATENATE 'Company Summary Report as on' lv_date INTO w_string2 SEPARATED BY space.
      ENDIF.
      ls_layout-zebra      = 'X'.
      ls_layout-grid_title =  w_string2.
      ls_layout-sel_mode   = 'A'.
    ls_layout-no_merging = 'X'.
      ls_layout-cwidth_opt = 'X'.
      ls_layout-no_totline = 'X'.
      IF p_line = 'X'.
        ls_layout-ctab_fname = 'COLINFO'.
      ENDIF.
    ENDFORM.                    "layout_init
          CALL METHOD grid->set_table_for_first_display
            EXPORTING
              is_layout       = gs_layout
              is_variant      = va_layout "&see below
              i_save          = 'A'     "&see below
              i_default       = ''
            CHANGING
              it_outtab       = it_apout[]
              it_fieldcatalog = gt_fieldcatalog
              it_sort         = gt_sort.
    Edited by: Himanshu Dave on May 11, 2009 2:33 PM

  • Taking download into excel from ALV Grid - header is printing in two lines

    Hi All,
    I have a scenario where I am taking the download from ALV grid to an excel sheet. Now the header of the ALV (column names) is appearing in two lines in the downloaded excel sheet while items (records of the ALV table) are getting displayed in a single line.
    This download is taken from the standard download to local file (spreadsheet) button provided by SAP for ALVs.
    I am using function module "Reuse_alv_grid_display" for the purpose.
    Can somebody provide an idea how I can avoid the header printing in two lines and keep the length as it is.
    Thanks in Advance,
    Chandan

    Hi..
    1. Pass header name in internal table appned first line.
    2. after that pass u r data .
    3. Use  FM. WS_DOWNLOAD 
    Salil ......
    Edited by: salil chavan on Nov 26, 2008 11:07 AM

  • How to Expand ALV Grid Total Width

    I have to display 1476 characters in an ALV grid and then the users will use what they need when creating a layout.
    Problem is ALV stops after displaying 1375 (or so) characters) - any parm or action to do this (maybe in the catalog setup sent to the program?  Thanks!

    Hi Scott
    This may be a restriction ALV Grid puts. My recommendation will be that, split some fields and generate more than one rows with the same key (you should then add a new key field which will hold line numbers specific to one definite key). When you sort with ALV Grid's sort option the keys will vertically merged (if you do not turn off this feature via layout or field catalog settings). I know this is not so pretty but ALV is not intended to show that kind of stuff.
    Regards
    *--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

  • Alv grid total overflow

    hi all,
    I have an overflow error in alv total field.
    first i filled alv grid using et_table_for_first_display, again i changed itab data
    and use refresh_table_display to refresh data.
    the alv contains total fields in field catalog.... when i try to 'refresh_table_display '
    it comes an over flow error is coming and it comes every sort of records.. how can i trap this error ..??
    thanks and regards
    Jose

    Hi Anup,
    While using ALV with OOP methodology, you can create an extra row for giving the sum of any field.
    In the field catalog, there is a component named 'DO_SUM', if set, will give the total value for the field.
    In the method where you fill the field catalog , just add this component.
    eg:
    form catalog_fill changing p_field_catalog.
    data ls_fcat type lvc_s_fcat .
    ls_fcat-fieldname = 'CARRID' .
    ls_fcat-inttype = 'C' .
    ls_fcat-outputlen = '20' .
    ls_fcat-coltext = 'Carrier ID' .
    ls_fcat-web_field = 'carrid_handle'.
    ls_fcat-edit = 'X'.
    *ls_fcat-emphasize = 'C310'.   "needed for column coloring
    append ls_fcat to field_catalog .
    clear ls_fcat .
    ls_fcat-fieldname = 'FLDATE' .
    ls_fcat-ref_table = 'SFLIGHT' .
    ls_fcat-ref_table = 'FLDATE' .
    ls_fcat-outputlen = '20' .
    <b>ls_fcat-do_sum = 'X'.</b>
    ls_fcat-coltext = 'Flight Date' .
    ls_fcat-web_field = 'fldate_handle'.
    append ls_fcat to field_catalog .
    clear ls_fcat .
    ls_fcat-fieldname = 'PRICE' .
    ls_fcat-ref_table = 'SFLIGHT' .
    ls_fcat-ref_table = 'PRICE' .
    ls_fcat-outputlen = '20' .
    ls_fcat-coltext = 'Airfare' .
    append ls_fcat to field_catalog .
    endform.
    In this way, you can get the total of any field in ALV.
    Regards,
    SP.

  • ALV Grid Total Text (OOPS)

    Hi All,
    I have a simple ALV Grid Report(OOPS), I would like to give a Text for Total Row. In REUSE_ALV_GRID we have the option of giving this text, but i am not able to figure it out how to get the same in OOPS.
    Regards
    Anup

    Hi Anup,
    While using ALV with OOP methodology, you can create an extra row for giving the sum of any field.
    In the field catalog, there is a component named 'DO_SUM', if set, will give the total value for the field.
    In the method where you fill the field catalog , just add this component.
    eg:
    form catalog_fill changing p_field_catalog.
    data ls_fcat type lvc_s_fcat .
    ls_fcat-fieldname = 'CARRID' .
    ls_fcat-inttype = 'C' .
    ls_fcat-outputlen = '20' .
    ls_fcat-coltext = 'Carrier ID' .
    ls_fcat-web_field = 'carrid_handle'.
    ls_fcat-edit = 'X'.
    *ls_fcat-emphasize = 'C310'.   "needed for column coloring
    append ls_fcat to field_catalog .
    clear ls_fcat .
    ls_fcat-fieldname = 'FLDATE' .
    ls_fcat-ref_table = 'SFLIGHT' .
    ls_fcat-ref_table = 'FLDATE' .
    ls_fcat-outputlen = '20' .
    <b>ls_fcat-do_sum = 'X'.</b>
    ls_fcat-coltext = 'Flight Date' .
    ls_fcat-web_field = 'fldate_handle'.
    append ls_fcat to field_catalog .
    clear ls_fcat .
    ls_fcat-fieldname = 'PRICE' .
    ls_fcat-ref_table = 'SFLIGHT' .
    ls_fcat-ref_table = 'PRICE' .
    ls_fcat-outputlen = '20' .
    ls_fcat-coltext = 'Airfare' .
    append ls_fcat to field_catalog .
    endform.
    In this way, you can get the total of any field in ALV.
    Regards,
    SP.

  • Web Dynpro ALV grid totals

    Hi,
    I have created an application that uses a web dynpro alv grid.  I want to display totals - is there a setting that can do this automatically - if so, can you please tell me how to do this?    Thanks,

    Hi
    You can take help of following code snippet to create totals for a particular column
    Data: lr_function_settings TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
      DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
            lr_column          TYPE REF TO cl_salv_wd_column,
            lt_column type salv_wd_t_column_ref,
            ls_column type salv_wd_s_column_ref.
    Data:  lr_field_amnt type REF TO CL_SALV_WD_FIELD.
    * get reference of ALV component
      lr_salv_wd_table = wd_this->wd_cpifc_OVERVIEW_EARNED_ALV( ).
      wd_this->alv_config_table = lr_salv_wd_table->get_model( ).
    *  get function settings
      lr_function_settings ?= wd_this->alv_config_table.
    * display columns in correct order
      lr_column_settings ?= wd_this->alv_config_table.
      lt_column = lr_column_settings->get_columns( ).
      loop at lt_column into ls_column.
    CASE ls_column-id.
    when 'AMOUNT'
    * aggregate field
            CALL METHOD LR_FUNCTION_SETTINGS->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
              EXPORTING
                FIELDNAME = 'AMOUNT'
              RECEIVING
                VALUE     = lr_field_amnt.
    * create aggregate rule as total
            CALL METHOD LR_FIELD_AMNT->IF_SALV_WD_AGGR~CREATE_AGGR_RULE
              EXPORTING
                AGGREGATION_TYPE = IF_SALV_WD_C_AGGREGATION=>AGGRTYPE_TOTAL
              RECEIVING
                VALUE            = lv_aggr_rule.
    endcase.
    Regards
    Manas DUa

  • ALV Output - Need to show count of line items based on 1 key field.

    Hi All,
           In my prog i need to show an ALV ouput which is having Matnr,Material type and Division . MATNR is the key field. I need to show how many line items are present against a  particular MATNR in that ALV ouput itself. Not in the top of page. I think there might be some field in SLIS which can be use for the same. If any one has come across such a requirement then please revert back.
    thanx,
    Shyam.
    PS: Useful answers will be rewarded.

    Ok, so we are back to using the COUNT field and now using the SORT functionaity, the SORT will allow us to subtotal by MATNR.
    REPORT  zrich_0001.
    * Global ALV Data Declarations
    TYPE-POOLS: slis.
    * Internal Tables
    TYPES: BEGIN OF talv ,
           matnr TYPE mara-matnr,
           mtart TYPE mara-mtart,
           spart TYPE mara-spart,
           count TYPE i,
           END OF talv.
    DATA: ialv TYPE TABLE OF talv WITH HEADER LINE.
    DATA: fieldcat  TYPE slis_t_fieldcat_alv.
    DATA: sort     TYPE slis_t_sortinfo_alv.
    DATA: layout    TYPE slis_layout_alv.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM call_alv.
    *      Form  GET_DATA
    FORM get_data.
      SELECT matnr mtart spart INTO TABLE ialv
                FROM mara UP TO 500 ROWS.
    ENDFORM.                    "GET_DATA
    *  CALL_ALV
    FORM call_alv.
      PERFORM build_field_catalog.
      PERFORM build_sort.
      layout-countfname = 'COUNT'.              "<-----  HERE
    * Call ABAP List Viewer (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_sort     = sort
          is_layout   = layout
          it_fieldcat = fieldcat
        TABLES
          t_outtab    = ialv.
    ENDFORM.                    "CALL_ALV
    * BUILD_FIELD_CATALOG
    FORM build_field_catalog.
      CLEAR: fieldcat. REFRESH: fieldcat.
      DATA: tmp_fc TYPE slis_fieldcat_alv.
      tmp_fc-reptext_ddic = 'Material'.
      tmp_fc-fieldname    = 'MATNR'.
      tmp_fc-tabname      = 'IALV'.
      tmp_fc-outputlen    = '18'.
      APPEND tmp_fc TO fieldcat.
      tmp_fc-reptext_ddic = 'Material Type'.
      tmp_fc-fieldname    = 'MTART'.
      tmp_fc-tabname      = 'IALV'.
      tmp_fc-outputlen    = '4'.
      APPEND tmp_fc TO fieldcat.
      tmp_fc-reptext_ddic = 'Division'.
      tmp_fc-fieldname    = 'SPART'.
      tmp_fc-tabname      = 'IALV'.
      tmp_fc-outputlen    = '2'.
      APPEND tmp_fc TO fieldcat.
      tmp_fc-reptext_ddic = 'Count'.
      tmp_fc-fieldname    = 'COUNT'.
      tmp_fc-tabname      = 'IALV'.
      tmp_fc-outputlen    = '5'.
      tmp_fc-do_Sum       = 'X'.
      append tmp_fc to fieldcat.
    ENDFORM.                    "build_field_catalog
    *&      Form  build_sort
    *       text
    FORM build_sort.
      DATA: tmp_sort TYPE LINE OF slis_t_sortinfo_alv.
      CLEAR sort. REFRESH sort.
      CLEAR tmp_sort.
      tmp_sort-fieldname = 'MATNR'.
      tmp_sort-tabname   = 'IALV'.
      tmp_sort-up        = 'X'.
      tmp_sort-subtot    = 'X'.
      APPEND tmp_sort TO sort.
    ENDFORM.                    "build_sort
    Regards,
    Rich Heilman

  • ALV Grid Totals Issue

    Hi,
    We are using REUSE_ALV_GRID_DISPLAY for diaplying grid . we want the totals to be displayed for some fields.
    but for percentage fields we want to calculate the values. How do we do this?

    Hi Asharaghu,
    FOR TOTAL:
    there is a property of fieldcatalog, that is do_sum.
    USE COED LIKE:
    PERFORM fieldcat USING:
    '1' 'KUNNR' 'I_MARD' 'CUSTOMER NO' ,
    '2' 'DMBTR' 'I_MARD' 'CURRENCY' ,
    FORM fieldcat USING value(p_0029)
    value(p_0030)
    value(p_0031)
    value(p_0032)
    wa_fieldcat-col_pos = p_0029.
    wa_fieldcat-fieldname = p_0030.
    wa_fieldcat-tabname = p_0031.
    wa_fieldcat-reptext = p_0032.
    wa_fieldcat-do_sum = 'X'.
    APPEND wa_fieldcat TO i_fieldcat.
    ENDFORM. " FIELDCAT
    Then pass i_fieldcat through REUSE_ALV_GRID_DISPLAY.
    in final output you will get the total of currency field.
    Hope this can solve your problems.
    Regards,
    Tutun

  • ALV print problems for reports with two sort fields and subtotal at each

    When a report has two sort fields and subtotal at each of them, the print function is not working correctly. Please see the report below.
    The second "" (single star) record (the 10 RL record) and the '*' (double star) record (the 12 RL record)  are not printing.
    This is happening for any standard SAP reports. Any resolution? Any OSS Notes?
         Material/Stock Code          Grade       Units Count     Unit Type     Set Position     LFT
         520085V000          7818     1     RL     A     19,682 LF
         520085V000          7818     1     RL     A     19,682 LF
    *     520085V000               2     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000          7717     1     RL     A     36,167 LF
    *     599098V000               10     RL          
    **                    12     RL          
    ***                    12               
    Thanks
    Anand
    Edited by: Anand Velayudhan on Feb 9, 2009 11:50 PM

    Hi,
    Check these OSS Notes..
    Note 975777 - ALV total: Subtotals disappear from printout
    Note 1039655 - ALV total: Subtotals disappear from printout II
    Thanks
    Naren

  • New Z-table to auto-populate description based on the key field entered

    Hi Gurus,
    I have to created a z-table, there are several fields however I am interested in only two
    1) VSTEL and 2) PADEST for shipping point and the printer name. Also there are two other fields I have added to the table that are the descriptions for VSTEL and PADEST. Now the requirement is that when the user enteres a value in table maintenance ( sm30)
    for say VSTEL, then its description should auto populate or propose the right values. Same should happen for the PADEST and its description field.
    Thanks.

    Goto the Table maintenance generator of the Table.
    On this screen.
    Environment -
    > Modification -
    > Events
    Create New entry in the table with T = 05 and Z <any name>
    Save it.
    An editor button appears next to the from name.
    Click on it and create an include.
    Write your code in this include...
    select vstel
           padest
           from table XXXX into table I_XXXX
           where vstel = (Z_VSTEL)User enterd VSTEL in module pool.
    If sy-subrc = 0.
          loop at I_XX into wa_xxx.      
              if wa_xxx-vstel = Z_vstel.
                z_padest(Desc field in Tab maint) = wa_XXX-PADEST.  
              endif.
          endloop.
    endif.
    The same logic can be used to get the desc for VSTEL and PDEST.
    You can change this in many ways based on performance.
    The above code is just to give an idea...
    Regards,
    Kittu

  • How to trigging a object event which the object type has two key fields

    Hi,kind guys
    I use the object type QMSM about qualification notification task,it has two key fiedls,qualification notification number and task number (can display by t-code -QM03), I want to trigging the event 'create' in  BOR 'QMSM ' by function SWE_EVENT_CREATE(or SAP_WAPI_event_create), but it only has one object key ,
    example:
    CALL FUNCTION 'SWE_EVENT_CREATE'
      EXPORTING
        OBJTYPE                       =  OBJTYPE
        OBJKEY                        =  OBJKEY " only one key
        EVENT                         =   EVENT
    but the BOR object 'QMSM' has two keys,so it cann't be trigged rightly.
    thanks for any help.

    You have to Concatenate the Business object keys and pass it in one variable OBJKEY.
    Thanks
    Arghadip

  • ALV-GRID TOTAL

    Hi Experts,
    i have issue were in i need to show sum of the amount. like example...
    for Custmer 100 there are vendor number 10,20,30,40,50. so for all this vendor numbers..
    vendor-----  amount
    10 -
       100
    20----
    200
    30----
    300
    40----
    400
    50-------500
    so in the output i want it to be..
    customer--vendornumber--
    amount
       1000--10--
    1500
    20---
    30---
    40---
    50---
    .hope u experts have undestood. so how can i add the it and show it in the output....
    am  forwarding my code also..
    Corrects answers will be fully rewarded..
    REPORT  zrfi007 NO STANDARD PAGE HEADING LINE-SIZE 255 MESSAGE-ID z01.
    TYPE-POOLS: slis, abap.
    * TYPES Declaration
    TYPES: BEGIN OF ty_lfa1,
          lifnr TYPE lfa1-lifnr,
          name1 TYPE lfa1-name1,
          END OF ty_lfa1.
    TYPES:  BEGIN OF ty_bsik,
             bukrs  TYPE    bsik-bukrs,
             lifnr  TYPE    bsik-lifnr,
             belnr  TYPE    bsik-belnr,
             bldat  TYPE    bsik-bldat,
             waers  TYPE    bsik-waers,
             dmbtr  TYPE    bsik-dmbtr,
             wrbtr  TYPE    bsik-wrbtr,
              zfbdt TYPE    bsik-zfbdt,
             zbd1t  TYPE    bsik-zbd1t,
            zbd2t   TYPE    bsik-zbd2t,
            zbd3t   TYPE    bsik-zbd3t,
           END OF ty_bsik.
    TYPES: BEGIN OF ty_lfb1,
           lifnr TYPE lfb1-lifnr,
           bukrs TYPE lfb1-bukrs,
           END OF ty_lfb1.
    TYPES: BEGIN OF ty_final,
             bukrs  TYPE    bsik-bukrs,
             lifnr  TYPE    bsik-lifnr,
             belnr  TYPE    bsik-belnr,
             bldat  TYPE    bsik-bldat,
             days   TYPE    sy-datum,
             waers  TYPE    bsik-waers,
             dmbtr  TYPE    bsik-dmbtr,
    *         waers  type    bsik-waers,
             wrbtr  TYPE    bsik-wrbtr,
             zfbdt  TYPE    bsik-zfbdt,
             zbd1t  TYPE    bsik-zbd1t,
             zbd2t  TYPE    bsik-zbd2t,
             zbd3t  TYPE    bsik-zbd3t,
             name1  TYPE    lfa1-name1,
             current  TYPE    bsik-dmbtr,
            d30     TYPE    bsik-dmbtr,
            d60     TYPE    bsik-dmbtr,
            d90     TYPE    bsik-dmbtr,
            d120    TYPE    bsik-dmbtr,
            d180    TYPE    bsik-dmbtr,
            d240    TYPE    bsik-dmbtr,
            d360    TYPE    bsik-dmbtr,
            da365   TYPE    bsik-dmbtr,
    *        ct_date TYPE  sy-datum,
    *         date   TYPE datum,
    *         days  TYPE char8,
           END OF ty_final.
    * Data Declaration.
    DATA: gt_lfa1 TYPE STANDARD TABLE OF ty_lfa1,
          wa_lfa1 TYPE ty_lfa1.
    DATA: gt_final TYPE STANDARD TABLE OF ty_final,
          wa_final TYPE ty_final.
    DATA: gt_bsik TYPE STANDARD TABLE OF ty_bsik,
          wa_bsik TYPE ty_bsik.
    DATA: gt_lfb1 TYPE STANDARD TABLE OF ty_lfb1,
          wa_lfb1 TYPE ty_lfb1.
    DATA:   days        TYPE sy-datum.
    * ALV Components
    **** ALV Internal Table
    DATA : i_layout     TYPE slis_layout_alv OCCURS 0 WITH HEADER LINE,
           i_events     TYPE slis_t_event,
           i_fieldcat   TYPE slis_t_fieldcat_alv,
           i_print      TYPE slis_print_alv,
           i_list_top   TYPE slis_t_listheader,
           i_list_end   TYPE slis_t_listheader,
           i_sort       TYPE slis_t_sortinfo_alv.
    DATA:  wa_fieldcat  LIKE LINE OF i_fieldcat.
    * ALV Variable.
    DATA: v_top        TYPE slis_formname VALUE 'TOP_OF_PAGE',
          v_eop        TYPE slis_formname VALUE 'END_OF_PAGE',
          v_eol        TYPE slis_formname VALUE 'END_OF_LIST',
          v_tol        TYPE slis_formname VALUE 'TOP_OF_LIST'.
    **** ALV Variants
    DATA: i_variant      LIKE disvariant.
    * Selection screen
    DATA: v_bukrs TYPE bukrs,
          v_lifnr TYPE kunnr,
          pa_bldat TYPE bldat.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_bukrs FOR v_bukrs NO INTERVALS NO-EXTENSION OBLIGATORY,
                    s_lifnr FOR v_lifnr.
    *                bldat FOR v_bldat no-extension.
    PARAMETERS: p_bldat TYPE  bsik-bldat.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN SKIP 2.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS: p_detail RADIOBUTTON GROUP r1 DEFAULT 'X',
                p_sumry RADIOBUTTON GROUP r1.
    SELECTION-SCREEN END OF BLOCK b2.
    *  Top-Of-Page Declaration Header
    DATA: lwa_list_top LIKE LINE OF i_list_top.
    DATA: lv_header(70),
          lv_text(50),
          lv_text1(60),
          lv_text2(50),
          lv_text3(50) ,
          lv_text4(50),
          lv_date TYPE char10,
          lv_time TYPE char10.
    DATA: lv_butxt LIKE t001-butxt,
          lv_butxt1 LIKE lfa1-name1,
          lv_butxt2 LIKE lfb1-lifnr.
    INITIALIZATION.
    *TOP-OF-PAGE.
    * Validations for Selection screen
    AT SELECTION-SCREEN ON s_bukrs.
      IF NOT s_bukrs[] IS INITIAL.
        SELECT SINGLE bukrs FROM lfb1
         INTO s_bukrs
        WHERE bukrs IN s_bukrs.
      ENDIF.
      IF sy-subrc NE 0.
        MESSAGE e003.
      ENDIF.
    AT SELECTION-SCREEN ON s_lifnr.
      IF NOT s_lifnr[] IS INITIAL.
        SELECT SINGLE lifnr FROM lfa1
        INTO s_lifnr
        WHERE lifnr IN s_lifnr.
        IF sy-subrc NE 0.
          MESSAGE e005.
        ENDIF.
      ENDIF.
    AT SELECTION-SCREEN ON p_bldat.
      IF NOT p_bldat IS INITIAL.
        SELECT SINGLE bldat FROM bsid
        INTO p_bldat
        WHERE bldat = p_bldat.
        IF sy-subrc NE 0 .
          MESSAGE e004.
        ENDIF.
      ENDIF.
    * Selection For Top-of-page.
    ** Get company code description
      SELECT SINGLE butxt
        FROM t001 INTO lv_butxt
        WHERE bukrs IN s_bukrs.
    *  SELECT SINGLE lifnr  FROM lfb1
    *  INTO  lv_butxt2  WHERE bukrs IN s_bukrs.
    *  SELECT SINGLE name1 FROM lfa1
    *   INTO lv_butxt1 WHERE lifnr = lv_butxt2.
    START-OF-SELECTION.
      PERFORM data_retrival.
      PERFORM f_layout_init.
      PERFORM f_eventtab_build.
      i_variant-report = sy-repid.
      PERFORM f_print_control.
    *  PERFORM f_build_header_list.
    *  perform f_build_header_list1.
    *    PERFORM f_build_fieldcat.
      IF p_detail = 'X'.
        PERFORM f_build_sort.
        PERFORM fill_fieldcat.
        PERFORM f_build_header_list.
      ELSE.
        PERFORM f_build_sort1.
        PERFORM fill_fieldcat_sum.
        PERFORM f_build_header_list1.
      ENDIF.
      PERFORM f_list_display TABLES gt_final[].
    END-OF-SELECTION.
    *&      Form  data_retrival
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM data_retrival .
      SELECT   bukrs
               lifnr
               belnr
               bldat
               waers
               dmbtr
               wrbtr
               zfbdt
               zbd1t
               zbd2t
               zbd3t
               FROM bsik INTO TABLE gt_bsik
               WHERE bukrs IN s_bukrs
               AND   lifnr IN s_lifnr.
      SELECT lifnr
             name1
             FROM lfa1 INTO TABLE gt_lfa1
             FOR ALL ENTRIES IN gt_bsik
             WHERE lifnr = gt_bsik-lifnr.
      LOOP AT gt_bsik INTO wa_bsik.
        READ TABLE gt_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_bsik-lifnr.
        MOVE-CORRESPONDING wa_bsik TO wa_final.
        MOVE-CORRESPONDING wa_lfa1 TO wa_final.
        DATA: days TYPE char2,
              c4 TYPE char2.
        DATA: days1 TYPE sy-datum.
        DATA:duedate TYPE rfpos-faedt.
        CALL FUNCTION 'NET_DUE_DATE_GET'
          EXPORTING
            i_zfbdt       = wa_final-zfbdt
            i_zbd1t       = wa_final-zbd1t
            i_zbd2t       = wa_final-zbd2t
            i_zbd3t       = wa_final-zbd3t
            i_shkzg       = ' '
            i_rebzg       = ' '
    *   I_KOART       = 'D'
         IMPORTING
           e_faedt       = duedate.
        CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
          EXPORTING
            i_datum_bis                   = duedate
            i_datum_von                   = wa_final-bldat
    *   I_KZ_EXCL_VON                 = '0'
    *   I_KZ_INCL_BIS                 = '0'
    *   I_KZ_ULT_BIS                  = ' '
    *   I_KZ_ULT_VON                  = ' '
    *   I_STGMETH                     = '0'
    *   I_SZBMETH                     = '1'
         IMPORTING
           e_tage                        = days
         EXCEPTIONS
           days_method_not_defined       = 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.
        wa_final-days = duedate.
        DATA : wf_char TYPE char10.
        wf_char = days.
        IF wf_char+0(1) EQ '*' .
          SKIP.
        ELSE.
          IF days EQ 0.
            wa_final-current = wa_bsik-wrbtr.
          ELSEIF days LE 30 AND days GT 0.
            wa_final-d30 = wa_bsik-wrbtr.
          ELSEIF days LE 60 AND days GT 30 .
            wa_final-d60 = wa_bsik-wrbtr.
          ELSEIF days LE 90 AND days GT 60.
            wa_final-d90 = wa_bsik-wrbtr.
          ELSEIF days LE 120 AND days GT 90.
            wa_final-d120 = wa_bsik-wrbtr.
          ELSEIF days LE 180 AND days GT 120.
            wa_final-d180 = wa_bsik-wrbtr.
          ELSEIF days LE 240 AND days GT 180.
            wa_final-d240 = wa_bsik-wrbtr.
          ELSEIF days LE 360 AND days GT 240.
            wa_final-d360 = wa_bsik-wrbtr.
          ELSEIF days GT 365 .
            wa_final-da365 = wa_bsik-wrbtr.
          ENDIF.
        ENDIF.
        APPEND wa_final TO gt_final.
        CLEAR: wa_final,
               days,
               duedate,days1.
      ENDLOOP.
    ENDFORM.                    " data_retrival
    *&      Form  fill_fieldcat
    *       text
    FORM fill_fieldcat.
      PERFORM  fill_fields USING: 'Vendor Number' 'LIFNR',
                                  'Vendor Name' 'NAME1',
                                  'Document Number' 'BELNR',
                                  'Document Date' 'BLDAT',
                                  'Due Date' 'DAYS',
                                  'Total In Document Currency' 'WRBTR',
                                  'Currency' 'WAERS',
                                  'Total In Reporting Currency' 'DMBTR',
                                  'Current' 'CURRENT',
                                  '1-30 days' 'D30',
                                  '31-60 days' 'D60',
                                  '61-90 days' 'D90',
                                  '91-120 days' 'D120',
                                  '121-180 days' 'D180',
                                  '181-240 days' 'D240',
                                  '241-360 days'  'D360',
    *                              '181-365 days' 'D365',
                                  'Above 365 days' 'DA365'.
    ENDFORM.                    "fill_fieldcat
    *&      Form  fill_fieldcat_sum
    *       text
    FORM fill_fieldcat_sum.
      PERFORM  fill_fields USING: 'Vendor Number' 'LIFNR',
                                  'Vendor Name' 'NAME1',
                                  'Total In Reporting Currency' 'DMBTR',
                                  'Current' 'CURRENT',
                                  '1-30 days' 'D30',
                                  '31-60 days' 'D60',
                                  '61-90 days' 'D90',
                                  '91-120 days' 'D120',
                                  '121-180 days' 'D180',
                                  '181-240 days' 'D240',
                                  '241-360 days'  'D360',
                                  'Above 365 days' 'DA365'.
    ENDFORM.                    "fill_fieldcat_sum
    *&      Form  fill_fields
    *       text
    *      -->&01        text
    *      -->&02        text
    FORM fill_fields USING &01 &02 .
      wa_fieldcat-tabname = 'T_OUTPUT'.  "t_output_provgr
      wa_fieldcat-fieldname = &02.
      wa_fieldcat-seltext_m = &01.
    *  wa_fieldcat-ref_fieldname = fieldname.
    *  wa_fieldcat-ref_tabname = 'SFLIGHT'.
    *  w_fieldcat-do_sum = &03.
      APPEND wa_fieldcat TO i_fieldcat.
      CLEAR wa_fieldcat.
    ENDFORM.                    "fill_fields
    *&      Form  f_layout_init
    *       Set the layout
    FORM f_layout_init.
    *  P_layout-min_linesize       = 170.
    *  p_layout-max_linesize       = 170.
    *  P_layout-no_colhead         = abap_true.
    *  p_layout-detail_popup       = abap_true.
      i_layout-colwidth_optimize  = abap_true.
      i_layout-zebra              = abap_true.
    *  i_layout-subtotals_text     = 'SubTotal'.
    *  i_layout-totals_text        = 'Total'.
    ENDFORM.                    " f_layout_init
    *&      Form  f_eventtab_build
    *       Set the events
    FORM f_eventtab_build.
      DATA: ls_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = i_events.
      READ TABLE i_events WITH KEY name = slis_ev_top_of_page
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE v_top TO: ls_event-form,
                       ls_event-name.
        APPEND ls_event TO i_events.
      ENDIF.
      READ TABLE i_events WITH KEY name = slis_ev_end_of_page
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE v_eop TO: ls_event-form,
                       ls_event-name.
        APPEND ls_event TO i_events.
      ENDIF.
      READ TABLE i_events WITH KEY name = slis_ev_end_of_list
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE v_eol TO: ls_event-form,
                       ls_event-name.
        APPEND ls_event TO i_events.
      ENDIF.
      READ TABLE i_events WITH KEY name = slis_ev_top_of_list
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE v_tol TO: ls_event-form,
                       ls_event-name.
        APPEND ls_event TO i_events.
      ENDIF.
    ENDFORM.                    " f_eventtab_build
    *&      Form  f_print_control
    *       Set the print control
    FORM f_print_control .
    *  i_print-no_print_listinfos     = abap_true.
    *  i_print-no_print_selinfos      = abap_true.
    *  i_print-reserve_lines          = 2.
    *  i_print-no_change_print_params = abap_true.
    ENDFORM.                    " f_print_control
    *&      Form  f_build_header_list
    *       Build the header list (top of page)
    FORM f_build_header_list .
      lv_header = 'Vendor Open Item Analysis By Balance Of Overdue Items'(h01).
      lv_text   = 'Company Name:'(s01).
      lv_text1   = 'Open Item As Key Date:'(s02).
      lv_text2   = 'Company Code:'(s03).
      lv_text3   =  'Vendor Number:'(s04).
      lv_text4   =  'Vendor Name:'(s05).
    * Header
      CLEAR lwa_list_top.
      lwa_list_top-typ  = 'H'.
      lwa_list_top-info = lv_header.
      APPEND lwa_list_top TO i_list_top.
    * Run date Display
      lwa_list_top-typ  = 'S'.                " Item
      WRITE: sy-datum  TO lv_date MM/DD/YYYY.
      lwa_list_top-key = 'Date :'(025).
      lwa_list_top-info = lv_date.
      APPEND lwa_list_top TO i_list_top.
      CLEAR: lwa_list_top,
             lv_date.
    * Run time Display
      lwa_list_top-typ  = 'S'.                " Item
      WRITE: sy-uzeit  TO lv_time USING EDIT MASK '__:__:__'.
      lwa_list_top-key  = 'Time :'(026).
      lwa_list_top-info =  lv_time.
      APPEND lwa_list_top TO i_list_top.
      CLEAR: lwa_list_top,
             lv_time.
      CLEAR lwa_list_top.
    * Company Name
      lwa_list_top-typ  = 'S'.
      lwa_list_top-key  = lv_text.
      lwa_list_top-info = lv_butxt.
      APPEND lwa_list_top TO i_list_top.
      CLEAR lwa_list_top.
    *Open Item As Key Date
      lwa_list_top-typ  = 'S'.
      lwa_list_top-key  = lv_text1.
      lwa_list_top-info = p_bldat.
      APPEND lwa_list_top TO i_list_top.
      CLEAR lwa_list_top.
    * Company Code
      lwa_list_top-typ  = 'S'.
      lwa_list_top-key  = lv_text2.
      lwa_list_top-info = s_bukrs-low.
      APPEND lwa_list_top TO i_list_top.
      CLEAR lwa_list_top.
    ** Vendor Number
    *  lwa_list_top-typ  = 'S'.
    *  lwa_list_top-key  = lv_text3.
    *  lwa_list_top-info = lv_butxt2.
    *  APPEND lwa_list_top TO i_list_top.
    *  CLEAR lwa_list_top.
    **Vendor Name
    *  lwa_list_top-typ  = 'S'.
    *  lwa_list_top-key  = lv_text4.
    *  lwa_list_top-info = lv_butxt1.
    *  APPEND lwa_list_top TO i_list_top.
    ENDFORM.                    " f_build_header_list
    *&      Form  f_build_header_list1
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM f_build_header_list1 .
      lv_header = 'Vendor Open Item Analysis By Balance Of Overdue Items'(h01).
      lv_text   = 'Company Name:'(s01).
      lv_text1   = 'Open Item As Key Date:'(s02).
      lv_text2   = 'Company Code:'(s03).
      lv_text3   =  'Vendor Number:'(s04).
      lv_text4   =  'Vendor Name:'(s05).
      lwa_list_top-typ  = 'H'.
      lwa_list_top-info = lv_header.
      APPEND lwa_list_top TO i_list_top.
    * Run date Display
      lwa_list_top-typ  = 'S'.                " Item
      WRITE: sy-datum  TO lv_date MM/DD/YYYY.
      lwa_list_top-key = 'Date :'(025).
      lwa_list_top-info = lv_date.
      APPEND lwa_list_top TO i_list_top.
      CLEAR: lwa_list_top,
             lv_date.
    * Run time Display
      lwa_list_top-typ  = 'S'.                " Item
      WRITE: sy-uzeit  TO lv_time USING EDIT MASK '__:__:__'.
      lwa_list_top-key  = 'Time :'(026).
      lwa_list_top-info =  lv_time.
      APPEND lwa_list_top TO i_list_top.
      CLEAR: lwa_list_top,
             lv_time.
      CLEAR lwa_list_top.
    * Company Name
      lwa_list_top-typ  = 'S'.
      lwa_list_top-key  = lv_text.
      lwa_list_top-info = lv_butxt.
      APPEND lwa_list_top TO i_list_top.
      CLEAR lwa_list_top.
    *Open Item As Key Date
      lwa_list_top-typ  = 'S'.
      lwa_list_top-key  = lv_text1.
      lwa_list_top-info = p_bldat.
      APPEND lwa_list_top TO i_list_top.
      CLEAR lwa_list_top.
    ENDFORM.                    " f_build_header_list1
    *&      Form  f_build_sort
    *       Set the sorting sequence
    FORM f_build_sort .
      DATA: l_sort TYPE slis_sortinfo_alv.
      l_sort-spos      =  '1'.
      l_sort-fieldname = 'LIFNR'.
      l_sort-up        = abap_true.
      l_sort-group     = '*'.
    *  l_sort-subtot    = 'X'.
      APPEND l_sort TO i_sort.
    *  l_sort-spos      =  '2'.
    *  l_sort-fieldname = 'NAME1'.
    *  l_sort-up        = abap_true.
    *  l_sort-group     = '*'.
    **  l_sort-subtot    = 'X'.
    *  APPEND l_sort TO i_sort.
    *  l_sort-spos      =  '2'.
    *  l_sort-fieldname = 'LIFNR'.
    *  l_sort-up        = abap_true.
    *  l_sort-subtot    = abap_true.
    *  APPEND l_sort TO i_sort.
    *  l_sort-spos      =  '1'.
    *  l_sort-fieldname = 'VBELN'.
    *  l_sort-up        = abap_true.
    *  l_sort-subtot    = abap_true.
    *  APPEND l_sort TO i_sort.
    *  l_sort-spos      =  '2'.
    *  l_sort-fieldname = 'POSNR'.
    *  l_sort-up        = abap_true.
    *  l_sort-subtot    = abap_true.
    *  APPEND l_sort TO i_sort.
    ENDFORM.                    " f_build_sort
    *&      Form  f_list_display
    *       Display the ALV list report
    *      -->PT_DATA    Internal table containing the data
    FORM f_list_display TABLES pt_data.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = i_variant-report
          is_layout          = i_layout
          it_fieldcat        = i_fieldcat[]
          it_sort            = i_sort
          i_default          = 'X'
          i_save             = 'A'
          is_variant         = i_variant
          it_events          = i_events[]
          is_print           = i_print
        TABLES
          t_outtab           = pt_data.
    ENDFORM.                    "f_list_display
    *&      Form  TOP_OF_PAGE
    *       TOP_OF_PAGE Event
    FORM top_of_page.                                           "#EC CALLED
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
    *      i_logo             = 'ZLOGO_BAB'
          it_list_commentary = i_list_top
          i_alv_form         = 'X'.
    *  PERFORM f_print_header USING SPACE SPACE SPACE.
    ENDFORM.                    "TOP_OF_PAGE
    *&      Form  END_OF_PAGE
    *       END_OF_PAGE Event
    FORM end_of_page.                                           "#EC CALLED
    *  DATA: l_pos(3) TYPE n VALUE 0,
    *        l_foot(30) VALUE '*** END OF PAGE ***'.
    *  l_pos = ( sy-linsz / 2 ) - ( STRLEN( l_foot ) / 2 ).
    *  ULINE.
    *  WRITE: /, AT l_pos l_foot.
    ENDFORM.                    "END_OF_PAGE
    *&      Form  END_OF_LIST
    *       END_OF_LIST Event
    FORM end_of_list.                                           "#EC CALLED
    *  DATA: l_pos(3) TYPE n VALUE 0,
    *        l_foot(30) VALUE '*** END OF REPORT ***'.
    *  l_pos = ( sy-linsz / 2 ) - ( STRLEN( l_foot ) / 2 ).
    *  ULINE.
    *  WRITE: /, AT l_pos l_foot.
    ENDFORM.                    "END_OF_LIST
    *&      Form  f_print_header
    *       Print the header (Top-Of-Page)
    *      -->P_P_TITLE1  Title text 1
    *      -->P_P_TITLE2  Title text 2
    *      -->P_P_TITLE3  Title text 3
    FORM f_print_header  USING    p_title1 LIKE sy-title
                                  p_title2 LIKE sy-title
                                  p_title3 LIKE sy-title.
      DATA: l_post1 TYPE i,
            l_post2 TYPE i,
            l_post3 TYPE i,
            l_posin TYPE i.
      l_post1 = ( sy-linsz / 2 ) - ( STRLEN( p_title1 ) / 2 ).
      l_post2 = ( sy-linsz / 2 ) - ( STRLEN( p_title2 ) / 2 ).
      l_post3 = ( sy-linsz / 2 ) - ( STRLEN( p_title3 ) / 2 ).
      l_posin = sy-linsz - 17.
      WRITE:  / 'Report  :', sy-cprog.
      WRITE AT  l_post1 p_title1.
      WRITE AT  l_posin 'Date :'.
      WRITE     sy-datum.
      WRITE:  / 'Cli/Sys :', sy-mandt, '/', sy-sysid.
      WRITE AT  l_post2 p_title2.
      WRITE AT: l_posin 'Time :'.
      WRITE     sy-uzeit.
      WRITE:  / 'UserID  :', sy-uname.
      WRITE AT  l_post3 p_title3.
      WRITE AT  l_posin 'Page :'.
      WRITE     sy-pagno NO-ZERO.
    ENDFORM.                    " f_print_header
    *&      Form  f_build_sort1
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form f_build_sort1 .
    DATA: l_sort TYPE slis_sortinfo_alv.
      l_sort-spos      =  '1'.
      l_sort-fieldname = 'LIFNR'.
      l_sort-up        = abap_true.
      l_sort-group     = '*'.
    *  l_sort-subtot    = 'X'.
      APPEND l_sort TO i_sort.
    l_sort-spos      =  '2'.
      l_sort-fieldname = 'NAME1'.
      l_sort-up        = abap_true.
      l_sort-group     = '*'.
    *  l_sort-subtot    = 'X'.
      APPEND l_sort TO i_sort.
    *  l_sort-spos      =  '3'.
    *  l_sort-fieldname = 'DMBTR'.
    *  l_sort-up        = abap_true.
    *  l_sort-group     = '*'.
    *  l_sort-subtot    = 'X'.
    *  APPEND l_sort TO i_sort.
    endform.                    " f_build_sort1
    Regards
    Sunita.

    Hey,
    U can try out "SORTING THE VENDORS AND DO THE SUM in the NETWR"... try it out....see u sort the customers...rit?...keep it as usual and little mentoned above...
    hope dis help u out...
    Thanks.

  • ALV grid total andsub-total

    hi there...I know there´s a lot of posts about this subject but i didn't find what i´m looking for...
    I want to know if there´s some way to give a total and a sub-total of a field, but instead of the total and subtotal sums I just want a count of the number of rows for the field that I've sorted.
    FIELDCATALOG-FIELDNAME   = 'BUKRS'.
      FIELDCATALOG-SELTEXT_M   = 'BUKRS'.
      FIELDCATALOG-COL_POS     = 0.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'BUTXT'.
      FIELDCATALOG-SELTEXT_M   = 'BUTXT'.
      FIELDCATALOG-COL_POS     = 1.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'LIFNR'.
      FIELDCATALOG-SELTEXT_M   = 'LIFNR'.
      FIELDCATALOG-COL_POS     = 2.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'NAME1'.
      FIELDCATALOG-SELTEXT_M   = 'NAME1'.
      FIELDCATALOG-COL_POS     = 3.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'MBLNR'.
      FIELDCATALOG-SELTEXT_M   = 'MBLNR'.
      FIELDCATALOG-COL_POS     = 4.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'MJAHR'.
      FIELDCATALOG-SELTEXT_M   = 'MJAHR'.
      FIELDCATALOG-COL_POS     = 5.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'CPUDT'.
      FIELDCATALOG-SELTEXT_M   = 'CPUDT'.
      FIELDCATALOG-COL_POS     = 6.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'BUDAT'.
      FIELDCATALOG-SELTEXT_M   = 'BUDAT'.
      FIELDCATALOG-COL_POS     = 7.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'USNAM'.
      FIELDCATALOG-SELTEXT_M   = 'BUDAT'.
      FIELDCATALOG-COL_POS     = 8.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'MENGE'.
      FIELDCATALOG-SELTEXT_M   = 'MENGE'.
      FIELDCATALOG-COL_POS     = 9.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
      FIELDCATALOG-FIELDNAME   = 'DMBTR'.
      FIELDCATALOG-SELTEXT_M   = 'DMBTR'.
      FIELDCATALOG-COL_POS     = 10.
      APPEND FIELDCATALOG TO FIELDCATALOG.
      CLEAR  FIELDCATALOG.
    *          SORT
      WA_SORT-SPOS = 1.
      WA_SORT-FIELDNAME = 'BUKRS'.
      WA_SORT-TABNAME = 'ITAB'.
      WA_SORT-UP = 'X'.
      WA_SORT-SUBTOT = 'X'.
      APPEND WA_SORT TO IT_SORT.
      CLEAR WA_SORT.
      WA_SORT-SPOS = 2.
      WA_SORT-FIELDNAME = 'LIFNR'.
      WA_SORT-TABNAME = 'ITAB'.
      WA_SORT-UP = 'X'.
      WA_SORT-SUBTOT = 'X'.
      APPEND WA_SORT TO IT_SORT.
      CLEAR WA_SORT.
    in the alv i want to know the number of rows for each value of lifnr (sub-total) and in the end the total of the all values of lifnr
    thanks

    Hi,
    It is better to obtain this information not in ALV but working on the table. Using control level processing it is easy to achieve.
    data: begin of it_overview occurs 0
              lifnr type ..
              tot_item type i,     "number of lifnr withing subtotal
            end of it_overwiev.
    data: pos type i.   "to remember the position.
    "your output table
    Loop at it_ouptut.
       at new lifnr.
          pos = sy-tabix.    "remember first position of new LIFNR
       endat.
       at end of lifnr.
          it_overview-lifnr = it_output-lifnr.
          it_overview-tot_item = sy-tabix - pos.    "calculate how many within one LIFNR
          append it_overview.                             "store it in the table
           clear pos.
       endat.
    endloop.
    this way table IT_OVERVIEW stores LIFNRs and number of items forming their subtotals.
    To get total use:
    DESCRIEBE TABLE it_output.
    it_output-lifnr = 'TOTAL_ITEMS'.    "total items within all LIFNRs
    it_output-tot_item = sy-tfill.            "is equal to total lines in the table
    append it_output.
    Regards
    Marcin

  • How to calcluate a filed based on two other fields after TABING out.

    Hi,
    I need my third field be calculated based on the previous two fields after tabing out from each field.
    Price Quantity Amount
    12 10 120
    Both price and Quantity is text box and amount is readonly.I want if I change Price from 12 to 15 and tab out then amount should automatically get changed to 150.
    Regards,
    Prakash

    I believe you can use Partial Page Rendering (PPR) to accomplish this. You'd place a 'firePartialAction' event on the input field. This event would fire when you tab out and then you can invoke controlelr logic to set the other two fields appropriately.
    Check out the OA Framework Developer's Guide for examples.

Maybe you are looking for

  • Display extended ascii characters as question mark in xml file

    I am creating a XML file with encoding as UTF-8. Some tag values contain some extended ascii characters. When i run the java program to create the file in windows, the extended ascii characters are display correctly. But in linux it is displaying as

  • 4 gig or 8 gig of RAM?

    Clearly, FCP 7 maxed out with 4 gigs of RAM, but FCP-X can use more. The question is how significant is the real world usage of 8 gigs vs. 4 gigs with FCP-X? Has anyone out there started with FCP-X and 4 gigs and then upgraded to 8 gigs? If so, did y

  • Business Area Trail Balance

    Dear Experts, I am facing problem in Trail Balance We have implemented 4 Business Area in our company code, company code wise trail balance is matching but BA wise its not matching. I created 1 adjustment account  &  executed F.5D & F.5E transaction.

  • Lenovo vs Windows 7

    Hello, Just got my X200, should I get the Windows 7 from Lenovo or use the store upgrade. Will Lenovo's be and upgrade and won affect my documents or will it be some sort of recovery. I got the store upgrade at 50%. Let me know! X200, 8600, Ram 3G an

  • LSMW Read Data shortdump

    Hi guys.. I'm currently testing out on LSMW I'm trying to create new material for transaction MM01. But when i click on Step 9: Read Data i get a shortdump What happened?     The current ABAP program had to be terminated becaus     ABAP processor det