project QadFinancials > class BMfgDomain > method AdditionalUpdatesCopyDomainCtrlTables

Description

Copies records from a list of tables from one domain to another.


Parameters


icSourceDomaininputcharacter
icTargetDomaininputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BMfgDomain.PreSave


program code (program1/bmfgdomain.p)

empty temp-table tWriteCopyMfgDomain.

<Q-3 assign vlFcQueryRecordsAvailable = DomainsByCode (NoCache)
   (input ?, (DomainID)
    input icSourceDomain, (DomainCode)) in BDomain >

if vlFcQueryRecordsAvailable <> true 
then do:
    assign vcMessageText =   #T-5'The domain code &1 cannot be found.':75(31228)T-5#
        oiReturnStatus = -1.

    <M-4 run SetMessage (input  vcMessageText (icMessage), 
                     input  icSourceDomain (icArguments), 
                     input  '' (icFieldName), 
                     input  '' (icFieldValue), 
                     input  'E':U (icType), 
                     input  1 (iiSeverity), 
                     input  '' (icRowid), 
                     input  'QadFin-4730':U (icFcMsgNumber), 
                     input  '' (icFcExplanation), 
                     input  '' (icFcIdentification), 
                     input  '' (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BMfgDomain>
    return.
end.

/* **********************************************************************************/
/* This is the value of the {&DOMAINCTRLCOPYLIST} on 14 may 2008                    */
/* It is put here in comments so it is found when searching/scanning the code       */
/* acdf_mstr,bic_ctrl,bl_ctrl,cac_ctrl,caq_mstr,cas_mstr,cd_det                     */
/* clc_ctrl,co_ctrl,code_mstr,cs_mstr,drp_ctrl,egc_ctrl,emc_ctrl,es_mstr,esc_ctrl   */
/* esh_mstr,ess_mstr,fac_ctrl,famt_mstr,gl_ctrl,iao_mstr,iaod_det,icc_ctrl,iec_ctrl */
/* mfc_ctrl,mrpc_ctrl,opc_ctrl,pcc_ctrl,pgc_ctrl,pic_ctrl,pl_mstr,poc_ctrl,qcc_ctrl */
/* qoc_ctrl,rmc_ctrl,rpc_ctrl,rsn_ref,sac_ctrl,sbc_mstr,sc_mstr,shop_cal,soc_ctrl   */
/* spc_ctrl,src_ctrl,sroc_ctrl,sv_mstr,svc_ctrl,trl_mstr,tx2_mstr                   */
/* txc_ctrl,woc_ctrl                                                                */
/*                                                                                  */
/* The AIM tables must be treated differently. These tables do not use a            */
/* <table-name_prefix>_doamin field but a field called 'domain'. These tables must  */
/* use a different query to the other tables.                                       */
/* The tables are stored in the value of the preprocessor {&AIMCOPYLIST}            */
/* AlgoM, AlgoTypeM, TaskM, TransTypeM                                              */
/* **********************************************************************************/

/* AIM tables */
do viIndex = 1 to num-entries({&AIMCOPYLIST}):

    /* Create a write copy record for every table in the list. The fields that need to change are the OID
       and the xxx_domain field. At the moment the domain field name is got from the start of the table name
       + '_domain' - however, this is a temporary measure and will be got from the field list of the table */
    create tWriteCopyMfgDomain.
    
    assign vcTempCopyTable                        = entry(viIndex,{&AIMCOPYLIST})
           tWriteCopyMfgDomain.tcWriteCopyTable   = vcTempCopyTable
           /* for each gl_ctrl where gl_domain = <icSourceDomain> */
           tWriteCopyMfgDomain.tcWriteCopyPrepare = 
                        "for each ":U 
                        + vcTempCopyTable
                        + " where ":U + vcTempCopyTable
                        + ".":U 
                        + "domain = '":U + icSourceDomain + "'":U
           /* gl_domain, oid_gl_ctrl */
           tWriteCopyMfgDomain.tcWriteCopyField = "domain":U
                        + ",":U
                        + "oid_":U + vcTempCopyTable
           tWriteCopyMfgDomain.tcWriteCopyValue = icTargetDomain + chr(2) + "Sequence:MfgOid":U.

end.

/* Standard MFG/PRO tables */
do viIndex = 1 to num-entries({&DOMAINCTRLCOPYLIST}):

    /* Create a write copy record for every table in the list. The fields that need to change are the OID
       and the xxx_domain field. At the moment the domain field name is got from the start of the table name
       + '_domain' - however, this is a temporary measure and will be got from the field list of the table */
    create tWriteCopyMfgDomain.
    
    assign vcTempCopyTable                        = entry(viIndex,{&DOMAINCTRLCOPYLIST})
           tWriteCopyMfgDomain.tcWriteCopyTable   = vcTempCopyTable
           /* for each gl_ctrl where gl_domain = <icSourceDomain> */
           tWriteCopyMfgDomain.tcWriteCopyPrepare = 
                        "for each ":U 
                        + vcTempCopyTable
                        + " where ":U + vcTempCopyTable
                        + ".":U 
                        + substring(vcTempCopyTable, 1, index(vcTempCopyTable, "_":U),"CHARACTER":U)
                        + "domain = '":U + icSourceDomain + "'":U
           /* gl_domain, oid_gl_ctrl */
           tWriteCopyMfgDomain.tcWriteCopyField =
                        substring(vcTempCopyTable, 1, index(vcTempCopyTable, "_":U),"CHARACTER":U)
                        + "domain":U
                        + ",":U
                        + "oid_":U + vcTempCopyTable
           tWriteCopyMfgDomain.tcWriteCopyValue = icTargetDomain + chr(2) + "Sequence:MfgOid":U.

    /* Code to insert Language and Currency record in gl_ctrl */
    if entry(viIndex,{&DOMAINCTRLCOPYLIST}) EQ "gl_ctrl":U 
    then do:
        find first tCopyDomains where
                   tCopyDomains.DomainCode = icTargetDomain AND 
                   tCopyDomains.tc_Status  = 'N':U 
                   no-error.
        if available tCopyDomains 
        then do:
            find first tCopyDomainProperty where
                       tCopyDomainProperty.Domain_ID = tCopyDomains.Domain_ID AND
                       tCopyDomainProperty.tc_Status = 'N':U 
                       no-error.
            if available tCopyDomainProperty 
            then do:
                <Q-7 run CurrencyByCurrRoundingMethod (all) (Read) (NoCache)
                   (input ?, (CurrencyID)
                    input tCopyDomainProperty.tcCurrencyCode, (CurrencyCode)
                    input ?, (RoundingMethodCode)
                    output dataset tqCurrencyByCurrRoundingMethod) in BCurrency >

                find first tqCurrencyByCurrRoundingMethod no-error.

                assign tWriteCopyMfgDomain.tcWriteCopyField =  
                                             tWriteCopyMfgDomain.tcWriteCopyField 
                                                + ",gl_lang":U 
                                                + ",gl_base_curr":U
                                                + ",gl_rnd_mthd":U 
                                                + ",gl_entity":U 
                       tWriteCopyMfgDomain.tcWriteCopyValue = 
                                            tWriteCopyMfgDomain.tcWriteCopyValue 
                                            + chr(2) + tCopyDomains.tclngcode 
                                            + chr(2) + tCopyDomainProperty.tcCurrencyCode
                                            + chr(2)
                                            + (if available tqCurrencyByCurrRoundingMethod 
                                               then tqCurrencyByCurrRoundingMethod.tcRoundingMethodCode
                                               else "":U)
                                            + chr(2) + tCopyDomains.tcCompanyCode.
            end. /* available tCopyDomainProperty */
        end. /* if available tCopyDomains */
    end. /* if entry */    
    else if entry(viIndex,{&DOMAINCTRLCOPYLIST}) EQ "acdf_mstr":U 
    then do:
        assign tWriteCopyMfgDomain.tcWriteCopyPrepare =  tWriteCopyMfgDomain.tcWriteCopyPrepare + " and acdf_type <> 'ICO_ACCT'":U.
    end. /* if entry */
    else 
    if entry(viIndex,{&DOMAINCTRLCOPYLIST}) EQ "tx2_mstr":U 
    then do:
        assign tWriteCopyMfgDomain.tcWriteCopyPrepare = tWriteCopyMfgDomain.tcWriteCopyPrepare + " and tx2_tax_type = 'NON-TAX'":U.
    end.

end. /* do viIndex */