JD Edwards

JD Edwards
Lokesh Reddy Blog

Monday, September 22, 2014

On hand Quantity PQOH Aggregate for ITM,MCU,LOCN,LOTN

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:
 **************************************************************************/

Monday, July 7, 2014

Retrieve Media Object Text Using the Cache C Business Function

Retrieve Media Object Text from F00165

                     I used the cache API's to add the media text to cache and retrieve the media text from cache.Firstly I used an API called "jdeGTGet_GenericTextKeyStr" to load the Media Text in to a data structure field is "pMOData"  by using the primary keys in a table F00165.

jdeGTGet_GenericTextKeyStr (lpDS->szNameObject, lpDS->GenericTextKey, iSequenceNum, &pMOData, &lTotalRec);
Actually we have the media object system function GTXXXX used to retrieve the Media Text,why i created this business function is to retrieve the Media Text by the Specified size of characters in a line,so we cannot retrieve the Media text directly for huge length of text,thatswhy i used the cache API's to Add and Fetch Media Text  from the Cache.The API's used as follows

To add into Cache
jdeCacheAdd(hCache, (void *) &dsCacheData,(long int) sizeof(DS5600165C));

Retrieve From Cache
jdeCacheFetchPosition(hCache, hCacheCursor,&dsCacheKeys,(short int)0,&dsCacheData,sizeof(dsCacheData));
jdeCacheFetch(hCache, hCacheCursor, &dsCacheData ,(void *)NULL);
I used  a logic to split the Media Text from the whole Media Text

iLength = jdeStrlen(pMOData->pData);
jdeStrncpy(pMOData->pData, 
pMOData->pData,
DIM(pMOData->pData)-1);

