Unmeasured Billing Analysis

Hi..
What is the different between Volumetric Amount and Fixed Amount?
How to find the Premise volumetric and fixed amount with respect to Posting date,Rate Category and Cal. Year/Quarter 
Could you please proved is there any table or any transaction code exit
plz give me full information about the amounts and amount process types of amount process..
Thanks,
Sreenu
Edited by: bw070707 bw070707 on Aug 18, 2008 6:51 PM

Hi Sreenu,
depending on your environment, the fixed amount can be the amout you charge the customer idependently e.g. for the rent of the device. Additionally to that you usually charge a volmetric amout whic is usually calculated with usage times price. But you also can charge a fixed amout without any meter to be read e.g. for street lights. So - it would help very much if you tell a bit more. Oterwise I just can poit to:
http://help.sap.com/saphelp_erp60_sp/helpdata/en/45/556a3591541f67e10000009b38f889/frameset.htm
KR
Uwe

Similar Messages

  • Billing Analysis Error

    Hi Friends,
    I am getting following error when I am doing Billing analysis for an installation
    Bill. order for inst. 4100000010 sch.bill.date 03.08.2009 bill.proc. 01 not in selection
    Message no. AH371
    Need help.
    Regards
    Sudhakar.p

    hi,
    msg AH371 usually occurs when the billing date is before the scheduled billing date
    (which you gave during billing order creation).
    or if the meter reading entry is missing.
    hope this solves it.
    regards,
    Rakesh..

  • High bill analysis

    Hi,
    We are implementing an enhancement to analyze customer's bill, if the current month's bill is very high compared to previous month's bill then we have to look into some of the reasons proposed:
    Consumption History
    Meter Over Estimated
    Correcting a Previous Read
    Wrong Move In Read
    Wrong Move Out Read
    Rate Changes
    I would like to get some help from you to retrieve the data for each reason, are there any standard BAPI/FM to get the data or do I need to look in the tables like EABL, EABLG .
    Appreciate your help!

    Use the standard validations processes to set tolerances on meter reading entry. High values will be marked implausible, & require management before release to billing.
    SPRO>SAP Utilities>Device Management>Meter Reading>Validations
    Alternatively you could review package EE17 & see how the standard functions hang together.
    Enhancements in the EDM* space would then be the point of reference for custom logic you may need.
    specifically EDMLELSV, or EDMLELDE.

  • Job worker billing analysis and verification through stock transfer note

    Dear All,
    We give all the material to your job work location and then we get the material packed by our job worker and then we give our job worker packing charges as per the following:
    1. Sulphuric Acid 5 L = Rs.10/- per unit
    2. Nitric Acid 25L = Rs.50/- per unit.
    Like this.
    So tell me how should i maintain the job work charges against each FG for the job work, so that at the end of month i can download their monthly bill report through dispatches which they have made between that period.
    Kindly also tell me the code which i should use to check their monthly job work bills through dispatch done through stock transfer note.
    Regards,
    Phalgun Patel

    Hi Phalgun,
    Mr. Muhammad is right. You have to use Subcontracting process for your requirement.
    Just go through below link which gives you standard SAP Subcontracting process with configuration.
    http://help.sap.com/bp_bl603/BBLibrary/HTML/138_EN_IN.htm
    And also some other links as below.
    http://www.sap-img.com/materials/sub-contracting-cycle.htm
    http://www.sap-img.com/materials/subcontracting-key-points.htm
    http://www.sap-img.com/materials/what-is-subsequent-adjustment-in-process-of-subcontracting.htm
    Please check and revert if you have further queries.
    Regards,
    Hiren Ramani

  • RTP Billing Issue

    Hi Friends,
    I created RTP Component & RTP Interface. Acoordingly I created RTP rate with RTP operand. During Billing analysis the Input profile values are not fetched inside.
    Have anyone worked in this RTP Billing. If so, pls. share the detailed procedure or any link related to it.
    Regards,
    Sai Krishna

    Hi,
    You can check
    http://help.sap.com/saphelp_erp60/helpdata/en/1c/c5743c4dc1623de10000000a114084/frameset.htm
    Vlado

  • Error in task -Downloading a file from report

    Hi all,
    This is my code to download the content of report to Excel,Problem i am getting when trying to put heading for numerical fields .Its getting '0' in the heading .For remaining  Fields which are non-numberic its displaying nicely.Could any one solve this for me.
    report zt11.
      data :  itab type mard occurs 0 .
    select  * from mard into table itab .
    data: it_t001   type t001  occurs 0,
          it_fields type dfies occurs 0  with header line,
          begin of it_fnames occurs 0,
            reptext like dfies-reptext,
          end of it_fnames.
          CALL FUNCTION 'GET_FIELDTAB'
      EXPORTING
      LANGU                     = SY-LANGU
      ONLY                      = ' '
        TABNAME                   = 'MARD'
      WITHTEXT                  = 'X'
    IMPORTING
      HEADER                    =
      RC                        =
      TABLES
        FIELDTAB                  = it_fields
      EXCEPTIONS
        INTERNAL_ERROR            = 1
        NO_TEXTS_FOUND            = 2
        TABLE_HAS_NO_FIELDS       = 3
        TABLE_NOT_ACTIV           = 4
        OTHERS                    = 5
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    loop at it_fields.
      it_fnames-reptext = it_fields-reptext.
      append it_fnames.
    endloop.
    CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
      EXPORTING
        FILE_NAME                       = 'C:\T001'
      CREATE_PIVOT                    = 0
        DATA_SHEET_NAME                 = 'Companies'
      PIVOT_SHEET_NAME                = ' '
      PASSWORD                        = ' '
      PASSWORD_OPTION                 = 0
      TABLES
      PIVOT_FIELD_TAB                 =
        DATA_TAB                        = itab
       FIELDNAMES                      = it_fnames
      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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    short dump :  unable to interpret the "..... " as number.

    Hi,
    You are not formatting the internal table for field labels correctly.
    See the attached code and do accordingly.
    This will help you.
    Reward for useful answers.
    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 bvbeln = avbeln
                            join vbap as c
                            on baubel = cvbeln and
                               baupos = cposnr
                      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 .
          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.
        itab_out-vbeln   = itab_bill-vbeln.
        itab_out-fktyp   = itab_bill-fktyp.
        itab_out-vbtyp   = itab_bill-vbtyp.
        itab_out-fkdat   = itab_bill-fkdat.
        itab_out-fkart   = itab_bill-fkart.
        itab_out-bukrs   = itab_bill-bukrs.
        itab_out-kurrf   = itab_bill-kurrf.
        itab_out-waerk   = itab_bill-waerk.
        itab_out-kunag   = itab_bill-kunag.
        itab_out-vrkme   = itab_bill-vrkme.
        itab_out-posnr   = itab_bill-posnr.
        itab_out-charg   = itab_bill-charg.
        itab_out-fkimg   = itab_bill-fkimg.
        itab_out-werks   = itab_bill-werks.
        itab_out-matnr   = itab_bill-matnr.
        itab_out-kdmat   = itab_bill-kdmat.
       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' .
              if tcurx-currdec eq '0'.
                mbew-stprs = mbew-stprs * 100.
                mbew-verpr = mbew-verpr * 100.
              endif.
            endif.
            if itab_out-waerk eq t001-waers.
              itab_out-mvg_prs = mbew-verpr  ."/ itab_out-kurrf.
            else.
              itab_out-mvg_prs = mbew-verpr  / itab_out-kurrf.
            endif.
          else.
            clear:mbewh.
            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 tcurx-currdec eq '0'.
                mbewh-verpr = mbewh-verpr * 100.
              endif.
            endif.
            if itab_out-waerk eq t001-waers.
              itab_out-mvg_prs = mbewh-verpr ."/ itab_out-kurrf.
            else.
              itab_out-mvg_prs = mbewh-verpr  / itab_out-kurrf.
            endif.
            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' .
                if tcurx-currdec eq '0'.
                  mbew-verpr = mbew-verpr * 100.
                endif.
              endif.
              if itab_out-waerk eq t001-waers.
                itab_out-mvg_prs = mbew-verpr  ."/ itab_out-kurrf.
              else.
                itab_out-mvg_prs = mbew-verpr  / itab_out-kurrf.
              endif.
            endif.
          endif.
        endif.
    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.
        append itab_out.
        clear itab_out.
      endloop.
      loop at itab_out.
        if itab_out-vbtyp eq 'N' or itab_out-vbtyp eq 'O'.
          itab_out-fkimg   = itab_out-fkimg * -1.
          itab_out-sel_prc = itab_out-sel_prc * -1.
          itab_out-bil_amt = itab_out-bil_amt * -1.
          itab_out-mvg_prs = itab_out-mvg_prs * -1.
          itab_out-gp_mvp_amt = itab_out-gp_mvp_amt * -1.
          itab_out-gp_mvp_pr = itab_out-gp_mvp_pr * -1.
    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.
    *&      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.
      call function 'BAPI_COMPANYCODE_GET_PERIOD'
           exporting
                companycodeid = itab_out-bukrs
                posting_date  = w_date
           importing
                fiscal_year   = w_year
                fiscal_period = w_period.
    endform.                    " get_period
    *&      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.
        write:  /01 sy-vline,  2(10) itab_out-kunag,
                 12 sy-vline, 13(10) itab_out-vbeln,
                 23 sy-vline, 24(6)  itab_out-posnr,
                 30 sy-vline, 31(10) itab_out-fkdat,
                 41 sy-vline, 42(6)  itab_out-mode,
                 48 sy-vline, 49(7)  itab_out-density,
                 56 sy-vline, 57(18) itab_out-matnr,
                 75 sy-vline, 76(10) itab_out-charg,
                 86 sy-vline,
                 87(13) itab_out-fkimg unit itab_out-vrkme no-sign,
                 102(3) itab_out-vrkme,
                105 sy-vline,
                106(14) itab_out-sel_prc currency konv-waers no-sign,
                120 sy-vline,
                121(15) itab_out-bil_amt currency vbrk-waerk no-sign,
                138(3) itab_out-waerk,
                141 sy-vline,
                142(15) itab_out-mvg_prs currency vbrk-waerk no-sign,
                157 sy-vline,
                158(15) itab_out-gp_mvp_amt currency vbrk-waerk no-sign,
                173 sy-vline,174(6)  itab_out-gp_mvp_pr no-sign ,
                180 sy-vline,181(33) itab_out-kdmat,
                214 sy-vline.
        t_fkimg = t_fkimg + itab_out-fkimg.
        t_bil_amt = t_bil_amt + itab_out-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out-gp_mvp_amt.
        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.
        write: /01 sy-vline,  2(10) itab_out2-kunag,
                12 sy-vline, 13(10) itab_out2-vbeln,
                23 sy-vline, 24(6)  itab_out2-posnr,
                30 sy-vline, 31(10) itab_out2-fkdat,
                41 sy-vline, 42(6)  itab_out2-mode,
                48 sy-vline, 49(7)  itab_out2-density,
                56 sy-vline, 57(18) itab_out2-matnr,
                75 sy-vline, 76(10) itab_out2-charg,
                86 sy-vline,
                87(13) itab_out2-fkimg unit itab_out2-vrkme no-sign,
                102(3) itab_out2-vrkme,
                105 sy-vline,
                106(14) itab_out2-sel_prc currency vbrk-waerk no-sign,
                120 sy-vline,
                121(15) itab_out2-bil_amt currency vbrk-waerk no-sign,
                             138(3)  itab_out2-waerk,
                141 sy-vline,
                142(15) itab_out2-mvg_prs currency vbrk-waerk no-sign,
                157 sy-vline,
                158(15) itab_out2-gp_mvp_amt currency vbrk-waerk no-sign,
                173 sy-vline,174(6)  itab_out2-gp_mvp_pr no-sign,
                180 sy-vline,181(33) itab_out2-kdmat,
                214 sy-vline.
        t_fkimg = t_fkimg + itab_out2-fkimg.
        t_bil_amt = t_bil_amt + itab_out2-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out2-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out2-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out2-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out2-gp_mvp_amt.
        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.
        write:  /01 sy-vline,  2(10) itab_out3-kunag,
                 12 sy-vline, 13(10) itab_out3-vbeln,
                 23 sy-vline, 24(6)  itab_out3-posnr,
                 30 sy-vline, 31(10) itab_out3-fkdat,
                 41 sy-vline, 42(6)  itab_out3-mode,
                 48 sy-vline, 49(7)  itab_out3-density,
                 56 sy-vline, 57(18) itab_out3-matnr,
                 75 sy-vline, 76(10) itab_out3-charg,
                 86 sy-vline,
                 87(13) itab_out3-fkimg unit itab_out3-vrkme no-sign,
                 102(3) itab_out3-vrkme,
                 105 sy-vline,106(14) itab_out3-sel_prc no-sign,
                 120 sy-vline,
                 121(15) itab_out3-bil_amt currency vbrk-waerk no-sign,
                              138(3)  itab_out3-waerk,
                 141 sy-vline,142(15) itab_out3-mvg_prs no-sign
                                      currency vbrk-waerk,
                 157 sy-vline,158(15) itab_out3-gp_mvp_amt no-sign
                                      currency vbrk-waerk,
                 173 sy-vline,174(6)  itab_out3-gp_mvp_pr no-sign,
                 180 sy-vline,181(33) itab_out3-kdmat,
                 214 sy-vline.
        t_efkimg      = t_efkimg      + itab_out3-fkimg.
        t_ebil_amt    = t_ebil_amt    + itab_out3-bil_amt.
        t_egp_mvp_amt = t_egp_mvp_amt + itab_out3-gp_mvp_amt.
        t_fkimg = t_fkimg + itab_out3-fkimg.
        t_bil_amt = t_bil_amt + itab_out3-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out3-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out3-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out3-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out3-gp_mvp_amt.
        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.
      write :/2 'Company Code :'(011), s_bukrs-low ,
            85 'Billing Date :'(012) , s_fkdat-low , '-' ,s_fkdat-high ,
            190 'Page :'(013), sy-pagno,
            214 ' '.
      write at /1(214) sy-uline.
      write: /1 sy-vline,  2(10) 'Customer'(004) centered,
             12 sy-vline, 13(10) 'Billing'(009) centered,
             23 sy-vline, 24(6)  'Billing'(009) centered,
             30 sy-vline, 31(10) 'Billing'(009) centered,
             41 sy-vline, 42(6)  'Mode'(006) centered,
             48 sy-vline, 49(7)  'Density'(014) centered,
             56 sy-vline, 57(18) 'Material'(015) centered,
             75 sy-vline, 76(10) 'Batch'(016) centered,
             86 sy-vline, 87(13) 'Quantity'(017) centered,102(3) 'UOM'(027),
             105 sy-vline, 106(14) 'Selling'(018) centered ,
             120 sy-vline, 121(15) 'Billing'(009) centered,
                           138(3) 'Cur'(028),
             141 sy-vline, 142(15) 'Mvg.Avg.Price'(020) centered,
             157 sy-vline, 158(22) 'Gross Profit(MVP)'(022) centered,
             180 sy-vline, 181(33) 'Customer Material'(023) centered,
             214 sy-vline.
      write: /1 sy-vline,  2(10) 'Code'(024) centered,
             12 sy-vline, 13(10) 'Document'(025) centered,
             23 sy-vline, 24(6)  'Item'(026) centered,
             30 sy-vline, 31(10) 'Date'(036) centered,
             41 sy-vline,
             48 sy-vline,
             56 sy-vline,
             75 sy-vline,
             86 sy-vline,
            105 sy-vline, 106(14) 'Price'(030) centered ,
            120 sy-vline, 121(15) 'Amount'(031) centered,
            141 sy-vline, 142(15) '(per Unit)'(019) centered,
            157 sy-vline, 158(15) 'Amount'(031) centered,
            173 sy-vline, 174(6) ' % '(029) centered,
            180 sy-vline,
            214 sy-vline.
      format color off.
    endform.                    " rep_headers
    *&      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.
    *&      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-ta

  • Report output to a file

    Hi All,
    My requirement is on execution of a report ,this report output should be downloaded as a file prompting the user to select the location.
    Can any one help me in downloading the output format to a file. I need some inputs on the  approach for doing this .
    Thanks in advance .
    Padma

    Hi
    See the sample code in which the download to file is used
    and do accordingly
    instaed of the OLE..fun module you can use the GUI_DOWNLOAD also
    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 bvbeln = avbeln
                            join vbap as c
                            on baubel = cvbeln and
                               baupos = cposnr
                      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 .
          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.
        itab_out-vbeln   = itab_bill-vbeln.
        itab_out-fktyp   = itab_bill-fktyp.
        itab_out-vbtyp   = itab_bill-vbtyp.
        itab_out-fkdat   = itab_bill-fkdat.
        itab_out-fkart   = itab_bill-fkart.
        itab_out-bukrs   = itab_bill-bukrs.
        itab_out-kurrf   = itab_bill-kurrf.
        itab_out-waerk   = itab_bill-waerk.
        itab_out-kunag   = itab_bill-kunag.
        itab_out-vrkme   = itab_bill-vrkme.
        itab_out-posnr   = itab_bill-posnr.
        itab_out-charg   = itab_bill-charg.
        itab_out-fkimg   = itab_bill-fkimg.
        itab_out-werks   = itab_bill-werks.
        itab_out-matnr   = itab_bill-matnr.
        itab_out-kdmat   = itab_bill-kdmat.
       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' .
              if tcurx-currdec eq '0'.
                mbew-stprs = mbew-stprs * 100.
                mbew-verpr = mbew-verpr * 100.
              endif.
            endif.
            if itab_out-waerk eq t001-waers.
              itab_out-mvg_prs = mbew-verpr  ."/ itab_out-kurrf.
            else.
              itab_out-mvg_prs = mbew-verpr  / itab_out-kurrf.
            endif.
          else.
            clear:mbewh.
            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 tcurx-currdec eq '0'.
                mbewh-verpr = mbewh-verpr * 100.
              endif.
            endif.
            if itab_out-waerk eq t001-waers.
              itab_out-mvg_prs = mbewh-verpr ."/ itab_out-kurrf.
            else.
              itab_out-mvg_prs = mbewh-verpr  / itab_out-kurrf.
            endif.
            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' .
                if tcurx-currdec eq '0'.
                  mbew-verpr = mbew-verpr * 100.
                endif.
              endif.
              if itab_out-waerk eq t001-waers.
                itab_out-mvg_prs = mbew-verpr  ."/ itab_out-kurrf.
              else.
                itab_out-mvg_prs = mbew-verpr  / itab_out-kurrf.
              endif.
            endif.
          endif.
        endif.
    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.
        append itab_out.
        clear itab_out.
      endloop.
      loop at itab_out.
        if itab_out-vbtyp eq 'N' or itab_out-vbtyp eq 'O'.
          itab_out-fkimg   = itab_out-fkimg * -1.
          itab_out-sel_prc = itab_out-sel_prc * -1.
          itab_out-bil_amt = itab_out-bil_amt * -1.
          itab_out-mvg_prs = itab_out-mvg_prs * -1.
          itab_out-gp_mvp_amt = itab_out-gp_mvp_amt * -1.
          itab_out-gp_mvp_pr = itab_out-gp_mvp_pr * -1.
    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.
    *&      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.
      call function 'BAPI_COMPANYCODE_GET_PERIOD'
           exporting
                companycodeid = itab_out-bukrs
                posting_date  = w_date
           importing
                fiscal_year   = w_year
                fiscal_period = w_period.
    endform.                    " get_period
    *&      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.
        write:  /01 sy-vline,  2(10) itab_out-kunag,
                 12 sy-vline, 13(10) itab_out-vbeln,
                 23 sy-vline, 24(6)  itab_out-posnr,
                 30 sy-vline, 31(10) itab_out-fkdat,
                 41 sy-vline, 42(6)  itab_out-mode,
                 48 sy-vline, 49(7)  itab_out-density,
                 56 sy-vline, 57(18) itab_out-matnr,
                 75 sy-vline, 76(10) itab_out-charg,
                 86 sy-vline,
                 87(13) itab_out-fkimg unit itab_out-vrkme no-sign,
                 102(3) itab_out-vrkme,
                105 sy-vline,
                106(14) itab_out-sel_prc currency konv-waers no-sign,
                120 sy-vline,
                121(15) itab_out-bil_amt currency vbrk-waerk no-sign,
                138(3) itab_out-waerk,
                141 sy-vline,
                142(15) itab_out-mvg_prs currency vbrk-waerk no-sign,
                157 sy-vline,
                158(15) itab_out-gp_mvp_amt currency vbrk-waerk no-sign,
                173 sy-vline,174(6)  itab_out-gp_mvp_pr no-sign ,
                180 sy-vline,181(33) itab_out-kdmat,
                214 sy-vline.
        t_fkimg = t_fkimg + itab_out-fkimg.
        t_bil_amt = t_bil_amt + itab_out-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out-gp_mvp_amt.
        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.
        write: /01 sy-vline,  2(10) itab_out2-kunag,
                12 sy-vline, 13(10) itab_out2-vbeln,
                23 sy-vline, 24(6)  itab_out2-posnr,
                30 sy-vline, 31(10) itab_out2-fkdat,
                41 sy-vline, 42(6)  itab_out2-mode,
                48 sy-vline, 49(7)  itab_out2-density,
                56 sy-vline, 57(18) itab_out2-matnr,
                75 sy-vline, 76(10) itab_out2-charg,
                86 sy-vline,
                87(13) itab_out2-fkimg unit itab_out2-vrkme no-sign,
                102(3) itab_out2-vrkme,
                105 sy-vline,
                106(14) itab_out2-sel_prc currency vbrk-waerk no-sign,
                120 sy-vline,
                121(15) itab_out2-bil_amt currency vbrk-waerk no-sign,
                             138(3)  itab_out2-waerk,
                141 sy-vline,
                142(15) itab_out2-mvg_prs currency vbrk-waerk no-sign,
                157 sy-vline,
                158(15) itab_out2-gp_mvp_amt currency vbrk-waerk no-sign,
                173 sy-vline,174(6)  itab_out2-gp_mvp_pr no-sign,
                180 sy-vline,181(33) itab_out2-kdmat,
                214 sy-vline.
        t_fkimg = t_fkimg + itab_out2-fkimg.
        t_bil_amt = t_bil_amt + itab_out2-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out2-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out2-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out2-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out2-gp_mvp_amt.
        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.
        write:  /01 sy-vline,  2(10) itab_out3-kunag,
                 12 sy-vline, 13(10) itab_out3-vbeln,
                 23 sy-vline, 24(6)  itab_out3-posnr,
                 30 sy-vline, 31(10) itab_out3-fkdat,
                 41 sy-vline, 42(6)  itab_out3-mode,
                 48 sy-vline, 49(7)  itab_out3-density,
                 56 sy-vline, 57(18) itab_out3-matnr,
                 75 sy-vline, 76(10) itab_out3-charg,
                 86 sy-vline,
                 87(13) itab_out3-fkimg unit itab_out3-vrkme no-sign,
                 102(3) itab_out3-vrkme,
                 105 sy-vline,106(14) itab_out3-sel_prc no-sign,
                 120 sy-vline,
                 121(15) itab_out3-bil_amt currency vbrk-waerk no-sign,
                              138(3)  itab_out3-waerk,
                 141 sy-vline,142(15) itab_out3-mvg_prs no-sign
                                      currency vbrk-waerk,
                 157 sy-vline,158(15) itab_out3-gp_mvp_amt no-sign
                                      currency vbrk-waerk,
                 173 sy-vline,174(6)  itab_out3-gp_mvp_pr no-sign,
                 180 sy-vline,181(33) itab_out3-kdmat,
                 214 sy-vline.
        t_efkimg      = t_efkimg      + itab_out3-fkimg.
        t_ebil_amt    = t_ebil_amt    + itab_out3-bil_amt.
        t_egp_mvp_amt = t_egp_mvp_amt + itab_out3-gp_mvp_amt.
        t_fkimg = t_fkimg + itab_out3-fkimg.
        t_bil_amt = t_bil_amt + itab_out3-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out3-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out3-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out3-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out3-gp_mvp_amt.
        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.
      write :/2 'Company Code :'(011), s_bukrs-low ,
            85 'Billing Date :'(012) , s_fkdat-low , '-' ,s_fkdat-high ,
            190 'Page :'(013), sy-pagno,
            214 ' '.
      write at /1(214) sy-uline.
      write: /1 sy-vline,  2(10) 'Customer'(004) centered,
             12 sy-vline, 13(10) 'Billing'(009) centered,
             23 sy-vline, 24(6)  'Billing'(009) centered,
             30 sy-vline, 31(10) 'Billing'(009) centered,
             41 sy-vline, 42(6)  'Mode'(006) centered,
             48 sy-vline, 49(7)  'Density'(014) centered,
             56 sy-vline, 57(18) 'Material'(015) centered,
             75 sy-vline, 76(10) 'Batch'(016) centered,
             86 sy-vline, 87(13) 'Quantity'(017) centered,102(3) 'UOM'(027),
             105 sy-vline, 106(14) 'Selling'(018) centered ,
             120 sy-vline, 121(15) 'Billing'(009) centered,
                           138(3) 'Cur'(028),
             141 sy-vline, 142(15) 'Mvg.Avg.Price'(020) centered,
             157 sy-vline, 158(22) 'Gross Profit(MVP)'(022) centered,
             180 sy-vline, 181(33) 'Customer Material'(023) centered,
             214 sy-vline.
      write: /1 sy-vline,  2(10) 'Code'(024) centered,
             12 sy-vline, 13(10) 'Document'(025) centered,
             23 sy-vline, 24(6)  'Item'(026) centered,
             30 sy-vline, 31(10) 'Date'(036) centered,
             41 sy-vline,
             48 sy-vline,
             56 sy-vline,
             75 sy-vline,
             86 sy-vline,
            105 sy-vline, 106(14) 'Price'(030) centered ,
            120 sy-vline, 121(15) 'Amount'(031) centered,
            141 sy-vline, 142(15) '(per Unit)'(019) centered,
            157 sy-vline, 158(15) 'Amount'(031) centered,
            173 sy-vline, 174(6) ' % '(029) centered,
            180 sy-vline,
            214 sy-vline.
      format color off.
    endform.                    " rep_headers
    *&      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.
    *&      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.
     

  • Report on invoice

    hi to all , can u pls give coding for this
      report to  display list of invoices posted with ina specified range of dates .
    points will be rewarded for good ansers

    Hi
    use the Tables VBRK and VBRP for getting the invoice data
    see the sample code for fetching the Billing related data
    you change the output display from it as per your logic
    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 bvbeln = avbeln
                            join vbap as c
                            on baubel = cvbeln and
                               baupos = cposnr
                      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 .
          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.
        itab_out-vbeln   = itab_bill-vbeln.
        itab_out-fktyp   = itab_bill-fktyp.
        itab_out-vbtyp   = itab_bill-vbtyp.
        itab_out-fkdat   = itab_bill-fkdat.
        itab_out-fkart   = itab_bill-fkart.
        itab_out-bukrs   = itab_bill-bukrs.
        itab_out-kurrf   = itab_bill-kurrf.
        itab_out-waerk   = itab_bill-waerk.
        itab_out-kunag   = itab_bill-kunag.
        itab_out-vrkme   = itab_bill-vrkme.
        itab_out-posnr   = itab_bill-posnr.
        itab_out-charg   = itab_bill-charg.
        itab_out-fkimg   = itab_bill-fkimg.
        itab_out-werks   = itab_bill-werks.
        itab_out-matnr   = itab_bill-matnr.
        itab_out-kdmat   = itab_bill-kdmat.
       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' .
              if tcurx-currdec eq '0'.
                mbew-stprs = mbew-stprs * 100.
                mbew-verpr = mbew-verpr * 100.
              endif.
            endif.
            if itab_out-waerk eq t001-waers.
              itab_out-mvg_prs = mbew-verpr  ."/ itab_out-kurrf.
            else.
              itab_out-mvg_prs = mbew-verpr  / itab_out-kurrf.
            endif.
          else.
            clear:mbewh.
            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 tcurx-currdec eq '0'.
                mbewh-verpr = mbewh-verpr * 100.
              endif.
            endif.
            if itab_out-waerk eq t001-waers.
              itab_out-mvg_prs = mbewh-verpr ."/ itab_out-kurrf.
            else.
              itab_out-mvg_prs = mbewh-verpr  / itab_out-kurrf.
            endif.
            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' .
                if tcurx-currdec eq '0'.
                  mbew-verpr = mbew-verpr * 100.
                endif.
              endif.
              if itab_out-waerk eq t001-waers.
                itab_out-mvg_prs = mbew-verpr  ."/ itab_out-kurrf.
              else.
                itab_out-mvg_prs = mbew-verpr  / itab_out-kurrf.
              endif.
            endif.
          endif.
        endif.
    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.
        append itab_out.
        clear itab_out.
      endloop.
      loop at itab_out.
        if itab_out-vbtyp eq 'N' or itab_out-vbtyp eq 'O'.
          itab_out-fkimg   = itab_out-fkimg * -1.
          itab_out-sel_prc = itab_out-sel_prc * -1.
          itab_out-bil_amt = itab_out-bil_amt * -1.
          itab_out-mvg_prs = itab_out-mvg_prs * -1.
          itab_out-gp_mvp_amt = itab_out-gp_mvp_amt * -1.
          itab_out-gp_mvp_pr = itab_out-gp_mvp_pr * -1.
    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.
    *&      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.
      call function 'BAPI_COMPANYCODE_GET_PERIOD'
           exporting
                companycodeid = itab_out-bukrs
                posting_date  = w_date
           importing
                fiscal_year   = w_year
                fiscal_period = w_period.
    endform.                    " get_period
    *&      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.
        write:  /01 sy-vline,  2(10) itab_out-kunag,
                 12 sy-vline, 13(10) itab_out-vbeln,
                 23 sy-vline, 24(6)  itab_out-posnr,
                 30 sy-vline, 31(10) itab_out-fkdat,
                 41 sy-vline, 42(6)  itab_out-mode,
                 48 sy-vline, 49(7)  itab_out-density,
                 56 sy-vline, 57(18) itab_out-matnr,
                 75 sy-vline, 76(10) itab_out-charg,
                 86 sy-vline,
                 87(13) itab_out-fkimg unit itab_out-vrkme no-sign,
                 102(3) itab_out-vrkme,
                105 sy-vline,
                106(14) itab_out-sel_prc currency konv-waers no-sign,
                120 sy-vline,
                121(15) itab_out-bil_amt currency vbrk-waerk no-sign,
                138(3) itab_out-waerk,
                141 sy-vline,
                142(15) itab_out-mvg_prs currency vbrk-waerk no-sign,
                157 sy-vline,
                158(15) itab_out-gp_mvp_amt currency vbrk-waerk no-sign,
                173 sy-vline,174(6)  itab_out-gp_mvp_pr no-sign ,
                180 sy-vline,181(33) itab_out-kdmat,
                214 sy-vline.
        t_fkimg = t_fkimg + itab_out-fkimg.
        t_bil_amt = t_bil_amt + itab_out-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out-gp_mvp_amt.
        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.
        write: /01 sy-vline,  2(10) itab_out2-kunag,
                12 sy-vline, 13(10) itab_out2-vbeln,
                23 sy-vline, 24(6)  itab_out2-posnr,
                30 sy-vline, 31(10) itab_out2-fkdat,
                41 sy-vline, 42(6)  itab_out2-mode,
                48 sy-vline, 49(7)  itab_out2-density,
                56 sy-vline, 57(18) itab_out2-matnr,
                75 sy-vline, 76(10) itab_out2-charg,
                86 sy-vline,
                87(13) itab_out2-fkimg unit itab_out2-vrkme no-sign,
                102(3) itab_out2-vrkme,
                105 sy-vline,
                106(14) itab_out2-sel_prc currency vbrk-waerk no-sign,
                120 sy-vline,
                121(15) itab_out2-bil_amt currency vbrk-waerk no-sign,
                             138(3)  itab_out2-waerk,
                141 sy-vline,
                142(15) itab_out2-mvg_prs currency vbrk-waerk no-sign,
                157 sy-vline,
                158(15) itab_out2-gp_mvp_amt currency vbrk-waerk no-sign,
                173 sy-vline,174(6)  itab_out2-gp_mvp_pr no-sign,
                180 sy-vline,181(33) itab_out2-kdmat,
                214 sy-vline.
        t_fkimg = t_fkimg + itab_out2-fkimg.
        t_bil_amt = t_bil_amt + itab_out2-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out2-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out2-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out2-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out2-gp_mvp_amt.
        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.
        write:  /01 sy-vline,  2(10) itab_out3-kunag,
                 12 sy-vline, 13(10) itab_out3-vbeln,
                 23 sy-vline, 24(6)  itab_out3-posnr,
                 30 sy-vline, 31(10) itab_out3-fkdat,
                 41 sy-vline, 42(6)  itab_out3-mode,
                 48 sy-vline, 49(7)  itab_out3-density,
                 56 sy-vline, 57(18) itab_out3-matnr,
                 75 sy-vline, 76(10) itab_out3-charg,
                 86 sy-vline,
                 87(13) itab_out3-fkimg unit itab_out3-vrkme no-sign,
                 102(3) itab_out3-vrkme,
                 105 sy-vline,106(14) itab_out3-sel_prc no-sign,
                 120 sy-vline,
                 121(15) itab_out3-bil_amt currency vbrk-waerk no-sign,
                              138(3)  itab_out3-waerk,
                 141 sy-vline,142(15) itab_out3-mvg_prs no-sign
                                      currency vbrk-waerk,
                 157 sy-vline,158(15) itab_out3-gp_mvp_amt no-sign
                                      currency vbrk-waerk,
                 173 sy-vline,174(6)  itab_out3-gp_mvp_pr no-sign,
                 180 sy-vline,181(33) itab_out3-kdmat,
                 214 sy-vline.
        t_efkimg      = t_efkimg      + itab_out3-fkimg.
        t_ebil_amt    = t_ebil_amt    + itab_out3-bil_amt.
        t_egp_mvp_amt = t_egp_mvp_amt + itab_out3-gp_mvp_amt.
        t_fkimg = t_fkimg + itab_out3-fkimg.
        t_bil_amt = t_bil_amt + itab_out3-bil_amt.
        t_gp_mvp_amt = t_gp_mvp_amt + itab_out3-gp_mvp_amt.
        t_gr_fkimg      = t_gr_fkimg         + itab_out3-fkimg.
        t_gr_bil_amt    = t_gr_bil_amt       + itab_out3-bil_amt.
        t_gr_gp_mvp_amt = t_gr_gp_mvp_amt    + itab_out3-gp_mvp_amt.
        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.
      write :/2 'Company Code :'(011), s_bukrs-low ,
            85 'Billing Date :'(012) , s_fkdat-low , '-' ,s_fkdat-high ,
            190 'Page :'(013), sy-pagno,
            214 ' '.
      write at /1(214) sy-uline.
      write: /1 sy-vline,  2(10) 'Customer'(004) centered,
             12 sy-vline, 13(10) 'Billing'(009) centered,
             23 sy-vline, 24(6)  'Billing'(009) centered,
             30 sy-vline, 31(10) 'Billing'(009) centered,
             41 sy-vline, 42(6)  'Mode'(006) centered,
             48 sy-vline, 49(7)  'Density'(014) centered,
             56 sy-vline, 57(18) 'Material'(015) centered,
             75 sy-vline, 76(10) 'Batch'(016) centered,
             86 sy-vline, 87(13) 'Quantity'(017) centered,102(3) 'UOM'(027),
             105 sy-vline, 106(14) 'Selling'(018) centered ,
             120 sy-vline, 121(15) 'Billing'(009) centered,
                           138(3) 'Cur'(028),
             141 sy-vline, 142(15) 'Mvg.Avg.Price'(020) centered,
             157 sy-vline, 158(22) 'Gross Profit(MVP)'(022) centered,
             180 sy-vline, 181(33) 'Customer Material'(023) centered,
             214 sy-vline.
      write: /1 sy-vline,  2(10) 'Code'(024) centered,
             12 sy-vline, 13(10) 'Document'(025) centered,
             23 sy-vline, 24(6)  'Item'(026) centered,
             30 sy-vline, 31(10) 'Date'(036) centered,
             41 sy-vline,
             48 sy-vline,
             56 sy-vline,
             75 sy-vline,
             86 sy-vline,
            105 sy-vline, 106(14) 'Price'(030) centered ,
            120 sy-vline, 121(15) 'Amount'(031) centered,
            141 sy-vline, 142(15) '(per Unit)'(019) centered,
            157 sy-vline, 158(15) 'Amount'(031) centered,
            173 sy-vline, 174(6) ' % '(029) centered,
            180 sy-vline,
            214 sy-vline.
      format color off.
    endform.                    " rep_headers
    *&      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.
    *&      Form  append_fieldname
    Appending field Names
    form append_fieldname using p_title p_table p_field p_type.
      clear: fieldnames.
      fieldnames-title = p_title.
      fieldnam

  • For Reversal Document Maintainence

    Hi
       For SAP NetWeaver BI, we are using the standard data source '0UC_SALES_STATS_01'  for  Billing Analysis . We are facing one issue regarding this.
    The selection creteria for this data source is BUDAT(Posting Date of Invoice Doument) only .
    For Example we are extracted the data for the BUDAT = 31.01.2006.  In this scenario, assume one Business Partner Number is 1000071173, Consumption is 100 Units and Bill Amount is 500 Rs(INR) for a particular month bill. Now we extract the data from R/3 to BI.After Extraction it will move from R/3 Server to BW Server and it will load into the PSA and then in ODS.
    After some days,for some reason we have to reverse the bill and to reissue a corrected bill on the same posting date (i.e.31.01.2006).So for that Business Partner 1000071173,say, Consumpiton is revised to 75 Units and Bill Amount is revised to Rs 375 INR. So the previous Invoice Document is reversed (Full Reversal-Invoice and bill document both) and the new bill has been made for him with 75 units and Bill Amount Rs. 375 INR. When we extract this data again i.e BUDAT 31.01.2006 , we will get the 2 documents one for reversed and one for Corrected. After Extraction from R/3 to BI , In PSA we will get 2 more documents for him.  After transfering this two documents into ODS we will get total three documents for that Business Partner for a particular month bill. 
    Doc 1. Very first time i.e (in the Extraction Date 31.01.2006 with amount Rs 500 INR )
    Doc 2. Reverse Document for the Above Doc.
    Doc 3. For Corrected Bill.(Invoice document with Rs 375 INR)
    In our Business scenario,it is required that we have to display only the recent corrected value in any of the report.So in the time of extraction how can we overwrite or delete the previous records and to keep only the recent corrected value?
    Regards
    Prashanth

    Hi There,
    There shouldn't be any overwrite or deletion of previous records in BI.  In the R/3 system which is the ISU system, a reversal invoice should carry a negative consumption and bill amount.  For your example, after extraction and data loaded into BI:-
    Doc 1 in BI should have 100 Units and 500 INR   (Original or yr very first invoice)
    Doc 2 in BI should have -100 Units and -500 INR (Reversal Invoice)
    Doc 3 in BI should have 75 Units and 375 INR.    (Rebill Invoice)
    When you run a query for the respective Business Partner for that posting period, Doc 2 should offset Doc 1.  As a result you should get result from Doc 3 only, which is 75 Units and 375 INR.
    Cheers,
    Chris

  • Sales analysis report of items not inventoried in utility bill

    Buenas tardes:
    Espero me entiendan ya que mi ingles es un poco malo.
    quisiera saber si hay alguna forma de sacar un reporte de facturas de servicio donde los articulos son del tipo no inventariable, ya que en el analisis de ventas no me permite sacar este tipo de informacion,
    no se si me explique bien.
    Gracias
    Good afternoon:
    I hope you understand me because my English is a little bad.
    I wonder if there is any way to get a report of invoices for service where no type items are inventoried, as in the analysis of sales will not let me get this type of information,
    not if I explain it right.
    Thanks

    Welcome to the forum.
    Yes finding it difficult to understand what exactly your requirement is.  Assuming that you want to see some despatch details where delivery is not made and its like sale order related billing, please check the following TCodes.
    1)  VF05 or VF05N
    2)  MCTE
    3)  MCTA
    4)  MC+E
    Hope my understanding is correct,
    thanks
    G. Lakshmipathi

  • Profitability Analysis not generated in Contract billing Document

    I have created the Billing document against the contract order but the Profitability Analysis is not getting generated.  But any sale order related billing document is created; system automatically creates the Profitability Analysis.
    Can you tell me where the problem is or have I missed any steps?
    Regards,
    Devendra

    1) For a service material (DIEN), We are creating an Sales Order (VA01) and doing a order based billing (VF01). In the Sales Order we are giving the plant (no shipping point and storage location as it is a DIEN material).
    Once we do the billing we are able to see the Profitability Analysis document.
    2) Now we are using the same material we are creating a Contract (VA41) for a period of one year and doing a monthly billing. In this case we are using VF04 for doing the bills that are due.
    We are getting two results in this:
    a) If we give a Plant in the contract, the Profitability Analysis document is not getting generated at the time of billing.
    b) If we do not give any plant, the Profitability Analysis document is getting generated at the time of billing.
    Please note that we are using the same material, same pricing procedure in both the above cases 1) and 2). Only difference is that the source documents are different i.e., one is Sales Order and the other one is Contract.
    In our copa valuation we have assigned the conditions to value field, no derivation rule assigned.
    Regards
    Devendra
    Edited by: Devendrap on Apr 14, 2009 10:38 AM

  • Billing output dump analysis

    Hi,
    While taking print out of the invoice correction billing type, system is giving dump.
    The dump error analysis displayed following message-
    " In the current programme "ABCDE123", an arethmetic operation ('divide','/','div',or 'mod') with a type P operand attemptde to divide by 0."
    What does this mean and how this error can be removed?
    Pls. guide.
    Points will be rewarded.
    Regards

    hi
    if you feel this answer solve your query please reward with points
    You can solve this through the transaction code st22 and analyse the error with your abaper fix the solution
    thanks & Regards
    Rack29

  • Double actual cost in Profitability Analysis for cancelled billing doc

    Dear expert
    Say we have a billing doc posted in May, and we run ML closing and KE27 during month end closing, which transfered actual cost from material ledger to value field in PA.
    In June, we cancelled that billing document, the question is why the system automatically posted actual cost of cancelled billing docs to value field in PA right away (without KE27)?
    The reason I asked is because when we run KE27 for June closing, the SAP transfer again actual cost from material ledger to value field in PA. So we will have double posting of actual cost for cancelled billing document
    Please help, which setting did I missed to prevent SAP automatically posted actual cost of cancelled billing docs to value field in PA right away (without KE27)?
    Thx

    Hi
    Thats because you had double +ve also..
    Let me u/s your situation better
    1.PGI Posted COGS of Say, 100
    2. KE27 posted, say, addnl 20
    So, total COGS is now 120
    3. You posted a reversal now... It should post -100 and not -120.... Is it posting -120?
    Run KE27 for this month and see if it really posts -120 again... If it does, raise an OSS message to SAP... They are liable to help
    In my opinion, there is no Config set up for this... At best, you can try to assign different VF in KE4R for PV = 02 as compared to PV=01 and see if it helps
    br, Ajay M

  • Resuls Analysis for Service Contracts - Revenue in Excess of Billing.

    Dear Experts,
    We are running RA for Service Contracts.
    COntract period is 01/11/2010 to 30/10/2011.   Montlhy Value is 1000, Yearly value 12000
    1) The Billing Plan is Quarterly Billing (deferred).If we Run RA in KKA3.  Planned revenue showing is 12000 / 4 quarters = 3000 .
                                 If we Run RA in KKA3 , the planned revenue shown is 3000 instead of 12000.
    2)                          We have incurred some cost for the month of  November 2010.   If we RUN RA on KKA3 for the month of november 2010 , we should get 1000  as Actual Revenue and 2000  Should be shown in Revenue in Excess of Billing(REB). But it is not showing as Revenue in Excess of Billing.
    Please help.
    Regards,
    Shareeq
    Edited by: K M AHAMED SHAREEQ HUSSAIN on Oct 28, 2010 2:55 PM
    Edited by: K M AHAMED SHAREEQ HUSSAIN on Nov 4, 2010 4:18 PM

    Dear Experts,
    The Planned Revenue problem is solved now. We will have to run a Program(OSS Note). The Revenue in Excess of billing is there. Please help.
    Regards,
    Shareeq
    Edited by: K M AHAMED SHAREEQ HUSSAIN on Nov 7, 2010 4:32 PM

  • Milestone Billing & Progress Analysis

    Hello Experts,
    We are implementing PS for a manufacturing client where the client opting for a milestone billing as well the tracking of the progres of the project from the milestone for percentage billing processed, as have not come across this scenarion could any one please kindly help me out to configure this milestone billing process as well as the generation of the progress for the project.
    Kindly provide the brief how to go about the configuration once after that is done the process to go about it to acheive billing and progress for the project
    Awaiting for your kind reply.
    Thanks and Regards
    Praveen B M
    Edited by: Virendra Pal on Dec 3, 2009 12:57 PM

    Hello,
    Thanks for your reply as well for your suggestions. Yes have gone through the SAP help and i couldn't able to trace out the proper guidelines for project progress based on the milestone billing so, i opted to post in SDN.
    Could you please suggest me on progress tracking of projects with reference to milestone billing.
    Regards
    Praveen B M

