project QadFinancials > class BAPMatching > method AdditionalUpdatesAllLinesPLVarUsage

Description

AdditionalUpdatesAllLinesPLVarUsage; submethod of AdditionalUpdatesAllLines that is located in the same segment and that takes care of the creation of a posting-line for the UsageVariance (difference in qty)


Parameters


icAPMatchingPostingRowidIDinputcharacterAPMatchingPostingRowidID
icPostingTextinputcharacterPostingText
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllLines


program code (program6/bapmatching.p)

/* ===================================================================================================== */
/* USAGE Variances (Not applicable to lines with Logistic Charges, only applicable to finished pvod's)   */
/* If tAPMatchingLn.APMatchingLnPvodIsLgCharge=false & tAPMatchingLn.APMatchingLnIsPvodFinished=true &   */
/*    tAPMatchingLn.APMatchingLnVarUsageTC is filled                                                     */
/* then:                                                                                                 */
/* create a posting-line based on the values of tAPMatchingLn.APMatchingLnVarUsageTC and                 */
/* tAPMatchingLn.APMatchingLnVarUsageLc and keep PostingLine_ID in tAPMatchingLn.VarUsagePostingLine_ID  */
/* ===================================================================================================== */

/* ======================== */
/* Set default ReturnStatus */
/* Some validations         */
/* ======================== */
assign oiReturnStatus = -98.
<M-50 run AdditionalUpdatesAllLinesPLVarUsageSub1
   (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
If viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Return.

/* ==================================================================================== */
/* Find out the correct GL, Division and CostCentre that are used for this posting-line */
/* in case of rate-variances (project will always be empty)                             */
/* Case 1: Get the posting-info from the DefaultAccountMstr:incl-supplier-type (acdf)   */
/* Case 2: Get the posting-info from the DefaultAccountMstr:excl-supplier-type (acdf)   */
/* Case 3: Get the posting-info from the product-line:usage-var  (pl_apvu)              */
/* Case 4: Get the posting-info from the G/L control (gl_apvu)                          */
/* Case 5: Get the posting-info from the G/L control (gl_apvux)                         */
/* Case 6: Get the posting-info from the Creditor/Invoice (Creditor/CInvoice)           */
/* Case 7: Get the posting-info from the DeftAccMstr:purch-acc (acdf-incl supp-type)    */
/* Case 8: Get the posting-info from the DeftAccMstr:purch-acc (acdf-excl supp-type)    */
/* Case 9: Get the posting-info from the product-line:purch-acc (pl_pur)                */
/* Case 10: Get the posting-info from the Creditor/PurchMatrx:purch-acc (pl_pur)        */
/* ==================================================================================== */
/* Reset message-string and start a block; in case of a blocking error, we will leave the block */
assign vcMsgAPMatching = "":U.
FINDACCOUNTBLOCK: DO :
    /* First check the inventroy control-file */
    <Q-12 run DomainForInventoryControlFile (all) (Read) (Cache)
       (input tAPMatchingLn.PvoDomain, (DomainCode)
        output dataset tqDomainForInventoryControlFile) in BMfgDomain >
    find first tqDomainForInventoryControlFile where 
               tqDomainForInventoryControlFile.tcicc_domain = tAPMatchingLn.PvoDomain
               no-lock no-error.
    if not available tqDomainForInventoryControlFile
    then do : 
        assign vcMsgAPMatching = trim(substitute(#T-20'The inventory control account (&1) is not defined for domain (&2).':255(57569)t-20#,"ICC_CTRL":U,tAPMatchingLn.PvoDomain)) + chr(10) + 
                                 trim(substitute(#T-55'Technical details: &1.':222(55526)T-55#, "UsageVar/10":U)).
        Leave FINDACCOUNTBLOCK.
    end. /* if not available tqDomainForInventoryControlFile */ 
    /* Secondly check the PO-receipt history of the pendingvoucher - find was already done in the calling procedure */
    if not available tqPendingVoucherForMatchingAcc
    then do : 
        assign vcMsgAPMatching = trim(substitute(#T-21'The system cannot find the receipt history of the pending invoice detail based on its domain and ID (&1/&2/&3).':255(49445)t-21#,tAPMatchingLn.PvoDomain,string(tAPMatchingLn.PvoID),string(tAPMatchingLn.PvodLineID)))  + chr(10) + 
                                 trim(substitute(#T-56'Technical details: &1.':222(55526)T-56#, "UsageVar/11":U)).
        Leave FINDACCOUNTBLOCK.
    end. /* if not available tqPendingVoucherForMatchingAcc */ 
    If tqDomainForInventoryControlFile.tlicc_gl_tran = true
    then do :
        if tqPendingVoucherForMatchingAcc.tcprh_type = "":U or
           tqPendingVoucherForMatchingAcc.tcprh_type = "S":U
        then do : 
            /* Find acdf (account defaults) ; global domain and supplier-type */
            <Q-48 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
               (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                input 'PO':U, (Module)
                input 'PO_APVU_ACCT':U, (Type)
                input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (Key1)
                input tqPendingVoucherForMatchingAcc.tcprh_site, (Key2)
                input tqPendingVoucherForMatchingAcc.tcvd_type, (Key3)
                input '':U, (Key4)
                input '':U, (Key5)
                input '':U, (Key6)
                output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
            find tqAccountDefaultMasterByPrimKey where 
                 tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpt_prod_line and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key2   = tqPendingVoucherForMatchingAcc.tcprh_site     and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key3   = tqPendingVoucherForMatchingAcc.tcvd_type      and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                 tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                 no-lock no-error.
            if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
            then  /* === Case 1 === */
                  assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                         vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                         vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
            else do :
                <Q-49 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
                   (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                    input 'PO':U, (Module)
                    input 'PO_APVU_ACCT':U, (Type)
                    input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (Key1)
                    input tqPendingVoucherForMatchingAcc.tcprh_site, (Key2)
                    input '':U, (Key3)
                    input '':U, (Key4)
                    input '':U, (Key5)
                    input '':U, (Key6)
                    output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
                find tqAccountDefaultMasterByPrimKey where 
                     tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpt_prod_line and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key2   = tqPendingVoucherForMatchingAcc.tcprh_site     and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key3   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and 
                     tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                     no-lock no-error.
                if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
                then  /* === Case 2 === */
                      assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                             vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                             vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
                else do :
                    /* Find pl_rcpt in the pl_mstr - product-line */
                    <Q-13 run ProductLineForMatchingAcc (all) (Read) (Cache)
                       (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                        input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (ProductLineCode)
                        output dataset tqProductLineForMatchingAcc) in BMfgProductLine >
                    find first tqProductLineForMatchingAcc where 
                               tqProductLineForMatchingAcc.tcpl_domain    = tqPendingVoucherForMatchingAcc.tcpvo_domain and 
                               tqProductLineForMatchingAcc.tcpl_prod_line = tqPendingVoucherForMatchingAcc.tcpt_prod_line
                               no-lock no-error.
                    if available tqProductLineForMatchingAcc and tqProductLineForMatchingAcc.tcpl_apvu_acct <> "":U
                    then
                        /* === Case 3 === */
                        assign vcGLCode         = tqProductLineForMatchingAcc.tcpl_apvu_acct
                               vcDivisionCode   = tqProductLineForMatchingAcc.tcpl_apvu_sub
                               vcCostCentreCode = tqProductLineForMatchingAcc.tcpl_apvu_cc.
                    else do :
                        /* Find the control-file for the system-accounts */
                        <Q-51 run SystemAccountControlForAll (all) (Read) (Cache)
                           (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                            output dataset tqSystemAccountControlForAll) in BMfgSystemAccountControl >
                        find first tqSystemAccountControlForAll where 
                                   tqSystemAccountControlForAll.tcgl_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain
                                   no-lock no-error.
                        if not available tqSystemAccountControlForAll
                        then do :
                            assign vcMsgAPMatching = trim(substitute(#T-52'Domain/Account Control settings are not defined for domain: &1':255(49763)t-52#,tqPendingVoucherForMatchingAcc.tcpvo_domain)) + chr(10) + 
                                                     trim(substitute(#T-53'Technical details: case: &1.':222(49764)T-53#,"UsageVar/4":U)).
                            Leave FINDACCOUNTBLOCK.
                        end. /* if not available tqSystemAccountControlForAll */
                        /* === Case 4 === */
                        assign vcGLCode         = tqSystemAccountControlForAll.tcgl_apvu_acct
                               vcDivisionCode   = tqSystemAccountControlForAll.tcgl_apvu_sub
                               vcCostCentreCode = tqSystemAccountControlForAll.tcgl_apvu_cc.
                    end. /* if available tqProductLineForMatchingAcc */
                end. /* if not available tqAccountDefaultMasterByPrimKey */
            end. /* if not available tqAccountDefaultMasterByPrimKey */
        end. /* if tqPendingVoucherForMatchingAcc.tcprh_type = "":U or */
        else do :
            /* Find the control-file for the accounts-payable */
            <Q-35 run AccountsPayableCtrlByDomain (all) (Read) (NoCache)
               (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                output dataset tqAccountsPayableCtrlByDomain) in BMfgAccountPayableCtrl >
            find first tqAccountsPayableCtrlByDomain where 
                       tqAccountsPayableCtrlByDomain.tcapc_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain
                       no-lock no-error.
            if not available tqAccountsPayableCtrlByDomain
            then do :
                assign vcMsgAPMatching = trim(substitute(#T-24'The accounts payable control account is not defined for domain: &1':255(53328)t-24#,tqPendingVoucherForMatchingAcc.tcpvo_domain)) + chr(10) + 
                                         trim(substitute(#T-25'Technical details: case: &1.':222(49764)T-25#,"UsageVar/5/1":U)).
                Leave FINDACCOUNTBLOCK.
            end. /* if not available tqAccountsPayableCtrlByDomain */ 
            if tqAccountsPayableCtrlByDomain.tlapc_expvar = true /* Use Expense Account for Variances? */
            then do :
                /* Find the control-file for the system-accounts */
                <Q-36 run SystemAccountControlForAll (all) (Read) (Cache)
                   (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                    output dataset tqSystemAccountControlForAll) in BMfgSystemAccountControl >
                find first tqSystemAccountControlForAll where 
                           tqSystemAccountControlForAll.tcgl_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain
                           no-lock no-error.
                if not available tqSystemAccountControlForAll
                then do :
                    assign vcMsgAPMatching = trim(substitute(#T-39'Domain/Account Control settings are not defined for domain: &1':255(49763)t-39#,tqPendingVoucherForMatchingAcc.tcpvo_domain)) + chr(10) + 
                                             trim(substitute(#T-40'Technical details: case: &1.':222(49764)T-40#,"UsageVar/5/2":U)).
                    Leave FINDACCOUNTBLOCK.
                end. /* if not available tqSystemAccountControlForAll */
                /* === Case 5 === */
                assign vcGLCode         = tqSystemAccountControlForAll.tcgl_apvux_acct
                       vcDivisionCode   = tqSystemAccountControlForAll.tcgl_apvux_sub
                       vcCostCentreCode = tqSystemAccountControlForAll.tcgl_apvux_cc.
            end. /* if tqAccountsPayableCtrlByDomain.tlapc_expvar = true */
            else do :
                /* Check whether the supplier is defined on the pending-voucher */
                if tqPendingVoucherForMatchingAcc.tcprh_vend = "":U or
                   tqPendingVoucherForMatchingAcc.tcprh_vend = ?
                then do :
                    assign vcMsgAPMatching = trim(substitute(#T-42'The system cannot find the default accounting information for the supplier because the supplier is not specified on the pending invoice.':255(49769)t-42#,tqPendingVoucherForMatchingAcc.tcprh_vend)) + chr(10) + 
                                             trim(substitute(#T-43'Technical details: case: &1.':222(49764)T-43#,"UsageVar/6/1":U)).
                    Leave FINDACCOUNTBLOCK.
                end. /* if tqPendingVoucherForMatchingAcc.tcprh_vend = "":U */                                    
                /* === Case 6 === */
               assign vcGLCode         =  tAPMatchingLn.tcGLCode
                      vcDivisionCode   =  tAPMatchingLn.tcDivisionCode
                      vcCostCentreCode =  tAPMatchingLn.tcCostCentreCode.              
            end. /* Not if tqAccountsPayableCtrlByDomain.tlapc_expvar = true */
        end. /* Not if tqPendingVoucherForMatchingAcc.tcprh_type = "":U or */    
    end. /* If tqDomainForInventoryControlFile.tlicc_gl_tran = true */
    else do :   
        if tqPendingVoucherForMatchingAcc.tcprh_type = "":U or
           tqPendingVoucherForMatchingAcc.tcprh_type = "S":U
        then do :
            /* Find acdf (account defaults) incl supp-type; PurchaseAccountDef */
            <Q-16 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
               (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                input 'PO':U, (Module)
                input 'PO_PUR_ACCT':U, (Type)
                input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (Key1)
                input tqPendingVoucherForMatchingAcc.tcprh_site, (Key2)
                input tqPendingVoucherForMatchingAcc.tcvd_type, (Key3)
                input '':U, (Key4)
                input '':U, (Key5)
                input '':U, (Key6)
                output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
            find tqAccountDefaultMasterByPrimKey where
                 tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpt_prod_line and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key2   = tqPendingVoucherForMatchingAcc.tcprh_site     and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key3   = tqPendingVoucherForMatchingAcc.tcvd_type      and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and 
                 tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                 tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                 no-lock no-error.
            if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
            then 
                /* === Case 7 === */
                assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                       vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                       vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
            else do :
                /* Find acdf (account defaults) excl supp-type ; PurchaseAccountDef */
                <Q-58 run AccountDefaultMasterByPrimKey (all) (Read) (Cache)
                   (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                    input 'PO':U, (Module)
                    input 'PO_PUR_ACCT':U, (Type)
                    input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (Key1)
                    input tqPendingVoucherForMatchingAcc.tcprh_site, (Key2)
                    input '':U, (Key3)
                    input '':U, (Key4)
                    input '':U, (Key5)
                    input '':U, (Key6)
                    output dataset tqAccountDefaultMasterByPrimKey) in BMfgAccountDefaultMaster >
                find tqAccountDefaultMasterByPrimKey where
                     tqAccountDefaultMasterByPrimKey.tcacdf_domain = tqPendingVoucherForMatchingAcc.tcpvo_domain   and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key1   = tqPendingVoucherForMatchingAcc.tcpt_prod_line and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key2   = tqPendingVoucherForMatchingAcc.tcprh_site     and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key3   = "":U                                          and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key4   = "":U                                          and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key5   = "":U                                          and
                     tqAccountDefaultMasterByPrimKey.tcacdf_key6   = "":U
                     no-lock no-error.
                if available tqAccountDefaultMasterByPrimKey and tqAccountDefaultMasterByPrimKey.tcacdf_acct <> "":U
                then 
                    /* === Case 8 === */
                    assign vcGLCode         = tqAccountDefaultMasterByPrimKey.tcacdf_acct
                           vcDivisionCode   = tqAccountDefaultMasterByPrimKey.tcacdf_sub
                           vcCostCentreCode = tqAccountDefaultMasterByPrimKey.tcacdf_cc.
                else do :
                    <Q-17 run ProductLineForMatchingAcc (all) (Read) (Cache)
                       (input tqPendingVoucherForMatchingAcc.tcpvo_domain, (DomainCode)
                        input tqPendingVoucherForMatchingAcc.tcpt_prod_line, (ProductLineCode)
                        output dataset tqProductLineForMatchingAcc) in BMfgProductLine >
                    find first tqProductLineForMatchingAcc where 
                               tqProductLineForMatchingAcc.tcpl_domain    = tqPendingVoucherForMatchingAcc.tcpvo_domain and 
                               tqProductLineForMatchingAcc.tcpl_prod_line = tqPendingVoucherForMatchingAcc.tcpt_prod_line
                               no-lock no-error.
                    if available tqProductLineForMatchingAcc
                    then
                        /* === Case 9 === */
                        assign vcGLCode         = tqProductLineForMatchingAcc.tcpl_pur_acct
                               vcDivisionCode   = tqProductLineForMatchingAcc.tcpl_pur_sub
                               vcCostCentreCode = tqProductLineForMatchingAcc.tcpl_pur_cc.
                end. /* Not if available tqAccountDefaultMasterByPrimKey */
            end. /* Not if available tqAccountDefaultMasterByPrimKey */
        end. /* if tqPendingVoucherForMatchingAcc.tcprh_type = "":U or "S":U */
        else do :        
            /* Check whether the supplier is defined on the pending-voucher */
            if tqPendingVoucherForMatchingAcc.tcprh_vend = "":U or
               tqPendingVoucherForMatchingAcc.tcprh_vend = ?
            then do :
                assign vcMsgAPMatching = trim(substitute(#T-26'The system cannot find the default accounting information for the supplier because the supplier is not specified on the pending invoice.':255(49769)t-26#,tqPendingVoucherForMatchingAcc.tcprh_vend)) + chr(10) + 
                                         trim(substitute(#T-27'Technical details: case: &1.':222(49764)T-27#,"UsageVar/9/1":U)).
                Leave FINDACCOUNTBLOCK.
            end. /* if tqPendingVoucherForMatchingAcc.tcprh_vend = "":U */
            
            
            /* CA779219 - use the accounts of the matching line for MEMO items and Create GL Transactions disabled */
            if (tAPMatchingLn.tcGLCode <> '' and
                tAPMatchingLn.tcGLCode <> ?) or
               (tAPMatchingLn.APMatchingLnOpAllocCode <> '' and
                tAPMatchingLn.APMatchingLnOpAllocCode <> ?)
            then do :           
                 /* === Case  === */
                 assign vcGLCode         =  tAPMatchingLn.tcGLCode
                        vcDivisionCode   =  tAPMatchingLn.tcDivisionCode
                        vcCostCentreCode =  '':U.
            end.
            /* CA779219 */
            
            else do :
            /* Get the G/L and Division of the Creditor */
            <Q-18 run CreditorForGLDivProfileDetails (all) (Read) (Cache)
               (input tAPMatching.Company_ID, (CompanyId)
                input tqPendingVoucherForMatchingAcc.tcprh_vend, (CreditorCode)
                output dataset tqCreditorForGLDivProfileDetails) in BCreditor >
            find first tqCreditorForGLDivProfileDetails where 
                       tqCreditorForGLDivProfileDetails.tcCreditorCode = tqPendingVoucherForMatchingAcc.tcprh_vend 
                       no-lock no-error.
            if not available tqCreditorForGLDivProfileDetails 
            then do :           
                assign vcMsgAPMatching = trim(substitute(#T-28'The system cannot find the default accounting information of supplier &1. Check the supplier definition.':255(49770)t-28#,tqPendingVoucherForMatchingAcc.tcprh_vend)) + chr(10) + 
                                         trim(substitute(#T-29'Technical details: case: &1.':222(49764)T-29#,"UsageVar/9/2":U)).
                Leave FINDACCOUNTBLOCK.
            end. /* if not available tqCreditorForGLDivProfileDetails */
            /* === Case 10 === */
            assign vcGLCode         = tqCreditorForGLDivProfileDetails.tcGLCode
                   vcDivisionCode   = tqCreditorForGLDivProfileDetails.tcDivisionCode
                   vcCostCentreCode = "":U.
            end.       
        end. /* Not if tqPendingVoucherForMatchingAcc.tcprh_type = "":U or */
    end. /* If tqDomainForInventoryControlFile.tlicc_gl_tran = false */
END. /* FINDACCOUNTBLOCK */
if vcMsgAPMatching <> "":U
then do :
    assign oiReturnStatus = -3.
    <M-19 run SetMessage (input  vcMsgAPMatching (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'QadFin-5451':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if vcMsgAPMatching <> "":U */

/* ========================================= */
/* Check wether we have a G/L account by now */
/* GL can be blank if OpAllocCode is filled  */
/* ========================================= */
if (vcGLCode = "":U or 
    vcGLCode = ?) and
   (tAPMatchingLn.APMatchingLnOpAllocCode = "":U or
    tAPMatchingLn.APMatchingLnOpAllocCode = ?)
then do:
    assign oiReturnStatus  = -3
           vcMsgAPMatching = trim(substitute(#T-34'The system cannot find the required accounting information for the pending invoice details (Domain:&1, pending invoice: &2, pending invoice detail: &3).':255(49772)t-34#,tAPMatchingLn.PvoDomain,string(tAPMatchingLn.PvoID),string(tAPMatchingLn.PvodLineID))).
    <M-30 run SetMessage (input  vcMsgAPMatching (icMessage), 
                 input  '':U (icArguments), 
                 input  '':U (icFieldName), 
                 input  '':U (icFieldValue), 
                 input  'E':U (icType), 
                 input  3 (iiSeverity), 
                 input  '':U (icRowid), 
                 input  'QadFin-5452':U (icFcMsgNumber), 
                 input  '':U (icFcExplanation), 
                 input  '':U (icFcIdentification), 
                 input  '':U (icFcContext), 
                 output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    Return.
end. /* if vcGLCode = "":U or */

assign tAPMatchingLn.tcAPMatchingLnUsageVarGLCode  = vcGLCode
       tAPMatchingLn.tcAPMatchingLnUsageVarDivCode = vcDivisionCode
       tAPMatchingLn.tcAPMatchingLnUsageVarCCCode  = vcCostCentreCode.

/* =========================================================================== */
/* Create the posting line that covers the usage variances (difference in qty) */
/* - we use the GL-Div-CC-PRJ as stated above                                  */
/* - Positive amounts: posted on Debit / - Negative amounts: posted on Credit  */ 
/* =========================================================================== */
<M-57 run AdditionalUpdatesAllLinesPLVarUsageSub2
   (input  icAPMatchingPostingRowidID (icAPMatchingPostingRowidID), 
    input  icPostingText (icPostingText), 
    input  tAPMatchingLn.tcAPMatchingLnUsageVarGLCode (icGLCode), 
    input  tAPMatchingLn.tcAPMatchingLnUsageVarDivCode (icDivisionCode), 
    input  tAPMatchingLn.tcAPMatchingLnUsageVarCCCode (icCostCentreCode), 
    input  (if available tAPMatchingLn then tAPMatchingLn.APMatchingLnPvodPrjCode else '':U) (icProjectCode), 
    output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
If viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Return.

/* ======================== */
/* Set ReturnStatus = OK    */
/* ======================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.