project QadFinancials > class BJournalEntryMultiCy > method CreateMultiCyPostings

Description

This method receives the temptables used to create one cross-company transaction. This transaction should have at minimium one source and one non-source entity tPosting records.

The transactions are posted using the integration method BJournalEntry.ApiStdMaintainTTMulti (create activity) - calling switchCompany for each differnt entity.
The transaction is manually handled as all calls to BJournalEntry for the different entites are within one single transaction


Parameters


tPostingOneTrxinputtemp-table
tPostingLineOneTrxinputtemp-table
tPostingSafOneTrxinputtemp-table
tPostingVatOneTrxinputtemp-table
tPostingVatDelayOneTrxinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BJournalEntryMultiCy.ApiCreateCrossCyPostings
method BJournalEntryMultiCy.ApiCreateMultiCyPostings


program code (program1/bjournalentrymulticy.p)

/* ================================================================= */
/* This method receives the temptables used to create one            */
/* cross-company transaction                                         */
/* This transaction should have at minimium one tPosting record for  */
/* the current company (source) and one tPosting record for another  */
/* (non-source) entity tPosting records.                             */
/*                                                                   */
/* The transactions are posted using the integration method          */
/* BJournalEntry.ApiStdMaintainTTMulti  - calling switchCompany      */
/* for each differnt entity.                                         */
/* The transaction is manually handled as all calls to BJournalEntry */
/* are within one single transaction                                 */
/* ================================================================= */

