project QadFinancials > class BQCrossCyPosting > method ApiProcessQCrossCyPosting

Description

Method that will process QCrossCyPosting-records based on the input table of this method. The QCrossCyPosting records will be deleted and a movement record will be create for CI, DI,EI, ...


Parameters


iiQCrossCyPostingIdinputintegerQCrossCyPosting ID
iiExternalDebugLevelinputintegerExternalDebugLevel
icExternalDebugDirectoryinputcharacterExternalDebugDirectory
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCrossCyDaemonProcessor.PerformWorkItem


program code (program6/bqcrosscyposting.p)

/* ================== */
/* Exception Handling */
/* Empty the instance */
/* ================== */
assign oiReturnStatus = -98.
empty temp-table tQCrossCyDefaultSafs.
empty temp-table tQCrossyCyPostingCIMovement.
empty temp-table tQCrossyCyPostingDIMovement.
<M-52 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.

/* ============ */
/* Set Logging  */
/* ============ */
<M-50 run ApiProcessQCrossCyPostingLogging
   (input  iiQCrossCyPostingId (iiQCrossCyPostingId), 
    input  iiExternalDebugLevel (iiExternalDebugLevel), 
    input  icExternalDebugDirectory (icExternalDebugDirectory), 
    output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
/* no error-handling on this */

/* ======================== */
/* replace unknown values   */
/* validate input parameter */
/* ======================== */
if iiQCrossCyPostingId = ? then assign iiQCrossCyPostingId = 0.
if iiQCrossCyPostingId = 0
then do:
    assign vcMsgCrossCy   = trim(#T-54'A cross-company error occurred. You must enter a value in the ID field.':150(3473)T-54#)
           oiReturnStatus = -1.
   <M-15 run SetMessage
      (input  vcMsgCrossCy (icMessage), 
       input  '':U (icArguments), 
       input  '':U (icFieldName), 
       input  '':U (icFieldValue), 
       input  'E':U (icType), 
       input  3 (iiSeverity), 
       input  '':U (icRowid), 
       input  'QADFIN-1104':U (icFcMsgNumber), 
       input  '' (icFcExplanation), 
       input  '' (icFcIdentification), 
       input  '' (icFcContext), 
       output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
    Return.
end. /* if iiQCrossCyPostingId = 0 */

/* ======================= */
/* search the right record */
/* ======================= */
<M-53 run DataLoad
   (input  '':U (icRowids), 
    input  string(iiQCrossCyPostingId) (icPkeys), 
    input  '':U (icObjectIds), 
    input  '':U (icFreeform), 
    input  false (ilKeepPrevious), 
    output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
find first tQCrossCyPosting where
           tQCrossCyPosting.QCrossCyPosting_ID = iiQCrossCyPostingId
           no-error.
if not available tQCrossCyPosting
then do:
    assign vcMsgCrossCy   = trim(substitute(#T-55'The system cannot find the cross-company posting record based on its ID (&1).':255(3474)T-55#,string(iiQCrossCyPostingId)))  
           oiReturnStatus = -1.
    if viFcReturnSuper <> 0 
    then assign vcMsgCrossCy = vcMsgCrossCy + chr(10) + trim(substitute(#T-56'Error on &1: &2.':255(3475)T-56#,"DataLoad":U,string(viFcReturnSuper))).
    <M-16 run SetMessage
       (input  vcMsgCrossCy (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-1105':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
    Return.
end. /* if not available tQCrossCyPosting */

/* ================================= */
/* start/open journal entry instance */
/* ================================= */
if viBJournalEntryQCrossCyPostID = 0 or 
   viBJournalEntryQCrossCyPostID = ?
then do:
    <I-25 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BJournalEntry"}>
end. /* if viBJournalEntryQCrossCyPostID = 0 or  */
else do:
    <I-26 {bFcOpenInstance
         &CLASS           = "BJournalEntry"}>
end. /* Not if viBJournalEntryQCrossCyPostID = 0 or  */

/* =========== */
/* Start Block */
/* =========== */
BLOCKTRANSACTION: DO :
    
    /* ============================================================================================================================ */
    /* For Reverse cross-company the posting id of the original cross-company is stored in tQCrossCyPosting.APMatchingCostCentre_ID */
    /* For Reverse cross-company we simply call a submethod that will do all the work and  */
    /* ============================================================================================================================ */
    if tQCrossCyPosting.ComplPostingRevPosting_ID <> 0 and 
       tQCrossCyPosting.ComplPostingRevPosting_ID <> ? and 
       tQCrossCyPosting.APMatchingGL_ID = 0
    then do:
        <M-64 run ApiProcessQCrossCyPostingForReverse  (output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
         then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave BlockTransaction.
    end. /* if tQCrossCyPosting.ComplPostingRevPosting_ID <> 0 and  */
    
    /* ========================= */
    /* NON-Reverse cross-company */
    /* ========================= */
    else do: 
        
        /* ========================================== */
        /* Get the Originating posting and its period */
        /* ========================================== */
        <Q-91 run PostingByPostingId (all) (Read) (NoCache)
           (input tQCrossCyPosting.OriginatorCompany_ID, (CompanyId)
            input tQCrossCyPosting.OriginatorPosting_ID, (PostingId)
            input ?, (JournalTypeCode)
            output dataset tqPostingByPostingId) in BPosting>
        find first tqPostingByPostingId no-error.
        if not available tqPostingByPostingId
        then do:
            assign vcMsgCrossCy   = trim(#T-93'The system cannot find the original posting record.':150(3477)T-93#)
                   viBlockReturnStatus = -1.
            <M-92 run SetMessage
               (input  vcMsgCrossCy (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-9783':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
            Leave BlockTransaction.
        end. /* if not available tqPostingByPostingId */
        
        <Q-29 run PeriodByStartEndDate (first) (Read) (NoCache)
           (input tQCrossCyPosting.Company_ID, (CompanyId)
            input tqPostingByPostingId.ttPostingDate, (Date)
            output dataset tqPeriodByStartEndDate) in BPeriod>
        find first tqPeriodByStartEndDate no-lock no-error.
        if not available tqPeriodByStartEndDate
        then do:
            assign vcMsgCrossCy   = trim(#T-57'No current GL period found.':150(3476)T-57#)
                   viBlockReturnStatus = -1.
            <M-30 run SetMessage
               (input  vcMsgCrossCy (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-1106':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
            Leave BlockTransaction.
        end. /* if not available tqPeriodByStartEndDate */
        
        /* I19 requirement for Brazil ================================================================== *
         * When the original posting line in the first company contains filled in legal document number, *
         * then this number has to be also propagated to the counterpart posting                         *
         * Currently it is only implemented for AP matching                                              *
         * ============================================================================================= */
        assign vcLegalDocumentNumber = ?.

        if tQCrossCyPosting.APMatchingGL_ID <> 0 and 
           tQCrossCyPosting.APMatchingGL_ID <> ?
        then do:
            <Q-225 run PostingLineForLegalDocument (all) (Read) (NoCache)
               (input ?, (CompanyId)
                input tQCrossCyPosting.OriginatorPostingLine_ID, (PostingLineId)
                output dataset tqPostingLineForLegalDocument) in BPosting>
            for first tqPostingLineForLegalDocument where
                      tqPostingLineForLegalDocument.tiPostingLine_ID          = tQCrossCyPosting.OriginatorPostingLine_ID and
                      tqPostingLineForLegalDocument.tcPostingLineLegalDocNbr <> ?                                         and
                      tqPostingLineForLegalDocument.tcPostingLineLegalDocNbr <> "":U:
                assign vcLegalDocumentNumber = tqPostingLineForLegalDocument.tcPostingLineLegalDocNbr.
            end.
        end. /* if tQCrossCyPosting.APMatchingGL_ID <> 0 and */
                  
        
        /* ============================ */
        /* Create posting header record */
        /* ============================ */
        <M-88 run AddPostingHeader
           (input  tQCrossCyPosting.Company_ID (iiCompanyId), 
            input  tqPeriodByStartEndDate.tiPeriodYear (iiPeriodYear), 
            input  tqPeriodByStartEndDate.tiPeriodPeriod (iiPeriodPeriod), 
            input  tqPostingByPostingId.tcJournalCode (icJournalCode), 
            input  '' (icReportingJournalCode), 
            input  ? (iiVoucher), 
            input  tqPostingByPostingId.ttPostingDate (itPostingDate), 
            input  ? (itValueDate), 
            input  tqPostingByPostingId.tcPostingText (icPostingText), 
            input  tqPostingByPostingId.tcPostingBusinessRelationTxt (icPostingBusinessRelationText), 
            input  '':U (icPostingInvoiceReferenceText), 
            input  tqPostingByPostingId.tcPostingParentText (icPostingParentText), 
            input  tqPeriodByStartEndDate.tiPeriod_I (iiBPeriodId), 
            input  ? (icPostingOriginAddressCode), 
            input  ? (icPostingOriginDocument), 
            input  ? (icPostingOriginDocumentType), 
            input  '':U (icBatchNumber), 
            input  ? (icBankImpLineRef), 
            output viCrossCompanyGLPostingID (oiPostingId), 
            output vcPostingRowId (ocRowid), 
            output viPostingVoucher (oiPostingVoucher), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
        then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave BlockTransaction.
        
        /* ========================================== */
        /* Gather the info about the cross company GL */
        /* ========================================== */
        <Q-48 run GLPrim (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input ?, (GLCode)
            input tQCrossCyPosting.CrossCompanyGL_ID, (GLId)
            output dataset tqGLPrim) in BGL>
        find tqGLPrim where
             tqGLPrim.tiGL_ID = tQCrossCyPosting.CrossCompanyGL_ID
             no-lock no-error.
        if not available tqGLPrim
        then do:
            assign vcMsgCrossCy   = trim(#T-59'The GL account specified is not defined in the system.':150(3478)T-59#) + chr(10) +
                                    trim(substitute("GL ID: &1":U, string(tQCrossCyPosting.CrossCompanyGL_ID) ))
                   viBlockReturnStatus = -1.
            <M-47 run SetMessage
               (input  vcMsgCrossCy (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-1798':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
            Leave BlockTransaction.
        end. /* if not available tqGLPrim */
        <Q-36 run GLById (all) (Read) (NoCache)
           (input tQCrossCyPosting.Company_ID, (CompanyId)
            input tQCrossCyPosting.CrossCompanyGL_ID, (GLId)
            output dataset tqGLById) in BGL>
        find first tqGLById no-error.
        if not available tqGLByID
        then do:
            assign vcMsgCrossCy   = trim(#T-60'The specified cross-company GL account is not defined in the system.':150(3479)T-60#)
                   viBlockReturnStatus = -1.
            <M-37 run SetMessage
               (input  vcMsgCrossCy (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-1109':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
            Leave BlockTransaction.
        end. /* if not available tqGLByID */
        if tqGLById.tiDivisionProfile_ID <> 0 and
           tqGLById.tiDivisionProfile_ID <> ?
        then do:
            <Q-38 run GetDivisionFromProfile (all) (Read) (NoCache)
                  (input tQCrossCyPosting.Company_ID, (CompanyId)
                   input tqGLById.tiDivisionProfile_ID, (DivisionProfileId)
                   output dataset tqDivisionFromProfile) in BProfile >
            find first tqDivisionFromProfile no-error.
            if not available tqDivisionFromProfile
            then do:
                assign vcMsgCrossCy   = trim(substitute(#T-61'The sub-account of GL account (&1) is not defined.':150(3480)T-61#, tqGLPrim.tcGLCode))
                       viBlockReturnStatus = -1.
                <M-39 run SetMessage
                   (input  vcMsgCrossCy (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'QADFIN-1110':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
                Leave BlockTransaction.
            end. /* if not available tqDivisionFromProfile */
        end. /* if tqGLById.tiDivisionProfile_ID <> 0 and */
        
        /* ==================================================== */
        /* Get the intercompany code for the originator company */
        /* ==================================================== */
        assign vcBusinessRelationInterCoCode = "":U.
        <Q-90 run CompanyBusinessRelation (all) (Read) (NoCache)
           (input tQCrossCyPosting.OriginatorCompany_ID, (CompanyId)
            output dataset tqCompanyBusinessRelation) in BCompany>
        find tqCompanyBusinessRelation where
             tqCompanyBusinessRelation.tiCompany_ID = tQCrossCyPosting.OriginatorCompany_ID
             no-lock no-error.
        if available tqCompanyBusinessRelation
        then assign vcBusinessRelationInterCoCode = tqCompanyBusinessRelation.tcBusinessRelationICCode.
        
        /* ========================= */
        /* Get the LC and CC amounts */
        /* ========================= */
        if tQCrossCyPosting.CInvoice_ID <> 0 and 
           tQCrossCyPosting.CInvoice_ID <> ?
        then do:
            /* Calculate amount for Supplier invoice movement -> take exchange rates from invoice itself */
            <M-94 run ApiProcessQCrossCyPostingCalcAmountCI
               (output vdDebitLC (odDebitLC), 
                output vdCreditLC (odCreditLC), 
                output vdDebitCC (odDebitCC), 
                output vdCreditCC (odCreditCC), 
                output vdDebitTC (odDebitTC), 
                output vdCreditTC (odCreditTC), 
                output vdExchangeRate (odTCLCExchangeRate), 
                output vdExchangeRateScale (odTCLCExchangeRateScale), 
                output vdCCExchangeRate (odTCCCExchangeRate), 
                output vdCCExchangeRateScale (odTCCCExchangeRateScale), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0) then assign viBlockReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then leave BlockTransaction.
        end. /* if tQCrossCyPosting.CInvoice_ID <> 0 and  */
        else do:
            if tQCrossCyPosting.DInvoice_ID <> 0 and 
               tQCrossCyPosting.DInvoice_ID <> ? 
            then do :
                /* Calculate amount for Customer invoice movement -> take exchange rates from invoice itself */
                <M-98 run ApiProcessQCrossCyPostingCalcAmountDI
                   (output vdDebitLC (odDebitLC), 
                    output vdCreditLC (odCreditLC), 
                    output vdDebitCC (odDebitCC), 
                    output vdCreditCC (odCreditCC), 
                    output vdDebitTC (odDebitTC), 
                    output vdCreditTC (odCreditTC), 
                    output vdExchangeRate (odTCLCExchangeRate), 
                    output vdExchangeRateScale (odTCLCExchangeRateScale), 
                    output vdCCExchangeRate (odTCCCExchangeRate), 
                    output vdCCExchangeRateScale (odTCCCExchangeRateScale), 
                    output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
                if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0) then assign viBlockReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 then leave BlockTransaction.
            end. /* if tQCrossCyPosting.DInvoice_ID <> 0 and */
            else do:
                /* Calculate amounts using the rates */
                <M-132 run ApiProcessQCrossCyPostingCalcAmount
                   (output vdDebitLC (odDebitLC), 
                    output vdCreditLC (odCreditLC), 
                    output vdDebitCC (odDebitCC), 
                    output vdCreditCC (odCreditCC), 
                    output vdDebitTC (odDebitTC), 
                    output vdCreditTC (odCreditTC), 
                    output vdExchangeRate (odTCLCExchangeRate), 
                    output vdExchangeRateScale (odTCLCExchangeRateScale), 
                    output vdCCExchangeRate (odTCCCExchangeRate), 
                    output vdCCExchangeRateScale (odTCCCExchangeRateScale), 
                    output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
                if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0) then assign viBlockReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 then leave BlockTransaction.
            end. /* Not if tQCrossCyPosting.DInvoice_ID <> 0 and */
        end. /* Not if tQCrossCyPosting.CInvoice_ID <> 0 and  */
        
        /* ======================== */
        /* Get the currency-details */
        /* ======================== */
        <Q-44 run CurrencyPrim (all) (Read) (NoCache)
           (input ?, (CurrencyCode)
            input tQCrossCyPosting.Currency_ID, (Currency_ID)
            output dataset tqCurrencyPrim) in BCurrency>
        find tqCurrencyPrim where
             tqCurrencyPrim.tiCurrency_ID = tQCrossCyPosting.Currency_ID
             no-lock no-error.
        if not available tqCurrencyPrim
        then do:
            assign vcMsgCrossCy   = trim(#T-62'The specified currency is not defined in the system..':150(3481)T-62#) + chr(10) +
                                    trim(substitute("Currency ID: &1":U, string(tQCrossCyPosting.Currency_ID) ))
                   viBlockReturnStatus = -1.
            <M-45 run SetMessage
              (input  vcMsgCrossCy (icMessage), 
               input  '':U (icArguments), 
               input  '':U (icFieldName), 
               input  '':U (icFieldValue), 
               input  'E':U (icType), 
               input  3 (iiSeverity), 
               input  '':U (icRowid), 
               input  'QADFIN-1797':U (icFcMsgNumber), 
               input  '' (icFcExplanation), 
               input  '' (icFcIdentification), 
               input  '' (icFcContext), 
               output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
            Leave BlockTransaction.
        end. /* if not available tqCurrencyPrim */
        
        /* =================================== */
        /* Create the PostingLine on the IC-GL */ 
        /* =================================== */
        <M-89 run AddStandardPosting
           (input  vcPostingRowId (icPostingtcRowid), 
            input  tqGLPrim.tcGLCode (icGLCode), 
            input  (if available tqDivisionFromProfile then tqDivisionFromProfile.tcDivisionCode else '':U) (icDivisionCode), 
            input  ? (icCostCentreCode), 
            input  ? (icCostCentreText), 
            input  ? (icProjectCode), 
            input  ? (icProjectText), 
            input  vcBusinessRelationInterCoCode (icIntercoBusinessRelationCode), 
            input  tqCurrencyPrim.tcCurrencyCode (icCurrencyCode), 
            input  vdDebitTC (idDebitTC), 
            input  vdDebitLC (idDebitLC), 
            input  vdDebitCC (idDebitCC), 
            input  ? (idDebitPC), 
            input  vdCreditTC (idCreditTC), 
            input  vdCreditLC (idCreditLC), 
            input  vdCreditCC (idCreditCC), 
            input  ? (idCreditPC), 
            input  tQCrossCyPosting.QCrossCyPostingQTY (idQty), 
            input  #T-78'Cross-Company Posting':30(57722)T-78# (icLineText), 
            input  '':U (icSafText), 
            input  tQCrossCyDefaultSafs (tDefaultSafs), 
            input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType), 
            input  if vdExchangeRate = 0 then 1 else vdExchangeRate (idExchangeRate), 
            input  if vdexchangeratescale = 0 then 1 else vdExchangeRateScale (idExchangeRateScale), 
            input  vdCCExchangeRate (idPostingLineCCRate), 
            input  vdCCExchangeRateScale (idPostingLineCCScale), 
            output viCrossCompanyGLPostingLineID (oiPostingLineId), 
            input  ? (iiSafStructureId), 
            input  ? (icSafStructureCode), 
            input  ? (icAllocationKey), 
            input  true (ilLinkedCrCyDaemonReqExists), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
        then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave BlockTransaction.
        
        /* I19 requirement for Brazil ================================================================== *
         * When the original posting line in the first company contains filled in legal document number, *
         * then this number has to be also propagated to the counterpart posting                         *
         * ============================================================================================= */
        if vcLegalDocumentNumber <> ?
        then do:
            <M-864 run SetPostingLineLegalDocNumber
               (input  ? (icPostingLineTcRowID), 
                input  viCrossCompanyGLPostingLineID (iiPostingLineID), 
                input  vcLegalDocumentNumber (icLegalDocumentNumber), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
            then assign viBlockReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then leave BlockTransaction.
        end. /* if vcLegalDocumentNumber <> ? */
                       
        /* =============================================================================================== */
        /* Check which instance must be started, use variables so you can reuse them to close the instance */
        /* =============================================================================================== */
        assign viFcReturnSuper = 0.
        if tQCrossCyPosting.CInvoice_ID <> 0 and 
           tQCrossCyPosting.CInvoice_ID <> ?
        then do:
            /* Use the same amounts and rates as used for the cross-cy-posting-lines created above but with debit>credit and credit>debit */
            <M-34 run ApiProcessQCrossCyPostingForCI
               (input  vcPostingRowId (icPostingRowId), 
                input  vdCreditTC (idDebitTC), 
                input  vdDebitTC (idCreditTC), 
                input  vdCreditLC (idDebitLC), 
                input  vdDebitLC (idCreditLC), 
                input  vdCreditCC (idDebitCC), 
                input  vdDebitCC (idCreditCC), 
                input  vdExchangeRate (idTCLCExchangeRate), 
                input  vdExchangeRateScale (idTCLCExchangeScale), 
                input  vdCCExchangeRate (idTCCCExchangeRate), 
                input  vdCCExchangeRateScale (idTCCCExchangeScale), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
        end.
        if tQCrossCyPosting.DInvoice_ID <> 0 and 
           tQCrossCyPosting.DInvoice_ID <> ?
        then do:
            <M-43 run ApiProcessQCrossCyPostingForDI
               (input  vcPostingRowId (icPostingRowId), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
        end.
        if tQCrossCyPosting.APMatchingGL_ID <> 0 and 
           tQCrossCyPosting.APMatchingGL_ID <> ?
        then do:
            /* The debit-amts here equal the credit-amts of the previous call to AddStandardPosting earlier in this method */
            <M-87 run ApiProcessQCrossCyPostingForAPM
               (input  vcPostingRowId (icPostingRowId), 
                input  if tQCrossCyPosting.CrossCompanyGLIsCredit = true  then tQCrossCyPosting.QCrossCyPostingAmountTC else 0 (idDebitTC), 
                input  vdCreditLC (idDebitLC), 
                input  vdCreditCC (idDebitCC), 
                input  if tQCrossCyPosting.CrossCompanyGLIsCredit = false then tQCrossCyPosting.QCrossCyPostingAmountTC else 0 (idCreditTC), 
                input  vdDebitLC (idCreditLC), 
                input  vdDebitCC (idCreditCC), 
                output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
        end. /* if tQCrossCyPosting.APMatchingGL_ID <> 0 and tQCrossCyPosting.APMatchingGL_ID <> ? */
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
        then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave BlockTransaction.
        
        /* ====================================================================================== */
        /* Call submethod that will set the CrossCompany info of the newly created IC-postingline */
        /* and that will also set the CrossCompany info of the originator postingline             */
        /* ====================================================================================== */
        <M-79 run ApiProcessQCrossCyPostingJE
           (input  tQCrossCyPosting.OriginatorCompany_ID (iiOriginatorCompanyID), 
            input  tQCrossCyPosting.OriginatorPosting_ID (iiOriginatorPostingID), 
            input  tQCrossCyPosting.OriginatorPostingLine_ID (iiOriginatorPostingLineID), 
            input  tQCrossCyPosting.Company_ID (iiNewCompanyID), 
            input  viCrossCompanyGLPostingID (iiNewPostingID), 
            input  viCrossCompanyGLPostingLineID (iiNewPostingLineID), 
            output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
        then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then leave BlockTransaction.
            
    end. /* Not Reversal Request */   
    
    /* ==================================== */
    /* Delete the current record + Validate */
    /* ==================================== */
    assign tQCrossCyPosting.tc_Status = "D":U.
    <M-2 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
    then assign viBlockReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave BlockTransaction.
    
    /* ================== */
    /* Additional updates */
    /* ================== */
    <M-3 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
    then assign viBlockReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then leave BlockTransaction.
    
    /* ================ */
    /* Validate the BJE */
    /* ================ */
    <M-65 run SetPublicData (input  'vlPostingMustBeBalanced':U (icDataList), 
                     input  'true':U (icValueList), 
                     output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper < 0
    then do:
        assign vcMsgCrossCy        = trim(substitute(#T-73'A  cross-company error occurred. The system was unable to set property '&1' in the Journal Entry component.':255(14058)T-73#, "vlPostingMustBeBalanced":U))
               viBlockReturnStatus = viFcReturnSuper. 
        <M-75 run SetMessage
           (input  vcMsgCrossCy (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-3191':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
        if viFcReturnSuper < 0 
        then leave BlockTransaction.
    end. /* if viFcReturnSuper < 0 */
    <M-68 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper <> 0
    then do:
        if viFcReturnSuper < 0
        then assign vcMsgCrossCy = trim(substitute(#T-74'An error (&1) occurred when validating the journal entry of the cross-company posting.':255(14062)T-74#, string(viFcReturnSuper))).
        else assign vcMsgCrossCy = trim(substitute(#T-77'A warning (&1) occurred when validating the journal entry of the cross-company posting.':255(14060)T-77#, string(viFcReturnSuper))).
        assign viBlockReturnStatus = viFcReturnSuper. 
        <M-76 run SetMessage
           (input  vcMsgCrossCy (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  (if viBlockReturnStatus < 0 then 'E':U else 'W':U) (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-3192':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
        <M-70 run SetPublicData
           (input  'vlPostingMustBeBalanced':U (icDataList), 
            input  'false':U (icValueList), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viBlockReturnStatus < 0
        then leave BlockTransaction.
    end. /* if viFcReturnSuper <> 0 */
    
    /* ============================================ */
    /* Datasave: real commit of the tranaction      */
    /* Make sure all external components are closed */
    /* ============================================ */
    <I-80 {bFcCloseInstance
       &CLASS           = "BJournalEntry"}>
    <M-4 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BQCrossCyPosting>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viBlockReturnStatus = 0)
    then assign viBlockReturnStatus = viFcReturnSuper.
    if viBlockReturnStatus < 0 
    then leave BlockTransaction.
    /* Return in case the DataSave was succesful as than the CloseInstance at the end of this method should be avoided becuase the BJournalEntry-instance is already stopped by then / makes rue to set oiReturnStatus = 0 to indicate it went correct */
    if viBlockReturnStatus >= 0
    then do :
        assign oiReturnStatus = 0.
        Return.
    end. /* if viBlockReturnStatus >= 0 */
  
end. /* BLOCKTRANSACTION */

/* ========================================================================= */
/* Close BJournalEntry in all cases the DataSave was not executed succesfuly */
/* ========================================================================= */
<I-49 {bFcCloseInstance
     &CLASS           = "BJournalEntry"}>

/* ===================================== */
/* Check return-status used in the block */
/* ===================================== */
if viBlockReturnStatus <> 0
then assign oiReturnStatus = viBlockReturnStatus.
if viBlockReturnStatus < 0
then Return.

/* ================== */                    
/* Exception handling */
/* ================== */
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 = "BQCrossCyPosting".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiProcessQCrossCyPosting".
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/bqcrosscyposting.apiprocessqcrosscyposting.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiQCrossCyPostingId = <parameter value>
       vhParameter::iiExternalDebugLevel = <parameter value>
       vhParameter::icExternalDebugDirectory = <parameter value>.

/* 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.