iCounter = 0;
while ( iLoopIndex < iLength )
{
   dsCacheData.szMediaText[iCounter++] = pMOData->pData[iPosition++];
if(iLoopIndex%120==0)
{
jdeStrncpy(dsCacheData.szMediaText, 
pMOData->pData,
DIM(pMOData->pData)-1);
MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
JDECMReturn = jdeCacheAdd(hCache, (void *) &dsCacheData,(long int) sizeof(DS5600165C)); jdeStrcpy(dsCacheData.szMediaText,dsCacheData.GenericTextKey,DIM(dsCacheData.GenericTextKey)-1);
iCounter=0;
}
I used the Data structure for Cache and Media Object Text as follows as

LPMODATA pMOData;/* Data Structure for the Media Object */

 typedef struct 
{
  MATH_NUMERIC      mnJobnumber;                         
  JCHAR             szComputerID[16];                    
  JCHAR             cModeProcessing;                     
  JCHAR             szNameObject[11];                    
  JCHAR             GenericTextKey[255]; 
  MATH_NUMERIC mninsertCounter;
  int               nMediaObjectSequenceNumber;          
  JCHAR             cSuppressErrorMessage;               
  JCHAR             szErrorMessageId[11]; 
  JCHAR szMediaText[255];
  /*PJSTR pMediaText;*/
} DS5600165C, *LPDS5600165C;/* Data Structure for the Cache */

  typedef struct 
{
  MATH_NUMERIC      mnJobnumber;
  MATH_NUMERIC insertCounter[15];
  JCHAR             szComputerID[16];  

 } KEY_DS5600165C, LPKEY_DS5600165C;

Cache Business Function Header File as follows as

/***************************************************************************** 
 *    Header File:  B5600165.h 
 * 
 *    Description:  Retrieve Media Object Text from F00165 Header File 
 * 
 *        History: 
 *          Date        Programmer  SAR# - Description 
 *          ----------  ----------  ------------------------------------------- 
 *   Author 09-06-2014  Unkno       Unknown  - 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. 
 ****************************************************************************/ 
#ifndef __B5600165_H
#define __B5600165_H 
/***************************************************************************** 
 * Table Header Inclusions 
 ****************************************************************************/ 
/***************************************************************************** 
 * External Business Function Header Inclusions 
 ****************************************************************************/ 
 #include <b0000564.h>
/***************************************************************************** 
 * Global Definitions 
 ****************************************************************************/ 
/***************************************************************************** 
 * Structure Definitions 
 ****************************************************************************/ 
 LPMODATA pMOData;/* Data Structure for the Media Object */

 typedef struct 
{
  MATH_NUMERIC      mnJobnumber;                         
  JCHAR             szComputerID[16];                    
  JCHAR             cModeProcessing;                     
  JCHAR             szNameObject[11];                    
  JCHAR             GenericTextKey[255]; 
  MATH_NUMERIC mninsertCounter;
  int               nMediaObjectSequenceNumber;          
  JCHAR             cSuppressErrorMessage;               
  JCHAR             szErrorMessageId[11]; 
  JCHAR szMediaText[255];
  /*PJSTR pMediaText;*/
} DS5600165C, *LPDS5600165C;/* Data Structure for the Cache */

  typedef struct 
{
  MATH_NUMERIC      mnJobnumber;
  MATH_NUMERIC insertCounter[15];
  JCHAR             szComputerID[16];  

 } KEY_DS5600165C, LPKEY_DS5600165C;

/***************************************************************************** 
 * DS Template Type Definitions 
 ****************************************************************************/ 


/**
 * TYPEDEF for Data Structure
 * D5600165 : Add Media Objects to Cache
 *
 * Copyright Oracle USA
 *
 * This is a JDEdwards EnterpriseOne generated file.
 * Do not modify this file.
 * Only re-generate with the appropriate tool.
 * Generation Date : 15-06-2014
 */

#ifndef DATASTRUCTURE_D5600165
#define DATASTRUCTURE_D5600165

typedef struct tagDSD5600165
{
  MATH_NUMERIC   mnJobnumber;
  JCHAR          szComputerID[16];
  JCHAR          cActionCode;
  JCHAR          szNameObject[11];
  JCHAR          GenericTextKey[255];
  int            nMediaObjectSequenceNumber;
  JCHAR          cSuppressErrorMessage;
  JCHAR          szErrorMessageId[11];
  JCHAR          szLengthOfString[4];
  MATH_NUMERIC   mnLengthOfString;
} DSD5600165 , *LPDSD5600165;

#define IDERRmnJobnumber_1                        1L
#define IDERRszComputerID_2                       2L
#define IDERRcActionCode_3                        3L
#define IDERRszNameObject_4                       4L
#define IDERRGenericTextKey_5                     5L
#define IDERRnMediaObjectSequenceNumber_6         6L
#define IDERRcSuppressErrorMessage_7              7L
#define IDERRszErrorMessageId_8                   8L
#define IDERRszLengthOfString_10                  10L
#define IDERRmnLengthOfString_11                  11L

#endif /* DATASTRUCTURE_D5600165 */





 /*****************************************
 * TYPEDEF for Data Structure
 *    Template Name: Retrieve Media Objects from Cache                           
 *    Template ID:   D5600165A
 *    Generated:     Mon Jun 09 18:53:05 2014
 *
 * DO NOT EDIT THE FOLLOWING TYPEDEF
 *    To make modifications, use the OneWorld Data Structure
 *    Tool to Generate a revised version, and paste from
 *    the clipboard.
 *
 **************************************/

#ifndef DATASTRUCTURE_D5600165A
#define DATASTRUCTURE_D5600165A

typedef struct tagDSD5600165A
{
  MATH_NUMERIC      mnJobnumber;                         
  JCHAR             szComputerID[16];                    
  JCHAR             cActionCode;                         
  JCHAR             szMediaTextOutput[176];              
} DSD5600165A, *LPDSD5600165A;
#define IDERRmnJobnumber_1                        1L
#define IDERRszComputerID_2                       2L
#define IDERRcActionCode_3                        3L
#define IDERRszMediaTextOutput_4                  4L



#endif

/***************************************************************************** 
 * Source Preprocessor Definitions 
 ****************************************************************************/ 
#if defined (JDEBFRTN) 
#undef JDEBFRTN 
#endif 
#if defined (WIN32) 
#if defined (WIN32) 
#define JDEBFRTN(r) __declspec(dllexport) r 
#else 
#define JDEBFRTN(r) __declspec(dllimport) r 
#endif 
#else 
#define JDEBFRTN(r) r 
#endif 
/***************************************************************************** 
 * Business Function Prototypes 
 ****************************************************************************/ 
 JDEBFRTN (ID) JDEBFWINAPI AddMediaTextToCache              (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165 lpDS); 
 JDEBFRTN (ID) JDEBFWINAPI RetrieveMediaextFromCache        (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165A lpDS); 
/***************************************************************************** 
 * Internal Function Prototypes 
 ****************************************************************************/ 
 JDECM_RESULT I5600165_CreateCache ( HUSER hUser, HCACHE *hCache );
#endif    /* __B5600165_H */ 
Cache Business Function Source File:
#include <jde.h> 
#define b5600165_c 
/***************************************************************************** 
 *    Source File:  b5600165 
 * 
 *    Description:  Retrieve Media Object Text from F00165 Source File 
 * 
 *        History: 
 *          Date        Programmer  SAR# - Description 
 *          ----------  ----------  ------------------------------------------- 
 *   Author 09-06-2014  Unkno       Unknown  - 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 <b5600165.h> 
/************************************************************************** 
 *  Business Function:  AddMediaTextToCache 
 * 
 *        Description:  Add Media Object Text To Cache 
 * 
 *         Parameters: 
 *           LPBHVRCOM           lpBhvrCom    Business Function Communications 
 *           LPVOID              lpVoid       Void Parameter - DO NOT USE! 
 *           LPDSD560            lpDS         Parameter Data Structure Pointer   
 * 
 *************************************************************************/ 
JDEBFRTN (ID) JDEBFWINAPI AddMediaTextToCache (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165 lpDS)  
   /************************************************************************ 
    *  Variable declarations 
    ************************************************************************/ 

HUSER  hUser ;
HCACHE  hCache               = (HCACHE) NULL;
HJDECURSOR  hCacheCursor         = (HJDECURSOR) NULL;

ID idJDBReturn = JDEDB_PASSED;
long lTotalRec = 0;
int iSequenceNum = 0;
JCHAR szMediaText;
ID idReturnCode = ER_SUCCESS;
int iCounter                = 0;
int iLoopIndex = 1;
    int iPosition               = 0;
    int iLength                 = 0;
MATH_NUMERIC mninsertCounter = {1};
PJSTR pSegment = NULL;
int i = 0, iSegmentNum = 0;
JCHAR           token[2] = {0};

/************************************************************************ 
* Cache Management variables and structures 
************************************************************************/
ID JDECMReturn   =  JDECM_PASSED ;
JCHAR              szCacheName[41]= {0};
JCHAR           szJobNumberString[MAXLEN_MATH_NUMERIC] = {0};

/************************************************************************ 
    * Declare structures 
    ************************************************************************/ 

KEY_DS5600165C dsCacheKeys ;
DS5600165C dsCacheData ;
DSD0000564          dsNextNumbers;
   /************************************************************************ 
    * Declare pointers 
    ************************************************************************/ 
   /************************************************************************ 
    * Check for NULL pointers 
    ************************************************************************/ 
   if ((lpBhvrCom == (LPBHVRCOM) NULL) || 
       (lpVoid    == (LPVOID)    NULL) || 
       (lpDS      == (LPDSD5600165) NULL)) 
   { 
     jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL); 
     return ER_ERROR; 
   } 
   /************************************************************************ 
    * Set pointers 
    ************************************************************************/ 
   idJDBReturn = JDB_InitBhvr((void *) lpBhvrCom, &hUser, (JCHAR *) _J('\0'),JDEDB_COMMIT_AUTO);
    if(idJDBReturn==JDEDB_PASSED)
{ /* allocate the cache memory */
JDECMReturn = I5600165_CreateCache (  hUser, &hCache );
 jdeCacheOpenCursor(hCache, &hCacheCursor);
}
else
{
jdeSetGBRError(lpBhvrCom, lpVoid, (ID) 0, _J("3143")); 
return (ER_ERROR);
}
   /************************************************************************ 
    * Main Processing 
    ************************************************************************/ 