METHODBLOCK: 
DO on error undo, throw:

    /* ============================= */
    /* Start Start Transaction Block */
    /* ============================= */    
    <I-85 {bFcStartAndOpenInstance
         &ADD-TO-TRANSACTION   = "true"
         &CLASS                = "Transaction"}>
         
    TRANSACTIONBLOCK: 
    DO on error undo, throw:
         
        <M-38 run StartTransaction  (output viFcReturnSuper (oiReturnStatus)) in Transaction>
        
        if viFcReturnSuper < 0
        then do :
            assign viBlockReturnStatus = viFcReturnSuper
                   vcMessage = trim(#T-77'A Journal entry integration error occurred. The transaction not correctly started.':255(880211560)T-77#).
            <M-5 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  1 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-120918':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
            <I-59 {bFcCloseInstance
                 &CLASS           = "Transaction"}>
            leave METHODBLOCK.
        end. /* if viFcReturnSuper < 0 */
            
        /* ========================================================================================================================= */
        /* Normally we would here close the communication to class Transaction but we wont do it for performance reasons as this way */ 
        /* the transaction does not have to be re-open when other instances are added to the transactionthe instance to commit it.   */
        /* ========================================================================================================================= */    
        empty temp-table tCrossCompanyPostingLines.
        assign viSourceCompanyID   = viCompanyID
               vcSourceCompanyCode = vcCompanyCode.
            
        /* ============================================================================== */     
        /* Want to ensure we start with the current entity, so iterate thru the           */
        /* tCompaniesInvolved table which has the current entity at first entry in table  */
        /* uses the tiCompanySort to order the entities - current entity is set to 1      */
        /* ===============================================================================*/    
        for each tCompaniesInvolved 
            by tCompaniesInvolved.tiCompanySort descending 
            on error undo, throw:         
            
            empty temp-table tPostingOneCy.
            empty temp-table tPostingLineOneCy.
            empty temp-table tPostingVatOneCy.
            empty temp-table tPostingVatDelayOneCy.
            empty temp-table tPostingSafOneCy.
            empty temp-table tNonSourceCCyPostingLines.

            for each tPostingOneTrx where 
                     tPostingOneTrx.Company_ID = tCompaniesInvolved.tiCompanyId 
                     on error undo, throw:
                              
                /* copy the postings for this company into BPosting temptables */
                create tPostingOneCy.
                buffer-copy tPostingOneTrx to tPostingOneCy.
            
                for each tPostingLineOneTrx where
                         tPostingLineOneTrx.tc_parentrowid = tPostingOneTrx.tc_rowid 
                         on error undo, throw:
                         
                    create tPostingLineOneCy.
                    buffer-copy tPostingLineOneTrx to tPostingLineOneCy.
                   
                    /* =================================================================== */ 
                    /* update the linking details if this is a cross company postingline   */
                    /* for a non source entity                                             */
                    /* =================================================================== */    
                    if tPostingOneCy.Company_ID                     <> viCompanyID and
                        tPostingLineOneTrx.tcGLTypeCode             = {&GLTYPECODE-CROSS} and
                        tPostingLineOneCy.PostingLineCrossExternRef <> '' 
                    then do:
                        find first tCrossCompanyPostingLines where 
                                   tCrossCompanyPostingLines.PostingLineCrossExternRef = tPostingLineOneCy.PostingLineCrossExternRef 
                                   no-error.
                        if available tCrossCompanyPostingLines
                        then assign tPostingLineOneCy.tcCrossCompanyCode         = vcSourceCompanyCode
                                    tPostingLineOneCy.CrossCompany_ID            = viSourceCompanyID 
                                    tPostingLineOneCy.CrossCompanyPosting_ID     = tCrossCompanyPostingLines.Posting_ID
                                    tPostingLineOneCy.CrossCompanyPostingLine_ID = tCrossCompanyPostingLines.PostingLine_ID.                                   
                        else do:
                            assign vcMessage = trim(substitute(#T-83'Unable to link postings in entity &1.':255(868857513)T-83#,tPostingOneCy.company_id)).
                            <M-40 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-298127':U (icFcMsgNumber), 
                                input  '':U (icFcExplanation), 
                                input  '':U (icFcIdentification), 
                                input  '':U (icFcContext), 
                                output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
                             assign viBlockReturnStatus = -1.
                             leave TRANSACTIONBLOCK.  
                         end. /* else do */   
                         
                     end. /* tPostingOneCy.Company_ID <> viCompanyID */  
                    
                    for each tPostingVatOneTrx where 
                             tPostingVatOneTrx.tc_parentrowid = tPostingLineOneTrx.tc_rowid 
                             on error undo, throw:                  
                        create tPostingVatOneCy.
                        buffer-copy tPostingVatOneTrx to tPostingVatOneCy.
                    end. /* for each tPostingVatOneTrx */
               
                    for each tPostingVatDelayOneTrx where
                             tPostingVatDelayOneTrx.tc_parentrowid = tPostingLineOneTrx.tc_rowid 
                             on error undo, throw:                   
                        create tPostingVatDelayOneCy.
                        buffer-copy tPostingVatDelayOneTrx to tPostingVatDelayOneCy.
                    end. /* for each tPostingVatDelayOneTrx */
                   
                    for each tPostingSafOneTrx where
                             tPostingSafOneTrx.tc_parentrowid = tPostingLineOneTrx.tc_rowid 
                             on error undo, throw:                   
                         create tPostingSafOneCy.
                         buffer-copy tPostingSafOneTrx to tPostingSafOneCy.
                    end. /* for each tPostingSafOneTrx */  
                    
                end. /* for each tPostingLineOneTrx */
                
            end. /* for each tPostingOneTrx */
       
            /* =================================================================== */   
            /* post the transactions for this company                              */
            /* switch company if the posting is for a different company            */   
            /* =================================================================== */         
            if (viSourceCompanyID <> tCompaniesInvolved.tiCompanyId)
            then do:
                /* Switch session to posting company */
                <I-19 {bFcOpenInstance
                     &CLASS           = "Session"}>
                <M-25 run SwitchCompany
                   (input  '':U (icCompanyCode), 
                    input  tCompaniesInvolved.tiCompanyId (iiCompanyId), 
                    output viFcReturnSuper (oiReturnStatus)) in Session>
                 <I-65 {bFcCloseInstance
                      &CLASS           = "Session"}>
                if viFcReturnSuper < 0
                then do:
                    assign viBlockReturnStatus = viFcReturnSuper 
                           vcMessage = trim(#T-22'The system failed to switch the entity.':255(334825313)T-22#).
                       <M-31 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-625104':U (icFcMsgNumber), 
                           input  ' ':U (icFcExplanation), 
                           input  ' ':U (icFcIdentification), 
                           input  ' ':U (icFcContext), 
                           output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>                       
                       leave TRANSACTIONBLOCK.
                end. /* if viFcReturnSuper < 0 */
                
                assign viCurrentCompanyID = tCompaniesInvolved.tiCompanyId.
                
                if viFcReturnSuper > 0 and viBlockReturnStatus = 0
                then assign viBlockReturnStatus = viFcReturnSuper.
                
            end.  /* viCompanyId <> tCompaniesInvolved.tiCompanyId */     
        
            <I-81 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "true"
                 &CLASS                = "BJournalEntry"}>
                             
            assign vlBJournalEntryStarted = true.
                 
            /* ======================================= */     
            /* Set the activity code to create         */
            /* ======================================= */                 
            <M-56 run SetPublicData
               (input  'vcActivityCode':U (icDataList), 
                input  'ExcelIntegration':U (icValueList), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper < 0 
            then do:
                assign viBlockReturnStatus = viFcReturnSuper.
                leave TRANSACTIONBLOCK. 
            end. /* viFcReturnSuper < 0 */
            if viFcReturnSuper > 0 and viBlockReturnStatus = 0
            then assign viBlockReturnStatus = viFcReturnSuper.
                       
            /* ======================================= */     
            /* Post the posting for one entity         */
            /* ======================================= */                                        
            <M-66 run ApiStdMaintainMultiTT
               (input  tPostingOneCy (tApiPosting), 
                input  tPostingLineOneCy (tApiPostingLine), 
                input  tPostingSafOneCy (tApiPostingSaf), 
                input  tPostingVatOneCy (tApiPostingVat), 
                input  tPostingVatDelayOneCy (tApiPostingVatDelay), 
                input  'SAVE' (icAction), 
                output vcPrimaryKeys (ocLstPrimKey), 
                output vcReturnStatus (ocLstReturn), 
                output vcRowIDs (ocLstRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                
            if viFcReturnSuper < 0 
            then do:
                assign viBlockReturnStatus = viFcReturnSuper.
                leave TRANSACTIONBLOCK. 
            end. /* viFcReturnSuper < 0 */
            if viFcReturnSuper > 0 and viBlockReturnStatus = 0
            then assign viBlockReturnStatus = viFcReturnSuper.
               
            /* =============================================================== */     
            /* Get the cross company posting lines from the create JE          */
            /* Need to use the ids to do the linking                           */
            /* =============================================================== */         
            if viCompanyId = tCompaniesInvolved.tiCompanyId 
            then do:
                assign viBJournalEntyForSourceEntity = viBJournalEntryBJEMultiCyID.
                
                <M-9 run GetCrossCyPostingLines
                   (output tCrossCompanyPostingLines (tApiPostingLine), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                     
                if viFcReturnSuper < 0 
                then do:
                    assign viBlockReturnStatus = viFcReturnSuper.
                    leave TRANSACTIONBLOCK. 
                end. /* viFcReturnSuper < 0 */   
                if viFcReturnSuper > 0 and viBlockReturnStatus = 0
                then assign viBlockReturnStatus = viFcReturnSuper.                                   
                
            end. /* viCompanyId = tCompaniesInvolved.tiCompanyId */
            else do:        
                /* =============================================================== */
                /* If it's a non source entity posting                             */     
                /* replace the linking id's from the source posting lines with the */
                /*  ones from the related non source posting lines                 */
                /* =============================================================== */
                <M-7 run GetCrossCyPostingLines
                   (output tNonSourceCCyPostingLines (tApiPostingLine), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                if viFcReturnSuper < 0 
                then do:
                   assign viBlockReturnStatus = viFcReturnSuper.
                   leave TRANSACTIONBLOCK. 
                end. /* viFcReturnSuper < 0 */                                      
                if viFcReturnSuper > 0 and viBlockReturnStatus = 0
                then assign viBlockReturnStatus = viFcReturnSuper.
                
                for each tNonSourceCCyPostingLines :
                
                    find first tCrossCompanyPostingLines where 
                               tCrossCompanyPostingLines.PostingLineCrossExternRef = tNonSourceCCyPostingLines.PostingLineCrossExternRef 
                               no-error.
                    if available tCrossCompanyPostingLines 
                    then assign tCrossCompanyPostingLines.tcCrossCompanyCode = ttCompanyJEGL.tcCompanyCode
                                tCrossCompanyPostingLines.CrossCompany_ID = tNonSourceCCyPostingLines.Company_ID
                                tCrossCompanyPostingLines.CrossCompanyPosting_ID = tNonSourceCCyPostingLines.Posting_ID
                                tCrossCompanyPostingLines.CrossCompanyPostingLine_ID = tNonSourceCCyPostingLines.PostingLine_ID.
                    else do:
                        assign vcMessage = trim(substitute(#T-37'Unable to link postings in entity &1.':255(868857513)T-37#,viCompanyID)).
                        <M-17 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-474589':U (icFcMsgNumber), 
                             input  '':U (icFcExplanation), 
                             input  '':U (icFcIdentification), 
                             input  '':U (icFcContext), 
                             output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
                        assign viBlockReturnStatus = -1.
                        leave TRANSACTIONBLOCK.  
                    end. /* else do */                          
                           
                end.  /* for each tNonSourceCCyPostingLines */    
                    
            end. /* viCompanyId <> tCompaniesInvolved.tiCompanyId */
       
            <I-35 {bFcCloseInstance
                 &CLASS           = "BJournalEntry"}>
            assign vlBJournalEntryStarted = false.   
 
        end.  /* for each tCompaniesInvolved */   
    
        /* =============================================================== */     
        /* Update the source entity JE transaction with the cross company */
        /* details from corresponding cross cy je transactions            */
        /* =============================================================== */             
        
        /* First switch session to original source company */        
        <I-28 {bFcOpenInstance
             &CLASS           = "Session"}>             
        <M-87 run SwitchCompany
           (input  '':U (icCompanyCode), 
            input  viSourceCompanyID (iiCompanyId), 
            output viFcReturnSuper (oiReturnStatus)) in Session>
        <I-33 {bFcCloseInstance
             &CLASS           = "Session"}>    
                 
        if viFcReturnSuper < 0
        then do:
            assign viBlockReturnStatus = viFcReturnSuper
                   vcMessage = trim(#T-10'The system failed to switch the entity.':255(334825313)T-10#).
            <M-34 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-595704':U (icFcMsgNumber), 
                input  ' ':U (icFcExplanation), 
                input  ' ':U (icFcIdentification), 
                input  ' ':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
             leave TRANSACTIONBLOCK.   
        end. /* if viFcReturnSuper < 0 */
        if viFcReturnSuper > 0 and viBlockReturnStatus = 0
        then assign viBlockReturnStatus = viFcReturnSuper.
    
        assign viBJournalEntryBJEMultiCyID = viBJournalEntyForSourceEntity
               viCurrentCompanyID          = viSourceCompanyID.
     
        <I-11 {bFcOpenInstance
             &CLASS           = "BJournalEntry"}>
     
        /* Update the cross company id's on the source entity posting */
        <M-79 run UpdateCrossCompanyIDs
           (input  tCrossCompanyPostingLines (tApiPostingLine), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        
        <I-74 {bFcCloseInstance
             &CLASS           = "BJournalEntry"}>
        
        if viFcReturnSuper < 0 
        then do:
           assign viBlockReturnStatus = viFcReturnSuper.
           leave TRANSACTIONBLOCK. 
        end. /* if viFcReturnSuper < 0 */
        if viFcReturnSuper > 0 and viBlockReturnStatus = 0
        then assign viBlockReturnStatus = viFcReturnSuper.
        
        FINALLY:
            /* make sure that the journalentry instance is closed */
            if vlBJournalEntryStarted = true 
            then do:
                <I-90 {bFcCloseInstance
                     &CLASS           = "BJournalEntry"}>
                assign vlBJournalEntryStarted = false. 
            end.  /* if vlBJournalEntryStarted = true */
            
        END FINALLY.    
    
    /* ======================================================================================= */
    /* End TransactionBlock // Note: the transaction-component is always closed at this point  */
    /* ======================================================================================= */
    end. /* TRANSACTION BLOCK */

    /* ================================ */
    /* Close the journal entry instance */
    /* ================================ */                       
    if vlBJournalEntryStarted  = true
    then do :
        <I-86 {bFcCloseInstance
             &CLASS           = "BJournalEntry"}>
    end. /* if vlBJournalEntryStarted */    
    
    /* ==================================================================================== */
    /* In case of errors, we need to perform AbortTransaction: otherwise the components are */
    /* not correctly closed (important for the reset of the Numbering-mechanism)            */
    /* ==================================================================================== */
    <I-94 {bFcOpenInstance
         &CLASS           = "Transaction"}>
    
    /* check for errors in the big block */                     
    if viBlockReturnStatus <> 0 
    then do:
        assign oiReturnStatus = viBlockReturnStatus.
        if oiReturnStatus < 0
        then do :
           <M-57 run AbortTransaction
              (input  ? (ihParentInstance), 
               output vcDummy (ocInstances), 
               output viFcReturnSuper (oiReturnStatus)) in Transaction>
            
           if viFcReturnSuper < 0 
           then do :
                assign vcMessage= trim(substitute(#T-63'An error occurred while cancelling the transaction: &1. See other messages for further details.':255(14416)T-63#,string(viFcReturnSuper))).
                <M-76 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-825320':U (icFcMsgNumber), 
                    input  ' ':U (icFcExplanation), 
                    input  ' ':U (icFcIdentification), 
                    input  ' ':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy> 
           end. /* If viFcReturnSuper < 0) */
           /* close the transaction */        
           <I-78 {bFcCloseInstance
                 &CLASS           = "Transaction"}>    
           leave METHODBLOCK.    
        end. /*  oiReturnStatus < 0*/             
        
    end. /* if viBlockReturnStatus */   
         
    /* ==================================================================================== */
    /* The remove is needed because otherwise the commit tries to execute some methods that */
    /* our parent-class (BusinessComponent) doesn't have. This also implicates that with    */
    /* the call towards CommitTransaction we do not pass a value for 'ihParentInstance'     */
    /* ==================================================================================== */
    <M-4 run RemoveInstance
       (input  viFcCurrentInstanceId (iiInstanceNr), 
        output viFcReturnSuper (oiReturnStatus)) in Transaction>
        
    if viFcReturnSuper <> 0 
    then do:
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then do :
            assign vcMessage = trim(substitute(#T-84'An error occurred when removing the current instance from the transaction: &1. See other messages for further details.':255(14417)T-84#,string(viFcReturnSuper))).
            <M-49 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  1 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-742820':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
                
            <M-14 run AbortTransaction            
               (input  ? (ihParentInstance), 
                output vcDummy (ocInstances), 
                output viFcReturnSuper (oiReturnStatus)) in Transaction>
                
            if viFcReturnSuper <> 0 
            then do :
                assign vcMessage = trim(substitute(#T-91'An error occurred while cancelling the transaction: &1. See other messages for further details.':255(14416)T-91#,string(viFcReturnSuper))).
                <M-96 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  1 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-398024':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
            end. /* if viFcReturnSuper <> 0 */
            
            <I-67 {bFcCloseInstance
                 &CLASS           = "Transaction"}>
            leave METHODBLOCK.
            
        end. /* if oiReturnStatus < 0 */
        
    end. /* if viFcReturnSuper <> 0 */       

    /* Commit the transaction */            
    <M-6 run CommitTransaction
       (input  true (ilStop), 
        input  ? (ihParentInstance), 
        output vcDummy (ocInstances), 
        output viFcReturnSuper (oiReturnStatus)) in Transaction>
    
    if viFcReturnSuper <> 0
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then do :
            assign vcMessage = trim(substitute(#T-73'An error occurred when saving the transaction: &1. See other messages for further details.':255(14418)T-73#,string(viFcReturnSuper))).
            <M-13 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  1 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-183494':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
                
            <M-26 run AbortTransaction
               (input  ? (ihParentInstance), 
                output vcDummy (ocInstances), 
                output viFcReturnSuper (oiReturnStatus)) in Transaction>
                
            if viFcReturnSuper <> 0 
            then do :
                assign vcMessage = trim(substitute(#T-29'An error occurred while cancelling the transaction: &1. See other messages for further details.':255(14416)T-29#,string(viFcReturnSuper))).
                <M-2 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  1 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-939669':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
            end. /* if viFcReturnSuper <> 0 */
            
            <I-43 {bFcCloseInstance
                 &CLASS           = "Transaction"}>
            leave METHODBLOCK.
            
        end. /* if oiReturnStatus < 0 */
        
    end. /* if viFcReturnSuper < 0 */
    
    /* ================================================= */
    /* Stop the transaction in case it was started here   */
    /* Mark the instance as we have no active transaction */
    /* ================================================== */
    if valid-handle(vhTransactionInst) = true
    then do:
        <I-70 {bFcCloseAndStopInstance
             &CLASS           = "Transaction"}>
    end. /* if valid-handle(vhTransactionInst) */
    else do:
        <I-80 {bFcCloseInstance
             &CLASS           = "Transaction"}>
    end. /* else - valid-handle(vhTransactionInst) */    
  
    FINALLY:   
        /* Ensure we switch session to original source company */
        /* or the UI will get messed up and inconsistent       */        
        if viCurrentCompanyID <> viSourceCompanyID
        then do:
         
            <I-68 {bFcOpenInstance
                 &CLASS           = "Session"}>
                 
            <M-54 run SwitchCompany
               (input  '':U (icCompanyCode), 
                input  viSourceCompanyID (iiCompanyId), 
                output viFcReturnSuper (oiReturnStatus)) in Session>
                
            <I-52 {bFcCloseInstance
                 &CLASS           = "Session"}>   
                  
            if viFcReturnSuper < 0
            then do:
                assign oiReturnStatus = viFcReturnSuper
                       vcMessage = trim(#T-21'The system failed to switch the entity.':255(334825313)T-21#).
                <M-95 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-723436':U (icFcMsgNumber), 
                    input  ' ':U (icFcExplanation), 
                    input  ' ':U (icFcIdentification), 
                    input  ' ':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntryMultiCy>
                 leave METHODBLOCK.   
            end. /* if viFcReturnSuper < 0 */ 
            
            assign viCurrentCompanyID = viSourceCompanyID.
        end. /*  if viCurrentCompanyID <> viSourceCompanyID */
        
        
        /* Empty all instance-less temp-tables */
        empty temp-table tPostingOneCy.
        empty temp-table tPostingLineOneCy.
        empty temp-table tPostingVatOneCy.
        empty temp-table tPostingVatDelayOneCy.
        empty temp-table tPostingSafOneCy.
        empty temp-table tNonSourceCCyPostingLines.

    END FINALLY.        
     
end. /*METHODBLOCK*/