Você está na página 1de 8

#include <jde.

h>
#define b5503_c
/*****************************************************************************
*
Source File: b5503
*
*
Description: Database Functions - BF Source File
*
*
History:
*
Date
Programmer
SAR# - Description
*
---------- --------------------------------------------------* Author 08/06/2007 Mithun Sheth
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 <b5503.h>
/************************************************************************
* Global Variable declarations
************************************************************************/
/*Notice the reason for declaring the HREQUEST, HUSER variables at Globa
l level.
This is so that both the Functions; RetrieveAddressInfo & UpdateAddressI
nfo can use it.
Moreso, since the Function UpdateAddressInfo calls the Function Retrieve
AddressInfo,
there is no need to re-assign the HREQUEST & HUSER for the same Table an
d same No. of columns
thus resulting in code resuability.*/
ID
ID
HREQUEST
HUSER

JDEDBReturn
= ER_SUCCESS;
JDEDBResult
= JDEDB_PASSED;
hRequestF0101 = (HREQUEST)NULL;
hUser
= (HUSER)NULL;

/************************************************************************
/**************************************************************************
* Business Function: RetrieveAddressInfo
*
*
Description: Retrieve Address Info - BF

*
*
*
*
*

Parameters:
LPBHVRCOM
LPVOID
LPDSD55

lpBhvrCom
lpVoid
lpDS

Business Function Communications


Void Parameter - DO NOT USE!
Parameter Data Structure Pointer

*
*************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI RetrieveAddressInfo (LPBHVRCOM lpBhvrCom, LPVOID lpVoi
d, LPDSD5503 lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
ushort
NID

nNumColsF0101 = 3;
szColsF0101[3] = {NID_AN8, NID_AT1, NID_ALPH};

/************************************************************************
* Declare structures
************************************************************************/
/*This is Key Structure of the Primary Key from the file F0101.h */
KEY1_F0101
dsKey1F0101 = {0};
/*This is the Columns Structure from the file B5503.h.
This shall be used for storing the fetch results
If all columns need to be fetched then better create structure of type F
0101 from the file F0101.h*/
DSF0101
dsColsF0101 = {0};
/***********************************************************************
*
* Declare pointers
************************************************************************/
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid
== (LPVOID)
NULL) ||
(lpDS
== (LPDSD5503)
NULL))
{
/*Initialize lpDS Error Code value as '0' (ERROR). This would be return
ed
back to the calling Program */
lpDS->cErrorCode = '0';
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}
/************************************************************************
* Set pointers
************************************************************************/

