cancel
Showing results for 
Search instead for 
Did you mean: 

Error -5002:Date not within the forecast period when adding Sales Forecast

Former Member
0 Kudos

Hi,

I am trying to add Sales Forecast through the DI APIs but I got the error code: -5002 and the error message is "Date not within the forecast period [OFCT

.UserSign][line: 1]". I set myposting period to 2006 as current too so I am very perplexed with the error thrown. My C# Code is below:

SAPbobsCOM.SalesForecast vFCT = (SAPbobsCOM.SalesForecast) company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSalesForecast);

vFCT.ForecastCode = "F01";

vFCT.ForecastName = "Forecast for First Quarter 2006";

vFCT.ForecastStartDate = new DateTime(2006,1,1,0,0,0,0);

vFCT.ForecastEndDate = new DateTime(2006, 3, 12,0,0,0,0);

vFCT.Lines.ItemNo = "A00001";

vFCT.Lines.Quantity = 200;

vFCT.Lines.Add();

vFCT.Lines.SetCurrentLine(1);

vFCT.Lines.ItemNo = "A00002";

vFCT.Lines.Quantity = 500;

int retVal = vFCT.Add();

int errCode;

string errMsg;

if (0 != retVal){

company.GetLastError(out errCode, out errMsg);

Console.WriteLine(string.Format("Error code: {0}; Error Message: ",errCode, errMsg));

}

else {

Console.WriteLine("Successfully add sales forecast");

}

I would appreciate if anyone can help point me out how i can solve this problem.

Sunny

Accepted Solutions (1)

Accepted Solutions (1)

barend_morkel2
Active Contributor
0 Kudos

Hi Sansanee,

Seeing as we are in 2006, make sure your financial period (under Administration-System Init-General Settings-Posting Periods) is set up for 2006.

Former Member
0 Kudos

Hi Barend,

I did that even before I ran my code. That is why I am not sure why I get this error.

Sunny

former_member184566
Active Contributor
0 Kudos

Hi Sansanee

The reason it is not working is that for the lines you haven't specified the date....remember you need to set the quantities for certain months/days. Also the date format you are using for start and end.....not sure if sap likes that format.

here is a sample in vb.net, it works on my side

Dim SalesForecast As SAPbobsCOM.SalesForecast

SalesForecast = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSalesForecast)

SalesForecast.ForecastCode = "SDK"

SalesForecast.ForecastName = "Testing"

SalesForecast.ForecastStartDate = "2006/01/01"

SalesForecast.ForecastEndDate = "2006/12/01"

SalesForecast.Lines.ItemNo = "138391"

SalesForecast.Lines.ForecastedDay = "2006/01/01"

SalesForecast.Lines.Quantity = 1

lRetCode = SalesForecast.Add()

If lRetCode <> 0 Then

oCompany.GetLastError(lRetCode, sErrMsg)

MsgBox(sErrMsg)

End If

hope this helps

Former Member
0 Kudos

Hi Louis

Your code works fine, but what does one have to do in code to change the FormView?

Now the formview is always daily. But what if you want to make it weekly? Any idea how you do that?

Many thanks in advance

Iris

Answers (0)