ParseNumericString (&mninsertCounter, _J("1"));
iSequenceNum = 1;
/*Sequence would the ordinal number in MO Texts*/
if (iSequenceNum < 0) 
  jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("164F"), (LPVOID) NULL);   
return (ER_ERROR);
else 
  
idJDBReturn = jdeGTGet_GenericTextKeyStr (lpDS->szNameObject, lpDS->GenericTextKey, iSequenceNum, &pMOData, &lTotalRec);
if (idJDBReturn == JDEDB_PASSED)
{
 memset((void *)(&dsCacheData), (int)(_J('\0')), sizeof(DS5600165C));  
 memset((void *)(&dsCacheKeys), (int)(_J('\0')), sizeof(KEY_DS5600165C));
if(JDECMReturn==JDECM_PASSED)
MathCopy(&dsCacheKeys.mnJobnumber,&lpDS->mnJobnumber);
jdeStrncpy((JCHAR *)dsCacheKeys.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
if (hCacheCursor)
{
JDECMReturn = jdeCacheFetchPosition(hCache, hCacheCursor,(void *) &dsCacheKeys,(short int)3,(void *) &dsCacheData,sizeof(DS5600165C));    
}
  else
  {
  lpDS->cSuppressErrorMessage=_J('1');
   }
/* Get Internal Number */
idReturnCode = jdeCallObject(_J("GetInternalNextNumber"), NULL, lpBhvrCom, (void *)lpVoid, &dsNextNumbers,(CALLMAP *)NULL, (int)0, (JCHAR *)NULL, (JCHAR *)NULL, (int)0);
if (idReturnCode != ER_SUCCESS)
{
jdeErrorSet(lpBhvrCom, lpVoid, (ID)0, _J("3143"), (LPVOID)NULL);
JDB_FreeBhvr(hUser);
return idReturnCode;
}
MathCopy(&lpDS->mnJobnumber,&dsNextNumbers.mnJobnumberA);
MathCopy(&dsCacheData.mnJobnumber,&lpDS->mnJobnumber);
jdeStrcpy((JCHAR *)dsCacheData.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
ZeroMathNumeric(&dsCacheData.mninsertCounter);
iLength = jdeStrlen(pMOData->pData);
jdeStrncpy(pMOData->pData, 
pMOData->pData,
DIM(pMOData->pData)-1);

iCounter = 0;
while ( iLoopIndex < iLength )
{
   dsCacheData.szMediaText[iCounter++] = pMOData->pData[iPosition++];
if(iLoopIndex%120==0)
{
jdeStrncpy(dsCacheData.szMediaText, 
pMOData->pData,
DIM(pMOData->pData)-1);
MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
JDECMReturn = jdeCacheAdd(hCache, (void *) &dsCacheData,(long int) sizeof(DS5600165C));
jdeStrcpy(dsCacheData.szMediaText,dsCacheData.GenericTextKey,DIM(dsCacheData.GenericTextKey)-1);
iCounter=0;
}
iLoopIndex++;
}
lpDS->cActionCode=_J('0');
if (JDECMReturn != JDECM_PASSED)
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("0002"), (LPVOID) NULL); 
return (ER_ERROR);
jdeCacheCloseCursor(hCache, hCacheCursor);
}
}
  else
  {
  jdeStrcpy(lpDS->szErrorMessageId,_J("CACHE CURSOR OPEN FAILED"));
  }
 }
