TDS query

Hi All,
I am developing a report for Monthly TDS Statement.(for vendors only)
Selection criteria are
1) Company Code
2) Posting Date
3) Vendor
I am getting the required data from WITH_ITEM table. But my doubt is what should be my starting point to fetch the document numbers of vendor payment.
Should I start with BSIK / BSAK?
I am considering one e.g in which for a vendor there are 3 docs. In only one doc I am getting TDS data. So I want to fetch only those docs for vendors where TDS is present.
Please help.
Thanks in Advance.
- Neha.

Hi Neha
why you required vendor payment document numbers
regards
Nagesh

Similar Messages

  • TDS Query report

    Hi All,
             My client is using SAP B1 9.0 pl8. I need TDS report in required format.
    Document date,
    Party name.
    Address,
    PAN no.
    Type of Deductee
    Vendor bill date
    bill no.
    Description
    Basic value
    Service tax amount
    Others(fright charge/any charges)
    Total tax value
    Rate of tax
    Section code
    location(branch)
    remarks.
      pls help me in this regard. waiting for replay.
    Regards,
    Saikrishna.

    Try This
    SELECT T2.[DocNum], T0.[DocDate], T2.[CardCode], T2.[CardName], T2.[BaseAmnt], T4.[Rate], T4.[WTAmnt], T0.[BSRCode], T0.[ChallanNo], T1.[DueDate], T1.[CheckNum], T1.[CheckSum] FROM OVPM T0  INNER JOIN VPM1 T1 ON T0.DocEntry = T1.DocNum INNER JOIN OPCH T2 ON T0.DocEntry = T2.DepositNum INNER JOIN PCH1 T3 ON T2.DocEntry = T3.DocEntry INNER JOIN PCH5 T4 ON T2.DocEntry = T4.AbsEntry GROUP BY T2.[DocNum], T0.[DocDate], T2.[CardCode], T2.[CardName], T4.[WTAmnt], T1.[DueDate], T1.[CheckNum], T1.[CheckSum], T0.[BSRCode], T0.[ChallanNo], T2.[BaseAmnt], T4.[Rate]
    Regards
    Kennedy

  • TDS Amount on Vendor Advance Shows positive value in *QUERY* for TDS Report

    Hi Everybody,
    I have made a query for List of TDS Report with Vendor informations as required by my client. In which the value of TDS on Vendor Advance Payment appears as positive value instaead of negative value. Please suggest how to rectify.
    Thanks,
    Paul

    Dear,
    If you have cleared the advance in F-54, then this will reverse the tax amount. That could be the reason for tax amount in debit.

  • How to get tax break up of TDS using SQL query ?

    Hi all,
    We are developing a TDS report using SQL query
    Report will contain VendorCode,Date(ap inv date),Vendor name,
    Bill value,TDS Amount,
    Bill Value – 100.000,
    TDS (2%) - 2.000,
    TDS Surcharge(10% on TDS) - 0.2,
    TDS Cess(2%(TDS+TDS Surcharge)) - 0.044,
    TDS HeCess(1%(TDS+TDS Surcharge)) - 0.022.
    We have developed this report which displays upto
    VendorCode,Date(ap inv date),Vendor name,
    Bill value,TDS Amount.
    How to show tax break up of TDS in SQL query ?
    Thanks,
    With regards,
    Jeyakanthan.

    Hi gauraw,
    Thank for your reply.
    I modified the query , pasted the query
    as below in query generator,
    Select T0.DocNum,T0.DocDate,T0.CardCode as 'Ledger',T1.TaxbleAmnt As 'Bill value',T1.WTAmnt as 'TDSAmt',(TDSAmt * 0.1) as 'TDS_Surch',
    (((TDSAmt0.1) + TDSAmt)0.02)  as 'TDSCess',
    (((TDSAmt0.1) + TDSAmt)0.01)  as 'TDSHCess'
    FROM OPCH T0  INNER JOIN PCH5 T1 ON T0.DocEntry = T1.AbsEntry
    WHERE (T0.DocDate >= '[%0]' and T0.DocDate <= '[%1]')
    on clicking execute its showing error message invalid column
    name 'TDSAmt'.
    With regards,
    Jeyakanthan

  • Query for TDS

    Hi all
    My problem is that i want a report in this report i need some field like docnum,docdate,cardname from opch table and baseamount,taxamount,wtname,wtrate from inv5 it is tds table but i am unable to get link between opch and inv5 how can we generate this report
    i have a query but it not working fine due to link .
    query-
    SELECT T0.[DocNum], T0.[DocDate], T0.[CardName], T0.[DocTotal], T0.[WTSum],T1.[WTName], T1.[Rate] 
    FROM OPCH T0 , OWHT T1
    Thanks & regard
    areeba ali

    Hi,
    My dear for purchasing it is going in pch5 not inv5.
    Try this...
    select T0.DocNum, T0.DocDate, T0.CardName, T0.DocTotal, T0.WTSum,T2.WTName, T1.Rate from opch T0
    inner join pch5 T1 on T0.Docentry=T1.Absentry
    inner join owht T2 on T1.WTcode=T2.WTCode
    Thanks
    Sachin

  • Query of TDS tax

    Dear Experts
    Please guide me follow
    1) How can i create a new tax code of TDS in sap business one ?
    2) How can i set a TDS tax code for a particular business partner ?
    3) How can i create a new TDS invoice ?
    Awaiting all the expert adwise.
    Thanks in advanced

    Hi Sai...........
    Please update your ID in your SCN Business Card so that I can send you the documentation for how to work on TDS entries......
    Regards,
    Rahul

  • Ex. Witholding Tax (TDS) : Business Place / Section Code : query

    Dear Experts,
    while posting any transaction which has With. Tax postings : in order to have correct returns & reporting, we mention business place / section code without fails.
    these fields are frequently missed by End User, could you please provide some solution for making it mandatory while posting transactions. i do not find them in Fields status groups too.
    please help.

    Hi
    you can make the user to enter them with out fail by using substitution or Validation rule depending on your business requirement.
    Validation Rule
    If T code =MIRO or T code = FB60
    Check if Business Place ="xyz" and Section Code ="yyyy"
    If check fails, system throws up the error message.
    You write Validation rule in GGB0 and assign to your company code in OB28. Similarly write a substitution rule in GGB1 and assign in OBBH
    Regards
    Sanil Bhandari

  • Query produces duplicate values in successive rows. Can I null them out?

    I've had very good success (Thanks Andy) in getting detailed responses to my posted questions, and I'm wondering whether there is a way in a report region join query that produces successive rows with duplicate values that I can suppress(replace) the print of the duplicate values in those rows. In case I've managed to twist the question into an unintelligible mess (One of my specialties), let me provide an example:
    We're trying to list the undergraduate institutions that an applicant has attended, and display information about dates of attendence, gpa, and major(s)/minor(s) taken. The rub is that there can be multiple major(s)/minor(s) for a given undergraduate institution, so the following is produced by the query:
    University of Hard Knox 01/02 01/06 4.00 Knitting
    University of Hard Knox 01/02 01/06 4.00 Cloth Repair
    Advanced University 02/06 01/08 3.75 Clothing Design
    Really Advanced U 02/08 01/09 4.00 Sports Clothing
    Really Advanced U 02/08 01/09 4.00 Tennis Shoe Burlap
    I want it to look like this:
    University of Hard Knox 01/02 01/06 4.00 Knitting
    Cloth Repair
    Advanced University 02/06 01/08 3.75 Clothing Design
    Really Advanced U 02/08 01/09 4.00 Sports Clothing
    Tennis Shoe Burlap
    * (edit) Please note that the cloth repair and tennis shoe repair rows would be correctly positioned in a table, but unfortunately got space suppresed here for some reason. *
    Under Andy's tuteage, I'd say the answer is probably javascript looping through the DOM looking for the innerHTML of specific TDs in the table, but I'd like to confirm that, or, does Apex provide a checkbox that I can check that will produce the same results? Thanks in advance guys, and sorry for all the questions. We've been tasked to use Apex for our next project and to learn it by using it, since the training budget is non-existant this year. I love unfunded mandates ;)
    Phil
    Edited by: Phil McDermott on Aug 13, 2009 9:34 AM

    Hi Phil,
    Javascript is useful, as is the column break functionality within Report Attributes (which would be my first choice if poss).
    If you need to go past 3 columns, I would suggest doing something in the SQL statement itself. This will mean that the sorting would probably having to be controlled, but it is doable.
    Here's a fairly old thread on the subject: Re: Grouping on reports (not interactive) - with an example here: [http://htmldb.oracle.com/pls/otn/f?p=33642:112] (I've even used a custom template for the report, but you don't need to go that far!)
    This uses the LAG functionality within SQL to compare the values on one row to the values on the preceeding row - being able to compare these values allows you to determine which ones to display or hide.
    Andy

  • Update purchase register query

    Hi All,
    I want Updation in Following query, My client want item name and Quantity also in this.
    SELECT  M.DocNum AS 'AP Inv. #', M.DocDate as 'Date', M.CardName as 'Vendor Name',M.NumAtCard as 'Vendor Ref',
    (Select Sum(LineTotal) FROM PCH1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-90 and DocEntry=M.DocEntry) as 'ED (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-90 and DocEntry=M.DocEntry) as 'ED (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-60 and DocEntry=M.DocEntry) as 'ECess (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-60 and DocEntry=M.DocEntry) as 'EDCS (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-55 and DocEntry=M.DocEntry) as 'Hcess (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-55 and DocEntry=M.DocEntry) as 'HECS (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=1 and DocEntry=M.DocEntry) as 'VAT (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=1 and DocEntry=M.DocEntry) as ' VAT (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=4 and DocEntry=M.DocEntry) as 'CST (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=4 and DocEntry=M.DocEntry) as ' CST (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-40 and DocEntry=M.DocEntry) as 'CVD (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-40 and DocEntry=M.DocEntry) as ' CVD (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=5 and DocEntry=M.DocEntry) as 'SERVICE (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=5 and DocEntry=M.DocEntry) as ' Ser.Tax (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=6 and DocEntry=M.DocEntry) as 'Cess_sertax (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=6 and DocEntry=M.DocEntry) as 'CS on Ser.Tax (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-10 and DocEntry=M.DocEntry) as 'Hcess_st (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-10 and DocEntry=M.DocEntry) as 'HECS_ST (Rs.)',
    (Select Sum(LineTotal) From PCH3 Q Where Q.DocEntry=M.DocEntry) AS 'Freight (Rs.)',
    M.WTSum AS 'TDS (Rs.)',
    M.DocTotal as 'Total (Rs.)'
    FROM OPCH M LEFT OUTER JOIN PCH1 L on L.DocEntry=M.DocEntry
    LEFT OUTER JOIN PCH4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum
    LEFT OUTER JOIN PCH5 J ON M.DocEntry = J.AbsEntry
    LEFT OUTER JOIN PCH3 Q ON M.DocEntry = Q.DocEntry
    WHERE (M.DocDate >= '[%0]' AND M.DocDate <= '[%1]')
    GROUP BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.[DiscSum],M.WTSum,M.DocTotal
    ORDER BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.[DiscSum],M.WTSum,M.DocTotal
    Thanks
    Deepak Tyagi

    Dear Thanga ,
    I am posting Again my Query and modify this with item name and quantity. This query is working well at my system..
    SELECT  M.DocNum AS 'AP Inv. #', M.DocDate as 'Date', M.CardName as 'Vendor Name',M.NumAtCard as 'Vendor Ref',
    (Select Sum(Quantity) FROM PCH1 L Where L.DocEntry=M.DocEntry) as 'TotQty',
    (Select Sum(LineTotal) FROM PCH1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-90 and DocEntry=M.DocEntry) as 'ED (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-90 and DocEntry=M.DocEntry) as 'ED (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-60 and DocEntry=M.DocEntry) as 'ECess (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-60 and DocEntry=M.DocEntry) as 'EDCS (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-55 and DocEntry=M.DocEntry) as 'Hcess (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-55 and DocEntry=M.DocEntry) as 'HECS (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=1 and DocEntry=M.DocEntry) as 'VAT (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=1 and DocEntry=M.DocEntry) as ' VAT (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=4 and DocEntry=M.DocEntry) as 'CST (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=4 and DocEntry=M.DocEntry) as ' CST (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-40 and DocEntry=M.DocEntry) as 'CVD (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-40 and DocEntry=M.DocEntry) as ' CVD (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=5 and DocEntry=M.DocEntry) as 'SERVICE (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=5 and DocEntry=M.DocEntry) as ' Ser.Tax (Rs.) ',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=6 and DocEntry=M.DocEntry) as 'Cess_sertax (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=6 and DocEntry=M.DocEntry) as 'CS on Ser.Tax (Rs.)',
    (SELECT distinct (TaxRate) FROM PCH4 where statype=-10 and DocEntry=M.DocEntry) as 'Hcess_st (Rate)',
    (SELECT Sum(TaxSum) FROM PCH4 where statype=-10 and DocEntry=M.DocEntry) as 'HECS_ST (Rs.)',
    (Select Sum(LineTotal) From PCH3 Q Where Q.DocEntry=M.DocEntry) AS 'Freight (Rs.)',
    M.WTSum AS 'TDS (Rs.)',
    M.DocTotal as 'Total (Rs.)'
    FROM OPCH M LEFT OUTER JOIN PCH1 L on L.DocEntry=M.DocEntry
    LEFT OUTER JOIN PCH4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum
    LEFT OUTER JOIN PCH5 J ON M.DocEntry = J.AbsEntry
    LEFT OUTER JOIN PCH3 Q ON M.DocEntry = Q.DocEntry
    WHERE (M.DocDate >= '[%0]' AND M.DocDate <= '[%1]')
    GROUP BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.[DiscSum],M.WTSum,M.DocTotal
    ORDER BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.[DiscSum],M.WTSum,M.DocTotal
    Thanks & Regards
    Deepak Tyagi

  • Query For OutGoing Excise Invoice

    Hi Experts,
    I need to run areport for  OutGoingExcise Invoice.
    So pls give me a query to capture all the taxes related to that invoices like BED,EDCess,HECess. and VAT.
    Thanx in Advance,
    Regards,
    Vamsi.

    Hi Guys...
    Below is the query i used to run the report for OutGoing Excise Invoice.
    I need some modifications in this query.
    We are having two branches Branch1 and Branch2.
    While running the query we need to pay Excise duty for both the branches seperately,So i need to run a report for branchwise.
    So pls give me some solution.
    SELECT M.DocNum AS 'INV No. #', M.DocDate as 'Date', M.CardName as 'Customer Name',
    (Select Sum(LineTotal) FROM OEI1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)',
    (SELECT Avg(TaxRate) FROM OEI4 where statype=-90 and DocEntry=M.DocEntry) as 'ED %',
           (SELECT Sum(TaxSum) FROM OEI4 where statype=-90 and DocEntry=M.DocEntry) as 'ED (Rs.)',
    (SELECT Avg(TaxRate) FROM OEI4 where statype=-60 and DocEntry=M.DocEntry) as 'EDCS %',
           (SELECT Sum(TaxSum) FROM OEI4 where statype=-60 and DocEntry=M.DocEntry) as 'EDCS (Rs.)',
    (SELECT Avg(TaxRate) FROM OEI4 where statype=-55 and DocEntry=M.DocEntry) as 'HECS %',
           (SELECT Sum(TaxSum) FROM OEI4 where statype=-55 and DocEntry=M.DocEntry) as 'HECS (Rs.)',
    M.WTSum AS 'TDS (Rs.)',
    M.DocTotal as 'Total (Rs.)'
    FROM OOEI M LEFT OUTER JOIN OEI1 L on L.DocEntry=M.DocEntry
    LEFT OUTER JOIN OEI4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum
    LEFT OUTER JOIN OEI5 J ON M.DocEntry = J.AbsEntry
    LEFT OUTER JOIN OEI3 Q ON M.DocEntry = Q.DocEntry
    WHERE (M.DocDate >= '[%0]' AND M.DocDate <= '[%1]')  AND
    GROUP BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,M.DocTotal
    ORDER BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,M.DocTotal
    Regards,
    Vamsi.

  • Error while executing query in wizard

    Hi,
    When I run the following query in SAP's Query Generator , I get the error 'Invalid column name 'GS09'
    select DocNum,convert(varchar,T0.docdate,103) PostingDate, T1.seriesname, isnull(numatcard,'') 'Vendor Ref', CardName, sum(quantity) Qty, sum(p1.linetotal) Row_Total,  Discsum Discount, T0.Vatsum Tax, sum(isnull(p3.totalsumsy,00)) Freight , sum(isnull(p5.WTAmnt,0)) 'TDS Total',
    T0.doctotalsy - T0.paidsys 'Net Amount' from opch T0 inner join pch1 p1 on T0.docentry = p1.docentry
    left outer join pch3 p3 on T0.docentry = p3.docentry
    left outer join pch5 p5 on T0.docentry = p5.Absentry
    inner join nnm1 T1 on T0.series = T1.series and T1.objectcode = 18
    where T1.seriesname = case when len([%0]) > 0 then [%0] else T1.seriesname end and T0.docdate >= case  when  len([%1]) > 0 then  [%1]  else  T0.docdate end and T0.docdate <= case  when  len([%2]) > 0 then  [%2]  else  T0.docdate end 
    group by docnum, numatcard, cardname, T0.docdate, Discsum,T0.Vatsum,T1.seriesname, T0.doctotalsy - T0.paidsys
    I am passing 'GS09' as my series parameter. when i remove the condition
    T1.seriesname = case when len([%0]) > 0 then [%0] else T1.seriesname end
    it works fine. 
    anything wrong with this particular line? I am working on PL 44, 2005 B version.
    regards,
    Binita

    Thanks for replying Vijay,
    I have tried as you said but in my case, it does not give the parameter at all for seriesname to enter! if I change the code
    ('%2')
    to
    [%2]
    then only it shows me it. I am re-writing my query:
    select DocNum,convert(varchar,T0.docdate,103) PostingDate, T1.seriesname, isnull(numatcard,'') 'Vendor Ref', CardName, sum(quantity) Qty, sum(p1.linetotal) Row_Total,  Discsum Discount, T0.Vatsum Tax, sum(isnull(p3.totalsumsy,00)) Freight , sum(isnull(p5.WTAmnt,0)) 'TDS Total',
    T0.doctotalsy - T0.paidsys 'Net Amount' from opch T0 inner join pch1 p1 on T0.docentry = p1.docentry
    left outer join pch3 p3 on T0.docentry = p3.docentry
    left outer join pch5 p5 on T0.docentry = p5.Absentry
    inner join nnm1 T1 on T0.series = T1.series and T1.objectcode = 18
    where T0.docdate >= case when len([%0]) > 0 then [%0] else T0.docdate end  and T0.docdate <= case when len([%1]) > 0 then [%1] else T0.docdate end 
    and T1.seriesname = case when len('%2') > 0 then '%2' else T1.seriesname end
    group by docnum, numatcard, cardname, T0.docdate, Discsum,T0.Vatsum,T1.seriesname, T0.doctotalsy - T0.paidsys
    thanks,
    Binita

  • Error while posting TDS through J1INC

    Hi,
         My client is posting TDS with TCode: J1INC and while executing error message ," FI/CO interface: Inconsistent FI/CO line item data for updating" is displayed. Message No is RW016. I have checked all the configurations for Tax codes and its fine. The error is applicable to one particular document no. This document is normal IV document with a PO.
    Please help in this regards

    Hi Friend,
    Youhave to enter for third time for your reference site say for example RFST and again third time i have to enter the RP.
    Idealy you should first maintain for reference site initially.
    eample I am maintaining MM41 for my store (site) so first at DC level and then at store level and then again when I accept to save the article at refercne Store level I have feed in the RP type.
    Hope this solves you query.
    Regards,
    Ashutosh

  • Problem in Sales Order Query

    Hi All,
    I have problem....This is query which ic combination of Sales Order, Return, Delivery and AR Invoice.....Please tell me why this query is not working ......I want Document No, Quantity, Doc Date from Sales Order, Return, Delivery and AR Invoice and Tax bifergation also.....I per my view this query there should not be any problem but it is not working...please tell me where I am wrong....Just copy and paste this query and check in ur system.......
    SELECT b.Doc_Num1 as 'SO. No.',
    b.DocDate    as      'SO. Date',
    b.Doc_Num2   AS      'Del.Doc.No.',
    b.DocDate    AS      'Delivery Date',
    b.Doc_Num3   as      'A/R Invoice No.',
    b.DocDate    as      'Inv. Date',
    b.Doc_Num4   AS      'RETURN Doc.No.',
    b.DocDate    as      'Ret.Date',
    b.CardName   as      'Vendor Name',
    b.NumAtCard  as      'Bill No. & Date',
    b.ItemCode   as      'Item Code',
    b.Dscription as      'Dscription',
    b.Quantity1  as      'AR Invoice Quantity',
    b.Quantity2  as      'Sales Order Quantity',
    b.Quantity3  as      'Delivery Quantity',
    b.Quantity4  as      'Return Quantity',
    b.LineTotal  as      'Base Amt.(Rs.)',
    b.WTSum           AS      'TDS (Rs.)',
    b.DocTotal    as     'Total (Rs.)',
    sum(b.BED)    as           'Bed Value',
    sum(b.EDCS)   as          'EDCS Value',
    sum(b.HECS)   as          'HECS Value',
    sum(b.VAT)        as           'VAT Value',
    sum(b.CST)        as           'CST Value',
    sum(b.CVD)        as           'CVD Value',
    sum(b.SerTax)  as           'SERTAX Value',
    sum(b.CSonSerTax) as      'CS Value',
    sum(b.HECS_ST)      as      'HESC Value' 
    from (
    select *,( a.Bed + a.EDCS + a.HECS + a.VAT + a.CST +a.CVD + a.SerTax + a.CSonSerTax  + a.HECS_ST ) as Filter from (SELECT distinct
    T0.DocNum,
    T0.DocDate,
    T2.DocNum,
    T2.DocDate,
    M.DocNum,
    M.DocDate,
    M.CardName,
    M.NumAtCard,
    L.ItemCode,
    L.Dscription,
    L.Quantity,
    T1.Quantity,
    T3.Quantity,
    S.DocNum,
    S.DocDate,
    X.Quantity,
    L.LineTotal,
    M.DocEntry,
    M.[DiscSum],
    M.WTSum,
    M.DocTotal,
    M.WTSum,
    M.DocTotal,

    Hi Sonal,
    Try this,
    SELECT  T0.DocNum as 'SO. No.',
    T0.DocDate as 'SO. Date',
    T2.DocNum AS 'Del.Doc.No.',
    T2.DocDate AS 'Delivery Date',
    M.DocNum as 'A/R Invoice No.',
    M.DocDate as 'Inv. Date',
    T4.DocNum AS 'Return No.',
    T4.DocDate AS 'Return Date',
    M.CardName as 'Vendor Name',
    M.NumAtCard as 'Bill No. & Date',
    ISNULL(L.ItemCode,'Service Item') as 'Item Code',
    L.Dscription,
    L.Quantity,
    (Select Sum(LineTotal) FROM INV1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)',
    (SELECT Sum(TaxSum) FROM INV4 where statype=-90 and DocEntry=M.DocEntry) as 'ED (Rs.)',
    (SELECT Sum(TaxSum) FROM INV4 where statype=-60 and DocEntry=M.DocEntry) as 'EDCS (Rs.)',
    (SELECT Sum(TaxSum) FROM INV4 where statype=7 and DocEntry=M.DocEntry) as 'HECS (Rs.)',
    (SELECT Sum(TaxSum) FROM INV4 where statype=1 and DocEntry=M.DocEntry) as ' VAT (Rs.) ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=4 and DocEntry=M.DocEntry) as ' CST (Rs.) ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=10 and DocEntry=M.DocEntry) as ' CVD (Rs.) ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=5 and DocEntry=M.DocEntry) as ' Ser.Tax (Rs.) ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=6 and DocEntry=M.DocEntry) as 'CS on Ser.Tax (Rs.)',
    (SELECT Sum(TaxSum) FROM INV4 where statype=8 and DocEntry=M.DocEntry) as 'HECS_ST (Rs.)',
    (Select Sum(LineTotal) From INV3 Q Where Q.DocEntry=M.DocEntry) AS 'Freight (Rs.)',
    M.WTSum AS 'TDS (Rs.)',
    M.DocTotal as 'Total (Rs.)'
    FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN ODLN T2 ON T2.DocEntry = T1.TrgetEntry
    INNER JOIN DLN1 T3 on T3.DocEntry = T2.Docentry
    INNER JOIN OINV M ON M.DocEntry = T3.TrgetEntry
    LEFT OUTER JOIN INV1 L on L.DocEntry=M.DocEntry
    LEFT JOIN ORDN T4 ON T4.DocEntry = L.TrgetEntry
    LEFT JOIN RDN1 T5 ON T5.DocEntry = T4.DocEntry
    LEFT OUTER JOIN INV4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum
    LEFT OUTER JOIN INV5 J ON M.DocEntry = J.AbsEntry
    LEFT OUTER JOIN INV3 Q ON M.DocEntry = Q.DocEntry
    WHERE M.DocDate >= '[%0]' AND M.DocDate <= '[%1]'
    GROUP BY
    T0.DocNum,T0.DocDate,T2.DocNum,T2.DocDate, M.DocNum,M.DocDate,T4.DocNum, T4.DocDate, M.CardName,M.NumAtCard,L.ItemCode,L.Dscription,L.Quantity,
    M.DocEntry,M.[DiscSum],M.WTSum,M.DocTotal
    ORDER BY
    T0.DocNum,T0.DocDate,T2.DocNum,T2.DocDate, M.DocNum,M.DocDate,T4.DocNum,T4.DocDate, M.CardName,M.NumAtCard,L.ItemCode,L.Dscription,L.Quantity,
    M.DocEntry,M.[DiscSum],M.WTSum,M.DocTotal
    Regards,
    Madhan.

  • Select query taking long time (more then 6 min)

    Dear experts,
    DATA:IT_CHEQ2 TYPE TABLE OF TY_BSAS,
         WA_CHEQ2 LIKE LINE OF IT_CHEQ2.
    DATA : IT_CHEQ3 TYPE STANDARD TABLE OF TY_BSAS WITH HEADER LINE.
    TYPES:BEGIN OF TY_BSAS,
           BUKRS TYPE BSAS-BUKRS,
           HKONT TYPE BSAS-HKONT,
           AUGDT TYPE BSAS-AUGDT,
           AUGBL TYPE BSAK-AUGBL,
           ZUONR TYPE BSAK-ZUONR,
           GJAHR TYPE BSAK-GJAHR,
           BELNR TYPE BSAK-BELNR,
           BUZEI TYPE BSAK-BUZEI,
           BUDAT TYPE BSAK-BUDAT,
           XBLNR TYPE BSAK-XBLNR,
           BLART TYPE BSAK-BLART,
           SHKZG TYPE BSAK-SHKZG,
           DMBTR TYPE BSAK-DMBTR,
           WMWST TYPE BSAK-WMWST,
          AUGGJ TYPE BSAK-AUGGJ, " CLEARING FYSICAL YEAR
           OT_TAX TYPE BSAK-DMBTR,
           TDS   TYPE BSAK-DMBTR,
           VAT    TYPE BSAK-DMBTR, "Vat amount
           WCT   TYPE BSAK-DMBTR,
           ADV    TYPE BSAK-DMBTR,  "Advance
           CHAMT TYPE BSAK-DMBTR,
           CHNO  TYPE PAYR-CHECT,
           CHDATE TYPE PAYR-ZALDT,
           DBIT_NOTE TYPE BSAK-DMBTR,
           PAY_ADJ   TYPE BSAK-DMBTR,
           PEND_SES TYPE BSAK-DMBTR, "PENDING SES
           CR_PARTY(50)  TYPE C,
          END OF TY_BSAS.
    SELECT BUKRS HKONT AUGDT AUGBL ZUONR GJAHR BELNR BUZEI BUDAT XBLNR BLART SHKZG
                      DMBTR WMWST
                      FROM BSAS INTO " APPENDING
               CORRESPONDING FIELDS OF TABLE IT_CHEQ3
                      FOR ALL ENTRIES IN IT_CHEQ2
                      WHERE AUGBL = IT_CHEQ2-AUGBL and
                        BUKRS = IT_CHEQ2-BUKRS   AND
    *                  AUGBL = IT_CHEQ2-AUGBL
                          GJAHR = IT_CHEQ2-GJAHR
                      AND  XBLNR = IT_CHEQ2-XBLNR.
    line company code  hkont       augdt               augbl               zuonr              gjahr        belnr                 buzei  budat
    1     1018     0012100030     20110831     2100009710     20110831     2011     2100009710     005     20110831
    xblnr       blart        shkzg
    RA03     KZ         H            37067.00         0.00     2011     0.00     0.00
    2     1018     0012100030     20110831     2100009710     20110831     2011     2100009710     006     20110831
         RA03     KZ     H     393850.00     0.00     2011     0.00     0.00
    3     1018     0012100030     20110831     2100009710     20110831     2011     2100009710     004     20110831     RA03     KZ     S     723589.13     0.00     2011     0.00     0.00
    4     1018     0012100030     20110831     2100009710     20110823     2011     3900001250     001     20110823     RA03     RS     H     712921.13     0.00     2011     0.00     0.00
    5     1018     0023200000     20110831     2100009710     20110831     2011     2100009710     008     20110831     RA03     KZ     H     21788.00     0.00     2011     0.00     0.00
    6     1018     0023200000     20110831     2100009710     20110831     2011     2100009710     007     20110831     RA03     KZ     H     1162821.00     0.00     2011     0.00     0.00
    if i put same entry in se11 for bsas it takes 7 second
    and in query takes  more then 6 min ,kindly tell why
    help me gurus
    regards
    victor

    Tested point 2.
    There is no difference.
    REPORT  Z_YZ_SELECT_ORDER.
    types: begin of t_orderadm,
             description type CRMT_PROCESS_DESCRIPTION,
             created_at type COMT_CREATED_AT_USR,
             LOGICAL_SYSTEM type CRMT_LOGSYS,
             TEMPLATE_TYPE type CRMT_TEMPLATE_TYPE_DB,
             VERIFY_DATE type CRMT_VERIFY_DATE,
             GUID type CRMT_OBJECT_GUID,
           end of t_orderadm.
    types: begin of t_orderadm_1,
             GUID type CRMT_OBJECT_GUID,
             description type CRMT_PROCESS_DESCRIPTION,
             LOGICAL_SYSTEM type CRMT_LOGSYS,
             TEMPLATE_TYPE type CRMT_TEMPLATE_TYPE_DB,
             created_at type COMT_CREATED_AT_USR,
             VERIFY_DATE type CRMT_VERIFY_DATE,
           end of t_orderadm_1.
    data: lt_orders type table of t_orderadm,
          lt_orders_1 type table of t_orderadm_1.
    select description created_at logical_system template_type verify_date guid
      into table lt_orders
      from crmd_orderadm_h.
    select guid description logical_system template_type created_at verify_date
      into table lt_orders_1
      from crmd_orderadm_h.
    write 'done'.
    First select - mixed order of fields. Response time: 82.155 microseconds for 39380 records selected.
    Second select - fields in the order of the table. Response time: 81.061 microseconds for the same 39380 records selected.
    Then I changed the order of SELECT statements. I have put first the select with ordered fields, and second - select with mixed order of fields. The runtimes were the following:
    Ordered fields - 82.649 microseconds
    Mixed order of fields - 80.270 microseconds.
    So I'm going to change the Wiki page in order to avoid  in future advices that make no sense.

  • Tds details of vendor coming but not business area.

    Hi Experts,
    I am making a report to display vendor data with its TDS details in accounting documents.
    I am getting all the data from other tables rather 1 table BSEG, which is a cluster table. I need to retrieve business are from BSEG i.e. (BSEG-GSBER).
    I am using another select query for this, but when i put debugger at loop of business are, it is showing the data, but in alv display it is not showing business area.
    Hence i need your help on that.
    Please go through the program code given below.
    Thanks,
    Deepanshu Mathur
    TABLES: BSEG,BKPF,WITH_ITEM,T059Z,T059ZT,LFA1.
    DATA: BEGIN OF ITAB OCCURS 0,
            BELNR LIKE BKPF-BELNR,                    " Accounting Document Number
            GJAHR LIKE BKPF-GJAHR,                    " Fiscal Year
            BUKRS LIKE BKPF-BUKRS,                    " Company Code
            BLDAT LIKE BKPF-BLDAT,                    " Document Date in Document
            BUDAT LIKE BKPF-BUDAT,                    " Posting Date in the Document
            LIFNR LIKE BSEG-LIFNR,                    " Account Number of Vendor or Creditor
            GSBER LIKE BSEG-GSBER,                    " Business Area
            WT_QSSHH LIKE WITH_ITEM-WT_QSSHH,         " Withholding tax base amount (local currency)
            WT_QBSHH LIKE WITH_ITEM-WT_QBSHH,         " Withholding tax amount (in local currency)
            WITHT LIKE WITH_ITEM-WITHT,               " Indicator for withholding tax type
            WT_WITHCD LIKE WITH_ITEM-WT_WITHCD,       " Withholding tax code
            QSCOD LIKE T059Z-QSCOD,                   " Official Withholding Tax Key
            QSATZ LIKE T059Z-QSATZ,                   " Withholding tax rate
            NAME1 LIKE LFA1-NAME1,                    " vendor name
            LAND1 LIKE LFA1-LAND1,                    " Country Key
            TEXT40 LIKE T059ZT-TEXT40,                " Text, 40 Characters Long
            WAERS LIKE BKPF-WAERS,                    " Currency
            WT_ACCO LIKE WITH_ITEM-WT_ACCO,
          END OF ITAB.
    DATA: BEGIN OF LT_BSEG OCCURS 0,
            BELNR LIKE BSEG-BELNR,                    " Accounting Document Number
            GJAHR LIKE BSEG-GJAHR,                    " Fiscal Year
            BUKRS LIKE BSEG-BUKRS,                    " Company Code
            LIFNR LIKE BSEG-LIFNR,                    " Account Number of Vendor or Creditor
            GSBER LIKE BSEG-GSBER,                    " Business Area
          END OF LT_BSEG.
    SELECTION-SCREEN: BEGIN OF BLOCK FRAME WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: COCO FOR BKPF-BUKRS,
                    DOC_DATE FOR BKPF-BLDAT,
                    POST_DAT FOR BKPF-BUDAT,
                    FIS_YEAR FOR BKPF-GJAHR.
    SELECTION-SCREEN: END OF BLOCK FRAME.
    TYPE-POOLS:slis.
    DATA: body        TYPE slis_t_fieldcat_alv,
          header      TYPE slis_fieldcat_alv,
          gd_layout   TYPE slis_layout_alv,
          gd_repid    LIKE sy-repid.
    START-OF-SELECTION.
      PERFORM FETCH.
    END-OF-SELECTION.
    *&      Form  FETCH
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM FETCH .
    SELECT
      BKPF~BELNR BKPF~GJAHR BKPF~BUKRS BKPF~BLDAT BKPF~BUDAT BKPF~WAERS
      WITH_ITEM~BELNR WITH_ITEM~GJAHR WITH_ITEM~BUKRS WITH_ITEM~WT_QSSHH WITH_ITEM~WT_QBSHH WITH_ITEM~WITHT
      WITH_ITEM~WT_WITHCD WITH_ITEM~WT_ACCO
      LFA1~LIFNR LFA1~NAME1 LFA1~LAND1
      T059Z~WITHT T059Z~WT_WITHCD T059Z~QSCOD T059Z~QSATZ
      T059ZT~WITHT T059ZT~TEXT40 T059ZT~WT_WITHCD
      INTO CORRESPONDING FIELDS OF TABLE ITAB FROM BKPF
      JOIN WITH_ITEM ON WITH_ITEM~BELNR = BKPF~BELNR AND
                        WITH_ITEM~GJAHR = BKPF~GJAHR AND
                        WITH_ITEM~BUKRS = BKPF~BUKRS AND
                        WITH_ITEM~WT_QSSHH NE ' ' AND WITH_ITEM~WT_QBSHH NE ' '
      JOIN LFA1 ON LFA1~LIFNR = WITH_ITEM~WT_ACCO
      JOIN T059Z ON T059Z~WITHT = WITH_ITEM~WITHT AND T059Z~WT_WITHCD = WITH_ITEM~WT_WITHCD
      JOIN T059ZT ON T059ZT~WITHT = WITH_ITEM~WITHT AND T059ZT~WT_WITHCD = WITH_ITEM~WT_WITHCD
      WHERE
            BKPF~BUKRS IN COCO AND
            BKPF~BLDAT IN DOC_DATE AND
            BKPF~BUDAT IN POST_DAT AND
            BKPF~GJAHR IN FIS_YEAR.
    SELECT
      BELNR GJAHR BUKRS LIFNR GSBER
      FROM BSEG
      INTO CORRESPONDING FIELDS OF TABLE LT_BSEG
      FOR ALL ENTRIES IN ITAB
      WHERE BELNR = ITAB-BELNR AND GJAHR = ITAB-GJAHR AND BUKRS = ITAB-BUKRS AND LIFNR NE ' ' .
    IF SY-SUBRC EQ 0.
    SORT ITAB BY BLDAT BELNR.
    LOOP AT LT_BSEG WHERE BELNR = ITAB-BELNR AND GJAHR = ITAB-GJAHR AND BUKRS = ITAB-BUKRS AND LIFNR NE ' '.
    IF ( LT_BSEG-BELNR = ITAB-BELNR AND LT_BSEG-GJAHR = ITAB-GJAHR AND LT_BSEG-BUKRS = ITAB-BUKRS AND
         LT_BSEG-LIFNR NE ' ').
        MOVE LT_BSEG-GSBER TO ITAB-GSBER.
    ENDIF.
    APPEND ITAB.
    ENDLOOP.
      PERFORM BUILD_LAYOUT.
      PERFORM FIELDCATALOG.
      PERFORM ALVDISPLAY.
    ELSE.
      MESSAGE 'DATA NOT FOUND !' TYPE 'I'.
    ENDIF.
    ENDFORM.
    *&      Form  BUILD_LAYOUT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM BUILD_LAYOUT .
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-info_fieldname = 'WS_COLOR'.
      gd_LAYOUT-coltab_fieldname = 'CELL_COLOR'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  FIELDCATALOG
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM FIELDCATALOG .
      header-col_pos = '1'.
      header-tabname = 'ITAB'.
      header-fieldname = 'BLDAT'.
      header-seltext_l = 'Doc. Date'.
      header-just = 'C'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '2'.
      header-tabname = 'ITAB'.
      header-fieldname = 'BUDAT'.
      header-seltext_l = 'Posting Date'.
      header-just = 'C'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '3'.
      header-tabname = 'ITAB'.
      header-fieldname = 'GJAHR'.
      header-seltext_l = 'Fiscal Year'.
      header-just = 'C'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '4'.
      header-tabname = 'ITAB'.
      header-fieldname = 'BUKRS'.
      header-seltext_l = 'Company Code'.
      header-just = 'C'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '5'.
      header-tabname = 'ITAB'.
      header-fieldname = 'GSBER'.
      header-ref_tabname = 'BSEG'.
      header-ref_fieldname = 'GSBER'.
      header-just = 'L'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '6'.
      header-tabname = 'ITAB'.
      header-fieldname = 'BELNR'.
      header-seltext_l = 'Doc. No.'.
      header-ref_tabname = 'WITH_ITEM'.
      header-ref_fieldname = 'BELNR'.
      header-just = 'L'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '7'.
      header-tabname = 'ITAB'.
      header-fieldname = 'LIFNR'.
      header-seltext_l = 'Vendor'.
      header-ref_tabname = 'LFA1'.
      header-ref_fieldname = 'LIFNR'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '8'.
      header-tabname = 'ITAB'.
      header-fieldname = 'NAME1'.
      header-seltext_l = 'Vendor Name'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '9'.
      header-tabname = 'ITAB'.
      header-fieldname = 'LAND1'.
      header-seltext_l = 'Country'.
      header-ref_tabname = 'LFA1'.
      header-ref_fieldname = 'LAND1'.
      header-just = 'C'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '10'.
      header-tabname = 'ITAB'.
      header-fieldname = 'WITHT'.
      header-seltext_l = 'Withholding Tax Type'.
      header-ref_tabname = 'WITH_ITEM'.
      header-ref_fieldname = 'WITHT'.
      header-just = 'L'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '11'.
      header-tabname = 'ITAB'.
      header-fieldname = 'WT_WITHCD'.
      header-seltext_l = 'Withholding Tax Code'.
      header-ref_tabname = 'WITH_ITEM'.
      header-ref_fieldname = 'WT_WITHCD'.
      header-just = 'L'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '12'.
      header-tabname = 'ITAB'.
      header-fieldname = 'QSCOD'.
      header-seltext_l = 'Tax Key'.
      header-ref_tabname = 'T059Z'.
      header-ref_fieldname = 'QSCOD'.
      header-just = 'L'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '13'.
      header-tabname = 'ITAB'.
      header-fieldname = 'TEXT40'.
      header-seltext_l = 'Section Code'.
      header-ref_tabname = 'T059ZT'.
      header-ref_fieldname = 'TEXT40'.
      header-just = 'L'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '14'.
      header-tabname = 'ITAB'.
      header-fieldname = 'WAERS'.
      header-seltext_l = 'Currency'.
      header-just = 'C'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '15'.
      header-tabname = 'ITAB'.
      header-fieldname = 'WT_QSSHH'.
      header-seltext_l = 'TDS Base Amount'.
      header-ref_tabname = 'WITH_ITEM'.
      header-ref_fieldname = 'WT_QSSHH'.
      header-do_sum = 'X'.
      header-just = 'R'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '16'.
      header-tabname = 'ITAB'.
      header-fieldname = 'QSATZ'.
      header-seltext_l = 'TDS Tax Rate'.
      header-just = 'R'.
      APPEND header TO body.
      CLEAR header.
      header-col_pos = '17'.
      header-tabname = 'ITAB'.
      header-fieldname = 'WT_QBSHH'.
      header-seltext_l = 'TDS Amount'.
      header-ref_tabname = 'WITH_ITEM'.
      header-ref_fieldname = 'WT_QBSHH'.
      header-do_sum = 'X'.
      header-just = 'R'.
      APPEND header TO body.
      CLEAR header.
    ENDFORM.                    " FIELDCATALOG
    *&      Form  ALVDISPLAY
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM ALVDISPLAY .
    gd_repid = sy-repid.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       i_callback_program      = gd_repid
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
       IS_LAYOUT                         = gd_layout
       IT_FIELDCAT                       = body
      TABLES
        T_OUTTAB                          = ITAB
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.                    " ALVDISPLAY
    Form TOP_OF_PAGE.
    *ALV Header declarations
      data: t_header type slis_t_listheader,
            wa_header type slis_listheader,
            t_line like wa_header-info,
            ld_lines type i,
            ld_linesc(10) type c.
    * Title
      wa_header-typ  = 'H'.     " H = Header
      wa_header-info = 'TDS Report'.
      append wa_header to t_header.
      clear wa_header.
    * Date
      wa_header-typ  = 'S'.     " S = Selection
      wa_header-key = 'Date: '.
      CONCATENATE  sy-datum+6(2) '.'
                   sy-datum+4(2) '.'
                   sy-datum(4) INTO wa_header-info.   "todays date
      append wa_header to t_header.
      clear: wa_header.
    * Total No. of Records Selected
      describe table ITAB lines ld_lines.
      ld_linesc = ld_lines.
      concatenate 'Total No. of Records Selected: ' ld_linesc
                        into t_line separated by space.
      wa_header-typ  = 'A'.     " A = Action
      wa_header-info = t_line.
      append wa_header to t_header.
      clear: wa_header, t_line.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = t_header.
    *            i_logo             = 'Z_LOGO'.
    endform.                    "top-of-page

    Hi,
    Try Below code.
    1) your code is very bad I am not sure whether it will work or not because it has inner join queries on many tables.
    2) I made certain changes, please check the data selection part as below
    SELECT bkpf~belnr bkpf~gjahr bkpf~bukrs bkpf~bldat bkpf~budat bkpf~waers with_item~belnr
        with_item~gjahr with_item~bukrs with_item~wt_qsshh
      with_item~wt_qbshh with_item~witht with_item~wt_withcd with_item~wt_acco lfa1~lifnr
         lfa1~name1 lfa1~land1 t059z~witht t059z~wt_withcd t059z~qscod
         t059z~qsatz t059zt~witht t059zt~text40 t059zt~wt_withcd
        INTO CORRESPONDING FIELDS OF TABLE itab
         FROM bkpf
      INNER JOIN with_item ON with_item~belnr = bkpf~belnr AND with_item~gjahr = bkpf~gjahr
        AND with_item~bukrs = bkpf~bukrs AND with_item~wt_qsshh NE ' '
        AND with_item~wt_qbshh NE ' '
        INNER JOIN lfa1 ON lfa1~lifnr = with_item~wt_acco
        INNER JOIN t059z ON t059z~witht =
      with_item~witht AND t059z~wt_withcd = with_item~wt_withcd
        INNER JOIN t059zt ON t059zt~witht = with_item~witht AND t059zt~wt_withcd = with_item~wt_withcd
        WHERE bkpf~bukrs IN coco AND bkpf~bldat IN doc_date
        AND bkpf~budat IN post_dat AND bkpf~gjahr IN fis_year.
      IF itab[] IS NOT INITIAL.
        SELECT belnr gjahr bukrs lifnr gsber FROM bseg
          INTO CORRESPONDING FIELDS OF TABLE lt_bseg
          FOR ALL ENTRIES IN itab
          WHERE belnr = itab-belnr
          AND gjahr = itab-gjahr AND bukrs = itab-bukrs
          AND lifnr NE ' ' .
        IF sy-subrc EQ 0.
          SORT itab BY bldat belnr.
    *    LOOP AT lt_bseg WHERE belnr = itab-belnr AND
    *      gjahr = itab-gjahr AND bukrs = itab-bukrs AND lifnr NE ' '.
    *      IF ( lt_bseg-belnr = itab-belnr AND lt_bseg-gjahr = itab-gjahr
    *        AND lt_bseg-bukrs = itab-bukrs AND lt_bseg-lifnr NE ' ').
    *        MOVE lt_bseg-gsber TO itab-gsber.
    *      ENDIF.
    *      APPEND itab.
    *    ENDLOOP.
          LOOP AT itab.
            READ TABLE lt_bseg
            WITH KEY belnr = itab-belnr
            gjahr = itab-gjahr
             bukrs = itab-bukrs.
            MOVE lt_bseg-gsber TO itab-gsber.
            MODIFY itab.
            CLEAR :lt_bseg,itab.
          ENDLOOP.
          PERFORM build_layout. PERFORM fieldcatalog. PERFORM alvdisplay.
        ELSE.
          MESSAGE 'DATA NOT FOUND !' TYPE 'I'.
        ENDIF.
      ENDIF.

Maybe you are looking for