Maybe you are looking for

  • How to get the DB2 system date in the ODI

    Hello, I m new to ODI. And I m having some issues. I ve a source in DB2. And I ve to load the data from DB2 to Oracle. So in the source(DB2) I ve some tables. One Table is ABCD. In that we have nearly 15 columns. In that we have a column called AG2R(

  • Photoshop CS6 und Filter

    Leider musste ich feststellen, dass viele meiner Filter in CS6 nicht mehr funktionieren bzw. einen Crash verursachen. Das betrifft nicht nur kostenlose 8bf-Plugins, sondern auch gekaufte, wie z. B. KPT Collection. Gibt es eine Möglichkeit, die Filter

  • Currency: MXP to USD how to convert ?

    Hi everybody, I´m junior, I have a question, I need to convert currency MXP to USD, I need to know what is the actual value of dollar, I know that the system have the value but I couldn´t find it. Can anybody tell me How can I know it? Thanks,

  • My old Dell D830 died. I have another laptop. I need to deactivate my CS5.5 on my new laptop, but how do I deactivate it when I can't access the other PC?

    I now have a HP Elite Book, 8770w 64 bit i7 processor 8GB RAM. The HD died and I wasn't able to deactivate my software. How do I deactivate it so that I can load it on my new laptop.

  • Refreshing Entire page vs Center Region

    I have a web center portal application where i have a three column template. I have links (these are 'golinks' as of now) in the left region on click of which i am loading content in the center region. This content is coming from an ADF taskflow as p