Question

Issue with linking APInvDtl with TranGLC in a BAQ.

  • 6 January 2021
  • 9 replies
  • 674 views

Userlevel 1

I am trying to pull some data for accounting, and need to be able to have Invoice information for all of last year.    I have all the fields that are needed, except that I need the GL account each line of every invoice was charge to added.    I have read several other issues that have been posted around this type of issue and nothing I have seen there has helped.   I think I am close to having it, just not sure what I am doing wrong.    Here is what I have:

 

select 
    [APInvDtl].[InvoiceNum] as [APInvDtl_InvoiceNum],
    [APInvDtl].[InvoiceLine] as [APInvDtl_InvoiceLine],
    [APInvHed].[InvoiceDate] as [APInvHed_InvoiceDate],
    [APTran].[TranDate] as [APTran_TranDate],
    [CheckHed].[CheckNum] as [CheckHed_CheckNum],
    [Vendor].[Name] as [Vendor_Name],
    [Vendor].[VendorID] as [Vendor_VendorID],
    [APInvDtl].[PONum] as [APInvDtl_PONum],
    [APInvDtl].[OurQty] as [APInvDtl_OurQty],
    [APInvDtl].[PUM] as [APInvDtl_PUM],
    [APInvDtl].[UnitCost] as [APInvDtl_UnitCost],
    [APInvDtl].[ExtCost] as [APInvDtl_ExtCost],
    [PurTerms].[Description] as [PurTerms_Description],
    [APInvDtl].[Description] as [APInvDtl_Description],
    [TranGLC].[GLAccount] as [TranGLC_GLAccount],
    [APInvDtl].[PartNum] as [APInvDtl_PartNum],
    [Vendor].[TaxPayerID] as [Vendor_TaxPayerID],
    [APInvDtl].[POLine] as [APInvDtl_POLine],
    [APInvHed].[FiscalYear] as [APInvHed_FiscalYear],
    [APInvDtl].[PackSlip] as [APInvDtl_PackSlip],
    [APInvDtl].[PackLine] as [APInvDtl_PackLine],
    [RcvHead].[EntryPerson] as [RcvHead_EntryPerson],
    [RcvHead].[ReceiptDate] as [RcvHead_ReceiptDate],
    [APTran].[CheckNum] as [APTran_CheckNum]
from Erp.APInvDtl as APInvDtl
inner join Erp.APInvHed as APInvHed on 
    APInvDtl.Company = APInvHed.Company
    and APInvDtl.VendorNum = APInvHed.VendorNum
    and APInvDtl.InvoiceNum = APInvHed.InvoiceNum
    and ( APInvHed.FiscalYear = 2020  )

left outer join Erp.APTran as APTran on 
    APInvHed.Company = APTran.Company
    and APInvHed.VendorNum = APTran.VendorNum
    and APInvHed.InvoiceNum = APTran.InvoiceNum
inner join Erp.Vendor as Vendor on 
    APTran.Company = Vendor.Company
    and APTran.VendorNum = Vendor.VendorNum
inner join Erp.CheckHed as CheckHed on 
    APTran.Company = CheckHed.Company
    and APTran.HeadNum = CheckHed.HeadNum
    and APTran.CheckNum = CheckHed.CheckNum
inner join Erp.PurTerms as PurTerms on 
    APInvHed.Company = PurTerms.Company
    and APInvHed.TermsCode = PurTerms.TermsCode
left outer join Erp.RcvHead as RcvHead on 
    APInvDtl.Company = RcvHead.Company
    and APInvDtl.VendorNum = RcvHead.VendorNum
    and APInvDtl.PurPoint = RcvHead.PurPoint
    and APInvDtl.PackSlip = RcvHead.PackSlip
left outer join Erp.TranGLC as TranGLC on 
    APInvDtl.Company = TranGLC.Company
    and APInvDtl.VendorNum = TranGLC.Key1
    and APInvDtl.InvoiceNum = TranGLC.Key2
    and APInvDtl.InvoiceLine = TranGLC.Key3
    and ( TranGLC.RelatedToFile = 'APInvDtl'  )
order by Vendor.

 

 

Hopefully someone can see something and can tell me where I am going wrong on this.


9 replies

Userlevel 1

Hi Jenny,

I think your issue is the last join condition TranGLC.RelatedToFile = 'APInvDtl'. Looking at our DB, we don’t have any records with that condition. All I can find is APAlcDtl, ApInvExp, APInvHed, APInvTax and APLnTax. I would look at APTran also.

Dragos

Userlevel 1

I have a table called APInvDtl.    Not sure why you wouldn’t have that, just like you would have a table called APInvHed.     Header file and detail file for AP Invoices.

 

here is a screen shot showing the tables and the mapping of them.

As you can see Table 1 is APInvDtl.    that I am trying to link to TranGLC.   But not getting any errors, just no data from the TranGLC is being pulled in.

Userlevel 1

As it is AP, you need to look for “APInvExp”. 

Thierry

Userlevel 1

Hi Jenny,

Sorry, I meant there are no records in TranGLC table that meet the criteria TranGLC.RelatedToFile = 'APInvDtl'. We do have the APInvDtl table of course. Have a look at the other conditions like TranGLC.RelatedToFile = 'APInvExp' as @thierry.cools suggested.

Dragos

Userlevel 1

I have see a few people respond, I do appreciate that.  However, sounds like either I am way off, and have a table that no one else has or I am just missing something here totally.   I did find this fiel that was posted on a different issue but a lot like mine.   It shows the Key fields and what they map to, when linking the TranGLC to other tables.   I think I am doing what this shows, but might be a syntax issue or something.    Check his out:

TranGLC Keys and RelatedToFile

 

Userlevel 1

