The business function that calls our NER is B4500050 - F4072 Calculate Price Adjustments. Within here the key fields that we are looking for are located within the lpds4500050A->lpdsData array. The lpds->idF4211RowPtr is passed into the NER using a Data Structure that JDE said that we needed to use (D4500210). We are then trying to pass that pointer into B4200210 – F4211 Get Sales Detail Row to retrieve the DOCO, KCOO, LNID and DCTO. Using this key information we would then fetch into the F4211 to retrieve the SHAN, ECST and ITWT. We use the SHAN to lookup into a custom table to retrieve the Freight allowance. We then do a calculation to determine what the excess freight amount is and pass that back into the BF DomesticAdjustmentPerUnit.
The problem is that passing in the Pointer to the B4200210 and trying to retrieve the key information it does not work. We get nothing back so the rest of the lookups fail and we cannot calculate the excess freight.
Below is the BSFN that calls our custom NER, the data structure that JDE says we have to use and then our custom NER code.
/**************************************************************************
* Function: I4500050_CallExtenalProgram
*
* Notes:
*
* Returns:
*
* Parameters:
**************************************************************************/
ID I4500050_CallExtenalProgram(LPBHVRCOM lpBhvrCom, LPVOID lpVoid,
LPDSD4500050 lpDS,LPDS4500050A lpds4500050A)
{
/************************************************************************
* Variable & Pointer declarations
************************************************************************/
ID idReturnValue = ER_SUCCESS;
ID idErrorFlag = ER_SUCCESS;
/************************************************************************
* Data Structures & Pointers
************************************************************************/
DSD4500210 dsExtProgram;
LPDS4500050D lpdsAdjustment = lpds4500050A->lpdsAdjustment;
LPDS4500050F lpdsData = lpds4500050A->lpdsData;
/************************************************************************
* Main Processing
************************************************************************/
memset((void *)&dsExtProgram, (int)_J('\0'), sizeof(DSD4500210));
dsExtProgram.idF4211RowPtr = lpDS->idF4211RowPtr;
dsExtProgram.idF4102RowPtr = lpDS->idF4102RowPtr;
jdeStrcpy((JCHAR *)dsExtProgram.szCurrencyCodeFrom,
(const JCHAR *)lpDS->szCurrencyCodeFrom);
jdeStrcpy((JCHAR *)dsExtProgram.szCurrencyCodeTo,
(const JCHAR *)lpDS->szCurrencyCodeTo);
idReturnValue = jdeCallObject(lpdsAdjustment->frmn,NULL,
lpBhvrCom, lpVoid, (LPVOID)&dsExtProgram,
(CALLMAP *)NULL, (int)0, (JCHAR *)NULL,
(JCHAR *)NULL, (int)0);
if ((idReturnValue != ER_SUCCESS) ||
(dsExtProgram.cErrorCode == _J('1')))
{
jdeStrcpy((JCHAR *)lpDS->szErrorMesgID,
(const JCHAR *)dsExtProgram.szErrorMessageID);
if (dsExtProgram.cSuppressErrorMessage != _J('1'))
{
jdeErrorSet(lpBhvrCom, lpVoid, (ID)0, dsExtProgram.szErrorMessageID, (void *)NULL);
}
idErrorFlag = ER_ERROR;
}
else
{
/*------
* The price returned by the external program should be in the
* pricing UOM.
*------*/
jdeStrcpy((JCHAR *)lpdsAdjustment->uom, (const JCHAR *)lpdsData->sduom4);
MathCopy(&lpds4500050A->mnAdjustment, &dsExtProgram.mnDomesticAdjustmentPerUnit);
if ((lpds4500050A->cCurrencyCtrl != _J('N')) &
(lpds4500050A->bExchRate))
{
MathCopy(&lpds4500050A->mnForeignAdjustment, &dsExtProgram.mnForeignAdjustmentPerUnit);
}
}
return idErrorFlag;
}
Data Structure:
======
NAMED ER: Calculate Excess Feight
======
evt_AmountExtendedCost_ECST
evt_AmountUnitWeight_ITWT
evt_FrtAllowance_A301
evt_AddressNumberShipTo_SHAN
evt_DocumentOrderInvoiceE_DOCO
evt_OrderType_DCTO
evt_CompanyKeyOrderNo_KCOO
evt_LineNumber_LNID
evt_FreightAllowance_AA
0001 //
0002 // Calculate excess freight: Excess Freight is Propaid Freight less Allowance
0003 // per Ton by X Tons or ((SDDECST)-(SDITWT/2000)(X))
0004 // Where X = $ allowance per ton
0005 //
0006 // Declare Variables
0007 VA evt_AmountExtendedCost_ECST = 0
0008 VA evt_AmountUnitWeight_ITWT = 0
0009 VA evt_FrtAllowance_A301 = 0
0010 //
0011 // Retrieve key information using the F4211.ptr that was passed in. Then using
0012 // the key information get the SHAN, ECST and ITWT.
0013 F4211 Get Sales Detail Row
VA evt_DocumentOrderInvoiceE_DOCO <- BF mnOrderNumber
VA evt_OrderType_DCTO <- BF szOrderType
VA evt_CompanyKeyOrderNo_KCOO <- BF szKeyCompany
VA evt_LineNumber_LNID <- BF mnLineNumber
BF szErrorMessageID <- BF szErrorMesg
BF cSuppressErrorMessage <- BF cSuppressErrorMesg
BF idF4211RowPtr -> BF idPtrToF4211Record
0014 //
0015 F4211.Fetch Single
VA evt_CompanyKeyOrderNo_KCOO = TK Order Company (Order Number)
VA evt_DocumentOrderInvoiceE_DOCO = TK Document (Order No, Invoice, etc.)
VA evt_OrderType_DCTO = TK Order Type
VA evt_LineNumber_LNID = TK Line Number
VA evt_AddressNumberShipTo_SHAN <- TK Address Number - Ship To
VA evt_AmountExtendedCost_ECST <- TK Amount - Extended Cost
VA evt_AmountUnitWeight_ITWT <- TK Unit Weight
0016 //
0017 // Lookup freight allowance
0018 F5801001.Fetch Single
VA evt_AddressNumberShipTo_SHAN = TK Address Number
VA evt_FrtAllowance_A301 <- TK Generic String 01
0019 Convert String to Math Numeric
VA evt_FrtAllowance_A301 -> BF szInputString
VA evt_FreightAllowance_AA <- BF mnOutputMathNumeric
0020 //
0021 BF mnDomesticAdjustmentPerUnit = [VA evt_AmountExtendedCost_ECST]-(([VA evt_AmountUnitWeight_ITWT]/2000)*[VA evt_FreightAllowance_AA])
0022 //
0023 // Validate that excess freight does not issue a credit for revenue orders
0024 // Do not print excess freight on invoice
0025 If VA evt_AmountExtendedCost_ECST is greater than <Zero> And BF mnDomesticAdjustmentPerUnit is less than <Zero>
0026 BF mnDomesticAdjustmentPerUnit = 0
0027 End If
0028 //
0029 // Also, validate that excess freight does not issue a debit for a credit memo
0030 // order
0031 // Do not print excess freight on invoice
0032 If VA evt_AmountExtendedCost_ECST is less than <Zero> And BF mnDomesticAdjustmentPerUnit is greater than <Zero>
0033 BF mnDomesticAdjustmentPerUnit = 0
0034 End If
0035 //
0036 // Validate that excess freight does not issue a credit for revenue orders
0037 //