else
  {
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("0002"), (LPVOID) NULL); 
return (ER_ERROR);
  }
}
/************************************************************************     
    * Function Clean Up 
    ************************************************************************/
if(hCacheCursor != (HJDECURSOR)NULL)
{
jdeCacheCloseCursor(hCache, hCacheCursor);
}
JDB_FreeBhvr(hUser);
return (ER_SUCCESS); 
/**************************************************************************
 *   Function:  I5600165_CreateCache
 *
 *      Notes:  This function will create the cache.
 *
 *    Returns:  Standard   ID
 *
 * Parameters:
 *              LPBHVRCOM      lpBhvrCom    Business Function Communications.
 *              LPVOID         lpVoid       Void Parameter  - DO NOT  USE!
 *
 **************************************************************************/
JDECM_RESULT   I5600165_CreateCache ( HUSER hUser, HCACHE *hCache )
{
  /************************************************************************
   *  Variable declarations
   ************************************************************************/
   JDECM_RESULT   JDECMReturn   =  JDECM_PASSED ;

  /************************************************************************
   * Declare structures
   *************************************************************************/
  /*  create 2 indexes */
    JDECMINDEXSTRUCT      dsCacheKeys1[1];
DS5600165C            dsKeys ;
KEY_DS5600165C   dsCacheKeys;
  /************************************************************************
   * Declare pointers
   ************************************************************************/
  /************************************************************************
   * Main Processing
   ************************************************************************/
   memset((void *)(&dsCacheKeys1), (int)(_J('\0')), sizeof(JDECMINDEXSTRUCT));
   memset((void *) (&dsKeys),       (int)( _J('\0')),  sizeof(DS5600165C));
   dsCacheKeys1->nNumSegments       = (short int)3;
dsCacheKeys1->CacheKey[0].nOffset= (short int)offsetof(DS5600165C, mnJobnumber);
dsCacheKeys1->CacheKey[0].nSize  = (short int) sizeof(dsKeys.mnJobnumber);
dsCacheKeys1->CacheKey[0].idDataType = EVDT_MATH_NUMERIC;
dsCacheKeys1->CacheKey[1].nOffset= (short int)offsetof(DS5600165C, szComputerID);
dsCacheKeys1->CacheKey[1].nSize  = (short int)DIM(dsKeys.szComputerID);
dsCacheKeys1->CacheKey[1].idDataType = EVDT_STRING;
dsCacheKeys1->CacheKey[2].nOffset= (short int)offsetof(DS5600165C, mninsertCounter);
dsCacheKeys1->CacheKey[2].nSize  = (short int) sizeof(dsKeys.mninsertCounter);
dsCacheKeys1->CacheKey[2].idDataType = EVDT_MATH_NUMERIC;
/*FormatMathNumeric(szJobNumberString, &lpDS->mnJobnumber);*/
JDECMReturn = jdeCacheInit(hUser, hCache, _J("B5600165"), dsCacheKeys1);
   return (JDECMReturn);
}  /* end of I5600165_CreateCache */
/************************************************************************** 
 *  Business Function:  RetrieveMediaextFromCache 
 * 
 *        Description:  Retrieve Media Object Text From Cache 
 * 
 *         Parameters: 
 *           LPBHVRCOM           lpBhvrCom    Business Function Communications 
 *           LPVOID              lpVoid       Void Parameter - DO NOT USE! 
 *           LPDSD5600           lpDS         Parameter Data Structure Pointer   
 * 
 *************************************************************************/ 
