2007 Aug 17 7:59 PM
Hi Frnds ,
I have a requirement where i have to display
series no. isbn quantity
-
-
-
mat isbn quantity
-
-
-
-
-
-
actually if i have series 1 then it contains mat a,b
i have to display as an alv hierarchical list. but there is no direct relation between series and mat... a series may contain 3 books.
i am able to display the list but first header gets displayed and when i click back button the items gets displayed . i cant use hierarchical list .please suggest me a solution.
regards
jana
2007 Aug 17 8:11 PM
Try this code.
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.
Thanks
Mahesh
2007 Aug 17 8:10 PM
Can you use <b>Field1 isbn quantity</b> in the output display where Field1 will have Series no or Mat no for example
Series1 isbn1 quantity1
Mat2 isbn2 quantity2
Mat3 isbn3 quantity3
-Kriss
2007 Aug 17 8:11 PM
Try this code.
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.
Thanks
Mahesh
2007 Aug 17 9:17 PM
Just use FM : REUSE_ALV_HIERSEQ_LIST_DISPLAY
See the below simple example code :
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