C BSFN - How to add a JDEDATE in a database request

MartaCH

Member
Hi,
I would like to add a filter by field the DRQJ from the F3111 (>= 01/01/2017) in a query of a C function.
I can check the correct value in debug , but when I monitorize the select from the database, is getting allways the value 0 for DRQJ field instead of the date.
¿Could somebody help me to find out the issue?
Thanks!

This is the code:

CHAR I3400310_SelectF3111_F4801_F4801T(LPDSD3400310PL lpDS, LPDSB3400310INTERNAL lpdsB3400310Internal)
{
JCHAR cErrorCode = _J('0');
ID idJDBReturn = JDEDB_PASSED;

SELECTSTRUCT dsSelect[5] = { 0 };
ushort uNumSelect = (ushort)6;
SELECTSTRUCT dsSelect[6] = { 0 };
JDEDATE todaysDate = {2017,01,01};

JCHAR szRejectStatus[7][3] = {_J("95"),
_J("91"),
_J("92"),
_J("96"),
_J("97"),
_J("98"),
_J("99")};
/* SORTSTRUCT dsSort[2] = { 0 };*/
int nIndex = 0;



memset((void *)(dsSelect), (int)(_J('\0')), sizeof(dsSelect));

/* First part of select. (Item # && Branch && CoBy == ' ' and Status < 95) */
jdeNIDcpy(dsSelect[nIndex].Item1.szDict, NID_CPIT);
jdeNIDcpy(dsSelect[nIndex].Item1.szTable, NID_F3111);
dsSelect[nIndex].lpValue = &lpDS->mnComponentItemNumber;
dsSelect[nIndex].nValues = 1;
dsSelect[nIndex].nAndOr = JDEDB_ANDOR_AND;
dsSelect[nIndex].nCmp = JDEDB_CMP_EQ;
nIndex++;

jdeNIDcpy(dsSelect[nIndex].Item1.szDict, NID_CMCU);
jdeNIDcpy(dsSelect[nIndex].Item1.szTable, NID_F3111);
dsSelect[nIndex].lpValue = lpDS->szComponentBranch;
dsSelect[nIndex].nValues = 1;
dsSelect[nIndex].nAndOr = JDEDB_ANDOR_AND;
dsSelect[nIndex].nCmp = JDEDB_CMP_EQ;
nIndex++;

jdeNIDcpy(dsSelect[nIndex].Item1.szDict, NID_SRST);
jdeNIDcpy(dsSelect[nIndex].Item1.szTable, NID_F4801);
dsSelect[nIndex].lpValue = (void *) szRejectStatus;
dsSelect[nIndex].nValues = (unsigned short) DIM(szRejectStatus);
dsSelect[nIndex].nAndOr = JDEDB_ANDOR_AND;
dsSelect[nIndex].nCmp = JDEDB_CMP_NI;
nIndex++;


jdeNIDcpy(dsSelect[nIndex].Item1.szDict, NID_COBY);
jdeNIDcpy(dsSelect[nIndex].Item1.szTable, NID_F3111);
dsSelect[nIndex].lpValue = _J(" ");
dsSelect[nIndex].nValues = 1;
dsSelect[nIndex].nAndOr = JDEDB_ANDOR_AND;
dsSelect[nIndex].nCmp = JDEDB_CMP_EQ;
nIndex++;

/***********************************************/
/*FIELD ADDED*/

jdeNIDcpy(dsSelect[nIndex].Item1.szDict, NID_DRQJ);
jdeNIDcpy(dsSelect[nIndex].Item1.szTable, NID_F3111);
dsSelect[nIndex].lpValue = (void *) &todaysDate;
dsSelect[nIndex].nValues = 1;
dsSelect[nIndex].nAndOr = JDEDB_ANDOR_AND;
dsSelect[nIndex].nCmp = JDEDB_CMP_GE;
nIndex++;
/***********************************************/

if(!IsJDEDATENull(&lpDS->jdEffectiveThruDate))
{
jdeNIDcpy(dsSelect[nIndex].Item1.szDict, NID_DRQJ);
jdeNIDcpy(dsSelect[nIndex].Item1.szTable, NID_F4801);
dsSelect[nIndex].lpValue = (void *)&lpDS->jdEffectiveThruDate;
dsSelect[nIndex].nValues = (ushort)1;
dsSelect[nIndex].nAndOr = JDEDB_ANDOR_AND;
dsSelect[nIndex].nCmp = JDEDB_CMP_LE;


}
else
{
uNumSelect--;
}

JDB_SetSelection((HREQUEST) lpdsB3400310Internal->ds3400310CachePointers.hRequestF3111_2,
(LPSELECT)dsSelect,
(ushort)uNumSelect,
JDEDB_SET_REPLACE);

if(idJDBReturn == JDEDB_PASSED)
{


idJDBReturn = JDB_SelectKeyed((HREQUEST) lpdsB3400310Internal->ds3400310CachePointers.hRequestF3111_2,
(ID)(0), NULL, 0);

}
if(idJDBReturn != JDEDB_PASSED)
{
cErrorCode = _J('1');
}

return(cErrorCode);
}
 
Not sure I completely understand your question. But, for starters, use JDEToday(&todaysDate) - probably not your problem since your code should work with the hard coded date. When you say you "monitorize the select from the database" are you looking at the SELECT statement in the debug log and you are seeing "WHERE ... DRQJ >= 0 ..."?

Also review your logic around nIndex. It looks too... "complex". Just do this:

If condition
<< set select var values>>
nIndex++;
endif


You shouldn't need to nIndex--;

Oh, and looking at your code. Increase your NEWSELECTSTRUCT array size. I think you have it at 5 and you have a possible max of 6 <<<< this most likely your problem.
 
Last edited:
Back
Top