/*Initialize lpDS Error Code value as '1' (NO ERROR). This would be retu
rned
back to the calling Program. This is the default value indicating SUCCES
S.*/
lpDS->cErrorCode = '1';
/************************************************************************
* Main Processing
************************************************************************/
/*Initialize and retrive environment and user handles */
JDEDBReturn = JDB_InitBhvr(lpBhvrCom, &hUser, (JCHAR *)NULL, JDEDB_COMMIT_AUT
O);
if(JDEDBReturn == ER_ERROR)
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("3143"), (LPVOID) NUL
L);
/*Initialize lpDS Error Code value as '0' (ERROR). This would be
returned
back to the calling Program */
lpDS->cErrorCode = '0';
return ER_ERROR;
}
/*Open the F0101 table */
JDEDBResult = JDB_OpenTable(hUser, NID_F0101, ID_F0101_ADDRESS,
szColsF0101, nNu
mColsF0101, (JCHAR *)NULL,
&hRequestF0101);
if(JDEDBResult != JDEDB_PASSED)
{
/*Set Error if Open Table failed */
jdeErrorSet(lpBhvrCom, lpVoid, (ID)0, _J("3143"), (LPVOID)NULL);
/*Initialize lpDS Error Code value as '0' (ERROR). This would be
returned
back to the calling Program */
lpDS->cErrorCode = '0';
/*Free all behaviour handles & requests */
JDB_FreeBhvr(hUser);
return ER_ERROR;
}
else
{
/*Clear Memory of DSF0101 Data Structure */
JDB_ClearColBuffer(hRequestF0101, (void *)&dsColsF0101);
/*Allocate Memory to Pointer of Key Data Structure & initialize
it with 0*/
memset((void *)(&dsKey1F0101),(int)('\0'), sizeof(KEY1_F0101));
/*Copy lpDS Data Structure value (Address No) to Key Data Struct
ure to form
the Fetch Statement (basically to form the WHERE clause of a SEL

ECT Statement */
MathCopy((LPMATH_NUMERIC)&(dsKey1F0101.aban8), (LPMATH_NUMERIC)&
(lpDS->mnAddressNumber));
/*Perform Fetch based on Key Strucutre loaded above. This is equ
ivalent to FetchSingle */
JDEDBResult = JDB_FetchKeyed(hRequestF0101, ID_F0101_ADDRESS,
&dsKey1F
0101, 1, &dsColsF0101, FALSE);
/*The below statements can also be used instead of JDB_FetchKeye
d above.
This shall be eqivalent of Select & FetchNext combination */
/*JDEDBReturn = JDB_SelectKeyed(hRequestF0101, ID_F0101_ADDRESS
,&dsKey1F0101, 1);
JDEDBReturn = JDB_FetchMatchingKey(hRequestF0101, &dsKey1F0101,
1, &dsColsF0101, FALSE);*/
if (JDEDBResult != JDEDB_PASSED)
{
/*To set the Error ONLY when the Function is called as a
Stand Alone.*/
if(lpDS->cModeCode == '1')
{
/*Set Error on the FC Address No if Fetch failed
. Note the use of IDERRmnAddressNumber_1 here. */
jdeErrorSet(lpBhvrCom, lpVoid, (ID)IDERRmnAddres
sNumber_1, _J("007P"), (LPVOID)NULL);
/*Initialize lpDS Error Code value as '0' (ERROR
). This would be returned
back to the calling Program */
lpDS->cErrorCode = '0';
return ER_ERROR;
}
}
else
{
/*Load the Search Type & Alpha Name in the lpDS Data Str
ucture */
jdeStrcpy(lpDS->szAddressType1, (JCHAR *)dsColsF0101.aba
t1, sizeof(lpDS->szAddressType1));
jdeStrcpy(lpDS->szNameAlpha, (JCHAR *)dsColsF0101.abalph
, sizeof(lpDS->szNameAlpha));
/*Even the below copy statement can be used instead of j
deStrcpy */
/*strncpy(lpDS->szAddressType1, (const char *)dsColsF010
1.abat1, sizeof(lpDS->szAddressType1));
strncpy(lpDS->szNameAlpha, (const char *)dsColsF0101.aba
lph, sizeof(lpDS->szNameAlpha));*/
}
}
/************************************************************************
* Function Clean Up
************************************************************************/

/*If the Function RetrieveAddressInfo is being called as standalone then


to release the Handles;
HREQUEST & HUSER. If called from the Function UpdateAddressInfo, then to
retain them as they shall
be used within UpdateAddressInfo.*/
if(lpDS->cModeCode == '1')
{
/*Free the request handle*/
JDB_CloseTable(hRequestF0101);
/* Free all behavior handles and requests */
JDB_FreeBhvr(hUser);
}
return (ER_SUCCESS);
}
/**************************************************************************
* Business Function: UpdateAddressInfo
*
*
Description: Update Address Info - BF
*
*
Parameters:
*
LPBHVRCOM
lpBhvrCom
Business Function Communications
*
LPVOID
lpVoid
Void Parameter - DO NOT USE!
*
LPDSD55
lpDS
Parameter Data Structure Pointer
*
*************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI UpdateAddressInfo (LPBHVRCOM lpBhvrCom, LPVOID lpVoid,
LPDSD5504 lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
/***********************************************************************
*
* Declare structures
************************************************************************/
/************************************************************************
* Declare pointers
************************************************************************/
DSD5503

lpDS5503

DSF0101

UpdateColsF0101 =

{0};

{0};

