project QadFinancials > class BBudgetLinkAcc > method ApiCreateOrUpdateBudgetLinkAcc

Description

This method allows other components to insert or update records in the class-table.


Parameters


tApiBudgetLinkAccinputtemp-tableApiBudgetLinkAcc; instanceless temp-table used as input table for method ApiCreateOrUpdateBudgetLinkAcc
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BQBudgetActual.AdditonalUpdatesDelete


program code (program9/bbudgetlinkacc.p)

define buffer bApiBudgetLinkAcc for tApiBudgetLinkAcc.

/* ================================================================ */
/* Return if no data is passed                                      */
/* ================================================================ */
if not can-find (first tApiBudgetLinkAcc) 
then return.

/* ================================================================ */
/* Set Return-status = Default-error                                */
/* ================================================================ */
assign oiReturnStatus = -98.

/* ================================================================ */
/* Start Queries                                                    */
/* ================================================================ */
<Q-13 run BudgetWBSByBudgetIDWBSCode  (Start) in BBudget >
<Q-16 run BudgetLinkAccByPeriodWBS  (Start) in BBudgetLinkAcc >

/* ================================================================ */
/* Empty the instance                                               */
/* ================================================================ */
<M-2 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BBudgetLinkAcc>
if viFcReturnSuper <> 0 
then do :
    assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then return.
end.  /* if viFcReturnSuper <> 0 */

/* ================================================================ */
/* Temporary table contains just list WBS topics, extend this list  */
/* about all parent WBS topics                                      */
/* ================================================================ */
repeat preselect each tApiBudgetLinkAcc:    
    
    find next tApiBudgetLinkAcc no-error.
    if not available tApiBudgetLinkAcc
    then leave.

    assign viBudgetWBSID = tApiBudgetLinkAcc.BudgetWBS_ID.
    
    do while viBudgetWBSID <> ? and viBudgetWBSID <> 0:
        
        /* Get BudgetWBS definition */
        <Q-12 run BudgetWBSByBudgetIDWBSCode (all) (Read) (NoCache)
          (input ?, (BudgetID)
           input viBudgetWBSID, (BudgetWBSID)
           input ?, (BudgetWBSCode)
           input ?, (ParentBudgetWBSID)
           input ?, (BudgetCode)
           input ?, (BudgetStatus)
           output dataset tqBudgetWBSByBudgetID) in BBudget >
    
        find first tqBudgetWBSByBudgetID no-lock no-error.
        if available tqBudgetWBSByBudgetID                 and
           tqBudgetWBSByBudgetID.tiParentBudgetWBS_ID <> ? and
           tqBudgetWBSByBudgetID.tiParentBudgetWBS_ID <> 0
        then do:
            assign viBudgetWBSID = tqBudgetWBSByBudgetID.tiParentBudgetWBS_ID.
            
            /* Create record for processing of parent Budget WBS */
            create bApiBudgetLinkAcc.
            assign bApiBudgetLinkAcc.BudgetWBS_ID = viBudgetWBSID
                   bApiBudgetLinkAcc.tc_Rowid     = string(rowid(bApiBudgetLinkAcc)).
            buffer-copy tApiBudgetLinkAcc except BudgetWBS_ID tc_Rowid to bApiBudgetLinkAcc.
        end.
        else do:
            /* Current BudgetWBS is root one */
            assign viBudgetWBSID = ?.
        end.
    end.
end.

/* ======================================================================= */
/* Create list of existing records in DB and create new instnace records   */
/* for not existing                                                        */
/* ======================================================================= */
assign vcList = "":U.

for each tApiBudgetLinkAcc:
    find first tBudgetLinkAcc where
               tBudgetLinkAcc.Budget_ID       = tApiBudgetLinkAcc.Budget_ID    and 
               tBudgetLinkAcc.BudgetWBS_ID    = tApiBudgetLinkAcc.BudgetWBS_ID and 
               tBudgetLinkAcc.Period_ID       = tApiBudgetLinkAcc.Period_ID    and
               tBudgetLinkAcc.Layer_ID        = tApiBudgetLinkAcc.Layer_ID
               no-lock no-error.
        
    if not available tBudgetLinkAcc
    then do:
        /* Try to find existing record */ 
        <Q-17 run BudgetLinkAccByPeriodWBS (all) (Read) (NoCache)
           (input tApiBudgetLinkAcc.Budget_ID, (Budget_ID)
            input tApiBudgetLinkAcc.Period_ID, (Period_ID)
            input tApiBudgetLinkAcc.BudgetWBS_ID, (BudgetWBS_ID)
            input tApiBudgetLinkAcc.Layer_ID, (Layer_ID)
            output dataset tqBudgetLinkAccByPeriodWBS) in BBudgetLinkAcc >
        find first tqBudgetLinkAccByPeriodWBS where
                   tqBudgetLinkAccByPeriodWBS.tiBudget_ID       = tApiBudgetLinkAcc.Budget_ID    and 
                   tqBudgetLinkAccByPeriodWBS.tiBudgetWBS_ID    = tApiBudgetLinkAcc.BudgetWBS_ID and 
                   tqBudgetLinkAccByPeriodWBS.tiPeriod_ID       = tApiBudgetLinkAcc.Period_ID    and
                   tqBudgetLinkAccByPeriodWBS.tiLayer_ID        = tApiBudgetLinkAcc.Layer_ID
                   no-lock no-error.
        if not available tqBudgetLinkAccByPeriodWBS
        then do:
            <M-18 run AddDetailLine (input  'BudgetLinkAcc':U (icTable), 
                            input  '':U (icParentRowid), 
                            output viFcReturnSuper (oiReturnStatus)) in BBudgetLinkAcc>
            assign tBudgetLinkAcc.Budget_ID       = tApiBudgetLinkAcc.Budget_ID   
                   tBudgetLinkAcc.BudgetWBS_ID    = tApiBudgetLinkAcc.BudgetWBS_ID
                   tBudgetLinkAcc.Period_ID       = tApiBudgetLinkAcc.Period_ID
                   tBudgetLinkAcc.Layer_ID        = tApiBudgetLinkAcc.Layer_ID.
        end.
        else do:
            if vcList = "":U
            then vcList = string (tqBudgetLinkAccByPeriodWBS.tiBudgetLinkAcc_ID).
            else if lookup (string(tqBudgetLinkAccByPeriodWBS.tiBudgetLinkAcc_ID),vcList,chr(4)) = 0
                 then vcList = vcList + chr(4) + string (tqBudgetLinkAccByPeriodWBS.tiBudgetLinkAcc_ID).
        end.
    end.
