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

ALV Display - sub totals

hi gurus,

In my report program i have a monthly report displaying the data for that month.

1. Now in my ALV grid i want The SUB-TOTALS for the work center wise data for a field of the alv. there are many workcenters data in my report. So after the end of each work center , i want the subtotal of a calculated TAT field.

2. At the end of the report, I want the average TAT(field calculated by my report program) for that month.

So how can i make the coding for the above.

Iam a fresher to this field, so give me in detail.

regards,

chaitanya

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 16, 2008 at 05:46 AM

    Hi

    i am giving a sample example for subtotals of alv.

    REPORT z_alv_subtotal.

    &----


    *& Table declaration

    &----


    TABLES: EKKO.

    &----


    *& Type pool declaration

    &----


    TYPE-POOLS: SLIS. " Type pool for ALV

    &----


    *& Selection screen

    &----


    SELECT-OPTIONS: S_EBELN FOR EKKO-EBELN.

    &----


    *& Type declaration

    &----


    • Type declaration for internal table to store EKPO data

    TYPES: BEGIN OF X_DATA,

    EBELN TYPE CHAR30, " Document no.

    EBELP TYPE EBELP, " Item no

    MATNR TYPE MATNR, " Material no

    MATNR1 TYPE MATNR, " Material no

    WERKS TYPE WERKS_D, " Plant

    WERKS1 TYPE WERKS_D, " Plant

    NTGEW TYPE ENTGE, " Net weight

    GEWE TYPE EGEWE, " Unit of weight

    END OF X_DATA.

    &----


    *& Internal table declaration

    &----


    DATA:

    • Internal table to store EKPO data

    I_EKPO TYPE STANDARD TABLE OF X_DATA INITIAL SIZE 0,

    • Internal table for storing field catalog information

    I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

    • Internal table for Top of Page info. in ALV Display

    I_ALV_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,

    • Internal table for ALV Display events

    I_EVENTS TYPE SLIS_T_EVENT,

    • Internal table for storing ALV sort information

    I_SORT TYPE SLIS_T_SORTINFO_ALV,

    I_EVENT TYPE SLIS_T_EVENT.

    &----


    *& Work area declaration

    &----


    DATA:

    WA_EKKO TYPE X_DATA,

    WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

    WA_EVENTS TYPE SLIS_ALV_EVENT,

    WA_SORT TYPE SLIS_SORTINFO_ALV.

    &----


    *& Constant declaration

    &----


    CONSTANTS:

    C_HEADER TYPE CHAR1

    VALUE 'H', "Header in ALV

    C_ITEM TYPE CHAR1

    VALUE 'S'.

    &----


    *& Start-of-selection event

    &----


    START-OF-SELECTION.

    • Select data from ekpo

    SELECT EBELN " Doc no

    EBELP " Item

    MATNR " Material

    MATNR " Material

    WERKS " Plant

    WERKS " Plant

    NTGEW " Quantity

    GEWEI " Unit

    FROM EKPO

    INTO TABLE I_EKPO

    WHERE EBELN IN S_EBELN

    AND NTGEW NE '0.00'.

    IF SY-SUBRC = 0.

    SORT I_EKPO BY EBELN EBELP MATNR .

    ENDIF.

    • To build the Page header

    PERFORM SUB_BUILD_HEADER.

    • To prepare field catalog

    PERFORM SUB_FIELD_CATALOG.

    • Perform to populate the layout structure

    PERFORM SUB_POPULATE_LAYOUT.

    • Perform to populate the sort table.

    PERFORM SUB_POPULATE_SORT.

    • Perform to populate ALV event

    PERFORM SUB_GET_EVENT.

    END-OF-SELECTION.

    • Perform to display ALV report

    PERFORM SUB_ALV_REPORT_DISPLAY.

    &----


    *& Form sub_build_header

    &----


    • To build the header

    ----


    • No Parameter

    ----


    FORM SUB_BUILD_HEADER .

    • Local data declaration

    DATA: L_SYSTEM TYPE CHAR10 , "System id

    L_R_LINE TYPE SLIS_LISTHEADER, "Hold list header

    L_DATE TYPE CHAR10, "Date

    L_TIME TYPE CHAR10, "Time

    L_SUCCESS_RECORDS TYPE I, "No of success records

    L_TITLE(300) TYPE C. " Title

    • Title Display

    L_R_LINE-TYP = C_HEADER. " header

    L_TITLE = 'Test report'(001).

    L_R_LINE-INFO = L_TITLE.

    APPEND L_R_LINE TO I_ALV_TOP_OF_PAGE.

    CLEAR L_R_LINE.

    • Run date Display

    CLEAR L_DATE.

    L_R_LINE-TYP = C_ITEM. " Item

    WRITE: SY-DATUM TO L_DATE MM/DD/YYYY.

    L_R_LINE-KEY = 'Run Date :'(002).

    L_R_LINE-INFO = L_DATE.

    APPEND L_R_LINE TO I_ALV_TOP_OF_PAGE.

    CLEAR: L_R_LINE,

    L_DATE.ENDFORM. " sub_build_header

    &----


    *& Form sub_field_catalog

    &----


    • Build Field Catalog

    ----


    • No Parameter

    ----


    FORM SUB_FIELD_CATALOG .

    • Build Field Catalog

    PERFORM SUB_FILL_ALV_FIELD_CATALOG USING:

    '01' '01' 'EBELN' 'I_EKPO' 'L' 'Doc No'(003) ' ' ' ' ' ' ' ',

    '01' '02' 'EBELP' 'I_EKPO' 'L' 'Item No'(004) 'X' 'X' ' ' ' ',

    '01' '03' 'MATNR' 'I_EKPO' 'L' 'Material No'(005) 'X' 'X' ' ' ' ',

    '01' '03' 'MATNR1' 'I_EKPO' 'L' 'Material No'(005) ' ' ' ' ' ' ' ',

    '01' '04' 'WERKS' 'I_EKPO' 'L' 'Plant'(006) 'X' 'X' ' ' ' ',

    '01' '04' 'WERKS1' 'I_EKPO' 'L' 'Plant'(006) ' ' ' ' ' ' ' ',

    '01' '05' 'NTGEW' 'I_EKPO' 'R' 'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'

    .

    ENDFORM. " sub_field_catalog

    &----


    *& Form sub_fill_alv_field_catalog

    &----


    *& For building Field Catalog

    &----


    *& p_rowpos Row position

    *& p_colpos Col position

    *& p_fldnam Fldname

    *& p_tabnam Tabname

    *& p_justif Justification

    *& p_seltext Seltext

    *& p_out no out

    *& p_tech Technical field

    *& p_qfield Quantity field

    *& p_qtab Quantity table

    &----


    FORM SUB_FILL_ALV_FIELD_CATALOG USING P_ROWPOS TYPE SYCUROW

    P_COLPOS TYPE SYCUCOL

    P_FLDNAM TYPE FIELDNAME

    P_TABNAM TYPE TABNAME

    P_JUSTIF TYPE CHAR1

    P_SELTEXT TYPE DD03P-SCRTEXT_L

    P_OUT TYPE CHAR1

    P_TECH TYPE CHAR1

    P_QFIELD TYPE SLIS_FIELDNAME

    P_QTAB TYPE SLIS_TABNAME.

    • Local declaration for field catalog

    DATA: WA_LFL_FCAT TYPE SLIS_FIELDCAT_ALV.

    WA_LFL_FCAT-ROW_POS = P_ROWPOS. "Row

    WA_LFL_FCAT-COL_POS = P_COLPOS. "Column

    WA_LFL_FCAT-FIELDNAME = P_FLDNAM. "Field Name

    WA_LFL_FCAT-TABNAME = P_TABNAM. "Internal Table Name

    WA_LFL_FCAT-JUST = P_JUSTIF. "Screen Justified

    WA_LFL_FCAT-SELTEXT_L = P_SELTEXT. "Field Text

    WA_LFL_FCAT-NO_OUT = P_OUT. "No output

    WA_LFL_FCAT-TECH = P_TECH. "Technical field

    WA_LFL_FCAT-QFIELDNAME = P_QFIELD. "Quantity unit

    WA_LFL_FCAT-QTABNAME = P_QTAB . "Quantity table

    IF P_FLDNAM = 'NTGEW'.

    WA_LFL_FCAT-DO_SUM = 'X'.

    ENDIF.

    APPEND WA_LFL_FCAT TO I_FIELDCAT.

    CLEAR WA_LFL_FCAT.

    ENDFORM. " sub_fill_alv_field_catalog

    &----


    *& Form sub_populate_layout

    &----


    • Populate ALV layout

    ----


    • No Parameter

    ----


    FORM SUB_POPULATE_LAYOUT . CLEAR WA_LAYOUT.

    WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'." Optimization of Col width

    ENDFORM. " sub_populate_layout

    &----


    *& Form sub_populate_sort

    &----


    • Populate ALV sort table

    ----


    • No Parameter

    ----


    FORM SUB_POPULATE_SORT .

    • Sort on material

    WA_SORT-SPOS = '01' .

    WA_SORT-FIELDNAME = 'MATNR'.

    WA_SORT-TABNAME = 'I_EKPO'.

    WA_SORT-UP = 'X'.

    WA_SORT-SUBTOT = 'X'.

    APPEND WA_SORT TO I_SORT .

    CLEAR WA_SORT.

    • Sort on plant

    WA_SORT-SPOS = '02'.

    WA_SORT-FIELDNAME = 'WERKS'.

    WA_SORT-TABNAME = 'I_EKPO'.

    WA_SORT-UP = 'X'.

    WA_SORT-SUBTOT = 'X'.

    APPEND WA_SORT TO I_SORT .

    CLEAR WA_SORT.

    ENDFORM. " sub_populate_sort

    &----


    *& Form sub_get_event

    &----


    • Get ALV grid event and pass the form name to subtotal_text

    • event

    ----


    • No Parameter

    ----


    FORM SUB_GET_EVENT .

    CONSTANTS : C_FORMNAME_SUBTOTAL_TEXT TYPE SLIS_FORMNAME VALUE

    'SUBTOTAL_TEXT'.

    DATA: L_S_EVENT TYPE SLIS_ALV_EVENT.

    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

    I_LIST_TYPE = 4

    IMPORTING

    ET_EVENTS = I_EVENT

    EXCEPTIONS

    LIST_TYPE_WRONG = 0

    OTHERS = 0.

    • Subtotal

    READ TABLE I_EVENT INTO L_S_EVENT

    WITH KEY NAME = SLIS_EV_SUBTOTAL_TEXT.

    IF SY-SUBRC = 0.

    MOVE C_FORMNAME_SUBTOTAL_TEXT TO L_S_EVENT-FORM.

    MODIFY I_EVENT FROM L_S_EVENT INDEX SY-TABIX.

    ENDIF.

    ENDFORM. " sub_get_event

    &----


    *& Form sub_alv_report_display

    &----


    • For ALV Report Display

    ----


    • No Parameter

    ----


    FORM SUB_ALV_REPORT_DISPLAY .

    DATA: L_REPID TYPE SYREPID .

    L_REPID = SY-REPID .

    • This function module for displaying the ALV report

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = L_REPID

    I_CALLBACK_TOP_OF_PAGE = 'SUB_ALV_TOP_OF_PAGE'

    IS_LAYOUT = WA_LAYOUT

    IT_FIELDCAT = I_FIELDCAT

    IT_SORT = I_SORT

    IT_EVENTS = I_EVENT

    I_DEFAULT = 'X'

    I_SAVE = 'A'

    TABLES

    T_OUTTAB = I_EKPO

    EXCEPTIONS

    PROGRAM_ERROR = 1

    OTHERS = 2.

    IF SY-SUBRC <> 0.

    • MESSAGE i000 WITH 'Error in ALV report display'(055).

    ENDIF.ENDFORM. " sub_alv_report_display

    &----


    • FORM sub_alv_top_of_page

    ----


    • Call ALV top of page

    ----


    • No parameter

    ----


    FORM SUB_ALV_TOP_OF_PAGE. "#EC CALLED

    • To write header for the ALV

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    IT_LIST_COMMENTARY = I_ALV_TOP_OF_PAGE.

    ENDFORM. "alv_top_of_page

    &----


    *& Form subtotal_text

    &----


    • Build subtotal text

    ----


    • P_total Total

    • p_subtot_text Subtotal text info

    ----


    FORM SUBTOTAL_TEXT CHANGING

    P_TOTAL TYPE ANY

    P_SUBTOT_TEXT TYPE SLIS_SUBTOT_TEXT.

    • Material level sub total

    IF P_SUBTOT_TEXT-CRITERIA = 'MATNR'.

    P_SUBTOT_TEXT-DISPLAY_TEXT_FOR_SUBTOTAL

    = 'Material level total'(009).

    ENDIF.

    • Plant level sub total

    IF P_SUBTOT_TEXT-CRITERIA = 'WERKS'.

    P_SUBTOT_TEXT-DISPLAY_TEXT_FOR_SUBTOTAL = 'Plant level total'(010).

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 16, 2008 at 06:13 AM

    HI,

    see the bolded portions to achieve the subtotals.

    TABLES : vbak.

    TYPE-POOLS: slis. " ALV Global types

    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.

    DATA:

    BEGIN OF gt_vbak OCCURS 0,

    vkorg LIKE vbak-vkorg, " Sales organization

    kunnr LIKE vbak-kunnr, " Sold-to party

    vbeln LIKE vbak-vbeln, " Sales document

    netwr LIKE vbak-netwr, " Net Value of the Sales Order

    waerk LIKE vbak-waerk, " Document currency

    END OF gt_vbak.

    INITIALIZATION.

    v_1 = 'Maximum of records to read'.

    START-OF-SELECTION.

    PERFORM f_read_data.

    PERFORM f_display_data.

    FORM f_read_data.

    SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak

    FROM vbak

    UP TO p_max ROWS

    WHERE kunnr IN s_kunnr

    AND vbeln IN s_vbeln

    AND vkorg IN s_vkorg.

    ENDFORM. " F_READ_DATA

    FORM f_display_data.

    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.

    rgds,

    bharat.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 16, 2008 at 07:06 AM

    Hi, try this code...

    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.

    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.

    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'(001).

    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[/code]

    Regards,

    kavitha

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 16, 2008 at 05:42 AM

    Hi Just check this sample program

    Dont forget to reward points if useful

    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.
    
    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.
    
    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'(001).
    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

    Regards,

    sas

    Edited by: saslove sap on Apr 16, 2008 7:42 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 16, 2008 at 05:49 AM

    hi,

    Go thru this program..

    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.

    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.

    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'(001).

    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

    pls reward if usel

    Regards,

    rekha

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 16, 2008 at 06:08 AM

    iam not yet completely understood ur replies.

    can u plz help me.

    only the changes i have to do in my prog in detail.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 09, 2008 at 05:43 AM

    s

    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.