Posted: Thu Oct 11, 2007 11:09 pm Post subject: Billing detail report
Code:
REPORT zesdr001
LINE-SIZE 215
LINE-COUNT 65
NO STANDARD PAGE HEADING
MESSAGE-ID zv.
***********************************************************************
* Tables Declaration
***********************************************************************
TABLES:vbrk, " Sales Document: Billing Header Data
mara, " Material Master Data
mbew, " Material Valuation data
mbewh, " Material Valuation: History Data
t001, " Company Codes
t001w, " Plants/Branches
konv, " Pricing Conditions Data
t179t, " Materials: Product hierarchies: Texts
tcurx, " Currency Conversion Table
vbuk, " Sales Document: Header Status data
tvko, " Organizational Unit: Sales Organizations
tvtw, " Organizational Unit: Dist.Channels
tspa, " Organizational Unit: Divisions
tvfk, " Billing Document Types
kna1. " Customer Master Data
************************************************************************
* Declaration of Data and Internal Tables
************************************************************************
* Internal table to store the Billing Details data.(VBRK,VBRP)
DATA: BEGIN OF itab_bill OCCURS 0,
vbeln LIKE vbrk-vbeln, " Billing Document Number
fktyp LIKE vbrk-fktyp, " Billing Category
vbtyp LIKE vbrk-vbtyp, " Sales Doc Category
fkdat LIKE vbrk-fkdat, " Billing doc date
fkart LIKE vbrk-fkart, " Billing Doc type
bukrs LIKE vbrk-bukrs, " Company Code
kurrf LIKE vbrk-kurrf, " Exchange type
knumv LIKE vbrk-knumv, " Condition Number
waerk LIKE vbrk-waerk, " Currency
kunag LIKE vbrk-kunag, " Sold to Party
vrkme LIKE vbrp-vrkme, " sales Unit
posnr LIKE vbrp-posnr, " Item Number
charg LIKE vbrp-charg, " Batch Number
fkimg LIKE vbrp-fkimg, " Billed quantity
werks LIKE vbrp-werks, " Plant
matnr LIKE vbrp-matnr, " Material Number
netwr LIKE vbrp-netwr, " Net Value of the doc
wavwr LIKE vbrp-wavwr, " Cost in Doc Currency
kdmat LIKE vbap-kdmat, " Customer Material
END OF itab_bill.
* Internal table to write the report output when Customer Mode
* Radiobutton is selected
DATA: BEGIN OF itab_out OCCURS 0,
kunag LIKE vbrk-kunag, " Customer No
vbeln LIKE vbrk-vbeln, " Billing Document Number
fkart LIKE vbrk-fkart, " Billing Doc type
fktyp LIKE vbrk-fktyp, " Billing Category
vbtyp LIKE vbrk-vbtyp, " Sales Doc Category
fkdat LIKE vbrk-fkdat, " Billing doc date
kunnr LIKE kna1-kunnr, " Customer
bukrs LIKE vbrk-bukrs, " Company Code
kurrf LIKE vbrk-kurrf, " Exchange Rate
waerk LIKE vbrk-waerk, " Currency
vrkme LIKE vbrp-vrkme, " Sales Unit
posnr LIKE vbrp-posnr, " Item Number
charg LIKE vbrp-charg, " Batch Number
fkimg LIKE vbrp-fkimg, " Billed quantity
werks LIKE vbrp-werks, " Plant
matnr LIKE vbrp-matnr, " Material NUmber
kdmat LIKE vbap-kdmat, " Customer Material
bil_amt(16) TYPE p DECIMALS 2, " Bill Amount
mode(10), " Mode
density(10), " Density
sel_prc(16) TYPE p DECIMALS 2, " Selling Price
mvg_prs LIKE mbew-verpr, " Moving Price
gp_mvp_amt LIKE vbrp-netwr, " GrossProfit Amount(MVP)
gp_mvp_pr(6) TYPE p DECIMALS 2, " ,, percentage
END OF itab_out.
* Internal table to write the report output when Mode
* Radiobutton is selected
DATA: BEGIN OF itab_out2 OCCURS 0,
mode(10),
vbeln LIKE vbrk-vbeln, " Billing Document Number
fktyp LIKE vbrk-fktyp, " Billing Category
vbtyp LIKE vbrk-vbtyp, " Sales Doc Category
fkdat LIKE vbrk-fkdat, " Billing doc date
kunag LIKE vbrk-kunag, " Sold to party
kunnr LIKE kna1-kunnr, " Customer
bukrs LIKE vbrk-bukrs, " Company Code
kurrf LIKE vbrk-kurrf, " Exchange Rate
waerk LIKE vbrk-waerk, " Currency
vrkme LIKE vbrp-vrkme, " Sales UNit
posnr LIKE vbrp-posnr, " Item No
charg LIKE vbrp-charg, " Batch Number
fkimg LIKE vbrp-fkimg, " Billed quantity
werks LIKE vbrp-werks, " Plant
matnr LIKE vbrp-matnr, " Material Number
kdmat LIKE vbap-kdmat, " Customer Material No
bil_amt(16) TYPE p DECIMALS 2, " Billing Amount
density(10), " density
sel_prc(16) TYPE p DECIMALS 4, " Selling Price
mvg_prs LIKE mbew-verpr, " Moving Price
gp_mvp_amt LIKE vbrp-netwr, " GrossProfit Amount(MVP)
gp_mvp_pr(6) TYPE p DECIMALS 2, " ,, percentage
END OF itab_out2.
* Internal table to write the report output when Density
* Radiobutton is selected
DATA: BEGIN OF itab_out3 OCCURS 0,
mode(10),
density(10),
vbeln LIKE vbrk-vbeln, " Billing Document Number
fktyp LIKE vbrk-fktyp, " Billing Category
vbtyp LIKE vbrk-vbtyp, " Sales Doc Category
fkdat LIKE vbrk-fkdat, " Billing doc date
kunag LIKE vbrk-kunag, " Sold to Party
kunnr LIKE kna1-kunnr, " Customer
bukrs LIKE vbrk-bukrs, " Company Code
kurrf LIKE vbrk-kurrf, " Exchange Rate
waerk LIKE vbrk-waerk, " Currency
vrkme LIKE vbrp-vrkme, " Sales Unit
posnr LIKE vbrp-posnr, " Item Number
charg LIKE vbrp-charg, " Batch Number
fkimg LIKE vbrp-fkimg, " Billed quantity
werks LIKE vbrp-werks, " Plant
matnr LIKE vbrp-matnr, " Material Number
kdmat LIKE vbap-kdmat, " Customer Material
bil_amt(16) TYPE p DECIMALS 2, " Bill Amount
sel_prc(16) TYPE p DECIMALS 4, " Selling Price
mvg_prs LIKE mbew-verpr, " Moving Price
gp_mvp_amt LIKE vbrp-netwr, " GrossProfit Amount(MVP)
gp_mvp_pr(6) TYPE p DECIMALS 2, " ,, percentage
END OF itab_out3.
*-Internal Table to Hold data to be downloaded to file
DATA: BEGIN OF itab_out1 OCCURS 0,
kunag(10), " Customer
vbeln(10), " Billing Doc No
fkdat(10), " Bill Date
posnr(6), " Item No
mode(6), " Mode
density(6), " Density
matnr(18), " Material
charg(10), " Batch Number
fkimg LIKE vbrp-fkimg, " Billed quantity
vrkme(4), " Sales Unit
sel_prc(14), " Selling Price
bil_amt(15) TYPE p DECIMALS 2, " Billing Amount
waerk(4), " Currency
mvg_prs(15), " Moving Price
gp_mvp_amt LIKE vbrp-netwr, " Gross profit Amount(MVP)
gp_mvp_pr(15), " ,, percentage
kdmat(35), " Customer Material
END OF itab_out1.
*Internal Table
DATA: BEGIN OF fieldnames OCCURS 0,
title(25) TYPE c,
table(5) TYPE c,
field(5) TYPE c,
type(1) TYPE c,
END OF fieldnames.
* Declaration Of Variables
DATA: w_period LIKE bapi0002_4-fiscal_period,
w_year LIKE bapi0002_4-fiscal_year,
w_date LIKE bsad-budat,
w_lin TYPE i. "No.of lines in Internal Table
DATA: t_fkimg LIKE vbrp-fkimg,
t_bil_amt(8) TYPE p DECIMALS 2,
t_gp_mvp_amt(8) TYPE p DECIMALS 2,
t_gr_fkimg LIKE vbrp-fkimg,
t_gr_bil_amt(8) TYPE p DECIMALS 2,
t_gr_gp_mvp_amt(8) TYPE p DECIMALS 2,
t_efkimg LIKE vbrp-fkimg,
t_ebil_amt(8) TYPE p DECIMALS 2,
t_egp_mvp_amt(8) TYPE p DECIMALS 2.
DATA:f_flg .
************************************************************************
* Select-Options
************************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK b WITH FRAME.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_bukrs FOR t001-bukrs NO INTERVALS NO-EXTENSION
OBLIGATORY,
s_vkorg FOR tvko-vkorg NO INTERVALS NO-EXTENSION,
s_vtweg FOR tvtw-vtweg NO INTERVALS NO-EXTENSION,
s_spart FOR tspa-spart NO INTERVALS NO-EXTENSION,
s_werks FOR t001w-werks NO INTERVALS NO-EXTENSION,
s_kunag FOR kna1-kunnr,
s_vbeln FOR vbuk-vbeln,
s_fkart FOR tvfk-fkart,
s_fkdat FOR vbrk-fkdat OBLIGATORY.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(20) text-008.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_cust TYPE c RADIOBUTTON GROUP cust.
SELECTION-SCREEN COMMENT 3(20) text-004 FOR FIELD p_cust.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_mode TYPE c RADIOBUTTON GROUP cust.
SELECTION-SCREEN COMMENT 3(20) text-006 FOR FIELD p_mode.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_dens TYPE c RADIOBUTTON GROUP cust.
SELECTION-SCREEN COMMENT 3(20) text-007 FOR FIELD p_dens.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_dwnlod AS CHECKBOX,
p_file LIKE rlgrap-filename. " default 'C:\zesdr001'.
SELECTION-SCREEN: END OF BLOCK b2.
SELECTION-SCREEN: END OF BLOCK b.
********At Selection Screen*********************************************
AT SELECTION-SCREEN.
* At Selection Screen on Value Request
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_help.
* Checking for the input values of selection screen.
PERFORM screen_check.
******* Top Of Page***************************************************
TOP-OF-PAGE.
PERFORM rep_headers.
********Start of Selection**********************************************
START-OF-SELECTION.
* Selecting data from the database tables
PERFORM invoice_selection.
DESCRIBE TABLE itab_bill LINES w_lin.
IF w_lin = 0.
MESSAGE i008. " No Data Found for the Given Selection Criteria
ELSE.
* Moving the data records into output internal table
PERFORM bill_details.
* When Customer Radio button is selected
IF p_cust EQ 'X'.
PERFORM invoice_output_cust.
* When Mode Radio button is selected
ELSEIF p_mode EQ 'X'.
PERFORM invoice_output_mode.
* When density Radio button is selected
ELSEIF p_dens EQ 'X'.
PERFORM invoice_output_dens.
ENDIF.
ENDIF.
********End of Selection************************************************
END-OF-SELECTION.
PERFORM init_fieldnames.
IF p_dwnlod = 'X'.
PERFORM read_data_for_dowlload.
* perform down_load_to_file using p_file.
PERFORM download_excel USING p_file.
ENDIF.
*&---------------------------------------------------------------------*
*& Form screen_check
*&---------------------------------------------------------------------*
* Ckecking for Selection Screen fields Validation
*----------------------------------------------------------------------*
FORM screen_check.
* Validation of Sales Organization
CLEAR tvko.
IF NOT s_vkorg-low IS INITIAL.
SELECT vkorg FROM tvko UP TO 1 ROWS
INTO tvko-vkorg
WHERE vkorg IN s_vkorg.
ENDSELECT.
IF sy-subrc NE 0.
MESSAGE e009. " Invalid Sales Organization
ENDIF.
ENDIF.
* Validation of Distribution Channel
CLEAR tvtw.
IF NOT s_vtweg-low IS INITIAL.
SELECT vtweg FROM tvtw UP TO 1 ROWS
INTO tvtw-vtweg
WHERE vtweg IN s_vtweg.
ENDSELECT.
IF sy-subrc NE 0.
MESSAGE e010. " Invalid Distribution Channel
ENDIF.
ENDIF.
* Validation of Division
CLEAR tspa.
IF NOT s_spart-low IS INITIAL.
SELECT spart FROM tspa UP TO 1 ROWS
INTO tspa-spart
WHERE spart IN s_spart.
ENDSELECT.
IF sy-subrc NE 0.
MESSAGE e011. " Invalid Division
ENDIF.
ENDIF.
* Validation for company code
CLEAR t001.
IF NOT s_bukrs-low IS INITIAL.
SELECT SINGLE bukrs FROM t001
INTO t001-bukrs
WHERE bukrs IN s_bukrs.
IF sy-subrc <> 0.
MESSAGE e007. " Enter valid Company Code
ENDIF.
ENDIF.
* Validation of billing Document Type
CLEAR tvfk.
IF NOT s_fkart IS INITIAL.
SELECT fkart FROM tvfk UP TO 1 ROWS
INTO tvfk-fkart
WHERE fkart IN s_fkart.
ENDSELECT.
IF sy-subrc NE 0.
MESSAGE e012. " Invalid Billing Document Type
ENDIF.
ENDIF.
* Validation of Billing Document Number
CLEAR vbuk.
IF NOT s_vbeln IS INITIAL.
SELECT vbeln FROM vbuk UP TO 1 ROWS
INTO vbuk-vbeln
WHERE vbeln IN s_vbeln AND
vbtyp = 'M'.
ENDSELECT.
IF sy-subrc NE 0.
MESSAGE e013. " Invalid Billing Doc Number
ENDIF.
ENDIF.
* Validation of Customer
CLEAR kna1.
IF NOT s_kunag IS INITIAL.
SELECT kunnr FROM kna1 UP TO 1 ROWS
INTO kna1-kunnr
WHERE kunnr IN s_kunag.
ENDSELECT.
IF sy-subrc NE 0.
MESSAGE e014. " Invalid Customer Number
ENDIF.
ENDIF.
* Validation of Plant
CLEAR t001w.
IF NOT s_werks IS INITIAL.
SELECT werks FROM t001w UP TO 1 ROWS
INTO t001w-werks
WHERE werks IN s_werks.
ENDSELECT.
IF sy-subrc NE 0.
MESSAGE e004. " Invalid Plant Number
ENDIF.
ENDIF.
* Validation for File path to download
IF p_dwnlod = 'X'.
IF p_file IS INITIAL.
MESSAGE e006. " Enter the Valid file path to Download
ENDIF.
ENDIF.
ENDFORM. "screen_check
*---------------------------------------------------------------------*
* FORM invoice_selection *
*---------------------------------------------------------------------*
* Selecting data from the database tables
*---------------------------------------------------------------------*
FORM invoice_selection.
SELECT
a~vbeln " Billing Doc Number
a~fktyp " Billing Category
a~vbtyp " Sales Doc category
a~fkdat " Billing doc date
a~fkart " Billing doc type
a~bukrs " Company code
a~kurrf " Exchange rate
a~knumv " Condition record Number
a~waerk " Currency
a~kunag " Sold to Party
b~vrkme " Sales Unit
b~posnr " Item Number
b~charg " Batch Number
b~fkimg " Billed quantity
b~werks " Plant
b~matnr " Material Number
b~netwr " Net Value of Bill Doc
b~wavwr " Cost in Doc Currency
c~kdmat " Customer Material
INTO TABLE itab_bill
FROM vbrk AS a JOIN vbrp AS b
ON b~vbeln = a~vbeln
JOIN vbap AS c
ON b~aubel = c~vbeln AND
b~aupos = c~posnr
WHERE a~vbeln IN s_vbeln AND
a~fkdat IN s_fkdat AND
a~bukrs IN s_bukrs AND
a~vtweg IN s_vtweg AND
a~vkorg IN s_vkorg AND
a~spart IN s_spart AND
a~fkart IN s_fkart AND
b~werks IN s_werks AND
a~kunag IN s_kunag AND
a~sfakn EQ ' ' AND
a~fksto EQ ' ' .
ENDFORM . "invoice_selection
*---------------------------------------------------------------------*
* FORM bill_details *
*---------------------------------------------------------------------*
* appending data into itab_out internal table
*---------------------------------------------------------------------*
FORM bill_details.
SORT itab_bill BY vbeln.
SELECT SINGLE waers FROM t001 INTO t001-waers
WHERE bukrs IN s_bukrs.
DATA:f_txt1(10),f_txt2(10),f_txt3(10).
LOOP AT itab_bill.
SELECT SINGLE currdec FROM tcurx INTO tcurx-currdec
WHERE currkey EQ itab_out-waerk.
IF sy-subrc EQ '0' .
IF tcurx-currdec EQ '0'.
itab_bill-netwr = itab_bill-netwr * 100.
itab_bill-wavwr = itab_bill-wavwr * 100.
ENDIF.
ENDIF.
itab_out-bil_amt = itab_bill-netwr.
CLEAR : konv.
* Pricing data from KONV table
SELECT SINGLE kbetr kwert kpein FROM konv INTO
(konv-kbetr,konv-kwert,konv-kpein)
WHERE knumv = itab_bill-knumv AND
kposn = itab_bill-posnr AND
kschl EQ 'ZSP1' AND
krech EQ 'C' AND
kinak EQ ' '.
* Currency conversion
SELECT SINGLE currdec FROM tcurx INTO tcurx-currdec
WHERE currkey EQ itab_out-waerk.
IF sy-subrc EQ '0' .
IF tcurx-currdec EQ '0'.
konv-kbetr = konv-kbetr * 100.
ENDIF.
ENDIF.
* Unit Price
itab_out-sel_prc = konv-kbetr.
* Unit Price Calculation
IF NOT konv-kpein IS INITIAL.
itab_out-sel_prc = itab_out-sel_prc / konv-kpein .
ENDIF.
* Call Function to get the Period for the given Billing date
* and Company Code
PERFORM get_period.
* Selecting Material Valuation Data
CLEAR:mbew.
IF itab_out-fktyp EQ 'L'.
SELECT SINGLE
lfmon lfgja verpr stprs vmver vmstp
FROM mbew
INTO (mbew-lfmon,mbew-lfgja,mbew-verpr,
mbew-stprs,mbew-vmver,mbew-vmstp)
WHERE matnr = itab_out-matnr
AND bwkey = itab_out-werks.
IF mbew-lfmon = w_period AND mbew-lfgja = w_year.
SELECT SINGLE currdec FROM tcurx INTO tcurx-currdec
WHERE currkey EQ t001-waers.
IF sy-subrc EQ '0' .
SELECT SINGLE
lfmon lfgja verpr stprs
FROM mbewh
INTO (mbewh-lfmon,mbewh-lfgja,mbewh-verpr,
mbewh-stprs)
WHERE matnr = itab_out-matnr
AND bwkey = itab_out-werks
AND lfmon = w_period
AND lfgja = w_year.
SELECT SINGLE currdec FROM tcurx INTO tcurx-currdec
WHERE currkey EQ t001-waers.
IF sy-subrc EQ '0' .
IF itab_out-mvg_prs IS INITIAL.
SELECT SINGLE
lfmon lfgja verpr stprs vmver vmstp
FROM mbew
INTO (mbew-lfmon,mbew-lfgja,mbew-verpr,
mbew-stprs,mbew-vmver,mbew-vmstp)
WHERE matnr = itab_out-matnr
AND bwkey = itab_out-werks.
SELECT SINGLE currdec FROM tcurx
INTO tcurx-currdec
WHERE currkey EQ t001-waers.
IF sy-subrc EQ '0' .
* To find Density and Mode from MARA and T179T tables
CLEAR :mara,t179t.
SELECT SINGLE prdha FROM mara
INTO mara-prdha
WHERE matnr = itab_out-matnr.
SELECT SINGLE vtext FROM t179t
INTO t179t-vtext
WHERE spras = 'EN' AND
prodh = mara-prdha(4).
SPLIT t179t-vtext AT ' ' INTO f_txt1 f_txt2 f_txt3.
itab_out-mode = f_txt2.
itab_out-density = f_txt3.
IF NOT itab_out-mvg_prs IS INITIAL.
IF itab_out-fktyp EQ 'L'.
itab_out-gp_mvp_amt = itab_out-bil_amt - itab_out-mvg_prs *
itab_out-fkimg.
ELSE.
itab_out-gp_mvp_amt = '0'.
ENDIF.
ENDIF.
IF NOT itab_out-mvg_prs IS INITIAL
AND NOT itab_out-sel_prc IS INITIAL.
itab_out-gp_mvp_pr = ( itab_out-sel_prc - itab_out-mvg_prs )
/ itab_out-sel_prc * 100.
ENDIF.
* If the bill amount is 0 then the quantity should also be 0.
IF itab_out-bil_amt = 0.
itab_out-fkimg = 0.
ENDIF.
* Check if the Bill amount is Credit memo amount, then the gross profit
* should also be the same bill amount irrespecitve of +ve or -ve.
IF itab_out-gp_mvp_amt = 0.
MOVE: itab_out-bil_amt TO itab_out-gp_mvp_amt.
ENDIF.
MODIFY itab_out.
CLEAR itab_out.
ENDIF.
ENDLOOP.
ENDFORM. "bill_details
*&---------------------------------------------------------------------*
*& Form get_period
*&---------------------------------------------------------------------*
* Getting Document Period
*----------------------------------------------------------------------*
FORM get_period.
CLEAR :w_period,w_year,w_date.
CONCATENATE itab_out-fkdat(4)
itab_out-fkdat+4(2)
itab_out-fkdat+6(2)
INTO w_date.
*&---------------------------------------------------------------------*
*& Form invoice_output_cust
*&---------------------------------------------------------------------*
* Report Output when customer is selected
*----------------------------------------------------------------------*
FORM invoice_output_cust.
WRITE AT /1(214) sy-uline.
SORT itab_out BY kunag vbeln fkart posnr fkdat.
LOOP AT itab_out.
IF f_flg = 'X'.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
f_flg = ' '.
ELSE.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
f_flg = 'X'.
ENDIF.
AT NEW kunag.
READ TABLE itab_out INDEX sy-tabix.
ENDAT.
AT END OF kunag.
FORMAT RESET.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
WRITE:/1(214) sy-uline.
WRITE:/01 sy-vline,
02 'Sub Total of Customer:'(035), itab_out-kunag,
87(13) t_fkimg UNIT itab_out-vrkme NO-SIGN,
121(15) t_bil_amt NO-SIGN,
158(15) t_gp_mvp_amt NO-SIGN,
214 ' ',
/1(214) sy-uline.
CLEAR: t_fkimg, t_bil_amt, t_gp_mvp_amt.
ENDAT.
AT LAST.
WRITE:/01 sy-vline,
02 'Grand Total :'(032),
87(13) t_gr_fkimg UNIT itab_out-vrkme NO-SIGN,
121(15) t_gr_bil_amt NO-SIGN,
158(15) t_gr_gp_mvp_amt NO-SIGN,
214 ' '.
ENDAT.
FORMAT COLOR OFF.
ENDLOOP.
WRITE AT /1(214) sy-uline.
ENDFORM. "invoice_output_cust
*&---------------------------------------------------------------------*
*& Form invoice_output_mode
*&---------------------------------------------------------------------*
* Report Output
*----------------------------------------------------------------------*
FORM invoice_output_mode.
LOOP AT itab_out.
MOVE-CORRESPONDING itab_out TO itab_out2.
APPEND itab_out2.
CLEAR: itab_out2.
ENDLOOP.
WRITE AT /1(214) sy-uline.
SORT itab_out2 BY mode vbeln posnr fkdat.
LOOP AT itab_out2.
IF f_flg = 'X'.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
f_flg = ' '.
ELSE.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
f_flg = 'X'.
ENDIF.
AT NEW mode.
READ TABLE itab_out2 INDEX sy-tabix.
ENDAT.
AT END OF mode.
FORMAT RESET.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
WRITE:/1(214) sy-uline.
WRITE:/01 sy-vline,
02 'Sub Total of Mode :'(033), itab_out2-mode,
87(13) t_fkimg UNIT itab_out-vrkme NO-SIGN,
121(15) t_bil_amt NO-SIGN,
158(15) t_gp_mvp_amt NO-SIGN,
214 ' ',
/1(214) sy-uline.
CLEAR: t_fkimg, t_bil_amt, t_gp_mvp_amt.
ENDAT.
AT LAST.
WRITE:/01 sy-vline,
02 'Grand Total :'(032),
87(13) t_gr_fkimg UNIT itab_out-vrkme NO-SIGN,
121(15) t_gr_bil_amt NO-SIGN,
158(15) t_gr_gp_mvp_amt NO-SIGN,
214 ' '.
ENDAT.
FORMAT COLOR OFF.
ENDLOOP.
WRITE AT /1(214) sy-uline.
ENDFORM. "invoice_output_mode
*&---------------------------------------------------------------------*
*& Form invoice_output_dens
*&---------------------------------------------------------------------*
* Report Output
*----------------------------------------------------------------------*
FORM invoice_output_dens.
LOOP AT itab_out.
MOVE-CORRESPONDING itab_out TO itab_out3.
APPEND itab_out3.
CLEAR: itab_out3.
ENDLOOP.
WRITE AT /1(214) sy-uline.
SORT itab_out3 BY mode density vbeln posnr fkdat.
LOOP AT itab_out3.
IF f_flg = 'X'.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
f_flg = ' '.
ELSE.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
f_flg = 'X'.
ENDIF.
AT NEW mode.
ENDAT.
AT NEW density.
READ TABLE itab_out3 INDEX sy-tabix.
ENDAT.
AT END OF density.
FORMAT RESET.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
WRITE:/1(214) sy-uline.
WRITE:/01 sy-vline,
02 'Sub Total of Density :'(034), itab_out3-density,
87(13) t_efkimg UNIT itab_out-vrkme NO-SIGN,
121(15) t_ebil_amt CURRENCY vbrk-waerk NO-SIGN,
158(15) t_egp_mvp_amt CURRENCY vbrk-waerk NO-SIGN,
214 ' ',
/1(214) sy-uline.
CLEAR: t_efkimg, t_ebil_amt,t_egp_mvp_amt.
ENDAT.
AT END OF mode.
FORMAT RESET.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
WRITE:/01 sy-vline,
02 'Sub Total of Mode :'(033), itab_out3-mode,
87(13) t_fkimg UNIT itab_out-vrkme NO-SIGN,
121(15) t_bil_amt NO-SIGN,
158(15) t_gp_mvp_amt NO-SIGN,
214 ' ',
/1(214) sy-uline.
CLEAR: t_fkimg, t_bil_amt, t_gp_mvp_amt.
ENDAT.
AT LAST.
WRITE:/01 sy-vline,
02 'Grand Total :'(032),
87(13) t_gr_fkimg UNIT itab_out-vrkme NO-SIGN,
121(15) t_gr_bil_amt NO-SIGN,
158(15) t_gr_gp_mvp_amt NO-SIGN,
214 ' '.
ENDAT.
FORMAT COLOR OFF.
ENDLOOP.
WRITE AT /1(214) sy-uline.
ENDFORM. "invoice_output_dens
*&---------------------------------------------------------------------*
*& Form f4_help
*&---------------------------------------------------------------------*
* To Get F4 Help to Select File Name
*----------------------------------------------------------------------*
FORM f4_help.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
ENDFORM. " f4_help
*&---------------------------------------------------------------------*
*& Form rep_headers
*&---------------------------------------------------------------------*
* Report Header
*----------------------------------------------------------------------*
FORM rep_headers.
FORMAT COLOR COL_HEADING ON.
FORMAT COLOR COL_HEADING ON.
SELECT SINGLE butxt FROM t001 INTO t001-butxt
WHERE bukrs = s_bukrs-low.
SKIP 2.
WRITE: /2 t001-butxt, 92 'BILLING ANALYSIS'(003),
190 'Date :'(010),sy-datum.
*&---------------------------------------------------------------------*
*& Form init_fieldnames
*&---------------------------------------------------------------------*
* Initialise all the fields to download in Excel Data File
*----------------------------------------------------------------------*
FORM init_fieldnames.
PERFORM append_fieldname USING text-004 'itab_out1'
'KUNAG' 'X'.
PERFORM append_fieldname USING text-037 'itab_out1'
'VBELN' 'X'.
PERFORM append_fieldname USING text-036 'itab_out1'
'FKDAT' 'X'.
PERFORM append_fieldname USING text-038 'itab_out1'
'POSNR' 'X'.
PERFORM append_fieldname USING text-006 'itab_out1'
'MODE' 'X'.
PERFORM append_fieldname USING text-014 'itab_out1'
'DENSITY' 'X'.
PERFORM append_fieldname USING text-015 'itab_out1'
'MATNR' 'X'.
PERFORM append_fieldname USING text-016 'itab_out1'
'CHARG' 'X'.
PERFORM append_fieldname USING text-017 'itab_out1'
'FKIMG' 'X'.
PERFORM append_fieldname USING text-039 'itab_out1'
'VRKME' 'X'.
PERFORM append_fieldname USING text-040 'itab_out1'
'SEL_PRC' 'X'.
PERFORM append_fieldname USING text-041 'itab_out1'
'BIL_AMT' 'X'.
PERFORM append_fieldname USING text-028 'itab_out1'
'WAERK' 'X'.
PERFORM append_fieldname USING text-020 'itab_out1'
'MVG_PRS' 'X'.
PERFORM append_fieldname USING text-044 'itab_out1'
'GP_MVP_AMT' 'X'.
PERFORM append_fieldname USING text-045 'itab_out1'
'GP_MVP_PR' 'X'.
PERFORM append_fieldname USING text-023 'itab_out1'
'KDMAT' 'X'.
ENDFORM. "init_fieldnames
*&---------------------------------------------------------------------*
*& Form append_fieldname
*&---------------------------------------------------------------------*
* Appending field Names
*----------------------------------------------------------------------*
FORM append_fieldname USING p_title p_table p_field p_type.
CLEAR: fieldnames.
fieldnames-title = p_title.
fieldnames-table = p_table.
fieldnames-field = p_field.
fieldnames-type = p_type.
APPEND fieldnames.
ENDFORM. "append_fieldname
*&---------------------------------------------------------------------*
*& Form download_excel
*&---------------------------------------------------------------------*
* Getting Data to Download to File
*----------------------------------------------------------------------*
FORM download_excel USING f_file.
CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
EXPORTING
file_name = f_file
TABLES
data_tab = itab_out1
fieldnames = fieldnames
EXCEPTIONS
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_filename = 6
invalid_pivot_fields = 7
download_problem = 8
OTHERS = 9.
IF sy-subrc = 0.
MESSAGE s005(zv) WITH p_file. "Download to & Successfully Completed
ENDIF.
ENDFORM. "download_excel
*&---------------------------------------------------------------------*
*& Form read_data_for_download
*&---------------------------------------------------------------------*
* Getting Data to Download to File
*----------------------------------------------------------------------*
FORM read_data_for_dowlload.
SORT itab_out BY vbeln posnr fkdat.
LOOP AT itab_out.
MOVE-CORRESPONDING itab_out TO itab_out1.
APPEND itab_out1.
CLEAR itab_out1.
ENDLOOP.
ENDFORM. " read_data_for_dowlload
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.