project QadFinancials > class BMfgAddress > method ReplicateFromFinancialsShipToDebtorLink


Parameters


tDebtorShiptosToUpdateinputtemp-table
icDomainCodeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BMfgAddress.ApiReplicateFromFinancialsShipTo


program code (program9/bmfgaddress.p)

MAIN_BLOCK:
do on error undo, leave:
    /* ====================== */
    /* Check input parameters */
    /* ====================== */
    if not can-find(first tDebtorShiptosToUpdate where
                          tDebtorShiptosToUpdate.DebtorShipToIsDebtor)
    then return.
    
    /* ================== */
    /* Exception Handling */
    /* ================== */
    assign oiReturnStatus                  = -98
           viLocalReturnStatus             = 0
           vcListAdMstr                    = '':U.
    
    /* ============================================================================== */
    /* Check which records need to be loaded                                          */
    /* Handle only those Ship-to addresses linked to Customer                         */
    /* ============================================================================== */
    for each tDebtorShiptosToUpdate where
             tDebtorShiptosToUpdate.DebtorShipToIsDebtor  = true and
             (tDebtorShiptosToUpdate.tc_Status            = "N":U or
              tDebtorShiptosToUpdate.tc_Status            = "D":U)
        break by tDebtorShiptosToUpdate.SharedSet_ID:
    
        /* ============================================================================================== */
        /* Check if the record needs to be replicated to one domain or to all domains of this shared set  */
        /* If icDomainCode is left blank, all domains for this shared set will be replicated.             */
        /* ============================================================================================== */
        if first-of(tDebtorShiptosToUpdate.SharedSet_ID)
        then do:
            <Q-38 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tDebtorShiptosToUpdate.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >
        end. /* if first-of(tDebtorShiptosToUpdate.SharedSet_ID) */

        /* =============================================================================================== */
        /* Get all Mfg Addresses of the linked Customer                                                    */
        /* =============================================================================================== */
        <Q-85 run DomainSharedSetForMfgAddress (all) (Read) (Cache)
           (input tDebtorShiptosToUpdate.SharedSet_ID, (SharedSetId)
            input icDomainCode, (DomainCode)
            input tDebtorShiptosToUpdate.DebtorShipToCode, (Address)
            output dataset tqDomainSharedSetForMfgAddress) in BDomain >
            
        for each tqDomainBySharedSetDomain where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:

            /* ============================================================ */
            /* Create a list of all tad_mstr records that need to be loaded */
            /* ============================================================ */
            if can-find(first tqDomainSharedSetForMfgAddress where
                              tqDomainSharedSetForMfgAddress.tcDomainCode = tqDomainBySharedSetDomain.tcDomainCode and
                              tqDomainSharedSetForMfgAddress.tcad_addr    = tDebtorShiptosToUpdate.DebtorShipToCode)
            then assign vcListAdMstr = vcListAdMstr                           + 
                                       (if vcListAdMstr = '':U
                                        then '':U
                                        else chr(4))                          +
                                       tqDomainBySharedSetDomain.tcDomainCode +
                                       chr(2)                                 +
                                       tDebtorShiptosToUpdate.DebtorShipToCode.
                                       
            if length(vcListAdMstr, "CHARACTER") > 30000
            then do:
                
                /* ========================= */
                /* Load the tad_mstr records */
                /* ========================= */
                  <M-79 run DataLoad
                     (input  '':U (icRowids), 
                      input  vcListAdMstr (icPkeys), 
                      input  '':U (icObjectIds), 
                      input  '':U (icFreeform), 
                      input  true (ilKeepPrevious), 
                      output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
                                        
                 if viFcReturnSuper <> 0
                 then assign viLocalReturnStatus = viFcReturnSuper.

                 assign vcListAdMstr = '':U.   

            end. /* length */                   
        end. /* for each tqDomainBySharedSetDomain: */
    end. /* for each tDebtorShiptosToUpdate where */


    /* ========================= */
    /* Load the tad_mstr records */
    /* ========================= */
    if vcListAdMstr <> "":U and 
       vcListAdMstr <> ?
    then do :
        <M-75 run DataLoad
           (input  '':U (icRowids), 
            input  vcListAdMstr (icPkeys), 
            input  '':U (icObjectIds), 
            input  '':U (icFreeform), 
            input  true (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturnStatus = 0 then assign viLocalReturnStatus = viFcReturnSuper.
        if viLocalReturnStatus < 0 then leave MAIN_BLOCK.
    end. /* if vcListVdMstr <> "":U and */

    /* ========================================= */
    /* Convert table tDebtorShiptosToUpdate to table tad_mstr */
    /* ========================================= */
    /* ============================================================================== */
    for each tDebtorShiptosToUpdate where
             tDebtorShiptosToUpdate.DebtorShipToIsDebtor  = true and
             (tDebtorShiptosToUpdate.tc_Status            = "N":U or
              tDebtorShiptosToUpdate.tc_Status            = "D":U)
        break by tDebtorShiptosToUpdate.SharedSet_ID:
    
        /* ============================================================================================== */
        /* Check if the shipto needs to be replicated to one domain or to all domains of this shared set  */
        /* If icDomainCode is left blank, all domains for this shared set will be replicated.             */
        /* ============================================================================================== */
        if first-of(tDebtorShiptosToUpdate.SharedSet_ID)
        then do:
            if tDebtorShiptosToUpdate.SharedSet_ID = 0 or
               tDebtorShiptosToUpdate.SharedSet_ID = ?
            then do:
                assign vcMessage           = trim(substitute(#T-71'The shared set ID for customer ship-to (&1) was not defined.':255(69639)T-71#, trim(string(tDebtorShiptosToUpdate.DebtorShipToCode)) ))
                       viLocalReturnStatus = -3.
                <M-72 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-473351':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgAddress>
                leave MAIN_BLOCK.
            end. /* if tDebtorShiptosToUpdate.SharedSet_ID = 0 or */

            <Q-45 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tDebtorShiptosToUpdate.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >            
        end. /* if first-of(tDebtorShiptosToUpdate.SharedSet_ID) */
            
        for each tqDomainBySharedSetDomain  where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
            /* ================================================================= */
            /* Create or update tad_mstr records based on tDebtorShiptosToUpdate */
            /* ================================================================= */
            find tad_mstr where
                 tad_mstr.ad_addr   = tDebtorShiptosToUpdate.DebtorShiptoCode and
                 tad_mstr.ad_domain = tqDomainBySharedSetDomain.tcDomainCode
                 no-error.
            if not available tad_mstr
            then next.

            /* Update data */
            assign tad_mstr.ad_ref    = (if tDebtorShiptosToUpdate.tc_Status = "N":U
                                         then tDebtorShiptosToUpdate.tcDebtorCode
                                         else "":U)
                   tad_mstr.tc_Status = (if tad_mstr.tc_Status = "":U then "C":U else tad_mstr.tc_Status).
        end. /* for each tqDomainBySharedSetDomain: */
    end. /* for each tDebtorShiptosToUpdate */
end. /* of MAIN_BLOCK */

/* ================== */                        
/* Exception Handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.