Application Development 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: 

ALV - Sort - Subtotal

Former Member
0 Kudos
185

hi,

Can u pls tell me what is the use of subtotal in sort exactly with an example of records..

I need to work out with this..in ALV.

will be rewarded.

Thankx in adv

1 ACCEPTED SOLUTION

Former Member
0 Kudos
49

REPORT ZALV.

TYPE-POOLS: SLIS.

DATA: G_REPID LIKE SY-REPID,

GS_PRINT TYPE SLIS_PRINT_ALV,

GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,

GT_EVENTS TYPE SLIS_T_EVENT,

GT_SORT TYPE SLIS_T_SORTINFO_ALV,

GS_LAYOUT TYPE SLIS_LAYOUT_ALV,

GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FIELDCAT_LN LIKE LINE OF GT_FIELDCAT,

COL_POS TYPE I.

DATA: BEGIN OF ITAB,

FIELD1(5) TYPE C,

FIELD2(5) TYPE C,

FIELD3(5) TYPE P DECIMALS 2,

END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0.

INCLUDE STRUCTURE ITAB.

DATA: END OF ITAB1.

DATA: BEGIN OF ITAB_FIELDCAT OCCURS 0.

INCLUDE STRUCTURE ITAB.

DATA: END OF ITAB_FIELDCAT.

  • Print Parameters

PARAMETERS:

P_PRINT AS CHECKBOX DEFAULT ' ', "PRINT IMMEDIATE

P_NOSINF AS CHECKBOX DEFAULT 'X', "NO SELECTION INFO

P_NOCOVE AS CHECKBOX DEFAULT ' ', "NO COVER PAGE

P_NONEWP AS CHECKBOX DEFAULT ' ', "NO NEW PAGE

P_NOLINF AS CHECKBOX DEFAULT 'X', "NO PRINT LIST INFO

P_RESERV TYPE I. "NO OF FOOTER LINE

INITIALIZATION.

G_REPID = SY-REPID.

PERFORM PRINT_BUILD USING GS_PRINT. "Print PARAMETERS

START-OF-SELECTION.

  • TEST DATA

MOVE 'TEST1' TO ITAB1-FIELD1.

MOVE 'TEST1' TO ITAB1-FIELD2.

MOVE '10.00' TO ITAB1-FIELD3.

APPEND ITAB1.

MOVE 'TEST2' TO ITAB1-FIELD1.

MOVE 'TEST2' TO ITAB1-FIELD2.

MOVE '20.00' TO ITAB1-FIELD3.

APPEND ITAB1.

DO 50 TIMES.

APPEND ITAB1.

ENDDO.

END-OF-SELECTION.

PERFORM BUILD.

PERFORM EVENTTAB_BUILD CHANGING GT_EVENTS.

PERFORM COMMENT_BUILD CHANGING GT_LIST_TOP_OF_PAGE.

PERFORM CALL_ALV.

FORM BUILD.

  • DATA FIELD CATALOG

  • Explain Field Description to ALV

DATA: FIELDCAT_IN TYPE SLIS_FIELDCAT_ALV.

CLEAR FIELDCAT_IN.

FIELDCAT_LN-FIELDNAME = 'FIELD1'.

FIELDCAT_LN-TABNAME = 'ITAB1'.

*FIELDCAT_LN-NO_OUT = 'X'. "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT

FIELDCAT_LN-KEY = ' '. "SUBTOTAL KEY

FIELDCAT_LN-NO_OUT = ' '.

FIELDCAT_LN-SELTEXT_L = 'HEAD1'.

APPEND FIELDCAT_LN TO GT_FIELDCAT.

CLEAR FIELDCAT_IN.

FIELDCAT_LN-FIELDNAME = 'FIELD2'.

FIELDCAT_LN-TABNAME = 'ITAB1'.

FIELDCAT_LN-NO_OUT = 'X'.

FIELDCAT_LN-SELTEXT_L = 'HEAD2'.

APPEND FIELDCAT_LN TO GT_FIELDCAT.

CLEAR FIELDCAT_IN.

FIELDCAT_LN-FIELDNAME = 'FIELD3'.

FIELDCAT_LN-TABNAME = 'ITAB1'.

FIELDCAT_LN-REF_FIELDNAME = 'MENGE'. "<- REF FIELD IN THE DICTIONNARY

FIELDCAT_LN-REF_TABNAME = 'MSEG'. "<- REF TABLE IN THE DICTIONNARY