I have done a BAQ just using the TranGLC table and can see that the data needed is there.   From what I see also in the table I posted is that the APInvExp  Table is for Expensed Invoices,, invoices that are not for a purchased made on a PO.

Userlevel 1

Hi Jenny,

Assuming you want to try the ApInvExp, in your BAQ, change the criteria for TranGLC to TranGLC.RelatedToFile=’APInvExp’. Then, add the table APInvExp and link it to the APInvDtl. Finally, delete the link between TranGLC and APInvDtl and link TranGLC with APInvExp with the following conitions.

APInvExp.VendorNum = TranGLC.Key1
and APInvExp.InvoiceNum = TranGLC.Key2
and APInvExp.InvoiceLine = TranGLC.Key3

and APInvExp.InvExpSeq=TranGLC.Key4

 

Dragos

 

Userlevel 1

Okay, I have figured out that the information I was given was not correct and linking the APInvDtl table.

So have tried the use of the APInvExp table.     looks like it is working except every record is duplicated.

 

Hoping someone would look over what I have and point in the the right direct to correct this error.

 

Here is the Table mapping:

mapping
 

And the Code:

select 
    [APInvDtl].[InvoiceNum] as [APInvDtl_InvoiceNum],
    [APInvDtl].[InvoiceLine] as [APInvDtl_InvoiceLine],
    [APInvHed].[InvoiceDate] as [APInvHed_InvoiceDate],
    [APTran].[TranDate] as [APTran_TranDate],
    [CheckHed].[CheckNum] as [CheckHed_CheckNum],
    [Vendor].[Name] as [Vendor_Name],
    [Vendor].[VendorID] as [Vendor_VendorID],
    [APInvDtl].[PONum] as [APInvDtl_PONum],
    [APInvDtl].[OurQty] as [APInvDtl_OurQty],
    [APInvDtl].[PUM] as [APInvDtl_PUM],
    [APInvDtl].[UnitCost] as [APInvDtl_UnitCost],
    [APInvDtl].[TotalMiscChrg] as [APInvDtl_TotalMiscChrg],
    [APInvDtl].[ExtCost] as [APInvDtl_ExtCost],
    [PurTerms].[Description] as [PurTerms_Description],
    [APInvDtl].[Description] as [APInvDtl_Description],
    [TranGLC].[GLAccount] as [TranGLC_GLAccount],
    [APInvDtl].[PartNum] as [APInvDtl_PartNum],
    [Vendor].[TaxPayerID] as [Vendor_TaxPayerID],
    [APInvDtl].[POLine] as [APInvDtl_POLine],
    [APInvHed].[FiscalYear] as [APInvHed_FiscalYear],
    [APInvDtl].[PackSlip] as [APInvDtl_PackSlip],
    [APInvDtl].[PackLine] as [APInvDtl_PackLine],
    [RcvHead].[EntryPerson] as [RcvHead_EntryPerson],
    [RcvHead].[ReceiptDate] as [RcvHead_ReceiptDate],
    [APTran].[CheckNum] as [APTran_CheckNum],
    [TranGLC].[TransAmt] as [TranGLC_TransAmt]
from Erp.APInvDtl as APInvDtl
left outer join Erp.APInvHed as APInvHed on 
    APInvDtl.Company = APInvHed.Company
    and APInvDtl.VendorNum = APInvHed.VendorNum
    and APInvDtl.InvoiceNum = APInvHed.InvoiceNum
    and ( APInvHed.FiscalYear = 2020  )

left outer join Erp.APTran as APTran on 
    APInvHed.Company = APTran.Company
    and APInvHed.VendorNum = APTran.VendorNum
    and APInvHed.InvoiceNum = APTran.InvoiceNum
left outer join Erp.CheckHed as CheckHed on 
    APTran.Company = CheckHed.Company
    and APTran.HeadNum = CheckHed.HeadNum
    and APTran.CheckNum = CheckHed.CheckNum
left outer join Erp.Vendor as Vendor on 
    APInvHed.Company = Vendor.Company
    and APInvHed.VendorNum = Vendor.VendorNum
inner join Erp.PurTerms as PurTerms on 
    APInvHed.Company = PurTerms.Company
    and APInvHed.TermsCode = PurTerms.TermsCode
left outer join Erp.RcvHead as RcvHead on 
    APInvDtl.Company = RcvHead.Company
    and APInvDtl.VendorNum = RcvHead.VendorNum
    and APInvDtl.PurPoint = RcvHead.PurPoint
    and APInvDtl.PackSlip = RcvHead.PackSlip
left outer join Erp.APInvExp as APInvExp on 
    APInvDtl.Company = APInvExp.Company
    and APInvDtl.VendorNum = APInvExp.VendorNum
    and APInvDtl.InvoiceNum = APInvExp.InvoiceNum
    and APInvDtl.InvoiceLine = APInvExp.InvoiceLine
left outer join Erp.TranGLC as TranGLC on 
    APInvExp.Company = TranGLC.Company
    and APInvExp.VendorNum = TranGLC.Key1
    and APInvExp.InvoiceNum = TranGLC.Key2
    and APInvExp.InvoiceLine = TranGLC.Key3
    and ( TranGLC.RelatedToFile = 'APInvExp'  )
order by Vendor.Name, APInvHed.InvoiceDate

 

 

 

 

 

This is what I have now, but need help getting rid of the duplication of records.   My guess is the joins, thinking I may have an issue there, but not sure what is causing it to duplicate every record, so they show up twice.

Userlevel 1

Hi Jenny,

You’re missing the InvExpSeq. In your link between TranGLC and APInvExp, add a new join condition:

APInvExp.InvExpSeq = TranGLC.Key4

Dragos

Reply