project QadFinancials > class BExpenseGLMatrix > method ApiSetExpenseGLMatrix


Parameters


tSetExpenseGLMatrixinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bexpenseglmatrix.p)

/* ================================================================= */
/* When no new, modified or deleted records, give warning and return */
/* ================================================================= */
if not can-find (first tSetExpenseGLMatrix)
then do :
    assign vcMessage      = trim(#T-11'The Expense GL Matrix table does not contain any records.':255(1895)T-11#)
           oiReturnStatus = -1. 
    <M-2 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'W':U (icType),
                     input  4 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1586':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>
    return.
end. /* if not can-find */

/* ====================== */
/* Replace unknown values */
/* ====================== */
for each tSetExpenseGLMatrix where
         tSetExpenseGLMatrix.tcEmployeeExpenseCode  = ? or
         tSetExpenseGLMatrix.tcItemExpenseCode      = ? or
         tSetExpenseGLMatrix.tcNoAnalysisGLCode     = ? or
         tSetExpenseGLMatrix.tcCostCentreGLCode     = ? or
         tSetExpenseGLMatrix.tcProjectGLCode        = ? :
     if tSetExpenseGLMatrix.tcEmployeeExpenseCode  = ? then assign tSetExpenseGLMatrix.tcEmployeeExpenseCode  = "":U.
     if tSetExpenseGLMatrix.tcItemExpenseCode      = ? then assign tSetExpenseGLMatrix.tcItemExpenseCode      = "":U.
     if tSetExpenseGLMatrix.tcNoAnalysisGLCode     = ? then assign tSetExpenseGLMatrix.tcNoAnalysisGLCode     = "":U.
     if tSetExpenseGLMatrix.tcCostCentreGLCode     = ? then assign tSetExpenseGLMatrix.tcCostCentreGLCode     = "":U.
     if tSetExpenseGLMatrix.tcProjectGLCode        = ? then assign tSetExpenseGLMatrix.tcProjectGLCode        = "":U.
end. /* for each tSetExpenseGLMatrix where */
         
/* ====================================================================== */
/* First clear the instance, otherwise problems when you execute it twice */
/* ====================================================================== */
<M-3 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then Return.

/* ==================================================== */
/* Get all existing records and replace unknown values  */
/* ==================================================== */
<Q-4 run ExpenseGLMatrixByIDs (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input ?, (CostCentreGL_ID)
           input ?, (EmployeeExpenseCode_ID)
           input ?, (ItemExpenseCode_ID)
           input ?, (NoAnalysisGL_ID)
           input ?, (ProjectGL_ID)
           input ?, (ExpenseGLMatrix_ID)
           output dataset tqExpenseGLMatrixByIDs) in BExpenseGLMatrix >
for each tqExpenseGLMatrixByIDs  :
     if tqExpenseGLMatrixByIDs.tcEmployeeExpenseCode  = ? then assign tqExpenseGLMatrixByIDs.tcEmployeeExpenseCode  = "":U.
     if tqExpenseGLMatrixByIDs.tcItemExpenseCode      = ? then assign tqExpenseGLMatrixByIDs.tcItemExpenseCode      = "":U.
     if tqExpenseGLMatrixByIDs.tcNoAnalysisGLCode     = ? then assign tqExpenseGLMatrixByIDs.tcNoAnalysisGLCode     = "":U.
     if tqExpenseGLMatrixByIDs.tcCostCentreGLCode     = ? then assign tqExpenseGLMatrixByIDs.tcCostCentreGLCode     = "":U.
     if tqExpenseGLMatrixByIDs.tcProjectGLCode        = ? then assign tqExpenseGLMatrixByIDs.tcProjectGLCode        = "":U.
end. /* for each tSetExpenseGLMatrix where */
      
      
/* ================================================================================ */
/* Go through all new, modified or deleted input records (input status is not used) */
/* ================================================================================ */
for each tSetExpenseGLMatrix no-lock :
    
    /* ========================================================== */
    /* Find the corresponding record in the database if it exists */
    /* ========================================================== */
    find tqExpenseGLMatrixByIDs where
         tqExpenseGLMatrixByIDs.tiSharedSet_ID         = tSetExpenseGLMatrix.SharedSet_ID         and
         tqExpenseGLMatrixByIDs.tcEmployeeExpenseCode  = tSetExpenseGLMatrix.tcEmployeeExpenseCode and
         tqExpenseGLMatrixByIDs.tcItemExpenseCode      = tSetExpenseGLMatrix.tcItemExpenseCode 
         no-lock no-error.
    
    /* ============================================ */
    /* If no changes are done then skip this record */
    /* ============================================ */
    if (available tqExpenseGLMatrixByIDs                                                    and
        tqExpenseGLMatrixByIDs.tcNoAnalysisGLCode = tSetExpenseGLMatrix.tcNoAnalysisGLCode and
        tqExpenseGLMatrixByIDs.tcCostCentreGLCode = tSetExpenseGLMatrix.tcCostCentreGLCode and
        tqExpenseGLMatrixByIDs.tcProjectGLCode    = tSetExpenseGLMatrix.tcProjectGLCode) OR
       (not available tqExpenseGLMatrixByIDs          and
        tSetExpenseGLMatrix.tcNoAnalysisGLCode = "":U and
        tSetExpenseGLMatrix.tcCostCentreGLCode = "":U and
        tSetExpenseGLMatrix.tcProjectGLCode    = "":U)
    then next.
    
    /* ======================================== */
    /* Load the instance / Create the instance  */
    /* ======================================== */
    find tExpenseGLMatrix where
         tExpenseGLMatrix.ExpenseGLMatrix_ID = tqExpenseGLMatrixByIDs.tiExpenseGLMatrix_ID
         no-error.
    if not available tExpenseGLMatrix
    then do :
        if available tqExpenseGLMatrixByIDs
        then do :
            <M-5 run DataLoad
          (input  ? (icRowids), 
           input  string(tqExpenseGLMatrixByIDs.tiExpenseGLMatrix_ID) (icPkeys), 
           input  ? (icObjectIds), 
           input  '' (icFreeform), 
           input  true (ilKeepPrevious), 
           output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then Return.
            find tExpenseGLMatrix where
                 tExpenseGLMatrix.ExpenseGLMatrix_ID = tqExpenseGLMatrixByIDs.tiExpenseGLMatrix_ID
                 no-error.
            if not available tExpenseGLMatrix
            then do :
                assign vcMessage      = trim(substitute(#T-12'The system cannot find the expense GL matrix based on its ID (&1).':255(1896)t-12#,string(tSetExpenseGLMatrix.ExpenseGLMatrix_ID))) + chr(10) +
                                        trim(substitute(#T-13'Employee expense code: &1.':255(1897)T-13#,tqExpenseGLMatrixByIDs.tcEmployeeExpenseCode)) + chr(10) + 
                                        trim(substitute(#T-14'Item expense code: &1.':255(1898)T-14#,tqExpenseGLMatrixByIDs.tcItemExpenseCode)) + chr(10) + 
                                        trim(#T-15'No actions will be taken.':255(18)T-15#)
                       oiReturnStatus = -3. /* runtime error */
                <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-1587':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>
                return.
            end. /* if not available tExpenseGLMatrix */
            else assign tExpenseGLMatrix.tc_Status = "C":U.
        end. /* if available tqExpenseGLMatrix */
        else do :
            <M-7 run AddDetailLine (input  'ExpenseGLMatrix':U (icTable), 
                        input  '':U (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0 then Return.
            assign tExpenseGLMatrix.tcEmployeeExpenseCode = tSetExpenseGLMatrix.tcEmployeeExpenseCode
                   tExpenseGLMatrix.tcItemExpenseCode     = tSetExpenseGLMatrix.tcItemExpenseCode.
        end. /* if not available tqExpenseGLMatrix */
    end. /* if not available tExpenseGLMatrix */
    
    /* ====================================================== */
    /* Mark for deletion in case the 3 GL-codes are empty     */
    /* Assign the GL-codes in the instance in all other cases */
    /* ====================================================== */
    if tSetExpenseGLMatrix.tcNoAnalysisGLCode = "":U and
       tSetExpenseGLMatrix.tcCostCentreGLCode = "":U and
       tSetExpenseGLMatrix.tcProjectGLCode    = "":U
    then assign tExpenseGLMatrix.tc_Status = "D":U.
    else assign tExpenseGLMatrix.tcNoAnalysisGLCode = tSetExpenseGLMatrix.tcNoAnalysisGLCode
                tExpenseGLMatrix.tcCostCentreGLCode = tSetExpenseGLMatrix.tcCostCentreGLCode
                tExpenseGLMatrix.tcProjectGLCode    = tSetExpenseGLMatrix.tcProjectGLCode.
    
end. /* end for each tSetExpenseGLMatrix */
                      
/* =========== */
/* Validations */
/* =========== */
<M-8 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then Return.

/* ================== */
/* Additional updates */
/* ================== */
<M-9 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then Return.

/* ======== */
/* Datasave */
/* ======== */
<M-10 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BExpenseGLMatrix>    
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then Return.


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 = "BExpenseGLMatrix".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiSetExpenseGLMatrix".
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/bexpenseglmatrix.apisetexpenseglmatrix.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tSetExpenseGLMatrix").
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.