FIELDCAT_LN-NO_OUT = ' '.

FIELDCAT_LN-DO_SUM = 'X'. "SUM UPON DISPLAY

APPEND FIELDCAT_LN TO GT_FIELDCAT.

  • DATA SORTING AND SUBTOTAL

DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.

CLEAR GS_SORT.

GS_SORT-FIELDNAME = 'FIELD1'.

GS_SORT-SPOS = 1.

GS_SORT-UP = 'X'.

GS_SORT-SUBTOT = 'X'.

APPEND GS_SORT TO GT_SORT.

CLEAR GS_SORT.

GS_SORT-FIELDNAME = 'FIELD2'.

GS_SORT-SPOS = 2.

GS_SORT-UP = 'X'.

*GS_SORT-SUBTOT = 'X'.

APPEND GS_SORT TO GT_SORT.

ENDFORM.

FORM CALL_ALV.

  • ABAP List Viewer

CALL FUNCTION 'REUSE_ALV_LIST_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_STRUCTURE_NAME = 'ITAB1'

IS_LAYOUT = GS_LAYOUT

IT_FIELDCAT = GT_FIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = GT_SORT[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = GT_EVENTS[]

  • IT_EVENT_EXIT =

IS_PRINT = GS_PRINT

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = ITAB1

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ENDFORM.

  • HEADER FORM

FORM EVENTTAB_BUILD CHANGING LT_EVENTS TYPE SLIS_T_EVENT.

CONSTANTS:

GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

*GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE'.

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = LT_EVENTS.

READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO LS_EVENT.

IF SY-SUBRC = 0.

MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.

APPEND LS_EVENT TO LT_EVENTS.

ENDIF.

  • define END_OF_PAGE event

  • READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE

  • INTO LS_EVENT.

  • IF SY-SUBRC = 0.

  • MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.

  • APPEND LS_EVENT TO LT_EVENTS.

  • ENDIF.

ENDFORM.

FORM COMMENT_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: GS_LINE TYPE SLIS_LISTHEADER.

CLEAR GS_LINE.

GS_LINE-TYP = 'H'.

GS_LINE-INFO = 'HEADER 1'.

APPEND GS_LINE TO GT_TOP_OF_PAGE.

CLEAR GS_LINE.

GS_LINE-TYP = 'S'.

GS_LINE-KEY = 'STATUS 1'.

GS_LINE-INFO = 'INFO 1'.

APPEND GS_LINE TO GT_TOP_OF_PAGE.

GS_LINE-KEY = 'STATUS 2'.

GS_LINE-INFO = 'INFO 2'.

APPEND GS_LINE TO GT_TOP_OF_PAGE.

  • CLEAR GS_LINE.

  • GS_LINE-TYP = 'A'.

*

  • GS_LINE-INFO = 'ACTION'.

  • APPEND GS_LINE TO GT_TOP_OF_PAGE.

ENDFORM.

FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.

WRITE: SY-DATUM, 'Page No', SY-PAGNO LEFT-JUSTIFIED.

ENDFORM.

FORM END_OF_PAGE.

WRITE at (sy-linsz) sy-pagno CENTERED.

ENDFORM.

  • PRINT SETTINGS

FORM PRINT_BUILD USING LS_PRINT TYPE SLIS_PRINT_ALV.

LS_PRINT-PRINT = P_PRINT. "PRINT IMMEDIATE

LS_PRINT-NO_PRINT_SELINFOS = P_NOSINF. "NO SELECTION INFO

LS_PRINT-NO_COVERPAGE = P_NOCOVE. "NO COVER PAGE

LS_PRINT-NO_NEW_PAGE = P_NONEWP.

LS_PRINT-NO_PRINT_LISTINFOS = P_NOLINF. "NO PRINT LIST INFO

LS_PRINT-RESERVE_LINES = P_RESERV.

ENDFORM.

*END OF ZALV PROGRAM

Check this program...

Regards,

Pavan

4 REPLIES 4

Former Member
0 Kudos
50

REPORT ZALV.

TYPE-POOLS: SLIS.

DATA: G_REPID LIKE SY-REPID,

GS_PRINT TYPE SLIS_PRINT_ALV,

GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,

GT_EVENTS TYPE SLIS_T_EVENT,

GT_SORT TYPE SLIS_T_SORTINFO_ALV,

GS_LAYOUT TYPE SLIS_LAYOUT_ALV,

GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FIELDCAT_LN LIKE LINE OF GT_FIELDCAT,

COL_POS TYPE I.

DATA: BEGIN OF ITAB,

FIELD1(5) TYPE C,

FIELD2(5) TYPE C,

FIELD3(5) TYPE P DECIMALS 2,

END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0.

INCLUDE STRUCTURE ITAB.

DATA: END OF ITAB1.

DATA: BEGIN OF ITAB_FIELDCAT OCCURS 0.

INCLUDE STRUCTURE ITAB.

DATA: END OF ITAB_FIELDCAT.

  • Print Parameters

PARAMETERS:

P_PRINT AS CHECKBOX DEFAULT ' ', "PRINT IMMEDIATE

P_NOSINF AS CHECKBOX DEFAULT 'X', "NO SELECTION INFO

P_NOCOVE AS CHECKBOX DEFAULT ' ', "NO COVER PAGE

P_NONEWP AS CHECKBOX DEFAULT ' ', "NO NEW PAGE

P_NOLINF AS CHECKBOX DEFAULT 'X', "NO PRINT LIST INFO

P_RESERV TYPE I. "NO OF FOOTER LINE

INITIALIZATION.

G_REPID = SY-REPID.

PERFORM PRINT_BUILD USING GS_PRINT. "Print PARAMETERS

START-OF-SELECTION.

  • TEST DATA

MOVE 'TEST1' TO ITAB1-FIELD1.

MOVE 'TEST1' TO ITAB1-FIELD2.

MOVE '10.00' TO ITAB1-FIELD3.

APPEND ITAB1.

MOVE 'TEST2' TO ITAB1-FIELD1.

MOVE 'TEST2' TO ITAB1-FIELD2.

MOVE '20.00' TO ITAB1-FIELD3.

APPEND ITAB1.

DO 50 TIMES.

APPEND ITAB1.

ENDDO.

END-OF-SELECTION.

PERFORM BUILD.

PERFORM EVENTTAB_BUILD CHANGING GT_EVENTS.

PERFORM COMMENT_BUILD CHANGING GT_LIST_TOP_OF_PAGE.

PERFORM CALL_ALV.

FORM BUILD.

  • DATA FIELD CATALOG

  • Explain Field Description to ALV

DATA: FIELDCAT_IN TYPE SLIS_FIELDCAT_ALV.

CLEAR FIELDCAT_IN.

FIELDCAT_LN-FIELDNAME = 'FIELD1'.

FIELDCAT_LN-TABNAME = 'ITAB1'.

*FIELDCAT_LN-NO_OUT = 'X'. "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT

FIELDCAT_LN-KEY = ' '. "SUBTOTAL KEY

FIELDCAT_LN-NO_OUT = ' '.

FIELDCAT_LN-SELTEXT_L = 'HEAD1'.

APPEND FIELDCAT_LN TO GT_FIELDCAT.

CLEAR FIELDCAT_IN.

FIELDCAT_LN-FIELDNAME = 'FIELD2'.

FIELDCAT_LN-TABNAME = 'ITAB1'.

FIELDCAT_LN-NO_OUT = 'X'.

FIELDCAT_LN-SELTEXT_L = 'HEAD2'.

APPEND FIELDCAT_LN TO GT_FIELDCAT.

CLEAR FIELDCAT_IN.

FIELDCAT_LN-FIELDNAME = 'FIELD3'.

FIELDCAT_LN-TABNAME = 'ITAB1'.

FIELDCAT_LN-REF_FIELDNAME = 'MENGE'. "<- REF FIELD IN THE DICTIONNARY

FIELDCAT_LN-REF_TABNAME = 'MSEG'. "<- REF TABLE IN THE DICTIONNARY

FIELDCAT_LN-NO_OUT = ' '.

FIELDCAT_LN-DO_SUM = 'X'. "SUM UPON DISPLAY

APPEND FIELDCAT_LN TO GT_FIELDCAT.

  • DATA SORTING AND SUBTOTAL

DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.

CLEAR GS_SORT.

GS_SORT-FIELDNAME = 'FIELD1'.

GS_SORT-SPOS = 1.

GS_SORT-UP = 'X'.

GS_SORT-SUBTOT = 'X'.

APPEND GS_SORT TO GT_SORT.

CLEAR GS_SORT.

GS_SORT-FIELDNAME = 'FIELD2'.

GS_SORT-SPOS = 2.

GS_SORT-UP = 'X'.

*GS_SORT-SUBTOT = 'X'.

APPEND GS_SORT TO GT_SORT.

ENDFORM.

FORM CALL_ALV.

  • ABAP List Viewer

CALL FUNCTION 'REUSE_ALV_LIST_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_STRUCTURE_NAME = 'ITAB1'

IS_LAYOUT = GS_LAYOUT

IT_FIELDCAT = GT_FIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = GT_SORT[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = GT_EVENTS[]

  • IT_EVENT_EXIT =

IS_PRINT = GS_PRINT

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = ITAB1

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ENDFORM.

  • HEADER FORM

FORM EVENTTAB_BUILD CHANGING LT_EVENTS TYPE SLIS_T_EVENT.

CONSTANTS:

GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

*GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE'.

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = LT_EVENTS.

READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO LS_EVENT.

IF SY-SUBRC = 0.

MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.

APPEND LS_EVENT TO LT_EVENTS.

ENDIF.

  • define END_OF_PAGE event

  • READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE

  • INTO LS_EVENT.

  • IF SY-SUBRC = 0.

  • MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.

  • APPEND LS_EVENT TO LT_EVENTS.

  • ENDIF.

ENDFORM.

FORM COMMENT_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: GS_LINE TYPE SLIS_LISTHEADER.

CLEAR GS_LINE.

GS_LINE-TYP = 'H'.

GS_LINE-INFO = 'HEADER 1'.

APPEND GS_LINE TO GT_TOP_OF_PAGE.

CLEAR GS_LINE.

GS_LINE-TYP = 'S'.

GS_LINE-KEY = 'STATUS 1'.

GS_LINE-INFO = 'INFO 1'.

APPEND GS_LINE TO GT_TOP_OF_PAGE.

GS_LINE-KEY = 'STATUS 2'.

GS_LINE-INFO = 'INFO 2'.

APPEND GS_LINE TO GT_TOP_OF_PAGE.

  • CLEAR GS_LINE.

  • GS_LINE-TYP = 'A'.

*

  • GS_LINE-INFO = 'ACTION'.

  • APPEND GS_LINE TO GT_TOP_OF_PAGE.

ENDFORM.

FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.

WRITE: SY-DATUM, 'Page No', SY-PAGNO LEFT-JUSTIFIED.

ENDFORM.

FORM END_OF_PAGE.

WRITE at (sy-linsz) sy-pagno CENTERED.

ENDFORM.

  • PRINT SETTINGS

FORM PRINT_BUILD USING LS_PRINT TYPE SLIS_PRINT_ALV.

LS_PRINT-PRINT = P_PRINT. "PRINT IMMEDIATE

LS_PRINT-NO_PRINT_SELINFOS = P_NOSINF. "NO SELECTION INFO

LS_PRINT-NO_COVERPAGE = P_NOCOVE. "NO COVER PAGE

LS_PRINT-NO_NEW_PAGE = P_NONEWP.

LS_PRINT-NO_PRINT_LISTINFOS = P_NOLINF. "NO PRINT LIST INFO

LS_PRINT-RESERVE_LINES = P_RESERV.

ENDFORM.

*END OF ZALV PROGRAM

Check this program...

Regards,

Pavan

Former Member
0 Kudos
49

hi,

when we sort the output then

a material may exist more than one time .....

now if u want to find the total amount of this material u can click on subtotal...

this is the use of subtotal...

Former Member
0 Kudos
49

Hi

You have to use <b>ls_fieldcat-do_sum =</b> for total or subtotal

Try with this report

*&---------------------------------------------------------------------*
*& Report  ZALVTOTAL                                                   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZALVTOTAL                               .

TYPES :
  BEGIN OF ty_vbak,
    vkorg TYPE vbak-vkorg,             " Sales organization
    kunnr TYPE vbak-kunnr,             " Sold-to party
    vbeln TYPE vbak-vbeln,             " Sales document
    netwr TYPE vbak-netwr,             " Net Value of the Sales Order
    waerk TYPE vbak-waerk,             " Document currency
  END OF ty_vbak.

DATA:
  vbak    TYPE vbak,
  gt_vbak TYPE TABLE OF ty_vbak.

SELECT-OPTIONS :
  s_vkorg FOR vbak-vkorg,              " Sales organization
  s_kunnr FOR vbak-kunnr,              " Sold-to party
  s_vbeln FOR vbak-vbeln.              " Sales document

SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.

*---------------------------------------------------------------------*
INITIALIZATION.

  v_1 = 'Maximum of records to read'.

*---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM f_read_data.

  PERFORM f_display_data.

*---------------------------------------------------------------------*
*      Form  f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.

  SELECT vkorg kunnr vbeln netwr waerk
      UP TO p_max ROWS
    INTO TABLE gt_vbak
    FROM vbak
   WHERE kunnr IN s_kunnr
     AND vbeln IN s_vbeln
     AND vkorg IN s_vkorg.

ENDFORM.                               " F_READ_DATA
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.

  TYPE-POOLS: slis.                    " ALV Global types

  DEFINE m_fieldcat.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname   = &1.
    ls_fieldcat-ref_tabname = 'VBAK'.
    ls_fieldcat-do_sum      = &2.
    ls_fieldcat-cfieldname  = &3.
    append ls_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.

  DEFINE m_sort.
    add 1 to ls_sort-spos.
    ls_sort-fieldname = &1.
    ls_sort-up        = 'X'.
    ls_sort-subtot    = &2.
    append ls_sort to lt_sort.
  END-OF-DEFINITION.

  DATA:
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv,
    lt_sort     TYPE slis_t_sortinfo_alv,
    ls_sort     TYPE slis_sortinfo_alv,
    ls_layout   TYPE slis_layout_alv.

  m_fieldcat 'VKORG' ''  ''.
  m_fieldcat 'KUNNR' ''  ''.
  m_fieldcat 'VBELN' ''  ''.
  m_fieldcat 'NETWR' 'X' 'WAERK'.
  m_fieldcat 'WAERK' ''  ''.

  m_sort 'VKORG' 'X'.                  " Sort by vkorg and subtotal
  m_sort 'KUNNR' 'X'.                  " Sort by kunnr and subtotal
  m_sort 'VBELN' ''.                   " Sort by vbeln

  ls_layout-cell_merge = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            is_layout   = ls_layout
            it_fieldcat = lt_fieldcat
            it_sort     = lt_sort
       TABLES
            t_outtab    = gt_vbak.

ENDFORM.                               " F_DISPLAY_DATA

Reward all helpfull answers

Regards

Pavan

Former Member
0 Kudos
49

Hi,

Check out the below example . u may get some idea



*&---------------------------------------------------------------------*
*& Report  ZMMS_ALV_SUBTOTAL                                           *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

    REPORT  ZMMS_ALV_SUBTOTAL                       .

    TYPE-POOLS: SLIS.

    DATA: BEGIN OF IT_OUTPUT OCCURS 0,
    VAR1(8) TYPE N,
    VAR2(10),
    VAR3 TYPE I,
    END OF IT_OUTPUT.

    DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    T_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
    IT_SORT TYPE SLIS_T_SORTINFO_ALV,
    T_SORT TYPE SLIS_SORTINFO_ALV,
    V_REPID LIKE SY-REPID.

    INITIALIZATION.
*      V_REPID = SY-REPID.

      SET PF-STATUS 'STANDARD' OF PROGRAM 'ZMMS_ALV_SUBTOTAL'.


    START-OF-SELECTION.

      PERFORM GET_DATA.
      PERFORM SORT_FIELDS.
      PERFORM FILL_FIELDCAT.
      PERFORM LIST_DISPLAY.

*&---------------------------------------------------------------------*
*    & Form GET_DATA
*&---------------------------------------------------------------------*
*     text
*----------------------------------------------------------------------*
*     --> p1 text
*     <-- p2 text
*----------------------------------------------------------------------*
    FORM GET_DATA.

      IT_OUTPUT-VAR1 = 1000.
      IT_OUTPUT-VAR2 = 'anupama'.
      IT_OUTPUT-VAR3 = '10000'.
      APPEND IT_OUTPUT.
      CLEAR IT_OUTPUT.

      IT_OUTPUT-VAR1 = 1000.
      IT_OUTPUT-VAR2 = 'siddhu'.
      IT_OUTPUT-VAR3 = '20000'.
      APPEND IT_OUTPUT.
      CLEAR IT_OUTPUT.

      IT_OUTPUT-VAR1 = 1000.
      IT_OUTPUT-VAR2 = 'chinni'.
      IT_OUTPUT-VAR3 = '100000'.
      APPEND IT_OUTPUT.
      CLEAR IT_OUTPUT.

      IT_OUTPUT-VAR1 = 2000.
      IT_OUTPUT-VAR2 = 'chicchu'.
      IT_OUTPUT-VAR3 = '10000'.
      APPEND IT_OUTPUT.
      CLEAR IT_OUTPUT.

      IT_OUTPUT-VAR1 = 2000.
      IT_OUTPUT-VAR2 = 'candy'.
      IT_OUTPUT-VAR3 = '10000'.
      APPEND IT_OUTPUT.
      CLEAR IT_OUTPUT.

      IT_OUTPUT-VAR1 = 1000.
      IT_OUTPUT-VAR2 = 'anupama'.
      IT_OUTPUT-VAR3 = '10000'.
      APPEND IT_OUTPUT.
      CLEAR IT_OUTPUT.

      IT_OUTPUT-VAR1 = 4000.
      IT_OUTPUT-VAR2 = 'anupama'.
      IT_OUTPUT-VAR3 = '10000'.
      APPEND IT_OUTPUT.
      CLEAR IT_OUTPUT.


    ENDFORM. " GET_DATA

*&---------------------------------------------------------------------*
*    & Form fill_fieldcat
*&---------------------------------------------------------------------*
*     text
*----------------------------------------------------------------------*
*     --> p1 text
*     <-- p2 text
*----------------------------------------------------------------------*
    FORM FILL_FIELDCAT.
     PERFORM FILL_FIELDS USING: 'IT_OUTPUT' 'VAR1' 'Variable 1' ' ' ,
                                'IT_OUTPUT' 'VAR2' 'Variable 2' ' ' ,
                                'IT_OUTPUT' 'VAR3' 'Variable 3' 'X' .

    ENDFORM. " fill_fieldcat

*&---------------------------------------------------------------------*
*    & Form fill_fields
*&---------------------------------------------------------------------*
*     text
*----------------------------------------------------------------------*
*     -->P_0146 text
*     -->P_0147 text
*     -->P_0148 text
*     -->P_0149 text
*----------------------------------------------------------------------*
    FORM FILL_FIELDS USING VALUE(TABNAME) TYPE SLIS_TABNAME
    VALUE(FIELDNAME) TYPE SLIS_FIELDNAME
    VALUE(SELTEXT_M) LIKE DD03P-SCRTEXT_M
    VALUE(DO_SUM) TYPE C.
      T_FIELDCAT-TABNAME = TABNAME.
      T_FIELDCAT-FIELDNAME = FIELDNAME.
      T_FIELDCAT-SELTEXT_M = SELTEXT_M.
      IF DO_SUM = 'X'.
        T_FIELDCAT-DATATYPE = 'CURR'.
      ENDIF.
      T_FIELDCAT-DO_SUM = DO_SUM.
      APPEND T_FIELDCAT TO IT_FIELDCAT.
      CLEAR T_FIELDCAT.
    ENDFORM. " fill_fields

*&---------------------------------------------------------------------*
*    & Form list_display
*&---------------------------------------------------------------------*
*     text
*----------------------------------------------------------------------*
*     --> p1 text
*     <-- p2 text
*----------------------------------------------------------------------*
    FORM LIST_DISPLAY.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM = V_REPID
          IT_FIELDCAT        = IT_FIELDCAT
          IT_SORT            = IT_SORT[]
        TABLES
          T_OUTTAB           = IT_OUTPUT
        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. " list_display

*&---------------------------------------------------------------------*
*    & Form sort_fields
*&---------------------------------------------------------------------*
*     text
*----------------------------------------------------------------------*
*     --> p1 text
*     <-- p2 text
*----------------------------------------------------------------------*
    FORM SORT_FIELDS.
      T_SORT-FIELDNAME = 'VAR1'.
      T_SORT-TABNAME = 'IT_OUTPUT'.
      T_SORT-SPOS = 1.
      T_SORT-UP = 'X'.
      T_SORT-SUBTOT = 'X'.
      APPEND T_SORT TO IT_SORT.
      CLEAR T_SORT.

      T_SORT-FIELDNAME = 'VAR3'.
      T_SORT-TABNAME = 'IT_OUTPUT'.
      T_SORT-SPOS = 2.
      T_SORT-UP = 'X'.
      APPEND T_SORT TO IT_SORT.
      CLEAR T_SORT.

    ENDFORM.                    "sort_fields

Reward Points if it is Useful.

Thanks,

Manjunath MS