JDEBFRTN (ID) JDEBFWINAPI RetrieveMediaextFromCache (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165A lpDS)  
   /************************************************************************ 
    *  Variable declarations 
    ************************************************************************/ 
JDECM_RESULT   JDECMReturn   =  JDECM_PASSED ;
    JCHAR szJobNumberString[MAXLEN_MATH_NUMERIC] = {0};
HCACHE hCache;
HJDECURSOR hCacheCursor;
HUSER hUser;
ID idJDBReturn = JDEDB_PASSED;
MATH_NUMERIC mninsertCounter  ;
int iLoopIndex,n=0, numRows=0,nFirsttime;
   /************************************************************************ 
    * Declare structures 
    ************************************************************************/ 
    DS5600165C dsCacheData;
JDECMINDEXSTRUCT      dsCacheKeys1[1];
KEY_DS5600165C   dsCacheKeys;
   /************************************************************************ 
    * Declare pointers 
    ************************************************************************/ 
   /************************************************************************ 
    * Check for NULL pointers 
    ************************************************************************/ 
   if ((lpBhvrCom == (LPBHVRCOM) NULL) || 
       (lpVoid    == (LPVOID)    NULL) || 
       (lpDS      == (LPDSD5600165A) NULL)) 
   { 
     jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL); 
     return ER_ERROR; 
   } 
   /************************************************************************ 
    * Set pointers 
    ************************************************************************/ 
      idJDBReturn = JDB_InitBhvr((void *) lpBhvrCom, &hUser, (JCHAR *) _J('\0'),JDEDB_COMMIT_AUTO);
   if(idJDBReturn!=JDEDB_PASSED)
 {
 jdeSetGBRError(lpBhvrCom, lpVoid, (ID) 0, _J("3143")); 
return (ER_ERROR);
  }
   /************************************************************************ 
    * Main Processing 
    ************************************************************************/ 
 JDECMReturn = I5600165_CreateCache (  hUser, &hCache ); 
if(lpDS->cActionCode==_J('0'))
   { nFirsttime=1;
ParseNumericString (&mninsertCounter, _J("1"));
ZeroMathNumeric(&dsCacheData.mninsertCounter);
 /*Load Keys */
  MathCopy(&dsCacheKeys.mnJobnumber,&lpDS->mnJobnumber);
  jdeStrncpy((JCHAR *)dsCacheKeys.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
  MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
  MathCopy(&dsCacheData.mnJobnumber,&lpDS->mnJobnumber);
  jdeStrcpy((JCHAR *)dsCacheData.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
  MathCopy(&dsCacheData.mninsertCounter,&mninsertCounter);
  JDECMReturn=jdeCacheOpenCursor(hCache,&hCacheCursor);
}
/*MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);*/
if (hCacheCursor==NULL)
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("0002"), (LPVOID) NULL); 
return (ER_ERROR);
}
else
{  
memset((void *)(&dsCacheData), (int)(_J('\0')), sizeof(DS5600165C));  
memset((void *)(&dsCacheKeys), (int)(_J('\0')), sizeof(KEY_DS5600165C));
if(nFirsttime==1)
if(hCacheCursor)
{
MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
MathCopy(&dsCacheData.mninsertCounter,&mninsertCounter);
JDECMReturn = jdeCacheFetchPosition(hCache, hCacheCursor,&dsCacheKeys,(short int)0,&dsCacheData,sizeof(dsCacheData));
}
nFirsttime=0;
}
else
{
if(hCacheCursor)
{

MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
MathCopy(&dsCacheData.mninsertCounter,&mninsertCounter);
JDECMReturn = jdeCacheFetch(hCache, hCacheCursor, &dsCacheData ,(void *)NULL);
}
}
if (JDECMReturn == JDECM_PASSED)
{

jdeStrcpy((JCHAR *)lpDS->szMediaTextOutput,dsCacheData.szMediaText);
lpDS->cActionCode=_J('1');
}
else
{
JDECMReturn = I5600165_CreateCache (hUser, &hCache);
if (JDECMReturn == JDECM_PASSED)
{
jdeCacheTerminateAll(hUser, hCache);
}
lpDS->cActionCode=_J('0');
}
}
   /************************************************************************ 
    * Function Clean Up 
    ************************************************************************/ 
if(lpDS->cActionCode==_J('0'))
{
if(hCacheCursor!= NULL)
{  
jdeCacheCloseCursor (hCache, hCacheCursor);
}
   return (ER_SUCCESS); 
}

