Code:
/* Other Processing Takes Place Here That Does Not Affect Below Code */
/* I read data from the table and write to below Array this section is in a loop. - Ascending Order*/
/* &aF564015MCU1[MCU1] = The array and &dsF564015. = Read table */
MathCopy(&aF564015MCU1[MCU1].mnAddressNumber, &dsF564015.otan8);
MathCopy(&aF564015MCU1[MCU1].mnIdentifierShortItem, &dsF564015.otitm);
jdeStrncpy(aF564015MCU1[MCU1].szOrderTemplate, dsF564015.otortp, DIM(aF564015MCU1[MCU1].szOrderTemplate));
jdeStrncpy(aF564015MCU1[MCU1].szCostCenter, dsF564015.otmcu, DIM(aF564015MCU1[MCU1].szCostCenter));
JDEDATECopy(&aF564015MCU1[MCU1].jdDateEffectiveJulian1, &dsF564015.oteftj);
JDEDATECopy(&aF564015MCU1[MCU1].jdDateExpiredJulian1, &dsF564015.otexdj);
JDEDATECopy(&aF564015MCU1[MCU1].jdDateEntered1, &dsF564015.otentj);
MathCopy(&aF564015MCU1[MCU1].mnTimeEntered, &dsF564015.otentt);
MCU1++;
/* Other Processing Takes Place Here That Does Not Effect Below Code */
while (MCU1 > 0)
{
/* Validate current and prior Array records are the same before update happens (Key Fields) */
if ((jdestrcmpwithnull(aF564015MCU1[MCU1].szOrderTemplate, aF564015MCU1[MCU1-1].szOrderTemplate) == 0)
&& (MathCompare(&aF564015MCU1[MCU1].mnAddressNumber, &aF564015MCU1[MCU1-1].mnAddressNumber) == 0)
&& (MathCopy(&aF564015MCU1[MCU1].mnIdentifierShortItem, &aF564015MCU1[MCU1-1].mnIdentifierShortItem) == 0)
&& (jdestrcmpwithnull(aF564015MCU1[MCU1].szCostCenter, aF564015MCU1[MCU1-1].szCostCenter) == 0))
{
/* Take current Effective Date EFTJ and minus 1. This will become the new expired date for the prior record. */
RTK_CER_AddDays( &NewDateExpiredEXDJ ,
&aF564015MCU1[MCU1].jdDateEffectiveJulian1 , -1 );
/* Make sure the dates are NOT equal */
if (SingleValueComp((LPVOID)&aF564015MCU1[MCU1-1].jdDateExpiredJulian1,
(LPVOID)&NewDateExpiredEXDJ,EVDT_JDEDATE)!=0)
{
/* Setup Key For UPDATE*/
jdeStrcpy((JCHAR *)(dsF564015Key1U.otortp), (const JCHAR *)(aF564015MCU1[MCU1-1].szOrderTemplate));
MathCopy(&dsF564015Key1U.otan8, &aF564015MCU1[MCU1-1].mnAddressNumber);
MathCopy(&dsF564015Key1U.otitm, &aF564015MCU1[MCU1-1].mnIdentifierShortItem);
jdeStrcpy((JCHAR *)(dsF564015Key1U.otmcu), (const JCHAR *)(aF564015MCU1[MCU1-1].szCostCenter));
JDEDATECopy (&dsF564015Key1U.otentj, &aF564015MCU1[MCU1-1].jdDateEntered1);
MathCopy(&dsF564015Key1U.otentt, &aF564015MCU1[MCU1-1].mnTimeEntered);
JDEDBReturn = JDB_FetchKeyed(hReqF564015, (ID) 0, (void *)(&dsF564015Key1U),
(unsigned short)(6), (void *)(&dsF564015), FALSE);
if (JDEDBReturn == JDEDB_PASSED)
{
/* Gather and assign Audit Field data to be Updated into F564015 */
jdeCallObject( _J("GetAuditInfo"), NULL, lpBhvrCom, lpVoid, &dsGetAuditInfo, (CALLMAP*) NULL, (int) 0, (JCHAR*) NULL,
(JCHAR*) NULL, (int) 0 );
jdeStrcpy((JCHAR *)(dsF564015.otuser), (const JCHAR *)(dsGetAuditInfo.szUserName));
memcpy((void *)(&dsF564015.otupmj), (const void *)(&dsGetAuditInfo.jdDate), sizeof(JDEDATE));
MathCopy(&dsF564015.otupmt, &dsGetAuditInfo.mnTime);
jdeStrcpy((JCHAR *)(dsF564015.otpid), (const JCHAR *)(_J("B564015X")));
jdeStrcpy((JCHAR *)(dsF564015.otjobn), (const JCHAR *)(dsGetAuditInfo.szWorkstation_UserId));
/* New Effective Thru Date into F564015 */
JDEDATECopy (&dsF564015.otexdj, &NewDateExpiredEXDJ);
/* Update F564015 with audit fields and new expiration date(s) */
JDEDBReturn = JDB_UpdateTable(hReqF564015, szTableIDF564015, (ID) 0,
(ID)(idIndexF564015), (void *)(&dsF564015Key1U),(6),
(void *)(&dsF564015));
if (JDEDBReturn == JDEDB_PASSED)
{
lpDS->cErrorCode = _J('0');
jdeStrcpy((JCHAR *)(lpDS->szDescript01), (const JCHAR *)(_J("End1")));
}
}
}
}
MCU1--;
}
}