Hi Bruno,
Sadly there is still no easy way for us to get the account.
Sometime back, I tried to write a query to get a WIPACCT of an Item.
I did not get to test it much. I will post it below.
Maybe you can look into it and improve it.
Would appreciate if any improvement you made, post it back here so it can be useful to somebody else.
Note that below is to get a WIPACCT (You need to change to your required column name) of an Item in a Warehouse on a specific date and specific to the rest of the params.
You will need to change this to make it an optional params.
This Query starts by determining whether the new Advance GL Account Determination is used on this company.
It will then branch out accordingly to use the old method or the new one.
Regards
Edy
public static string GetAdvAcctDetermination(string ItemCode, string WhsCode, DateTime RefDate, string BPGrpCod, string ShipCountr, string ShipState , string LicTradNum, string VatGroup, string CardCode, string CmpPrivate) { string sSQL = string.Format(@" DECLARE @ItemCode NVARCHAR(20)='{0}' DECLARE @WhsCOde NVARCHAR(8)='{1}' DECLARE @RefDate DATE= '{2:yyyyMMdd}' DECLARE @BPGrpCod INT = {3} DECLARE @ShipCountr NVARCHAR(3) = '{4}' DECLARE @ShipState NVARCHAR(3) = '{5}' DECLARE @LicTradNum NVARCHAR(32) ='{6}' DECLARE @VatGroup NVARCHAR(8) = '{7}' DECLARE @CardCode NVARCHAR(15) = '{8}' DECLARE @CmpPrivate NVARCHAR(1) = '{9}' DECLARE @NewAcctDe NVARCHAR(1) SELECT @NewAcctDe=NewAcctDe FROM OADM IF @NewAcctDe='N' BEGIN SELECT (CASE glmethod WHEN 'L' THEN t1.WipAcct WHEN 'W' THEN t2.WipAcct WHEN 'C' THEN t3.WipAcct END) WIPAcctCode FROM oitm t0 INNER JOIN oitw t1 ON t0.itemcode=t1.itemcode LEFT JOIN owhs t2 ON t1.whscode=t2.whscode LEFT JOIN oitb t3 ON t0.itmsgrpcod=t3.itmsgrpcod WHERE T0.ItemCode = @ItemCode AND T1.WhsCode = @WhsCode END ELSE BEGIN /*Advance GL Account Determination*/ DECLARE @SQL NVARCHAR(MAX)=' DECLARE @AbsEntry INT =0 DECLARE @Acct NVARCHAR(15)='''' SELECT @AbsEntry =MAX(AbsEntry) FROM OACP WHERE F_RefDate <=@RefDate SELECT TOP 1 @Acct = T1.WipAcct FROM OITM T0 JOIN OGAR T1 ON (T0.ItemCode = T1.ItemCode OR T1.ItemCode=''!^|'') AND ISNULL(T1.WipAcct,'''')<>'''' AND (T0.ItmsGrpCod = T1.ItmsGrpCod OR T1.ItmsGrpCod = -1) AND (T1.WhsCode = @WhsCode OR T1.WhsCode = ''!^|'') AND T1.Active = ''Y'' AND @RefDate BETWEEN T1.F_RefDate AND T1.T_RefDate AND @RefDate BETWEEN ISNULL(T1.FromDate,''19010101'') AND ISNULL(T1.ToDate,''21991231'') AND (T0.GLPickMeth = T1.GLMethod OR T1.GLMethod=''A'') AND (T1.BPGrpCod = @BPGrpCod OR T1.BPGrpCod=-1) AND (T1.ShipCountr = @ShipCountr OR T1.ShipCountr= ''!^|'') AND (T1.ShipState = @ShipState OR T1.ShipState= ''!^|'') AND (T1.LicTradNum = @LicTradNum OR T1.LicTradNum = ''!^|'') AND (T1.VatGroup = @VatGroup OR T1.VatGroup = ''!^|'') AND (T1.CardCode = @CardCode OR T1.CardCode = ''!^|'') AND (T1.CmpPrivate = @CmpPrivate OR T1.CmpPrivate = ''!^|'') WHERE T0.ItemCode = @ItemCode' DECLARE @Order NVARCHAR(2000) SELECT @Order=(SELECT CASE DmcAlias WHEN 'Item Group' THEN 'T1.ItmsGrpCod' WHEN 'Item Code' THEN 'T1.ItemCode' WHEN 'Warehouse Code' THEN 'T1.WhsCode' WHEN 'Business Partner Group' Then 'T1.BPGrpCod' WHEN 'Ship-to Country' Then 'T1.ShipCountr' WHEN 'Ship-to State' Then 'T1.ShipState' WHEN 'Federal Tax ID' Then 'T1.LicTradNum' WHEN 'Tax Code' Then 'T1.VatGroup' WHEN 'BP Code' Then 'T1.CardCode' WHEN 'BP Type' Then 'T1.CmpPrivate' END + ', ' FROM ODMC WHERE Active = 'Y' ORDER BY Priority FOR XML PATH('')) + '1' SET @SQL =@SQL + ' ORDER BY ' + @Order SET @SQL = @SQL + ' ' + ' if @Acct='''' SELECT @Acct = WipAcct From OACP WHERE AbsEntry = @AbsEntry SELECT @Acct ' Exec sp_ExecuteSQL @SQL,N'@RefDate DATE, @ItemCode NVARCHAR(20), @WhsCode NVARCHAR(15), @BPGrpCod INT , @ShipCountr NVARCHAR(3), @ShipState NVARCHAR(3), @LicTradNum NVARCHAR(32), @VatGroup NVARCHAR(8), @CardCode NVARCHAR(15) , @CmpPrivate NVARCHAR(1)', @RefDate, @ItemCode, @WhsCOde, @BPGrpCod, @ShipCountr, @ShipState, @LicTradNum, @VatGroup, @CardCode, @CmpPrivate END",ItemCode, WhsCode, RefDate, BPGrpCod, ShipCountr, ShipState, LicTradNum, VatGroup, CardCode, CmpPrivate); SAPbobsCOM.Recordset oRS = eCommon.oCompany.GetBusinessObject(BoObjectTypes.BoRecordset) as Recordset; oRS.DoQuery(sSQL); return oRS.Fields.Item(0).Value.ToString(); }