/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid
== (LPVOID)
NULL) ||
(lpDS
== (LPDSD5504)
NULL))
{

/*Initialize lpDS Error Code value as '0' (ERROR). This would be


returned
back to the calling Program */
lpDS->cErrorCode = '0';
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}
/************************************************************************
* Set pointers
************************************************************************/
/*Initialize lpDS Error Code value as '1' (NO ERROR). This would be retu
rned
back to the calling Program. This is the default value indicating SUCCES
S.*/
lpDS->cErrorCode = '1';
/*Allocate Memory to Pointer of Data Structure for RetrieveAddressInfo & ini
tialize it with 0*/
memset((void *)(&lpDS5503),(int)('\0'), sizeof(DSD5503));
/*Clear Memory of DSF0101 Data Structure */
JDB_ClearColBuffer(hRequestF0101, (void *)&UpdateColsF0101);
/*Load the value of Address No. passed to the Function to the DS of the
Function - RetrieveAddressInfo.*/
MathCopy((LPMATH_NUMERIC)&(lpDS5503.mnAddressNumber), (LPMATH_NUMERIC)&(
lpDS->mnAddressNumber));
/*Load the value of Mode Code ('2') to the DS of the Function - Retrieve
AddressInfo indicating
that the Function - RetrieveAddressInfo is being called from this Functi
on.*/
lpDS5503.cModeCode = '2';
/************************************************************************
* Main Processing
************************************************************************/
JDEDBReturn = jdeCallObject (_J("RetrieveAddressInfo"), (LPFNBHVR) NULL,
lpBhvrCom, lpVoid,
(void *)&lpDS55
03, (CALLMAP *)NULL, (int)0, (JCHAR *)NULL, (JCHAR *)NULL, (int)0);
if(JDEDBResult != JDEDB_PASSED)
{
/*Insert the record if the record does not exist & Mode Code is
set to Insert.*/
if(lpDS->cModeCode == '1')
{
MathCopy((LPMATH_NUMERIC)&(UpdateColsF0101.aban8), (LPMA
TH_NUMERIC)&(lpDS->mnAddressNumber));
jdeStrcpy(UpdateColsF0101.abat1, (JCHAR *)lpDS->szAddres
sType1, sizeof(lpDS->szAddressType1));
jdeStrcpy(UpdateColsF0101.abalph, (JCHAR *)lpDS->szNameA
lpha, sizeof(lpDS->szNameAlpha));
JDEDBResult = JDB_InsertTable(hRequestF0101, NID_F0101,

(ID)0, &UpdateColsF0101);
}
else
{
/*Set Error if record does not exists and Mode Code is s
et for Update/Delete.*/
jdeErrorSet(lpBhvrCom, lpVoid, (ID)IDERRmnAddressNumber_
5, _J("007P"), (LPVOID)NULL);
/*Initialize lpDS Error Code value as '0' (ERROR). This
would be returned
back to the calling Program */
lpDS->cErrorCode = '0';
return ER_ERROR;
}
}
else
{
switch(lpDS->cModeCode)
{
/*Set Error if Mode Code is for Insert and if the record
already exists.*/
case '1': jdeErrorSet(lpBhvrCom, lpVoid, (ID)IDERRmnAddr
essNumber_5, _J("183J"), (LPVOID)NULL);
/*Initialize lpDS Error Code value as
'0' (ERROR). This would be returned
back to the calling Program */
lpDS->cErrorCode = '0';
return ER_ERROR;
/*Update the record if the Mode Code is set to Update.*/
case '2': MathCopy((LPMATH_NUMERIC)&(UpdateColsF0101.aba
n8), (LPMATH_NUMERIC)&(lpDS->mnAddressNumber));
jdeStrcpy(UpdateColsF0101.abat1, (JCHA
R *)lpDS->szAddressType1, sizeof(lpDS->szAddressType1));
jdeStrcpy(UpdateColsF0101.abalph, (JCH
AR *)lpDS->szNameAlpha, sizeof(lpDS->szNameAlpha));
JDEDBResult = JDB_UpdateTable(hRequest
F0101, NID_F0101, (ID)0, (ID)NULL, (void *)NULL, 1, &UpdateColsF0101);
break;
/*Delete the record if the Mode Code is set to Delete.*/
case '3': MathCopy((LPMATH_NUMERIC)&(UpdateColsF0101.aba
n8), (LPMATH_NUMERIC)&(lpDS->mnAddressNumber));
JDEDBResult = JDB_DeleteTable(hRequest
F0101, NID_F0101, (ID)0, (ID)NULL, &UpdateColsF0101, 1);
break;
}
}
/************************************************************************
* Function Clean Up
************************************************************************/

/*Free the request handle */


JDB_CloseTable(hRequestF0101);
/*Free all behavior handles and requests */
JDB_FreeBhvr(hUser);
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:
**************************************************************************/

Você também pode gostar