project QadFinancials > class BMfgAddressListDetail > method ApiReplicateFromFinancialsCreditor

Description

Replicate Creditor to MFG/PRO Address List Detail


Parameters


tCreditorsToUpdate2inputtemp-table
icDomainCodeinputcharacterWhen the domaincode is filled --> Replicate only to this domain.
If the domaincode is empty --> Replicate to all domains in this shared set.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BMfgSupplier.AdditionalUpdates


program code (program9/bmfgaddresslistdetail.p)

/* ====================== */
/* Check input parameters */
/* ====================== */
if not can-find(first tCreditorstoUpdate2)
then return.

/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus                  = -98
       viLocalReturnStatus             = 0
       vcListLsMstr                    = '':U.

CONVERTBLOCK:
DO:
    /* ===================================== */
    /* Check which records need to be loaded */
    /* ===================================== */
    for each tCreditorstoUpdate2
        break by tCreditorstoUpdate2.SharedSet_ID:
    
        /* ================================================================================================ */
        /* Check if the Creditor 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(tCreditorstoUpdate2.SharedSet_ID)
        then do:
            <Q-39 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tCreditorstoUpdate2.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >
        end. /* if first-of(tCreditorstoUpdate2.SharedSet_ID) */
        
        /* =============================================================================================== */
        /* Get all Mfg Addresses which are already defined in the database                                 */
        /* =============================================================================================== */
        <Q-5 run DomainSharedSetForLsMstr (all) (Read) (NoCache)
           (input tCreditorsToUpdate2.SharedSet_ID, (SharedSetId)
            input icDomainCode, (DomainCode)
            input tCreditorsToUpdate2.CreditorCode, (Address)
            input 'Supplier':U, (AddressType)
            output dataset tqDomainSharedSetForLsMstr) in BDomain >
            
        for each tqDomainBySharedSetDomain where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
            /* ============================================================ */
            /* Create a list of all tls_mstr records that need to be loaded */
            /* ============================================================ */
            if can-find(first tqDomainSharedSetForLsMstr where
                              tqDomainSharedSetForLsMstr.tcDomainCode = tqDomainBySharedSetDomain.tcDomainCode and
                              tqDomainSharedSetForLsMstr.tcls_addr    = tCreditorsToUpdate2.CreditorCode)
            then assign vcListLsMstr = vcListLsMstr                           + 
                                       (if vcListLsMstr = '':U
                                        then '':U
                                        else chr(4))                          +
                                       tqDomainBySharedSetDomain.tcDomainCode +
                                       chr(2)                                 +
                                       tCreditorstoUpdate2.CreditorCode           +
                                       chr(2)                                 +
                                       "supplier":U.
                                       
            if length(vcListLsMstr, "CHARACTER") > 10000
            then do:                           
                <M-54 run DataLoad
               (input  '':U (icRowids), 
                input  vcListLsMstr (icPkeys), 
                input  '':U (icObjectIds), 
                input  '':U (icFreeform), 
                input  true (ilKeepPrevious), 
                output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
                 
                if viFcReturnSuper <> 0
                then assign viLocalReturnStatus = viFcReturnSuper.
                 
                assign vcListLsMstr = '':U.
            end. /*length*/   
        end. /* for each tqDomainBySharedSetDomain: */
    end. /* for each tCreditorstoUpdate2 */
    
    /* ========================= */
    /* Load the tls_mstr records */
    /* ========================= */
    if vcListLsMstr <> "":U and 
       vcListLsMstr <> ?
    then do :    
        <M-40 run DataLoad
           (input  '':U (icRowids), 
            input  vcListLsMstr (icPkeys), 
            input  '':U (icObjectIds), 
            input  '':U (icFreeform), 
            input  true (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
        if viFcReturnSuper <> 0
        then do:
            assign viLocalReturnStatus = viFcReturnSuper.
            leave CONVERTBLOCK.
        end. /* if viFcReturnSuper <> 0 */
    end. /* if vcListLsMstr <> "":U and  */ 

    /* =================================================== */
    /* Convert table tCreditorstoUpdate2 to table tls_mstr */
    /* =================================================== */
    for each tCreditorstoUpdate2
        break by tCreditorstoUpdate2.SharedSet_ID:
    
        /* ================================================================================================ */
        /* Check if the Creditor 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(tCreditorstoUpdate2.SharedSet_ID)
        then do:
            if tCreditorstoUpdate2.SharedSet_ID = 0 or
               tCreditorstoUpdate2.SharedSet_ID = ?
            then do:
                assign vcMessage           = trim(substitute(#T-52'The shared set ID for supplier (&1) was not defined.':255(69743)T-52#, trim(string(tCreditorstoUpdate2.CreditorCode)) ))
                       viLocalReturnStatus = -3.
                <M-42 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-8279':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
                leave CONVERTBLOCK.
            end. /* if tCreditorstoUpdate2.SharedSet_ID = 0 or */

            <Q-44 run DomainBySharedSetDomain (all) (Read) (Cache)
               (input tCreditorstoUpdate2.SharedSet_ID, (SharedSetId)
                input 0, (DomainID)
                input icDomainCode, (DomainCode)
                output dataset tqDomainBySharedSetDomain) in BDomain >            
        end. /* if first-of(tCreditorstoUpdate2.SharedSet_ID) */
            
        for each tqDomainBySharedSetDomain where
                 tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
            /* ================================================================== */
            /* Create or update tls_mstr records based on tCreditorstoUpdate2 */
            /* ================================================================== */
            find tls_mstr where
                 tls_mstr.ls_addr   = tCreditorstoUpdate2.CreditorCode and
                 tls_mstr.ls_domain = tqDomainBySharedSetDomain.tcDomainCode   and
                 tls_mstr.ls_type   = "supplier":U
                 no-error.
            if not available tls_mstr
            then do:
                if tCreditorstoUpdate2.tc_Status = "D"
                then next.

                <M-45 run AddDetailLine
                   (input  'ls_mstr':U (icTable), 
                    input  '':U (icParentRowid), 
                    output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
                if viFcReturnSuper <> 0
                then do:
                    assign viLocalReturnStatus = viFcReturnSuper.
                    leave CONVERTBLOCK.
                end. /* if viFcReturnSuper <> 0 */                
            end. /* if not available tls_mstr */  
            else assign tls_mstr.tc_Status = "C":U.

            assign tls_mstr.ls_addr       = tCreditorstoUpdate2.CreditorCode
                   tls_mstr.ls_domain     = tqDomainBySharedSetDomain.tcDomainCode
                   tls_mstr.ls_type       = "supplier":U
                   tls_mstr.tc_Status     = (if tCreditorstoUpdate2.tc_Status = "D":U
                                             then tCreditorstoUpdate2.tc_Status
                                             else tls_mstr.tc_Status).
        end. /* for each tqDomainBySharedSetDomain: */        
    end. /* for each tCreditorstoUpdate2 */
end. /* CONVERTBLOCK */

VALIDATEBLOCK:
DO:
    if viLocalReturnStatus < 0
    then leave VALIDATEBLOCK.

    /* ========== */
    /* ValidateBC */
    /* ========== */
    <M-49 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave VALIDATEBLOCK.

    /* ================== */
    /* Additional Updates */
    /* ================== */
    <M-50 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave VALIDATEBLOCK.
    
    /* ======== */
    /* DataSave */
    /* ======== */
    <M-51 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave VALIDATEBLOCK.
end. /* VALIDATEBLOCK */

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


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 = "BMfgAddressListDetail".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiReplicateFromFinancialsCreditor".
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/bmfgaddresslistdetail.apireplicatefromfinancialscreditor.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tCreditorsToUpdate2").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

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