Description:
This business function is used to retrieve the aggregate value of PQOH from F41021 table for each ITM,MCU,LOCN,LOTN .
#include <jde.h>
#define b5641021_c
/*****************************************************************************
* Source File: b5641021
*
* Description: Calculate PQOH Quantity Source File
*
* History:
* Date Programmer SAR# - Description
* ---------- ---------- -------------------------------------------
* Author 02-04-2014 Lokesh Reddy - Created
*
* Copyright (c) J.D. Edwards World Source Company, 1996
*
* This unpublished material is proprietary to J.D. Edwards World Source Company.
* All rights reserved. The methods and techniques described herein are
* considered trade secrets and/or confidential. Reproduction or
* distribution, in whole or in part, is forbidden except by express
* written permission of J.D. Edwards World Source Company.
****************************************************************************/
/**************************************************************************
* Notes:
*
**************************************************************************/
#include <b5641021.h>
/**************************************************************************
* Business Function: CalculatePQOHQuantity
*
* Description: Calculate PQOH Quantity
*
* Parameters:
* LPBHVRCOM lpBhvrCom Business Function Communications
* LPVOID lpVoid Void Parameter - DO NOT USE!
* LPDSD554 lpDS Parameter Data Structure Pointer
*
*************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI CalculatePQOHQuantity (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5541021 lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
ID idReturnValue = ER_SUCCESS ;
ID idJDBReturn = JDEDB_PASSED;
HREQUEST hRequest = (HREQUEST) NULL;
ushort uGroupBy = 0;
ushort uKeys = 0;
NID szColumns1[1] = {NID_ITM};
NID szColumns2[2] = {NID_ITM, NID_MCU};
NID szColumns3[3] = {NID_ITM,NID_MCU,NID_LOCN};
NID szColumns4[4] = {NID_ITM,NID_MCU,NID_LOCN,NID_LOTN};
/************************************************************************
* Declare structures
************************************************************************/
KEY1_F41021 dsF41021Key1 = {0};
DBREF dsF41021GroupBy[4] = {0};
AGGRGFUNCSTRUCT dsF41021Aggregate[1] = {0};
MATH_NUMERIC dsAggregateBuffer[1] = {0};
/************************************************************************
* Declare pointers
************************************************************************/
HUSER hUser = (HUSER) NULL ;
HREQUEST hRequestF41021 = (HREQUEST) NULL ;
LPVOID lpdsF41021Keys = (LPVOID) NULL ;
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5541021) NULL))
{
lpDS->cErrorCode = _J('1') ;
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}
idJDBReturn = JDB_InitBhvr((void*)lpBhvrCom, &hUser, (JCHAR *) NULL, JDEDB_COMMIT_AUTO);
if (idJDBReturn == JDEDB_FAILED)
{
lpDS->cErrorCode = _J('1') ;
jdeSetGBRError(lpBhvrCom, lpVoid, (ID) 0, _J("3143"));
return ER_ERROR;
}
/************************************************************************
* Set pointers
************************************************************************/
/************************************************************************
* Main Processing
************************************************************************/
memset((void *)&dsF41021Key1, (int)_J('\0'), sizeof(dsF41021Key1));
memset((void *)dsF41021Aggregate, (int)_J('\0'), sizeof(dsF41021Aggregate));
memset((void *)&dsAggregateBuffer, 0x00, sizeof(dsAggregateBuffer));
if(&lpDS->cErrorCode != _J('1'))
{
if(MathZeroTest(&lpDS->mnIdentifierShortItem) !=0)
{
uGroupBy = 1;
uKeys = 1;
if(!IsStringBlank(&lpDS->szCostCenter))
{
uGroupBy = 2;
uKeys = 2;
if(!IsStringBlank(&lpDS->szLocation))
{
uGroupBy = 3;
uKeys = 3;
if(!IsStringBlank(&lpDS->szLot))
{
uGroupBy = 4;
uKeys = 4;
}
}
}
}
/* If the then open the table with both ITM, MCU, LOCN and LOT. */
if(uKeys == 4)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A,szColumns4, (ushort)4, (JCHAR *)NULL, &hRequest);
}
/* If the then open the table with both ITM, MCU and LOCN. */
if(uKeys == 3)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A,szColumns3, (ushort)3, (JCHAR *)NULL, &hRequest);
}
/* If the then open the table with both ITM and MCU. */
if(uKeys == 2)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A,szColumns2, (ushort)2, (JCHAR *)NULL, &hRequest);
}
if(uKeys == 1)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A, szColumns1, (ushort)1, (JCHAR *)NULL, &hRequest);
}
/* idJDBReturn = JDB_OpenTable(hUser, NID_F41021,ID_F41021_ITEM__BRANCH___A,szColumns4,(ushort)uKeys,(JCHAR *)NULL,&hRequest);*/
if (idJDBReturn == JDEDB_PASSED)
{
/* Group the F41021 records by ITM and MCU */
jdeNIDcpy(dsF41021GroupBy[0].szDict, NID_ITM);
jdeNIDcpy(dsF41021GroupBy[0].szTable, NID_F41021);
dsF41021GroupBy[0].idInstance = 0;
if (uGroupBy > 1)
{
jdeNIDcpy(dsF41021GroupBy[1].szDict, NID_MCU);
jdeNIDcpy(dsF41021GroupBy[1].szTable, NID_F41021);
dsF41021GroupBy[1].idInstance = 0;
/* Group the F41021 records by ITM , MCU and LOCN */
if (uGroupBy > 2)
{
jdeNIDcpy(dsF41021GroupBy[2].szDict, NID_LOCN);
jdeNIDcpy(dsF41021GroupBy[2].szTable, NID_F41021);
dsF41021GroupBy[2].idInstance = 0;
/* Group the F41021 records by ITM , MCU ,LOCN and LOT */
if(uGroupBy>3)
{
jdeNIDcpy(dsF41021GroupBy[3].szDict, NID_LOTN);
jdeNIDcpy(dsF41021GroupBy[3].szTable, NID_F41021);
dsF41021GroupBy[3].idInstance = 0;
}
}
}
}
/* Set the F41021 Group By. */
idJDBReturn = JDB_SetGroupBy(hRequest, dsF41021GroupBy, uGroupBy);
if (idJDBReturn == JDEDB_PASSED)
{
/* Define F41021 Aggregate as SUM of PQOH */
jdeNIDcpy(dsF41021Aggregate[0].Item.szDict, NID_PQOH);
jdeNIDcpy(dsF41021Aggregate[0].Item.szTable, NID_F41021);
dsF41021Aggregate[0].Item.idInstance = 0;
dsF41021Aggregate[0].nFunction = JDB_AGGRGFUNC_SUM;
/* Set the F41021 Aggregate */
idJDBReturn = JDB_SetAggregate(hRequest, dsF41021Aggregate, 1, JDB_AGGRGFUNCTION_OPT_FUNC_COLUMNQUERY);
if (idJDBReturn == JDEDB_PASSED)
{
MathCopy(&dsF41021Key1.liitm, &lpDS->mnIdentifierShortItem);
if (uKeys > 1)
{
jdeStrcpy((JCHAR *)dsF41021Key1.limcu, (const JCHAR *)lpDS->szCostCenter);
if(uKeys >2)
{
jdeStrcpy((JCHAR *)dsF41021Key1.lilocn, (const JCHAR *)lpDS->szLocation);
if(uKeys > 3)
{
jdeStrcpy((JCHAR *)dsF41021Key1.lilotn, (const JCHAR *)lpDS->szLot);
}
}
}
/* If the set aggregate worked, select the correct F41021 records to sum:
* item,branch,location and lot(uKeys = 4) or item,branch and location(uKeys=3) or item and branch (uKeys = 2) or item only (uKeys = 1). */
idJDBReturn = JDB_SelectKeyed(hRequest, 0, &dsF41021Key1, uKeys);
if (idJDBReturn == JDEDB_PASSED)
{
idJDBReturn = JDB_FetchAggregate(hRequest, (void *)NULL, dsAggregateBuffer);
if (idJDBReturn == JDEDB_PASSED)
{
/* PQOH used to contain the quantity on hand for the specific * item/branch/location/lot of this transaction */
MathCopy(&lpDS->mnQtyOnHandPrimaryUn, &dsAggregateBuffer[0]);
}
}
}
}
if (hRequest != (HREQUEST)NULL)
{
JDB_CloseTable(hRequest);
}
return;
}
/************************************************************************
* Function Clean Up
************************************************************************/
if ( hUser )
{
JDB_FreeBhvr ( hUser ) ;
}
return (ER_SUCCESS);
}
/**************************************************************************
* Function: Ixxxxxxx_a // Replace "xxxxxxx" with source file number
* // and "a" with the function name
* Notes:
*
* Returns:
*
* Parameters:
**************************************************************************//* Internal function comment block */
/**************************************************************************
* Function: Ixxxxxxx_a // Replace "xxxxxxx" with source file number
* // and "a" with the function name
* Notes:
*
* Returns:
*
* Parameters:
**************************************************************************/
This business function is used to retrieve the aggregate value of PQOH from F41021 table for each ITM,MCU,LOCN,LOTN .
#include <jde.h>
#define b5641021_c
/*****************************************************************************
* Source File: b5641021
*
* Description: Calculate PQOH Quantity Source File
*
* History:
* Date Programmer SAR# - Description
* ---------- ---------- -------------------------------------------
* Author 02-04-2014 Lokesh Reddy - Created
*
* Copyright (c) J.D. Edwards World Source Company, 1996
*
* This unpublished material is proprietary to J.D. Edwards World Source Company.
* All rights reserved. The methods and techniques described herein are
* considered trade secrets and/or confidential. Reproduction or
* distribution, in whole or in part, is forbidden except by express
* written permission of J.D. Edwards World Source Company.
****************************************************************************/
/**************************************************************************
* Notes:
*
**************************************************************************/
#include <b5641021.h>
/**************************************************************************
* Business Function: CalculatePQOHQuantity
*
* Description: Calculate PQOH Quantity
*
* Parameters:
* LPBHVRCOM lpBhvrCom Business Function Communications
* LPVOID lpVoid Void Parameter - DO NOT USE!
* LPDSD554 lpDS Parameter Data Structure Pointer
*
*************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI CalculatePQOHQuantity (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5541021 lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
ID idReturnValue = ER_SUCCESS ;
ID idJDBReturn = JDEDB_PASSED;
HREQUEST hRequest = (HREQUEST) NULL;
ushort uGroupBy = 0;
ushort uKeys = 0;
NID szColumns1[1] = {NID_ITM};
NID szColumns2[2] = {NID_ITM, NID_MCU};
NID szColumns3[3] = {NID_ITM,NID_MCU,NID_LOCN};
NID szColumns4[4] = {NID_ITM,NID_MCU,NID_LOCN,NID_LOTN};
/************************************************************************
* Declare structures
************************************************************************/
KEY1_F41021 dsF41021Key1 = {0};
DBREF dsF41021GroupBy[4] = {0};
AGGRGFUNCSTRUCT dsF41021Aggregate[1] = {0};
MATH_NUMERIC dsAggregateBuffer[1] = {0};
/************************************************************************
* Declare pointers
************************************************************************/
HUSER hUser = (HUSER) NULL ;
HREQUEST hRequestF41021 = (HREQUEST) NULL ;
LPVOID lpdsF41021Keys = (LPVOID) NULL ;
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5541021) NULL))
{
lpDS->cErrorCode = _J('1') ;
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}
idJDBReturn = JDB_InitBhvr((void*)lpBhvrCom, &hUser, (JCHAR *) NULL, JDEDB_COMMIT_AUTO);
if (idJDBReturn == JDEDB_FAILED)
{
lpDS->cErrorCode = _J('1') ;
jdeSetGBRError(lpBhvrCom, lpVoid, (ID) 0, _J("3143"));
return ER_ERROR;
}
/************************************************************************
* Set pointers
************************************************************************/
/************************************************************************
* Main Processing
************************************************************************/
memset((void *)&dsF41021Key1, (int)_J('\0'), sizeof(dsF41021Key1));
memset((void *)dsF41021Aggregate, (int)_J('\0'), sizeof(dsF41021Aggregate));
memset((void *)&dsAggregateBuffer, 0x00, sizeof(dsAggregateBuffer));
if(&lpDS->cErrorCode != _J('1'))
{
if(MathZeroTest(&lpDS->mnIdentifierShortItem) !=0)
{
uGroupBy = 1;
uKeys = 1;
if(!IsStringBlank(&lpDS->szCostCenter))
{
uGroupBy = 2;
uKeys = 2;
if(!IsStringBlank(&lpDS->szLocation))
{
uGroupBy = 3;
uKeys = 3;
if(!IsStringBlank(&lpDS->szLot))
{
uGroupBy = 4;
uKeys = 4;
}
}
}
}
/* If the then open the table with both ITM, MCU, LOCN and LOT. */
if(uKeys == 4)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A,szColumns4, (ushort)4, (JCHAR *)NULL, &hRequest);
}
/* If the then open the table with both ITM, MCU and LOCN. */
if(uKeys == 3)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A,szColumns3, (ushort)3, (JCHAR *)NULL, &hRequest);
}
/* If the then open the table with both ITM and MCU. */
if(uKeys == 2)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A,szColumns2, (ushort)2, (JCHAR *)NULL, &hRequest);
}
if(uKeys == 1)
{
idJDBReturn = JDB_OpenTable(hUser, NID_F41021, ID_F41021_ITEM__BRANCH___A, szColumns1, (ushort)1, (JCHAR *)NULL, &hRequest);
}
/* idJDBReturn = JDB_OpenTable(hUser, NID_F41021,ID_F41021_ITEM__BRANCH___A,szColumns4,(ushort)uKeys,(JCHAR *)NULL,&hRequest);*/
if (idJDBReturn == JDEDB_PASSED)
{
/* Group the F41021 records by ITM and MCU */
jdeNIDcpy(dsF41021GroupBy[0].szDict, NID_ITM);
jdeNIDcpy(dsF41021GroupBy[0].szTable, NID_F41021);
dsF41021GroupBy[0].idInstance = 0;
if (uGroupBy > 1)
{
jdeNIDcpy(dsF41021GroupBy[1].szDict, NID_MCU);
jdeNIDcpy(dsF41021GroupBy[1].szTable, NID_F41021);
dsF41021GroupBy[1].idInstance = 0;
/* Group the F41021 records by ITM , MCU and LOCN */
if (uGroupBy > 2)
{
jdeNIDcpy(dsF41021GroupBy[2].szDict, NID_LOCN);
jdeNIDcpy(dsF41021GroupBy[2].szTable, NID_F41021);
dsF41021GroupBy[2].idInstance = 0;
/* Group the F41021 records by ITM , MCU ,LOCN and LOT */
if(uGroupBy>3)
{
jdeNIDcpy(dsF41021GroupBy[3].szDict, NID_LOTN);
jdeNIDcpy(dsF41021GroupBy[3].szTable, NID_F41021);
dsF41021GroupBy[3].idInstance = 0;
}
}
}
}
/* Set the F41021 Group By. */
idJDBReturn = JDB_SetGroupBy(hRequest, dsF41021GroupBy, uGroupBy);
if (idJDBReturn == JDEDB_PASSED)
{
/* Define F41021 Aggregate as SUM of PQOH */
jdeNIDcpy(dsF41021Aggregate[0].Item.szDict, NID_PQOH);
jdeNIDcpy(dsF41021Aggregate[0].Item.szTable, NID_F41021);
dsF41021Aggregate[0].Item.idInstance = 0;
dsF41021Aggregate[0].nFunction = JDB_AGGRGFUNC_SUM;
/* Set the F41021 Aggregate */
idJDBReturn = JDB_SetAggregate(hRequest, dsF41021Aggregate, 1, JDB_AGGRGFUNCTION_OPT_FUNC_COLUMNQUERY);
if (idJDBReturn == JDEDB_PASSED)
{
MathCopy(&dsF41021Key1.liitm, &lpDS->mnIdentifierShortItem);
if (uKeys > 1)
{
jdeStrcpy((JCHAR *)dsF41021Key1.limcu, (const JCHAR *)lpDS->szCostCenter);
if(uKeys >2)
{
jdeStrcpy((JCHAR *)dsF41021Key1.lilocn, (const JCHAR *)lpDS->szLocation);
if(uKeys > 3)
{
jdeStrcpy((JCHAR *)dsF41021Key1.lilotn, (const JCHAR *)lpDS->szLot);
}
}
}
/* If the set aggregate worked, select the correct F41021 records to sum:
* item,branch,location and lot(uKeys = 4) or item,branch and location(uKeys=3) or item and branch (uKeys = 2) or item only (uKeys = 1). */
idJDBReturn = JDB_SelectKeyed(hRequest, 0, &dsF41021Key1, uKeys);
if (idJDBReturn == JDEDB_PASSED)
{
idJDBReturn = JDB_FetchAggregate(hRequest, (void *)NULL, dsAggregateBuffer);
if (idJDBReturn == JDEDB_PASSED)
{
/* PQOH used to contain the quantity on hand for the specific * item/branch/location/lot of this transaction */
MathCopy(&lpDS->mnQtyOnHandPrimaryUn, &dsAggregateBuffer[0]);
}
}
}
}
if (hRequest != (HREQUEST)NULL)
{
JDB_CloseTable(hRequest);
}
return;
}
/************************************************************************
* Function Clean Up
************************************************************************/
if ( hUser )
{
JDB_FreeBhvr ( hUser ) ;
}
return (ER_SUCCESS);
}
/**************************************************************************
* Function: Ixxxxxxx_a // Replace "xxxxxxx" with source file number
* // and "a" with the function name
* Notes:
*
* Returns:
*
* Parameters:
**************************************************************************//* Internal function comment block */
/**************************************************************************
* Function: Ixxxxxxx_a // Replace "xxxxxxx" with source file number
* // and "a" with the function name
* Notes:
*
* Returns:
*
* Parameters:
**************************************************************************/
No comments:
Post a Comment