Friday, June 20, 2014

Encryption&Decryption of a Password using API’s in a C Business Function

I Created a Custom Business function to Encrypt and Decrypt the data using the API's

Firstly  created the corresponding data structure  & Created the Custom Table  F55ENC and store the encrypted value in the form of BLOBS.In Order the remain the backward compatible,Load library.
Created the Internal Function for encrypting & Decrypting tha data, by using the switch case.By using TripleDES(3DES) to open the handle library and define the Environment and finally close the handle library.
Triple DES (3DES) is the common name for the Triple Data Encryption Algorithm (TDEA or Triple DEA).
Code as Follows.

#include <jde.h>
typedef int (*LPFNEncryption3DES)(BYTE *outbuf, int *poutlen, JCHAR *inbuf,int inlen,JCHAR *encryptkey, int keylen,int type);
typedef int (*LPFNDecryption3DES)(JCHAR *outbuf, int *poutlen, BYTE *inbuf,  int inlen,JCHAR *encryptkey, int keylen,int type);
#define b57enc_c


/*****************************************************************************
 *    Source File:  b57enc
 *
 *    Description:  Encryption&Decryption Source File
 *
 *        History:
 *          Date        Programmer  SAR# - Description
 *          ----------  ----------  -------------------------------------------
 *   Author 28-04-2014  Unkno       Unknown  - 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 <b57enc.h>


/**************************************************************************
 *  Business Function:  EncryptionsDecryptions
 *
 *        Description:  Encryption and Decryption
 *
 *         Parameters:
 *           LPBHVRCOM           lpBhvrCom    Business Function Communications
 *           LPVOID              lpVoid       Void Parameter - DO NOT USE!
 *           LPDSD56             lpDS         Parameter Data Structure Pointer  
 *
 *************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI EncryptionsDecryptions (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD56ENC lpDS) 
 {
   /************************************************************************
    *  Variable declarations
    ************************************************************************/
       HUSER                hUser = (HUSER)NULL;
       ID                         idJDBReturn = JDEDB_PASSED;
       HREQUEST             hRequestF55ENC = (HREQUEST) NULL;
       void                 *blob;       
       ID                         idEncryptionError = ER_SUCCESS;
       MATH_NUMERIC         mnInsertcounter;
   /************************************************************************
    * Declare structures
    ************************************************************************/
       F55ENC               dsF55ENC = {0};
       DSD0000564           dsGetInternalNextNum;
   /************************************************************************
    * Declare pointers
    ************************************************************************/

   /************************************************************************
    * Check for NULL pointers
    ************************************************************************/
   if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
       (lpVoid    == (LPVOID)    NULL) ||
       (lpDS      == (LPDSD56ENC) NULL))
   {
     jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
     return ER_ERROR;
   }
 /**************************************************************************     
 * Call to the Initialize Behavior Routine     
 **************************************************************************/
   idJDBReturn = JDB_InitBhvr(lpBhvrCom, &hUser, (JCHAR *)NULL, JDEDB_COMMIT_AUTO); 
   if (idJDBReturn == JDEDB_FAILED)
   {                             
          jdeErrorSet(lpBhvrCom, lpVoid, (ID)0, _J("078S"), (LPVOID)NULL);
          return ER_ERROR; 
   }
   /************************************************************************
    * Set pointers
    ************************************************************************/

   /************************************************************************
    * Main Processing
    ************************************************************************/
       lpDS->cErrorCode = _J('0');
       idJDBReturn = JDB_OpenTable(hUser, NID_F55ENC, ID_F55ENC_JOBS_INERTC, NULL, 0, NULL, &hRequestF55ENC);
       if(hRequestF55ENC != (HREQUEST) NULL)
        {
              jdeCallObject(_J("GetInternalNextNumber"), NULL, lpBhvrCom, (void *) lpVoid, (void *) &dsGetInternalNextNum, (CALLMAP *) NULL, (int) 0, (JCHAR *) NULL,(JCHAR *) NULL, (int) 0);
              MathCopy(&dsF55ENC.enjobs, &dsGetInternalNextNum.mnJobnumberA);
                     IncrementMathNumeric(&mnInsertcounter, 1);
                     MathCopy(&dsF55ENC.eninsertc,&mnInsertcounter);
        
               /* Set values*/
               jdeStrcat(lpDS->szPassword, _J("\0"));                      
               idEncryptionError = I57enc_EncryptDecrypt(Encrypt_Operation, lpDS->szPassword, &dsF55ENC, hRequestF55ENC, lpBhvrCom, lpVoid);
               if(idEncryptionError == ER_SUCCESS)           
               {                                             
                      jdeStrncpy (dsF55ENC.enapluser, lpDS->szCreditCardNumber,DIM(dsF55ENC.enapluser));
                      jdeStrncpy (dsF55ENC.enjobn, lpDS->szMachine, DIM(dsF55ENC.enjobn));     
                      dsF55ENC.enupmj = lpDS->jdDateUpdated;                      
                      MathCopy(&dsF55ENC.enupmt, &lpDS->mnTimeLastUpdated);
                      idJDBReturn = JDB_InsertTable(hRequestF55ENC, NID_F55ENC, (ID) 0,   &dsF55ENC);             
                      if(idJDBReturn != JDEDB_PASSED)        
                      {                        
                            /*Insert Failed Set error*/     
                            lpDS->cErrorCode = _J('1');     
                      }           
               }           
               else        
               {
                      /*Encryption Failed Set error*/        
                      lpDS->cErrorCode = _J('4');                                              
        }           
}

      
   /************************************************************************
    * Function Clean Up
    ************************************************************************/
