Skip to Content
avatar image
Former Member

Internal table

I have an internal table and I need to sum up say quantities for identical material number records, something like grouping fields and summing up totals, then I need to siaplay this in ALV.

How can I do this.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

7 Answers

  • avatar image
    Former Member
    Oct 16, 2008 at 06:25 AM

    Hi MN,

    use SORT option in ALV FM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 06:28 AM

    HI

    these is field DO_SUM to add the all values of one field

    in SLIS

    it willl work

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 06:30 AM

    Hi,

    Make use of control level statements like AT NEW, AT END OF while looping the table. Before looping sort by MATNR.

     SORT ITAB BY MATNR.
    LOOP AT ITAB INTO WA.
    
         <UR STATEMENTS>
        
          AT END OF MATNR.
    
               W_QUANTITY = WA-QTY + W_QUANTITY.
    
          ENDAT.
    
    ENDLOOP.

    Regards,

    Swapna.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 06:31 AM

    Hi,

    First sort your table w.r.t. matnr.

    Then you can use

    declare another table it_final2 as your final table .

      SORT it_final BY matnr
      LOOP AT it_final INTO wa_final.
      sum = sum + wa_final-<your quantity field>.
        AT END OF matnr.
          wa_final2-matnr = wa_final-matnr.
           wa_final2-<your quantity field> = sum.
          APPEND wa_final2 TO it_final2.
    
          CLEAR wa_final2.
              ENDAT.
    
     ENDLOOP.
    
    

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 06:32 AM

    Hi MN,

    there will be an option in ALV.

    DATA:

    fs_sort_data TYPE slis_sortinfo_alv.

    DATA:

    t_sort_data TYPE slis_t_sortinfo_alv.

    fs_sort_data-fieldname = 'QUANTITY'.

    fs_sort_data-spos = '01'.

    fs_sort_data-up = c_flag_x.

    APPEND fs_sort_data TO t_sort_data.

    fs_sort_data-fieldname = 'AMOUNT'.

    fs_sort_data-up = c_flag_x.

    fs_sort_data-spos = '02'.

    APPEND fs_sort_data TO t_sort_data.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    is_layout = fs_layout

    it_fieldcat = t_fieldcat[]

    it_sort = t_sort_data[]

    TABLES

    t_outtab = t_final

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc NE 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF. " IF sy-subrc NE 0.

    Regards.

    Eswar.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 06:33 AM

    Hi MN

    In the below code the Gross weight will be added up for a particular material. See F1 for COLLECT statement.

    TYPES : BEGIN OF TY_MARA,
            MATNR TYPE MARA-MATNR,
            BRGEW TYPE MARA-BRGEW, "Gross Weight
            END OF TY_MARA.
    
    DATA : IT_MARA       TYPE TABLE OF TY_MARA,
           WA_MARA       TYPE TY_MARA,
           IT_MARA_COLL  TYPE TABLE OF TY_MARA.
    
    DATA : GR_TABLE TYPE REF TO CL_SALV_TABLE.
    
    SELECT MATNR
           BRGEW
    FROM MARA
    INTO TABLE IT_MARA UP TO 500 ROWS.
    
    LOOP AT IT_MARA INTO WA_MARA.
    
      COLLECT WA_MARA INTO IT_MARA_COLL.
    
    ENDLOOP.
    
    *TRY.
    CALL METHOD CL_SALV_TABLE=>FACTORY
    *  EXPORTING
    *    LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
    *    R_CONTAINER    =
    *    CONTAINER_NAME =
      IMPORTING
        R_SALV_TABLE   = GR_TABLE
      CHANGING
        T_TABLE        = IT_MARA_COLL
        .
    * CATCH CX_SALV_MSG .
    *ENDTRY.
    
    .
    
    CALL METHOD GR_TABLE->DISPLAY
      .

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2008 at 06:36 AM

    Hello,

    Try and use COLLECT Statement.

    Code snippet for your reference

    LOOP AT lt_output INTO ls_output .

    • Collect the fields from output table to Collect table

    ls_collect-ebeln = ls_output-ebeln.

    ls_collect-ebelp = ls_output-ebelp.

    ls_collect-wemng = ls_output-wemng.

    ls_collect-wamng = ls_output-wamng.

    • Sum up the values for Quantity of Goods Received (WEMNG) and

    • for Issued Quantity (WAMNG); for a given ebeln and ebelp.

    COLLECT ls_collect INTO lt_collect.

    ENDLOOP.

    Regards,

    Farheen

    Add comment
    10|10000 characters needed characters exceeded