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

REUSE_ALV_HIERSEQ_LIST_DISPLAY

Hi all,

I am trying to display two header line in my alv report diaplay. I am not able to display two lines of heading,, can any one please suggest me some examples as to how to do it.

Regards...

Vj

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 10, 2007 at 02:36 PM

    Hi,

    As far as i have worked with this FM you can only display one header and line items beneath it. Both the Header and Line items should be related to each other.

    As far as i know at least using the above FM, you cannot have two header lines.

    Regards,

    Goutham.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 10, 2007 at 02:36 PM

    hi...

    <b>HIERARCHY ALV</b>

    ********************************************************************************************

    REPORT ZALV2 NO STANDARD PAGE HEADING

    MESSAGE-ID ZMSG.

    **********************TABLES DECLARATION******************************

    TABLES : VBAK, " sales document header data

    VBAP. " sales document item data

    **********************TYPE POOL DECLARATION***************************

    TYPE-POOLS : SLIS.

    **********************TYPES DECLARATION*******************************

    *TYPES : BEGIN OF TY_VBAK,

    • VBELN TYPE VBAK-VBELN,

    • ERDAT TYPE VBAK-ERDAT,

    • ERNAM TYPE VBAK-ERNAM,

    • AUART TYPE VBAK-AUART,

    • NETWR TYPE VBAK-NETWR,

    • END OF TY_VBAK.

    *

    *TYPES : BEGIN OF TY_VBAP,

    • VBELN TYPE VBAP-VBELN,

    • POSNR TYPE VBAP-POSNR,

    • MATNR TYPE VBAP-MATNR,

    • MEINS TYPE VBAP-MEINS,

    • ZMENG TYPE VBAP-ZMENG,

    • END OF TY_VBAP.

    ***********************INTERNAL TABLES********************************

    *DATA : IT_VBAK TYPE STANDARD TABLE OF TY_VBAK,

    • IT_VBAP TYPE STANDARD TABLE OF TY_VBAP,

    DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

    " field catalog internal table

    DATA : BEGIN OF IT_VBAK OCCURS 0,

    " internal table for sales document header data

    VBELN TYPE VBAK-VBELN, " sales document

    ERDAT TYPE VBAK-ERDAT,

    " date on which document was created

    ERNAM TYPE VBAK-ERNAM,

    " name of the person who created it

    AUART TYPE VBAK-AUART, " sales document type

    NETWR TYPE VBAK-NETWR,

    " net value of the sales order in document currency

    END OF IT_VBAK.

    DATA : BEGIN OF IT_VBAP OCCURS 0,

    " internal table for sales document item data

    VBELN TYPE VBAP-VBELN, " sales document

    POSNR TYPE VBAP-POSNR, " sales document item

    MATNR TYPE VBAP-MATNR, " material number

    MEINS TYPE VBAP-MEINS, " base unit of measure

    ZMENG TYPE VBAP-ZMENG, " target quantity in sales units

    END OF IT_VBAP.

    DATA : TY_FIELDCAT TYPE SLIS_FIELDCAT_ALV, " field catalog type

    TY_KEYINFO TYPE SLIS_KEYINFO_ALV. " key information type

    ***********************VARIABLE DECLARATIONS**************************

    DATA : REPID TYPE SY-REPID, " program name

    IT_HEADER TYPE SLIS_TABNAME,

    " table to store header data

    IT_ITEM TYPE SLIS_TABNAME. " table to store item data

    ***********************SELECTION PARAMETERS***************************

    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

    SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN.

    " mulitple selection inputs for sales document

    SELECTION-SCREEN : END OF BLOCK B1.

    ***********************INITIALIZATION*********************************

    REPID = SY-REPID.

    " variable having the program name

    IT_HEADER = 'IT_VBAK'.

    IT_ITEM = 'IT_VBAP'.

    CLEAR TY_KEYINFO.

    TY_KEYINFO-HEADER01 = 'VBELN'.

    " comparing the keys and relating the header and item internal tables

    TY_KEYINFO-ITEM01 = 'VBELN'.

    TY_KEYINFO-HEADER02 = SPACE.

    TY_KEYINFO-ITEM02 = 'POSNR'.

    ***********************VALIDATION CHECK*******************************

    AT SELECTION-SCREEN.

    PERFORM VAL_CHK.

    " validation check for the input

    **********************PROCESSING LOGIC********************************

    START-OF-SELECTION.

    PERFORM POP_HDR.

    " populating the header data

    PERFORM POP_ITEM. " populating the item data

    PERFORM FIELD_CATALOG.

    " mapping all the fields to the field catalog

    PERFORM OUTPUT.

    " displaying ouput using the function module

    &----


    *& Form VAL_CHK

    &----


    • text VALIDATION CHECK FOR SALES DOCUMENT

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM VAL_CHK .

    SELECT VBELN

    ERDAT

    ERNAM

    AUART

    NETWR UP TO 1 ROWS

    FROM VBAK

    INTO CORRESPONDING FIELDS OF TABLE IT_VBAK

    WHERE VBELN IN S_VBELN.

    IF SY-SUBRC <> 0.

    MESSAGE I000 WITH 'NO HEADER DETAILS EXIST'.

    ELSE.

    SELECT VBELN

    POSNR

    MATNR

    MEINS

    ZMENG

    FROM VBAP

    INTO CORRESPONDING FIELDS OF TABLE IT_VBAP

    WHERE VBELN IN S_VBELN.

    IF SY-SUBRC <> 0.

    MESSAGE I000 WITH 'NO ITEM DETAILS EXIST'.

    ENDIF.

    ENDIF.

    CLEAR IT_VBAK.

    CLEAR IT_VBAP.

    ENDFORM. " VAL_CHK

    &----


    *& Form POP_HDR

    &----


    • text POPULATING THE HEADER DETAILS

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM POP_HDR .

    SELECT VBELN

    ERDAT

    ERNAM

    AUART

    NETWR

    FROM VBAK

    INTO CORRESPONDING FIELDS OF TABLE IT_VBAK

    WHERE VBELN IN S_VBELN.

    ENDFORM. " POP_HDR

    &----


    *& Form POP_ITEM

    &----


    • text POPULATING THE ITEM DETAILS

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM POP_ITEM .

    SELECT VBELN

    POSNR

    MATNR

    MEINS

    ZMENG

    FROM VBAP

    INTO CORRESPONDING FIELDS OF TABLE IT_VBAP

    WHERE VBELN IN S_VBELN.

    ENDFORM. " POP_ITEM

    &----


    *& Form FIELD_CATALOG

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM FIELD_CATALOG .

    TY_FIELDCAT-TABNAME = 'IT_VBAK'.

    TY_FIELDCAT-FIELDNAME = 'VBELN'.

    TY_FIELDCAT-SELTEXT_L = 'DOC NO'.

    TY_FIELDCAT-COL_POS = 1.

    TY_FIELDCAT-OUTPUTLEN = 10.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAK'.

    TY_FIELDCAT-FIELDNAME = 'ERDAT'.

    TY_FIELDCAT-SELTEXT_L = 'DATE'.

    TY_FIELDCAT-COL_POS = 2.

    TY_FIELDCAT-OUTPUTLEN = 8.

    TY_FIELDCAT-DATATYPE = 'DATS'.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAK'.

    TY_FIELDCAT-FIELDNAME = 'ERNAM'.

    TY_FIELDCAT-SELTEXT_L = 'NAME'.

    TY_FIELDCAT-COL_POS = 3.

    TY_FIELDCAT-OUTPUTLEN = 12.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAK'.

    TY_FIELDCAT-FIELDNAME = 'AUART'.

    TY_FIELDCAT-SELTEXT_L = 'DOC TYPE'.

    TY_FIELDCAT-COL_POS = 4.

    TY_FIELDCAT-OUTPUTLEN = 4.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAP'.

    TY_FIELDCAT-FIELDNAME = 'VBELN'.

    TY_FIELDCAT-SELTEXT_L = 'DOC NO'.

    TY_FIELDCAT-OUTPUTLEN = 10.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAP'.

    TY_FIELDCAT-FIELDNAME = 'POSNR'.

    TY_FIELDCAT-SELTEXT_L = 'ITEM'.

    TY_FIELDCAT-OUTPUTLEN = 6.

    TY_FIELDCAT-DATATYPE = 'NUMC'.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAP'.

    TY_FIELDCAT-FIELDNAME = 'MATNR'.

    TY_FIELDCAT-SELTEXT_L = 'MAT NO'.

    TY_FIELDCAT-OUTPUTLEN = 18.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAP'.

    TY_FIELDCAT-FIELDNAME = 'MEINS'.

    TY_FIELDCAT-SELTEXT_L = 'UNITS'.

    TY_FIELDCAT-OUTPUTLEN = 3.

    TY_FIELDCAT-DATATYPE = 'UNIT'.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    TY_FIELDCAT-TABNAME = 'IT_VBAP'.

    TY_FIELDCAT-FIELDNAME = 'ZMENG'.

    TY_FIELDCAT-SELTEXT_L = 'QUANT'.

    TY_FIELDCAT-OUTPUTLEN = 13.

    TY_FIELDCAT-DATATYPE = 'QUAN'.

    APPEND TY_FIELDCAT TO IT_FIELDCAT.

    CLEAR TY_FIELDCAT.

    ENDFORM. " FIELD_CATALOG

    &----


    *& Form OUTPUT

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM OUTPUT .

    CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

    EXPORTING

    • I_INTERFACE_CHECK = ' '

    I_CALLBACK_PROGRAM = REPID

    • I_CALLBACK_PF_STATUS_SET = ' '

    • I_CALLBACK_USER_COMMAND = ' '

    • IS_LAYOUT =

    IT_FIELDCAT = IT_FIELDCAT

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    • IT_SORT =

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • I_DEFAULT = 'X'

    • I_SAVE = ' '

    • IS_VARIANT =

    • IT_EVENTS =

    • IT_EVENT_EXIT =

    I_TABNAME_HEADER = IT_HEADER

    I_TABNAME_ITEM = IT_ITEM

    • I_STRUCTURE_NAME_HEADER =

    • I_STRUCTURE_NAME_ITEM =

    IS_KEYINFO = TY_KEYINFO

    • IS_PRINT =

    • IS_REPREP_ID =

    • I_BYPASSING_BUFFER =

    • I_BUFFER_ACTIVE =

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

    • ES_EXIT_CAUSED_BY_USER =

    TABLES

    T_OUTTAB_HEADER = IT_VBAK

    T_OUTTAB_ITEM = IT_VBAP

    • 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. " OUTPUT

    *******************************************************************************************

    <b><REMOVED BY MODERATOR></b>

    Vasu

    Message was edited by:

    Alvaro Tejada Galindo

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 10, 2007 at 02:37 PM

    check this Example program

    REPORT ZS_REPT_SD_REPORT_47

    MESSAGE-ID ZSD

    NO STANDARD PAGE HEADING

    LINE-COUNT 65(2)

    LINE-SIZE 127.

    ************************************************************************

    • Progname : ZS_REPT_SD_REPORT_47 *

    • Description : Service MRA Report *

    ----


    • LOGICAL DB : VERSION OF : *

    ----


    • DESCRIPTION : Service MRA Report *

    ----


    • AUTHOR : DRN Kishore *

    • DATE : 03/10/2005 *

    ----


    • MODIFICATION LOG (latest change first): *

    • Date Incident Request Author *

    • #30445 DRN Kishore *

    • Description: *

    ----


    TYPE-POOLS: SLIS.

    TABLES : VBRK, " Billing: Header Data

    VBRP, " Billing: Item Data

    KONV, " Conditions (Transaction Data)

    KNA1, " General Data in Customer Master

    TVKO, " Organizational Unit: Sales Organizations

    TVTW, " Organizational Unit: Distribution Channels

    TSPA, " Organizational Unit: Sales Divisions

    MARA, " General Material Data

    TVFK, " Billing: Document Types

    TVAU. " Sales Documents: Order Reasons

    &----


    &

    *& INTERNAL TABLES. *

    &----


    &

    • Internal table To hold the VBRK Billing data

    DATA : BEGIN OF IT_VBRK OCCURS 0,

    VBELN LIKE VBRK-VBELN, " Billing document

    KUNAG LIKE VBRK-KUNAG, " Sold-to

    FKDAT LIKE VBRK-FKDAT, " Bill Date

    FKART LIKE VBRK-FKART, " Bill doc type

    KNUMV LIKE VBRK-KNUMV, " doc cond number

    • field credit applied(TBD)

    WAERK LIKE VBRK-WAERK, " SD document currency

    END OF IT_VBRK.

    • Internal table To hold the VBRK Billing:Item data

    DATA : BEGIN OF IT_VBRP OCCURS 0,

    VBELN LIKE VBRP-VBELN, " Billing document

    POSNR LIKE VBRP-POSNR, " Billing item

    FKIMG LIKE VBRP-FKIMG, " Blled quantity

    MATNR LIKE VBRP-MATNR, " Material number

    AUGRU_AUFT LIKE VBRP-AUGRU_AUFT, " Order reason

    NETWR LIKE VBRP-NETWR, " Net val in

    END OF IT_VBRP.

    • Internal table To hold distinct doc condition no's and their

    • condition values

    DATA : BEGIN OF IT_KONV OCCURS 0,

    KNUMV LIKE KONV-KNUMV, " # of document condition

    KPOSN LIKE KONV-KPOSN, " Condition item number

    KWERT LIKE KONV-KWERT, " Condition value

    END OF IT_KONV.

    • Internal table To hold distinct doc condition no's

    DATA : BEGIN OF IT_KNUMV OCCURS 0,

    KNUMV LIKE KONV-KNUMV, " # of document condition

    END OF IT_KNUMV.

    • Final internal table for list display

    DATA : BEGIN OF IT_FINAL OCCURS 0,

    CUST_NO LIKE VBRK-KUNAG,

    BILL_DOC LIKE VBRK-VBELN,

    BILL_DATE LIKE VBRK-FKDAT,

    BILL_TYPE LIKE VBRK-FKART,

    MODEL LIKE VBRP-MATNR,

    SHP_COST LIKE KONV-KWERT,

    FLD_CR LIKE VBRP-NETWR, " vbrp-augru_auft = 'DU'

    MRA_CODE LIKE VBRP-AUGRU_AUFT,

    MRA_AMOUNT LIKE VBRP-NETWR,

    INVOICE_AMT LIKE VBRP-NETWR,

    CURRENCY LIKE VBRK-WAERK,

    END OF IT_FINAL.

    *--Internal table to store Document header details for display

    DATA : BEGIN OF IT_HEAD OCCURS 0,

    EXP,

    CUST_NO LIKE VBRK-KUNAG, " Customer Number

    BILL_DOC LIKE VBRK-VBELN, " Document number

    BILL_DATE LIKE VBRK-FKDAT, " Billing date

    BILL_TYPE LIKE VBRK-FKART, " Billing type

    END OF IT_HEAD.

    *--Internal table to store Document item details for display

    DATA : BEGIN OF IT_ITEM OCCURS 0,

    BILL_DOC LIKE VBRK-VBELN, " Document number

    MODEL LIKE VBRP-MATNR, " Material Number

    SHP_COST LIKE KONV-KWERT, " Doc Condition value

    FLD_CR LIKE VBRP-NETWR, " IF VBRP-AUGRU_AUFT='DU'

    MRA_CODE LIKE VBRP-AUGRU_AUFT, " MRA Code

    MRA_AMOUNT LIKE VBRP-NETWR, " IF VBRK-FKART = 'RE'

    INVOICE_AMT LIKE VBRP-NETWR, " Invoice Amount

    CURRENCY LIKE VBRK-WAERK, " Currency

    END OF IT_ITEM.

    *--To store the second level data : Billing document, amount

    DATA : BEGIN OF IT_DETAILS OCCURS 0,

    CUST_NO LIKE VBRK-KUNAG, " Customer Number

    BILL_DOC LIKE VBRK-VBELN, " Document number

    QUANTITY TYPE I,"VBRP-FKIMG, " Qty

    AMOUNT LIKE VBRP-NETWR, " Amount

    END OF IT_DETAILS.

    *---Structures for ALV List Display

    DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,

    LS_LAYOUT TYPE SLIS_LAYOUT_ALV,

    LS_VARIANT TYPE DISVARIANT,

    LS_EVENT TYPE SLIS_ALV_EVENT,

    LS_KEYINFO TYPE SLIS_KEYINFO_ALV,

    LS_SORTINFO TYPE SLIS_SORTINFO_ALV.

    *---Internal Tables for ALV List Display

    DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

    IT_EVENTS TYPE SLIS_T_EVENT,

    IT_SORTINFO TYPE SLIS_T_SORTINFO_ALV.

    DATA : V_REPID LIKE SY-REPID.

    DATA : V_TOTAL_SALES_QTY TYPE I, " Total Sales Quantity

    V_TOTAL_SALES_AMT LIKE VBRP-NETWR, " Total Sales Amount

    V_TOTAL_RTRNS_QTY TYPE I, " Total Returns Qty

    V_TOTAL_RTRNS_AMT LIKE VBRP-NETWR, " Total Returns Amt

    V_TOTAL_FLDCR_QTY TYPE I, " Total Fld Cr Qty

    V_TOTAL_FLDCR_AMT LIKE VBRP-NETWR, " Total Fld Cr Amount

    V_CURRENCY LIKE VBRK-WAERK. " Currency Key

    &----


    &

    *& SELECTION-SCREEN. *

    &----


    &

    SELECTION-SCREEN BEGIN OF BLOCK SEL1 WITH FRAME TITLE TEXT-001.

    SELECT-OPTIONS: S_VKORG FOR VBRK-VKORG " Sales Organization

    OBLIGATORY,

    S_VTWEG FOR VBRK-VTWEG " Distribution Channel

    OBLIGATORY,

    S_SPART FOR VBRK-SPART " Division

    OBLIGATORY,

    S_KUNAG FOR VBRK-KUNAG, " Sold-to-party

    S_MATNR FOR VBRP-MATNR, " Material

    S_FKDAT FOR VBRK-FKDAT " Billing Date

    OBLIGATORY,

    S_FKART FOR VBRK-FKART, " Billing Type

    S_AUGRU FOR VBRP-AUGRU_AUFT. " MRA Code

    SELECTION-SCREEN ULINE.

    SELECTION-SCREEN BEGIN OF LINE.

    PARAMETERS:RB_DTL RADIOBUTTON GROUP G1.

    SELECTION-SCREEN COMMENT 4(35) TEXT-002 . " Detail Report

    SELECTION-SCREEN END OF LINE.

    *- Product class summary by customer

    SELECTION-SCREEN BEGIN OF LINE.

    PARAMETERS:RB_SUM RADIOBUTTON GROUP G1.

    SELECTION-SCREEN COMMENT 4(35) TEXT-003. " Summary

    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN END OF BLOCK SEL1.

    &----


    &

    *& At Selection Screen Event *

    &----


    &

    AT SELECTION-SCREEN.

    *---Validate selection-screen. Check for inputs

    PERFORM VALIDATE.

    &----


    &

    *& TOP-OF-PAGE *

    &----


    &

    TOP-OF-PAGE.

    *---Display the standard top of page if summary is selected

    PERFORM TOP_OF_PAGE_REPORT.

    TOP-OF-PAGE DURING LINE-SELECTION.

    *---Display the standard top of page if summary is selected

    PERFORM TOP_OF_PAGE_REPORT.

    PERFORM DISPLAY_COLUMN_HEADERS.

    &----


    &

    *& START-OF-SELECTION. *

    &----


    &

    START-OF-SELECTION.

    *---Get the required data from tables

    PERFORM GET_DATA.

    &----


    &

    *& END-OF-SELECTION. *

    &----


    &

    END-OF-SELECTION.

    *---Display report

    PERFORM DISPLAY_DATA.

    &----


    &

    *& AT LINE SELECTION *

    &----


    &

    AT LINE-SELECTION.

    *--Display details for the quantity or the amount selected.

    PERFORM DISPLAY_DETAIL.

    &----


    *& Form VALIDATE *

    &----


    • Validate Billing date in the selection-screen *

    ----


    FORM VALIDATE.

    *- To Check Sales Organization

    SELECT VKORG UP TO 1 ROWS

    FROM TVKO

    INTO TVKO-VKORG

    WHERE VKORG IN S_VKORG.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E001.

    ENDIF.

    *- To Check Distribution Channel

    SELECT VTWEG UP TO 1 ROWS

    FROM TVTW

    INTO TVTW-VTWEG

    WHERE VTWEG IN S_VTWEG.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E002.

    ENDIF.

    *- To Check Division

    SELECT SPART UP TO 1 ROWS

    FROM TSPA

    INTO TSPA-SPART

    WHERE SPART IN S_SPART.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E003.

    ENDIF.

    *- To Check Shipt-to

    SELECT KUNNR UP TO 1 ROWS

    FROM KNA1

    INTO KNA1-KUNNR

    WHERE KUNNR IN S_KUNAG.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E030.

    ENDIF.

    *- To Check Model Number

    SELECT MATNR UP TO 1 ROWS

    FROM MARA

    INTO MARA-MATNR

    WHERE MATNR IN S_MATNR.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E047.

    ENDIF.

    *- To Check Billing Date

    SELECT FKDAT UP TO 1 ROWS

    FROM VBRK

    INTO VBRK-FKDAT

    WHERE FKDAT IN S_FKDAT.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E048.

    ENDIF.

    *- To Check Billing Type

    SELECT FKART UP TO 1 ROWS

    FROM TVFK

    INTO TVFK-FKART

    WHERE FKART IN S_FKART.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E004.

    ENDIF.

    *- To Check MRA Code

    SELECT AUGRU UP TO 1 ROWS

    FROM TVAU

    INTO TVAU-AUGRU

    WHERE AUGRU IN S_AUGRU.

    ENDSELECT.

    IF SY-SUBRC NE 0.

    MESSAGE E049.

    ENDIF.

    ENDFORM. " VALIDATE

    &----


    *& Form GET_DATA *

    &----


    • Get the required data from tables *

    ----


    FORM GET_DATA.

    *--Get Billing data from VBRK and VBRP

    PERFORM GET_BILLING_DATA.

    *--Get Shipping Costs from KONV based on the Document Condition Number

    PERFORM GET_SHIPPING_COSTS.

    ENDFORM. " GET_DATA

    &----


    *& Form GET_BILLING_DATA *

    &----


    • Get Billing data from VBRK and VBRP *

    ----


    FORM GET_BILLING_DATA.

    *---Get data Billing Document header details from VBRK

    • based on the selection criteria

    SELECT VBELN " Billing Document

    KUNAG " Customer

    FKDAT " Billing Date

    FKART " Billing Type

    KNUMV " Document Condition Number

    WAERK " Currency

    INTO TABLE IT_VBRK

    FROM VBRK

    WHERE VKORG IN S_VKORG " Sales Organisation

    AND VTWEG IN S_VTWEG " Distribution Channel

    AND SPART IN S_SPART " Division

    AND KUNAG IN S_KUNAG " Customer

    AND FKDAT IN S_FKDAT " Billing Date

    AND FKART IN S_FKART " Billing Type

    AND VBTYP NE 'N' " Cancelled Ducuments

    AND FKSTO NE 'X'. " Cancellation Indicator

    SORT IT_VBRK BY VBELN.

    *---Get data Billing Document item details from VBRP for all selected

    • from VBRP and other criteria entered in the selection criteria

    IF NOT IT_VBRK[] IS INITIAL.

    SELECT VBELN " Billing Document

    POSNR " Item Number

    FKIMG " Billed Quantity

    MATNR " Material Number

    AUGRU_AUFT " MRA Code

    NETWR " Invoice Amount

    FROM VBRP

    INTO TABLE IT_VBRP

    FOR ALL ENTRIES IN IT_VBRK

    WHERE VBELN = IT_VBRK-VBELN " Document Number

    AND MATNR IN S_MATNR " Material Number

    AND AUGRU_AUFT IN S_AUGRU. " MRA Code

    ENDIF.

    ENDFORM. " GET_BILLING_DATA

    &----


    *& Form GET_SHIPPING_COSTS *

    &----


    *& Get Shipping Costs from KONV based on the Document Condition Number *

    ----


    FORM GET_SHIPPING_COSTS.

    *--Get all the selected Document condition numbers into internal table

    IF NOT IT_VBRK[] IS INITIAL.

    LOOP AT IT_VBRK.

    IT_KNUMV-KNUMV = IT_VBRK-KNUMV.

    APPEND IT_KNUMV.

    ENDLOOP.

    *---Get the Condition values for the Cundition numbers

    IF NOT IT_KNUMV[] IS INITIAL.

    SORT IT_KNUMV BY KNUMV.

    DELETE ADJACENT DUPLICATES FROM IT_KNUMV COMPARING KNUMV.

    SELECT KNUMV

    KPOSN

    KWERT

    INTO TABLE IT_KONV

    FROM KONV

    FOR ALL ENTRIES IN IT_KNUMV

    WHERE KNUMV = IT_KNUMV-KNUMV

    AND KSCHL = 'ZFRT'.

    ENDIF.

    ENDIF.

    ENDFORM. " GET_SHIPPING_COSTS

    &----


    *& Form DISPLAY_DATA *

    &----


    • Display report *

    ----


    FORM DISPLAY_DATA.

    *--If data is selected, display the report

    IF NOT IT_VBRK[] IS INITIAL AND

    NOT IT_VBRP[] IS INITIAL.

    V_REPID = SY-REPID.

    *--If Detail report option is selected in the selection-screen

    IF RB_DTL = 'X'.

    *--Populate the header and item details in IT_HEAD and IT_ITEM

    PERFORM POPULATE_HEAD_ITEM.

    *--Build field catalog ie, display position, length, etc..of each column

    PERFORM BUILD_FIELD_CATALOG.

    *--Prepare the key fields info of the head and item tables

    PERFORM PREPARE_KEYINFO.

    *--Add events like top-of-page to events list

    PERFORM PREPARE_EVENT_LIST

    TABLES IT_EVENTS.

    *--Prepare the layout of the report

    PERFORM PREPARE_LAYOUT.

    *--Prepare the sort info and subtotals condition info

    PERFORM PREPARE_SORTINFO.

    *--Display the report using ALV

    PERFORM DISPLAY_ALV_REPORT.

    *--If Summary Option is selected in the selections-screen

    ELSE.

    *--Display the summary report

    PERFORM DISPLAY_SUMMARY.

    ENDIF.

    ELSE.

    MESSAGE I999 WITH TEXT-004.

    • No Data Available for the Given Selection Criteria

    ENDIF.

    ENDFORM. " DISPLAY_DATA

    &----


    *& Form POPULATE_HEAD_ITEM *

    &----


    • Populate the header and item details in IT_HEAD and IT_ITEM *

    ----


    FORM POPULATE_HEAD_ITEM.

    • V_TABIX = SY-TABIX.

    *--For each of the document header

    LOOP AT IT_VBRK.

    *--Get the item details and append to IT_ITEM Internal tble

    LOOP AT IT_VBRP WHERE VBELN = IT_VBRK-VBELN.

    IT_ITEM-BILL_DOC = IT_VBRP-VBELN.

    IT_ITEM-CURRENCY = IT_VBRK-WAERK.

    *--Get the condition value for the condition type

    READ TABLE IT_KONV WITH KEY KNUMV = IT_VBRK-KNUMV

    KPOSN = IT_VBRP-POSNR.

    IF SY-SUBRC = 0.

    IT_ITEM-SHP_COST = IT_KONV-KWERT.

    ENDIF.

    IT_ITEM-MODEL = IT_VBRP-MATNR.

    IT_ITEM-MRA_CODE = IT_VBRP-AUGRU_AUFT.

    *--If MRA Code is 'DU', display amount as field Credit

    IF IT_VBRP-AUGRU_AUFT = 'DU'.

    IT_ITEM-FLD_CR = IT_VBRP-NETWR.

    ENDIF.

    *--If billing type is 'RE', display amount as MRA Amount

    IF IT_VBRK-FKART = 'RE'.

    IT_ITEM-MRA_AMOUNT = IT_VBRP-NETWR.

    ENDIF.

    IT_ITEM-INVOICE_AMT = IT_VBRP-NETWR.

    APPEND IT_ITEM.

    CLEAR IT_ITEM.

    ENDLOOP.

    *--Append Header details to IT_HEAD Internal table

    IF SY-SUBRC EQ 0.

    IT_HEAD-CUST_NO = IT_VBRK-KUNAG.

    IT_HEAD-BILL_DOC = IT_VBRK-VBELN.

    IT_HEAD-BILL_DATE = IT_VBRK-FKDAT.

    IT_HEAD-BILL_TYPE = IT_VBRK-FKART.

    APPEND IT_HEAD.

    CLEAR IT_HEAD.

    ENDIF.

    ENDLOOP.

    ENDFORM. " POPULATE_HEAD_ITEM

    &----


    *& Form BUILD_FIELD_CATALOG *

    &----


    • Build field catalog ie, display position, length, etc..of each column*

    ----


    FORM BUILD_FIELD_CATALOG.

    *--Append Field Catalog of Header Level Data for Display

    PERFORM APPEND_FIELDCAT

    USING 1 'CUST_NO' 'IT_HEAD' 'Customer Number' 15 ' ' 'X'.

    PERFORM APPEND_FIELDCAT

    USING 2 'BILL_DOC' 'IT_HEAD' 'Billing Document' 16 ' ' ' '.

    PERFORM APPEND_FIELDCAT

    USING 3 'BILL_DATE' 'IT_HEAD' 'Billing Date' 12 ' ' ' '.

    PERFORM APPEND_FIELDCAT

    USING 4 'BILL_TYPE' 'IT_HEAD' 'Billing Type' 12 ' ' ' '.

    *--Append Field Catalog of Item Level Data for Display

    PERFORM APPEND_FIELDCAT

    USING 1 'MODEL' 'IT_ITEM' 'Model Number' 18 ' ' ' '.

    PERFORM APPEND_FIELDCAT

    USING 2 'SHP_COST' 'IT_ITEM' 'Shipping Cost' 18 IT_FINAL-CURRENCY 'X'.

    PERFORM APPEND_FIELDCAT

    USING 3 'FLD_CR' 'IT_ITEM' 'Field Credits' 21 IT_FINAL-CURRENCY 'X'.

    PERFORM APPEND_FIELDCAT

    USING 4 'MRA_CODE' 'IT_ITEM' 'MRA Code' 8 ' ' ' '.

    PERFORM APPEND_FIELDCAT

    USING 5 'MRA_AMOUNT' 'IT_ITEM' '$ Amount of MRA' 21

    IT_FINAL-CURRENCY 'X'.

    PERFORM APPEND_FIELDCAT

    USING 6 'INVOICE_AMT' 'IT_ITEM' '$ Amount of Invoice' 21

    IT_FINAL-CURRENCY 'X'.

    *--Add Hotspot to Billing Document Number

    LOOP AT IT_FIELDCAT INTO LS_FIELDCAT

    WHERE FIELDNAME = 'BILL_DOC'.

    LS_FIELDCAT-HOTSPOT = 'X'.

    MODIFY IT_FIELDCAT FROM LS_FIELDCAT.

    ENDLOOP.

    ENDFORM. " BUILD_FIELD_CATALOG

    &----


    *& Form APPEND_FIELDCAT *

    &----


    • Append Field Catalog to IT_FIELDCAT Internal Table *

    ----


    FORM APPEND_FIELDCAT USING POS FIELDNAME TABNAME

    TEXT LEN CURRENCY DOSUM.

    LS_FIELDCAT-COL_POS = POS. " Position

    LS_FIELDCAT-FIELDNAME = FIELDNAME. " Field Name in the internal table

    LS_FIELDCAT-TABNAME = TABNAME. " Internal Table name

    LS_FIELDCAT-SELTEXT_M = TEXT. " Column display text

    LS_FIELDCAT-SELTEXT_L = TEXT. " Column display text

    LS_FIELDCAT-OUTPUTLEN = LEN. " Display length of the column

    LS_FIELDCAT-DO_SUM = DOSUM. " Set summation flag

    LS_FIELDCAT-CURRENCY = CURRENCY. " Currency

    APPEND LS_FIELDCAT TO IT_FIELDCAT.

    CLEAR LS_FIELDCAT.

    ENDFORM. " APPEND_FIELDCAT

    &----


    *& Form PREPARE_KEYINFO *

    &----


    • Prepare the key fields info of the head and item tables *

    ----


    FORM PREPARE_KEYINFO.

    *--Key Fields Joining the Header and Item tables is Billing Document

    LS_keyinfo-header01 = 'BILL_DOC'.

    LS_keyinfo-item01 = 'BILL_DOC'.

    ENDFORM. " PREPARE_KEYINFO

    &----


    *& Form PREPARE_EVENT_LIST *

    &----


    • Add events like top-of-page to events list *

    ----


    FORM PREPARE_EVENT_LIST TABLES IT_EVENTS TYPE SLIS_T_EVENT.

    *--Add Top-OF-Page event to be triggered before the list is displayed

    CLEAR LS_EVENT.

    LS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.

    LS_EVENT-FORM = 'TOP_OF_PAGE_REPORT'.

    APPEND LS_EVENT TO IT_EVENTS.

    ENDFORM. " PREPARE_EVENT_LIST

    &----


    *& Form PREPARE_LAYOUT *

    &----


    • Prepare the layout of the report *

    ----


    FORM PREPARE_LAYOUT.

    LS_LAYOUT-expand_fieldname = 'EXP'. " Field for Exp/Col Icon

    LS_LAYOUT-no_uline_hs = 'X'. " No Horizontal lines

    LS_LAYOUT-subtotals_text = TEXT-015. " Text for Sub-totals

    LS_LAYOUT-totals_text = TEXT-016. " Text for totals

    LS_LAYOUT-no_subtotals = ' '. " Display Subtotals

    ENDFORM. " PREPARE_LAYOUT

    &----


    *& Form PREPARE_SORTINFO *

    &----


    • Prepare the sort info and subtotals condition info *

    ----


    FORM PREPARE_SORTINFO.

    *--Sort the output on Customer number and Billing Document Number and

    • display subtotals of amounts for each customer

    LS_SORTINFO-SPOS = 1. " Sort Position

    LS_SORTINFO-UP = 'X'. " Sort Sequence is Ascending

    LS_SORTINFO-TABNAME = 'IT_HEAD'. " Table name

    LS_SORTINFO-FIELDNAME = 'CUST_NO'. " field name in the table

    *--Subtotals of numeric fields for each customer.

    LS_SORTINFO-SUBTOT = 'X'. " Subtotals on this field

    APPEND LS_SORTINFO TO IT_SORTINFO.

    CLEAR LS_SORTINFO.

    LS_SORTINFO-SPOS = 2. " Sort position

    LS_SORTINFO-UP = 'X'. " Sort order is ascending

    LS_SORTINFO-TABNAME = 'IT_HEAD'. " Table name

    LS_SORTINFO-FIELDNAME = 'BILL_DOC'. " Field Name

    APPEND LS_SORTINFO TO IT_SORTINFO.

    CLEAR LS_SORTINFO.

    ENDFORM. " PREPARE_SORTINFO

    &----


    *& Form DISPLAY_ALV_REPORT *

    &----


    • Display the report using ALV *

    ----


    FORM DISPLAY_ALV_REPORT.

    • SET PF-STATUS 'STATUS'.

    CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

    EXPORTING

    • I_INTERFACE_CHECK = ' '

    I_CALLBACK_PROGRAM = V_REPID

    • I_CALLBACK_PF_STATUS_SET = ' '

    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

    IS_LAYOUT = LS_LAYOUT

    IT_FIELDCAT = IT_FIELDCAT

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    IT_SORT = IT_SORTINFO

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • I_DEFAULT = 'X'

    • I_SAVE = ' '

    • IS_VARIANT =

    IT_EVENTS = IT_EVENTS

    • IT_EVENT_EXIT =

    I_TABNAME_HEADER = 'IT_HEAD'

    I_TABNAME_ITEM = 'IT_ITEM'

    • I_STRUCTURE_NAME_HEADER =

    • I_STRUCTURE_NAME_ITEM =

    IS_KEYINFO = LS_KEYINFO

    • IS_PRINT =

    • IS_REPREP_ID =

    • I_BUFFER_ACTIVE =

    • I_BYPASSING_BUFFER =

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

    • ES_EXIT_CAUSED_BY_USER =

    TABLES

    T_OUTTAB_HEADER = IT_HEAD

    T_OUTTAB_ITEM = IT_ITEM

    EXCEPTIONS

    PROGRAM_ERROR = 1

    OTHERS = 2

    .

    IF SY-SUBRC <> 0.

    MESSAGE E999 WITH TEXT-013. " Error When Displaying Report

    ENDIF.

    ENDFORM. " DISPLAY_ALV_REPORT

    &----


    *& Form TOP_OF_PAGE_REPORT *

    &----


    • Display the standard top of page if summary is selected *

    ----


    FORM TOP_OF_PAGE_REPORT.

    *--Function module to display top of page

    CALL FUNCTION 'Z_REPORT_HEADER'

    EXPORTING

    DL_TITLE = SY-TITLE

    DL_REPID = V_REPID.

    ENDFORM. " TOP_OF_PAGE_REPORT

    &----


    *& Form DISPLAY_COLUMN_HEADERS *

    &----


    • Display the Column headers *

    ----


    FORM DISPLAY_COLUMN_HEADERS.

    *--Set color to I Header

    PERFORM FORMAT_COLOR USING 5 'X'.

    WRITE SY-ULINE(76).

    WRITE : /1 SY-VLINE,

    2(15) 'Customer Number' CENTERED,

    17 SY-VLINE,

    18(16) 'Billing Document' CENTERED,

    34 SY-VLINE,

    35(20) TEXT-008 CENTERED, " Quantity

    55 SY-VLINE,

    56(20) TEXT-009 CENTERED, " Amount

    76 SY-VLINE.

    WRITE SY-ULINE(76).

    ENDFORM. " DISPLAY_COLUMN_HEADERS

    &----


    *& Form DISPLAY_SUMMARY *

    &----


    • Display the summary report *

    ----


    FORM DISPLAY_SUMMARY.

    CLEAR : V_TOTAL_SALES_QTY,

    V_TOTAL_SALES_AMT,

    V_TOTAL_RTRNS_QTY,

    V_TOTAL_RTRNS_AMT,

    V_TOTAL_FLDCR_QTY,

    V_TOTAL_FLDCR_AMT.

    *--For each item record

    LOOP AT IT_VBRP.

    *--Check if the item record has a corresponding header record. If yes,

    • add the sums. Else, proceed to next record

    READ TABLE IT_VBRK WITH KEY VBELN = IT_VBRP-VBELN.

    IF SY-SUBRC = 0.

    *--Increment Total Sales Quantity by 1 for each line item

    V_TOTAL_SALES_QTY = V_TOTAL_SALES_QTY + IT_VBRP-FKIMG.

    *--Add the Amount to Total Sales Amount

    V_TOTAL_SALES_AMT = V_TOTAL_SALES_AMT + IT_VBRP-NETWR.

    *--If Billing type is 'RE', add to Returns

    IF IT_VBRK-FKART = 'RE'.

    *--Increment Returns Quantity by 1

    V_TOTAL_RTRNS_QTY = V_TOTAL_RTRNS_QTY + IT_VBRP-FKIMG.

    *--Add Amount to Total Returns Amount

    V_TOTAL_RTRNS_AMT = V_TOTAL_RTRNS_AMT + IT_VBRP-NETWR.

    ENDIF.

    *--If order Reason is 'DU' add to Field Credits

    IF IT_VBRP-AUGRU_AUFT = 'DU'.

    *--Increment Field Credit Quantity by 1

    V_TOTAL_FLDCR_QTY = V_TOTAL_FLDCR_QTY + IT_VBRP-FKIMG.

    *--Add Amouint to Total Field Credits Amount

    V_TOTAL_FLDCR_AMT = V_TOTAL_FLDCR_AMT + IT_VBRP-NETWR.

    ENDIF.

    ENDIF.

    ENDLOOP.

    READ TABLE IT_VBRK INDEX 1.

    V_CURRENCY = IT_VBRK-WAERK.

    -Display Summary report

    WRITE SY-ULINE(127).

    *--Set color to I Header

    PERFORM FORMAT_COLOR USING 5 'X'.

    WRITE : /1 SY-VLINE,

    2(41) TEXT-005 CENTERED, " Total Sales ( Net Sales )

    43 SY-VLINE,

    44(41) TEXT-006 CENTERED, " Total Returns

    85 SY-VLINE,

    86(41) TEXT-007 CENTERED, " Total Field Credits

    127 SY-VLINE.

    WRITE SY-ULINE(127).

    *--Set color to II Header

    PERFORM FORMAT_COLOR USING 1 'X'.

    WRITE : /1 SY-VLINE,

    2(20) TEXT-008 RIGHT-JUSTIFIED, " Quantity

    22 SY-VLINE,

    23(20) TEXT-009 RIGHT-JUSTIFIED, " Amount

    43 SY-VLINE,

    44(20) TEXT-008 RIGHT-JUSTIFIED, " Quantity

    64 SY-VLINE,

    65(20) TEXT-009 RIGHT-JUSTIFIED, " Amount

    85 SY-VLINE,

    86(20) TEXT-008 RIGHT-JUSTIFIED, " Quantity

    106 SY-VLINE,

    107(20) TEXT-009 RIGHT-JUSTIFIED, " Amount

    127 SY-VLINE.

    WRITE SY-ULINE(127).

    *--Set color to detail

    PERFORM FORMAT_COLOR USING 2 ' '.

    WRITE : /1 SY-VLINE,

    2(20) V_TOTAL_SALES_QTY RIGHT-JUSTIFIED HOTSPOT ON,

    22 SY-VLINE,

    23 V_TOTAL_SALES_AMT CURRENCY V_CURRENCY HOTSPOT ON,

    43 SY-VLINE,

    44(20) V_TOTAL_RTRNS_QTY RIGHT-JUSTIFIED HOTSPOT ON,

    64 SY-VLINE,

    65 V_TOTAL_RTRNS_AMT CURRENCY V_CURRENCY HOTSPOT ON,

    85 SY-VLINE,

    86(20) V_TOTAL_FLDCR_QTY RIGHT-JUSTIFIED HOTSPOT ON,

    106 SY-VLINE,

    107 V_TOTAL_FLDCR_AMT CURRENCY V_CURRENCY HOTSPOT ON,

    127 SY-VLINE.

    HIDE V_TOTAL_SALES_QTY.

    HIDE V_TOTAL_SALES_AMT.

    HIDE V_TOTAL_RTRNS_QTY.

    HIDE V_TOTAL_RTRNS_AMT.

    HIDE V_TOTAL_FLDCR_QTY.

    HIDE V_TOTAL_FLDCR_AMT.

    WRITE SY-ULINE(127).

    ENDFORM. " DISPLAY_SUMMARY

    &----


    *& Form FORMAT_COLOR

    &----


    • Format Color

    ----


    FORM FORMAT_COLOR USING COLOR

    INTENSITY.

    IF INTENSITY EQ 'X'.

    FORMAT INTENSIFIED ON COLOR = COLOR.

    ELSE.

    FORMAT INTENSIFIED OFF COLOR = COLOR.

    ENDIF.

    ENDFORM. " FORMAT_COLOR

    &----


    *& Form USER_COMMAND

    &----


    • Call back user command

    ----


    FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM

    P_LINE TYPE SLIS_SELFIELD.

    DATA : LV_VBELN TYPE VBRK-VBELN.

    *--If Billing document Is clicked

    IF P_LINE-TABNAME = 'IT_HEAD' AND P_LINE-FIELDNAME = 'BILL_DOC'.

    *--Move the Selected Billing Document Number to a variable

    LV_VBELN = P_LINE-VALUE.

    *--Set Parameter ID 'VF' with teh Selected Billing Document Number

    SET PARAMETER ID 'VF' FIELD LV_VBELN.

    *--Call Transaction VF03 to Display the Billing Document

    CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.

    ELSE.

    *--If anything other than Billing Document is Clicked,

    • Display an error message

    MESSAGE S999 WITH TEXT-010. "Please select a Billing Document

    ENDIF..

    ENDFORM. " USER_COMMAND

    &----


    *& Form DISPLAY_DETAIL

    &----


    • Display details for the quantity or the amount select

    ----


    FORM DISPLAY_DETAIL.

    DATA : LV_FIELD(20). " To store the field name selected

    DATA : LV_VBELN TYPE VBRK-VBELN.

    *--If user clicks on some record in the first screen of summary report

    IF SY-LSIND = '1'.

    *--Get the field that the user clicked on

    GET CURSOR FIELD LV_FIELD.

    *--IF User Clicks on Total Sales Amount or Quantity

    IF LV_FIELD = 'V_TOTAL_SALES_QTY' OR

    LV_FIELD = 'V_TOTAL_SALES_AMT'.

    *--Display Total Sales Details

    PERFORM GET_TOTAL_SALES_DETAILS.

    *--If User Clicks on Total Returns Quantity or Amount

    ELSEIF LV_FIELD = 'V_TOTAL_RTRNS_QTY' OR

    LV_FIELD = 'V_TOTAL_RTRNS_AMT'.

    *--Display Total Returns Details

    PERFORM GET_TOTAL_RETURNS_DETAILS.

    *--If User Clicks on Total Returns Quantity or Amount

    ELSEIF LV_FIELD = 'V_TOTAL_FLDCR_QTY' OR

    LV_FIELD = 'V_TOTAL_FLDCR_AMT'.

    *--Display Total Field Credits Details

    PERFORM GET_TOTAL_FLDCR_DETAILS.

    ENDIF.

    IF NOT IT_DETAILS[] IS INITIAL.

    PERFORM DISPLAY_DETAIL_REPORT.

    ENDIF.

    ELSEIF SY-LSIND = '2'.

    GET CURSOR FIELD LV_FIELD.

    IF LV_FIELD = 'IT_DETAILS-BILL_DOC'.

    IF NOT IT_DETAILS-BILL_DOC IS INITIAL.

    *--Move the Selected Billing Document Number to a variable

    LV_VBELN = IT_DETAILS-BILL_DOC.

    *--Set Parameter ID 'VF' with teh Selected Billing Document Number

    SET PARAMETER ID 'VF' FIELD LV_VBELN.

    *--Call Transaction VF03 to Display the Billing Document

    CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.

    ENDIF.

    ELSE.

    *--If anything other than Billing Document is Clicked,

    • Display an error message

    MESSAGE S999 WITH TEXT-010. " Please select a Billing Document.

    ENDIF..

    ENDIF.

    ENDFORM. " DISPLAY_DETAIL

    &----


    *& Form GET_TOTAL_SALES_DETAILS

    &----


    • IF User Clicks on Total Sales Amount or Quantity

    ----


    FORM GET_TOTAL_SALES_DETAILS.

    • Internal table To hold Net Value of Billing Document

    DATA : BEGIN OF LT_VBRP OCCURS 0,

    VBELN LIKE VBRP-VBELN, " Billing document

    POSNR LIKE VBRP-POSNR, " Billing item

    FKIMG LIKE VBRP-FKIMG, " Billed Quantity

    NETWR LIKE VBRP-NETWR, " Net val in

    END OF LT_VBRP.

    CLEAR : IT_DETAILS, IT_DETAILS[].

    LOOP AT IT_VBRK.

    CLEAR : LT_VBRP,LT_VBRP[].

    LOOP AT IT_VBRP WHERE VBELN = IT_VBRK-VBELN.

    LT_VBRP-VBELN = IT_VBRP-VBELN.

    LT_VBRP-POSNR = IT_VBRP-POSNR.

    LT_VBRP-FKIMG = IT_VBRP-FKIMG.

    LT_VBRP-NETWR = IT_VBRP-NETWR.

    APPEND LT_VBRP.

    CLEAR LT_VBRP.

    ENDLOOP.

    SORT LT_VBRP BY VBELN.

    LOOP AT LT_VBRP.

    AT NEW VBELN.

    IT_DETAILS-CUST_NO = IT_VBRK-KUNAG.

    IT_DETAILS-BILL_DOC = LT_VBRP-VBELN.

    CLEAR : IT_DETAILS-QUANTITY,

    IT_DETAILS-AMOUNT.

    ENDAT.

    IT_DETAILS-QUANTITY = IT_DETAILS-QUANTITY + LT_VBRP-FKIMG.

    IT_DETAILS-AMOUNT = IT_DETAILS-AMOUNT + LT_VBRP-NETWR.

    AT END OF VBELN.

    APPEND IT_DETAILS.

    CLEAR IT_DETAILS.

    ENDAT.

    ENDLOOP.

    ENDLOOP.

    ENDFORM. " GET_TOTAL_SALES_DETAILS

    &----


    *& Form GET_TOTAL_RETURNS_DETAILS

    &----


    • IF User Clicks on Total Returns Amount or Quantity

    ----


    FORM GET_TOTAL_RETURNS_DETAILS.

    DATA : BEGIN OF LT_VBRP OCCURS 0,

    VBELN LIKE VBRP-VBELN, " Billing document

    POSNR LIKE VBRP-POSNR, " Billing item

    FKIMG LIKE VBRP-FKIMG, " Billed Quantity

    NETWR LIKE VBRP-NETWR, " Net val in

    END OF LT_VBRP.

    CLEAR : IT_DETAILS, IT_DETAILS[].

    SORT IT_VBRP BY VBELN.

    LOOP AT IT_VBRK WHERE FKART = 'RE'.

    CLEAR : LT_VBRP,LT_VBRP[].

    LOOP AT IT_VBRP WHERE VBELN = IT_VBRK-VBELN.

    LT_VBRP-VBELN = IT_VBRP-VBELN.

    LT_VBRP-POSNR = IT_VBRP-POSNR.

    LT_VBRP-FKIMG = IT_VBRP-FKIMG.

    LT_VBRP-NETWR = IT_VBRP-NETWR.

    APPEND LT_VBRP.

    CLEAR LT_VBRP.

    ENDLOOP.

    SORT LT_VBRP BY VBELN.

    LOOP AT LT_VBRP.

    AT NEW VBELN.

    IT_DETAILS-CUST_NO = IT_VBRK-KUNAG.

    IT_DETAILS-BILL_DOC = LT_VBRP-VBELN.

    CLEAR : IT_DETAILS-QUANTITY,

    IT_DETAILS-AMOUNT.

    ENDAT.

    IT_DETAILS-QUANTITY = IT_DETAILS-QUANTITY + LT_VBRP-FKIMG.

    IT_DETAILS-AMOUNT = IT_DETAILS-AMOUNT + LT_VBRP-NETWR.

    AT END OF VBELN.

    APPEND IT_DETAILS.

    CLEAR IT_DETAILS.

    ENDAT.

    ENDLOOP.

    ENDLOOP.

    ENDFORM. " GET_TOTAL_RETURNS_DETAILS

    &----


    *& Form GET_TOTAL_FLDCR_DETAILS

    &----


    • IF User Clicks on Total Tield Credits Amount or Quantity

    ----


    FORM GET_TOTAL_FLDCR_DETAILS.

    DATA : BEGIN OF LT_VBRP OCCURS 0,

    VBELN LIKE VBRP-VBELN, " Billing document

    POSNR LIKE VBRP-POSNR, " Billing item

    FKIMG LIKE VBRP-FKIMG, " Billed Quantity

    NETWR LIKE VBRP-NETWR, " Net val in

    END OF LT_VBRP.

    CLEAR : IT_DETAILS, IT_DETAILS[].

    SORT IT_VBRP BY VBELN.

    LOOP AT IT_VBRK.

    CLEAR : LT_VBRP,LT_VBRP[].

    LOOP AT IT_VBRP WHERE VBELN = IT_VBRK-VBELN AND

    AUGRU_AUFT = 'DU'.

    LT_VBRP-VBELN = IT_VBRP-VBELN.

    LT_VBRP-POSNR = IT_VBRP-POSNR.

    LT_VBRP-FKIMG = IT_VBRP-FKIMG.

    LT_VBRP-NETWR = IT_VBRP-NETWR.

    APPEND LT_VBRP.

    CLEAR LT_VBRP.

    ENDLOOP.

    SORT LT_VBRP BY VBELN.

    LOOP AT LT_VBRP.

    AT NEW VBELN.

    IT_DETAILS-CUST_NO = IT_VBRK-KUNAG.

    IT_DETAILS-BILL_DOC = LT_VBRP-VBELN.

    CLEAR : IT_DETAILS-QUANTITY,

    IT_DETAILS-AMOUNT.

    ENDAT.

    IT_DETAILS-QUANTITY = IT_DETAILS-QUANTITY + LT_VBRP-FKIMG.

    IT_DETAILS-AMOUNT = IT_DETAILS-AMOUNT + LT_VBRP-NETWR.

    AT END OF VBELN.

    APPEND IT_DETAILS.

    CLEAR IT_DETAILS.

    ENDAT.

    ENDLOOP.

    ENDLOOP.

    ENDFORM. " GET_TOTAL_FLDCR_DETAILS

    &----


    *& Form DISPLAY_DETAIL_REPORT.

    &----


    • Display details for the quantity or the amount select

    ----


    FORM DISPLAY_DETAIL_REPORT..

    DATA : LV_TOTAL_AMOUNT_CUST LIKE VBRP-NETWR,

    LV_TOTAL_QTY_CUST TYPE I,

    LV_TOTAL_AMOUNT LIKE VBRP-NETWR,

    LV_TOTAL_QTY TYPE I,

    INTENSITY.

    SORT IT_DETAILS BY CUST_NO BILL_DOC.

    LOOP AT IT_DETAILS.

    IF INTENSITY = ' '.

    INTENSITY = 'X'.

    ELSE.

    INTENSITY = ' '.

    ENDIF.

    PERFORM FORMAT_COLOR USING 2 INTENSITY.

    WRITE : /1 SY-VLINE.

    AT NEW CUST_NO.

    WRITE : 2(15) IT_DETAILS-CUST_NO.

    ENDAT.

    WRITE : 17 SY-VLINE,

    18(16) IT_DETAILS-BILL_DOC HOTSPOT,

    34 SY-VLINE,

    35(20) IT_DETAILS-QUANTITY RIGHT-JUSTIFIED,

    55 SY-VLINE,

    56(20) IT_DETAILS-AMOUNT CURRENCY V_CURRENCY,

    76 SY-VLINE.

    LV_TOTAL_AMOUNT_CUST = LV_TOTAL_AMOUNT_CUST +

    IT_DETAILS-AMOUNT.

    LV_TOTAL_QTY_CUST = LV_TOTAL_QTY_CUST +

    IT_DETAILS-QUANTITY.

    LV_TOTAL_AMOUNT = LV_TOTAL_AMOUNT +

    IT_DETAILS-AMOUNT.

    LV_TOTAL_QTY = LV_TOTAL_QTY +

    IT_DETAILS-QUANTITY.

    HIDE IT_DETAILS-BILL_DOC.

    AT END OF CUST_NO.

    PERFORM FORMAT_COLOR USING 3 ' '.

    WRITE : /1 SY-VLINE,

    2 TEXT-015, " Net Total

    34 SY-VLINE,

    35(20) LV_TOTAL_QTY_CUST RIGHT-JUSTIFIED,

    55 SY-VLINE,

    56(20) LV_TOTAL_AMOUNT_CUST CURRENCY V_CURRENCY,

    76 SY-VLINE.

    CLEAR : LV_TOTAL_QTY_CUST, LV_TOTAL_AMOUNT_CUST.

    CLEAR INTENSITY.

    WRITE SY-ULINE(76).

    ENDAT.

    ENDLOOP.

    PERFORM FORMAT_COLOR USING 3 'X'.

    WRITE : /1 SY-VLINE,

    2 TEXT-014, " Total

    34 SY-VLINE,

    35(20) LV_TOTAL_QTY RIGHT-JUSTIFIED,

    55 SY-VLINE,

    56(20) LV_TOTAL_AMOUNT CURRENCY V_CURRENCY,

    76 SY-VLINE.

    WRITE SY-ULINE(76).

    ENDFORM. " DISPLAY_DETAIL_REPORT.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 10, 2007 at 04:42 PM

    Check the simple example :

    TYPE-POOLS: slis.

    DATA: BEGIN OF itab OCCURS 0,

    vbeln TYPE vbeln,

    expand,

    END OF itab.

    DATA: BEGIN OF itab1 OCCURS 0,

    vbeln TYPE vbeln,

    posnr TYPE posnr,

    matnr TYPE matnr,

    netpr TYPE netpr,

    END OF itab1.

    DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv.

    DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

    s_fieldcatalog-col_pos = '1'.

    s_fieldcatalog-fieldname = 'VBELN'.

    s_fieldcatalog-tabname = 'ITAB'.

    s_fieldcatalog-rollname = 'VBELN'.

    s_fieldcatalog-outputlen = '12'.

    APPEND s_fieldcatalog TO t_fieldcatalog.

    CLEAR: s_fieldcatalog.

    s_fieldcatalog-col_pos = '1'.

    s_fieldcatalog-fieldname = 'VBELN'.

    s_fieldcatalog-tabname = 'ITAB1'.

    s_fieldcatalog-rollname = 'VBELN'.

    s_fieldcatalog-outputlen = '12'.

    APPEND s_fieldcatalog TO t_fieldcatalog.

    CLEAR: s_fieldcatalog.

    s_fieldcatalog-col_pos = '2'.

    s_fieldcatalog-fieldname = 'POSNR'.

    s_fieldcatalog-tabname = 'ITAB1'.

    s_fieldcatalog-rollname = 'POSNR'.

    APPEND s_fieldcatalog TO t_fieldcatalog.

    CLEAR: s_fieldcatalog.

    s_fieldcatalog-col_pos = '3'.

    s_fieldcatalog-fieldname = 'MATNR'.

    s_fieldcatalog-tabname = 'ITAB1'.

    s_fieldcatalog-rollname = 'MATNR'.

    APPEND s_fieldcatalog TO t_fieldcatalog.

    CLEAR: s_fieldcatalog.

    s_fieldcatalog-col_pos = '4'.

    s_fieldcatalog-fieldname = 'NETPR'.

    s_fieldcatalog-tabname = 'ITAB1'.

    s_fieldcatalog-rollname = 'NETPR'.

    s_fieldcatalog-do_sum = 'X'.

    APPEND s_fieldcatalog TO t_fieldcatalog.

    CLEAR: s_fieldcatalog.

    DATA: s_layout TYPE slis_layout_alv.

    s_layout-subtotals_text = 'SUBTOTAL TEXT'.

    s_layout-key_hotspot = 'X'.

    s_layout-expand_fieldname = 'EXPAND'.

    SELECT vbeln UP TO 100 ROWS

    FROM

    vbak

    INTO TABLE itab.

    IF NOT itab[] IS INITIAL.

    SELECT vbeln posnr matnr netpr

    FROM vbap

    INTO TABLE itab1

    FOR ALL ENTRIES IN itab

    WHERE vbeln = itab-vbeln.

    ENDIF.

    DATA: v_repid TYPE syrepid.

    v_repid = sy-repid.

    DATA: s_keyinfo TYPE slis_keyinfo_alv.

    s_keyinfo-header01 = 'VBELN'.

    s_keyinfo-item01 = 'VBELN'.

    CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

    EXPORTING

    i_callback_program = v_repid

    is_layout = s_layout

    it_fieldcat = t_fieldcatalog

    i_tabname_header = 'ITAB'

    i_tabname_item = 'ITAB1'

    is_keyinfo = s_keyinfo

    TABLES

    t_outtab_header = itab

    t_outtab_item = itab1

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    Thanks

    Seshu

    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.