end.

/* ======================================================================= */
/* Read existing records from database                                     */
/* ======================================================================= */
if vcList <> "":U
then do:
    <M-22 run DataLoad (input  '':U (icRowids), 
                    input  vcList (icPkeys), 
                    input  '':U (icObjectIds), 
                    input  '':U (icFreeform), 
                    input  yes (ilKeepPrevious), 
                    output viFcReturnSuper (oiReturnStatus)) in BBudgetLinkAcc>
end.

/* ======================================================================= */
/* Update new values of actuals                                            */
/* ======================================================================= */
for each tApiBudgetLinkAcc:
    find first tBudgetLinkAcc where
               tBudgetLinkAcc.Budget_ID    = tApiBudgetLinkAcc.Budget_ID    and 
               tBudgetLinkAcc.BudgetWBS_ID = tApiBudgetLinkAcc.BudgetWBS_ID and 
               tBudgetLinkAcc.Period_ID    = tApiBudgetLinkAcc.Period_ID    and
               tBudgetLinkAcc.Layer_ID     = tApiBudgetLinkAcc.Layer_ID
               no-lock no-error.
    if not available tBudgetLinkAcc
    then do:
        assign oiReturnStatus  = -3
               vcMessage           = trim(substitute(#T-23'Internal error: the budget link could not be loaded although the record could be found in the database based on its ID (&1).':200(17780)T-23#,string(tqBudgetLinkAccByPeriodWBS.tiBudgetLinkAcc_ID))).
        
        <M-6 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-3480':U (icFcMsgNumber), 
         input  '':U (icFcExplanation), 
         input  '':U (icFcIdentification), 
         input  '':U (icFcContext), 
         output viFcReturnSuper (oiReturnStatus)) in BBudgetLinkAcc>
         return.
    end.

    assign tBudgetLinkAcc.BudgetLinkAccDebitLC = tBudgetLinkAcc.BudgetLinkAccDebitLC +
                                                 (if tApiBudgetLinkAcc.BudgetLinkAccDebitLC = ? 
                                                  then 0 else tApiBudgetLinkAcc.BudgetLinkAccDebitLC)
           tBudgetLinkAcc.BudgetLinkAccCreditLC = tBudgetLinkAcc.BudgetLinkAccCreditLC +
                                                 (if tApiBudgetLinkAcc.BudgetLinkAccCreditLC = ? 
                                                  then 0 else tApiBudgetLinkAcc.BudgetLinkAccCreditLC)
           tBudgetLinkAcc.BudgetLinkAccDebitCC = tBudgetLinkAcc.BudgetLinkAccDebitCC +
                                                 (if tApiBudgetLinkAcc.BudgetLinkAccDebitCC = ? 
                                                  then 0 else tApiBudgetLinkAcc.BudgetLinkAccDebitCC)
           tBudgetLinkAcc.BudgetLinkAccCreditCC = tBudgetLinkAcc.BudgetLinkAccCreditCC +
                                                 (if tApiBudgetLinkAcc.BudgetLinkAccCreditCC = ? 
                                                  then 0 else tApiBudgetLinkAcc.BudgetLinkAccCreditCC)
           tBudgetLinkAcc.BudgetLinkAccQTY      = tBudgetLinkAcc.BudgetLinkAccQTY + 
                                                 (if tApiBudgetLinkAcc.BudgetLinkAccQTY = ? 
                                                  then 0 else tApiBudgetLinkAcc.BudgetLinkAccQTY).               .
     assign tBudgetLinkAcc.tc_Status = if tBudgetLinkAcc.tc_Status = '':U 
                                       then 'C':U else tBudgetLinkAcc.tc_Status.
end.

/* ================================================================ */
/* Stop queries                                                     */
/* ================================================================ */
<Q-20 run BudgetLinkAccByPeriodWBS  (Stop) in BBudgetLinkAcc >
<Q-21 run BudgetWBSByBudgetIDWBSCode  (Stop) in BBudget >

/* ================================================================ */
/* Perfom Validation, AdditionalUpdates and DataSave                */
/* ================================================================ */
<M-9 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBudgetLinkAcc>
if viFcReturnSuper <> 0 
then do :
    assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then return.
end.  /* if viFcReturnSuper <> 0 */
<M-10 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBudgetLinkAcc>
if viFcReturnSuper <> 0 
then do :
    assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then return.
end.  /* if viFcReturnSuper <> 0 */
<M-11 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBudgetLinkAcc>
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 = "BBudgetLinkAcc".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiCreateOrUpdateBudgetLinkAcc".
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/bbudgetlinkacc.apicreateorupdatebudgetlinkacc.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tApiBudgetLinkAcc").
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.