project QadFinancials > class BBudgetLink > method ApiCreateOrUpdateBudgetLink
Description
This method allows other components to insert or update records in the class-table
Parameters
tApiBudgetLink | input | temp-table | ApiBudgetLink; instanceless temp-table used as input table for method ApiCreateOrUpdateBudgetLink |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bbudgetlink.p)
/* ================================================================ */
/* Return if no data is passed */
/* ================================================================ */
if not can-find (first tApiBudgetLink)
then return.
/* ================================================================ */
/* Set Return-status = Default-error */
/* ================================================================ */
assign oiReturnStatus = -98.
/* ================================================================ */
/* Empty the instance */
/* ================================================================ */
<M-1 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BBudgetLink>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end. /* if viFcReturnSuper <> 0 */
/* ============ */
/* Start query */
/* ============ */
<Q-11 run BudgetLinkByBudgetPerWBS (Start) in BBudgetLink >
/* ======================================================================= */
/* Go through the input and create/update a record for every input-record */
/* ======================================================================= */
CREATIONBLOCK : DO :
for each tApiBudgetLink :
/* ====================================================== */
/* If the record we are looking for is not yet in loaded: */
/* Try to Load the record the record based on input */
/* 1. Budget_ID + BudgetPeriod_ID + BudgetWBS_ID */
/* If no record exists based on the input then create it */
/* After this block tBudgetLink is available!!!! */
/* ====================================================== */
find first tBudgetLink where
tBudgetLink.Budget_ID = tApiBudgetLink.Budget_ID and
tBudgetLink.BudgetWBS_ID = tApiBudgetLink.BudgetWBS_ID and
tBudgetLink.BudgetPeriod_ID = tApiBudgetLink.BudgetPeriod_ID
no-lock no-error.
if not available tBudgetLink
then do :
if tApiBudgetLink.Budget_ID <> 0 and
tApiBudgetLink.BudgetWBS_ID <> 0 and
tApiBudgetLink.BudgetPeriod_ID <> 0 and
tApiBudgetLink.Budget_ID <> ? and
tApiBudgetLink.BudgetWBS_ID <> ? and
tApiBudgetLink.BudgetPeriod_ID <> ?
then do :
<Q-6 run BudgetLinkByBudgetPerWBS (all) (Read) (Cache)
(input ?, (BudgetLinkID)
input tApiBudgetLink.Budget_ID, (BudgetID)
input tApiBudgetLink.BudgetWBS_ID, (BudgetWBSID)
input tApiBudgetLink.BudgetPeriod_ID, (FromBudgetPeriodID)
input tApiBudgetLink.BudgetPeriod_ID, (ToBudgetPeriodID)
output dataset tqBudgetLinkByBudgetPerWBS) in BBudgetLink >
find first tqBudgetLinkByBudgetPerWBS where
tqBudgetLinkByBudgetPerWBS.tiBudget_ID = tApiBudgetLink.Budget_ID and
tqBudgetLinkByBudgetPerWBS.tiBudgetWBS_ID = tApiBudgetLink.BudgetWBS_ID and
tqBudgetLinkByBudgetPerWBS.tiBudgetPeriod_ID = tApiBudgetLink.BudgetPeriod_ID
no-lock no-error.
if available tqBudgetLinkByBudgetPerWBS
then do :
<M-8 run DataLoad
(input '':U (icRowids),
input string(tqbudgetLinkByBudgetPerWBS.tiBudgetLink_ID) (icPkeys),
input '':U (icObjectIds),
input '' (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BBudgetLink>
if viFcReturnSuper <> 0
then do :
assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave CREATIONBLOCK.
end. /* if viFcReturnSuper <> 0 */
find first tBudgetLink where
tBudgetLink.BudgetLink_ID = tqbudgetLinkByBudgetPerWBS.tiBudgetLink_ID
no-error.
if not available tBudgetLink
then do :
assign viLocalReturnStatus = -3
vcMessage = trim(substitute(#T-13'Internal error: the budget link could not be loaded although the record could be found in the database based on its ID (&1).':200(736)T-13#,string(tqbudgetLinkByBudgetPerWBS.tiBudgetLink_ID))).
<M-9 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1814':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBudgetLink>
Leave CREATIONBLOCK.
end. /* if not available tBudgetLink */
end. /* if available tqBudgetLinkByBudgetPerWBS */
end. /* if tApiBudgetLink.Budget_ID <> 0 and */
end. /* if not available tBudgetLink */
find first tBudgetLink where
tBudgetLink.Budget_ID = tApiBudgetLink.Budget_ID and
tBudgetLink.BudgetWBS_ID = tApiBudgetLink.BudgetWBS_ID and
tBudgetLink.BudgetPeriod_ID = tApiBudgetLink.BudgetPeriod_ID
no-lock no-error.
if not available tBudgetLink
then do :
<M-10 run AddDetailLine (input 'BudgetLink':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BBudgetLink>
assign tBudgetLink.Budget_ID = tApiBudgetLink.Budget_ID
tBudgetLink.BudgetWBS_ID = tApiBudgetLink.BudgetWBS_ID
tBudgetLink.BudgetPeriod_ID = tApiBudgetLink.BudgetPeriod_ID.
end. /* if not available tBudgetLink */
else assign tBudgetLink.tc_Status = "C":U.
/* ================================ */
/* Update the content of the record */
/* ================================ */
assign tBudgetLink.BudgetLinkActualTC = tBudgetLink.BudgetLinkActualTC + (if tApiBudgetLink.BudgetLinkActualTC = ? then 0 else tApiBudgetLink.BudgetLinkActualTC)
tBudgetLink.BudgetLinkActualQTY = tBudgetLink.BudgetLinkActualQTY + (if tApiBudgetLink.BudgetLinkActualQTY = ? then 0 else tApiBudgetLink.BudgetLinkActualQTY)
tBudgetLink.BudgetLinkActualSalesTC = tBudgetLink.BudgetLinkActualSalesTC + (if tApiBudgetLink.BudgetLinkActualSalesTC = ? then 0 else tApiBudgetLink.BudgetLinkActualSalesTC)
tBudgetLink.BudgetLinkActualSalesQTY = tBudgetLink.BudgetLinkActualSalesQTY + (if tApiBudgetLink.BudgetLinkActualSalesQTY = ? then 0 else tApiBudgetLink.BudgetLinkActualSalesQTY)
tBudgetLink.BudgetLinkCommitTC = tBudgetLink.BudgetLinkCommitTC + (if tApiBudgetLink.BudgetLinkCommitTC = ? then 0 else tApiBudgetLink.BudgetLinkCommitTC)
tBudgetLink.BudgetLinkCommitQTY = tBudgetLink.BudgetLinkCommitQTY + (if tApiBudgetLink.BudgetLinkCommitQTY = ? then 0 else tApiBudgetLink.BudgetLinkCommitQTY).
end. /* for each tApiQQBudgetLinkActual */
END. /* CREATIONBLOCK */
/* ============ */
/* Stop query */
/* ============ */
<Q-12 run BudgetLinkByBudgetPerWBS (Stop) in BBudgetLink >
/* ================ */
/* Check for errors */
/* ================ */
if viLocalReturnStatus <> 0
then do :
assign oiReturnStatus = viLocalReturnStatus.
if oiReturnStatus < 0 then return.
end. /* if viLocalReturnStatus <> 0 */
/* ================================================================ */
/* Perfom Validation, AdditionalUpdates and DataSave */
/* ================================================================ */
<M-2 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBudgetLink>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end. /* if viFcReturnSuper <> 0 */
<M-3 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBudgetLink>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end. /* if viFcReturnSuper <> 0 */
<M-4 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBudgetLink>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end. /* if viFcReturnSuper <> 0 */
/* ================================================================ */
/* Set Return-status = OK */
/* ================================================================ */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BBudgetLink".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiCreateOrUpdateBudgetLink".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bbudgetlink.apicreateorupdatebudgetlink.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tApiBudgetLink").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.