/* I57enc_CloseF55ENC (hRequestF55ENC);*/
        JDB_CloseTable(hRequestF55ENC); 
        JDB_FreeBhvr(hUser);
   return (!idJDBReturn);
}
 /**************************************************************************** *
 Function:    I55enc_CloseF55ENC *
 *         Notes:    Closes the table *
 *       Returns:    Success / Failure *
 * Parameters:       hrequest
 ****************************************************************************/
/*void I55enc_CloseF55ENC (HREQUEST hRequestF55ENC)
{
       if (hRequestF55ENC  != (HREQUEST) NULL)
       {            
              JDB_CloseTable(hRequestF55ENC);           
       }     
}
/* Internal function comment block */
/**************************************************************************
 *   Function:  I57enc_a   // Replace "xxxxxxx" with source file number
 *                           // and "a" with the function name
 *      Notes:
 *
 *    Returns:
 *
 * Parameters:
 **************************************************************************/
 ID I57enc_EncryptDecrypt(int Operation, JCHAR* szPassword, F55ENC* dsF55ENC, HREQUEST hRequestF55ENC, LPBHVRCOM lpBhvrCom, LPVOID lpVoid)
 {    
        JCHAR EKey[71]={"12345678967"};
        /*JCHAR      EncryptionKey={"12345678967"};*/
        int          EKeyLen=11;  
        int          PasswordLen=0;      
        BYTE         EncryptedPassword[1024]={0};            
        int          EncryptedPasswordLen= 0;  
        JCHAR DecryptedPassword[70]={0};
        int          DecryptedPasswordLen=0;          
        JCHAR               szLib[256]           = {0};
        JCHAR               szConvertLib[256]    = {0};
        HINSTANCE       hLibrary;
        LPFNEncryption3DES          lpDoEncryption     = NULL; 
        LPFNDecryption3DES          lpDoDecryption     = NULL;      
        int iResult = 0;   
        ENCRYPTEDBLOB       myblobstructure = {0};
        DBREF dbRef = {0}; 
        int          iKeyVersion=0;      
        
        /*In order to remain backwards compatable, LoadLib*/      
       #if defined (JDENV_UNIX)         
        jdeStrcpy(szConvertLib, _J("jdeknet"));  
        jdeWriteLogEntry(JDEDEBUGLOG, _J("B9801000"), __FILE__, __LINE__, 0, _J("F98OWSEC Maintain Security LoadLib jdeknet"));
#else     
        jdeStrcpy(szConvertLib, _J("JDEKRNL")); 
        jdeWriteLogEntry(JDEDEBUGLOG, _J("B9801000"), __FILE__, __LINE__, 0, _J("F98OWSEC Maintain Security LoadLib JDEKRNL"));   
#endif      
        BuildFullLibName( szConvertLib, szLib );    
        hLibrary = LoadLibrary ( szLib );     
        if( !hLibrary )    
        {      
               jdeWriteLogEntry(JDEDEBUGLOG, _J("B9801000"), __FILE__, __LINE__, 0, _J("F98OWSEC Maintain Security LoadLib Failed"));
               return ER_ERROR;     
        }      
#if defined (JDENV_PC)
        lpDoEncryption = (LPFNEncryption3DES) jdeGetProcAddress(hLibrary, _J("_jdeEncryptWKey@28"));  
        lpDoDecryption = (LPFNDecryption3DES) jdeGetProcAddress(hLibrary, _J("_jdeDecryptWKey@28"));  
#else       
        lpDoEncryption = (LPFNEncryption3DES) jdeGetProcAddress(hLibrary, _J("jdeEncryptWKey"));  
        lpDoDecryption = (LPFNDecryption3DES) jdeGetProcAddress(hLibrary, _J("jdeDecryptWKey"));  
#endif              
        /**********Close hlibrary handle******************/  
        FreeLibrary(hLibrary);   
        hLibrary = 0L;           
        if (lpDoEncryption != NULL && lpDoDecryption != NULL)  
        {
               /*Do encryption/decryption*/    
               switch (Operation)       
               {                  
               case Encrypt_Operation:
                     /* if(lpDS->cErrorCode == _J('0'))
                           {
                                  jdeStrncpy(EKey, EncryptionKey, DIM(EKey));
                                  EKeyLen = jdeStrlen(EKey);*/
                                                      
                            /*Encrypt the Password*/               
                            PasswordLen = jdeStrlen(szPassword);
                            /*ensure to pass the reference address of EncryptedLen */          
                            iResult=lpDoEncryption(EncryptedPassword,&EncryptedPasswordLen,szPassword,PasswordLen,EKey,EKeyLen,1);      
                            /*return the encrypted value and length in dstr*/                  
                            jdeNIDcpy(dbRef.szTable,NID_F55ENC);          
                            jdeNIDcpy(dbRef.szDict,NID_APLPSWD);          
                             dbRef.idInstance = 0;                  
                            dsF55ENC->enaplpswd.lpValue = JDB_SetBLOBSize(hRequestF55ENC,dbRef,sizeof(myblobstructure));      
                            dsF55ENC->enaplpswd.lSize = sizeof(myblobstructure);                      
                            dsF55ENC->enaplpswd.lMaxSize= 2048;                                
                            memcpy(myblobstructure.bEncryptedPassword,EncryptedPassword,EncryptedPasswordLen);      
                            myblobstructure.iEncPasswordSize=EncryptedPasswordLen;                           
                           /* myblobstructure.iKeyVersion=dsD55enc.nEncryptionKeyVersion;       */      
                            memcpy(dsF55ENC->enaplpswd.lpValue,&myblobstructure,sizeof(myblobstructure));
                     /* }
                      else
                      {
                            return ER_ERROR;   
                      } */
                       /*return ER_ERROR;*/
                      break;      
               case Decrypt_Operation:  
                      /*set the encrypted value*/
                      memcpy(EncryptedPassword,((ENCRYPTEDBLOB*)(dsF55ENC->enaplpswd.lpValue))->bEncryptedPassword,sizeof(EncryptedPassword));
                      EncryptedPasswordLen = ((ENCRYPTEDBLOB*)(dsF55ENC->enaplpswd.lpValue))->iEncPasswordSize;                             
                            /*ensure to pass the reference address of DecryptedLen */                 
                            iResult=lpDoDecryption(DecryptedPassword,&DecryptedPasswordLen,EncryptedPassword,EncryptedPasswordLen,EKey,EKeyLen,1);                                 
                            /*return the Password*/                       
                            jdeStrcpy (szPassword, DecryptedPassword);                  
                            return ER_ERROR;   
                          
                      break;             
               default:           
                      jdeWriteLogEntry(JDEDEBUGLOG, _J("B9801000"), __FILE__, __LINE__, 0, _J("Invalid action"));    
                      return ER_ERROR;                
                      break;             
               }
               if(iResult==0)
               {                  
                      jdeVWriteLogEntry(_J("B9801000"), __FILE__, __LINE__, 0, _J("Failed on encryption/decryption")); 
                      return ER_ERROR;         
               }    
        }    
        else 
        {           
               /*do normal thing without encryption/decryption*/    
               /*No Encryption Available so just save or return it as is*/
               switch (Operation)       
               {                  
               case Encrypt_Operation:         
                      PasswordLen = (jdeStrlen(szPassword)+1) *  sizeof(JCHAR);   
                      jdeNIDcpy(dbRef.szTable,NID_F55ENC);                        
                      jdeNIDcpy(dbRef.szDict,NID_APLPSWD);   
                      dbRef.idInstance = 0;                                
                      dsF55ENC->enaplpswd.lpValue = JDB_SetBLOBSize(hRequestF55ENC, dbRef, PasswordLen);
                      memcpy(dsF55ENC->enaplpswd.lpValue,szPassword,PasswordLen);                     
                      dsF55ENC->enaplpswd.lSize = PasswordLen;                                               
                      break;                          
               case Decrypt_Operation:
                      jdeStrcpy (szPassword, ((JCHAR*)dsF55ENC->enaplpswd.lpValue));                                
                      break;                    
               default:           
                      break;             
               }    
        }           
        return ER_SUCCESS;
}
/* Internal function comment block */
/**************************************************************************
 *   Function:  Ixxxxxxx_a   // Replace "xxxxxxx" with source file number
 *                           // and "a" with the function name
 *      Notes:
 *
 *    Returns:
 *
 * Parameters:
 **************************************************************************/


  

and