tDebtorsToUpdate2 | input | temp-table | |
icDomainCode | input | character | When the domaincode is filled --> Replicate only to this domain. If the domaincode is empty --> Replicate to all domains in this shared set. |
oiReturnStatus | output | integer | Return status of the method. |
/* ====================== */ /* Check input parameters */ /* ====================== */ if not can-find(first tDebtorstoUpdate2) then return. /* ================== */ /* Exception Handling */ /* ================== */ assign oiReturnStatus = -98 viLocalReturnStatus = 0 vcListLsMstr = '':U. CONVERTBLOCK: DO: /* ===================================== */ /* Check which records need to be loaded */ /* ===================================== */ for each tDebtorstoUpdate2 where tDebtorsToUpdate2.tc_Status <> 'N' break by tDebtorstoUpdate2.SharedSet_ID: /* ============================================================================================== */ /* Check if the Debtor 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(tDebtorstoUpdate2.SharedSet_ID) then do: <Q-22 run DomainBySharedSetDomain (all) (Read) (Cache) (input tDebtorstoUpdate2.SharedSet_ID, (SharedSetId) input 0, (DomainID) input icDomainCode, (DomainCode) output dataset tqDomainBySharedSetDomain) in BDomain > end. /* if first-of(tDebtorstoUpdate2.SharedSet_ID) */ /* =============================================================================================== */ /* Get all Mfg Addresses which are already defined in the database */ /* =============================================================================================== */ <Q-62 run DomainSharedSetForLsMstr (all) (Read) (NoCache) (input tDebtorsToUpdate2.SharedSet_ID, (SharedSetId) input icDomainCode, (DomainCode) input tDebtorsToUpdate2.DebtorCode, (Address) input 'customer':U, (AddressType) output dataset tqDomainSharedSetForLsMstr) in BDomain > if can-find(first tqDomainSharedSetForLsMstr) then do: 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 = tDebtorsToUpdate2.DebtorCode) then assign vcListLsMstr = vcListLsMstr + (if vcListLsMstr = '':U then '':U else chr(4)) + tqDomainBySharedSetDomain.tcDomainCode + chr(2) + tDebtorstoUpdate2.DebtorCode + chr(2) + "customer":U. if length(vcListLsMstr, "CHARACTER") > 30000 then do: /* ========================= */ /* Load the tls_mstr records */ /* ========================= */ <M-94 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. /* if can-find(first tqDomainSharedSetForLsMstr) */ end. /* for each tDebtorstoUpdate2 */ /* ========================= */ /* Load the tls_mstr records */ /* ========================= */ if vcListLsMstr <> "":U and vcListLsMstr <> ? then do : <M-23 run DataLoad (input '':U (icRowids), input vcListLsMstr (icPkeys), input '':U (icObjectIds), input '':U (icFreeform), input false (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 tDebtorstoUpdate2 to table tls_mstr */ /* ================================================= */ for each tDebtorstoUpdate2 break by tDebtorstoUpdate2.SharedSet_ID: /* ============================================================================================== */ /* Check if the debtor 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(tDebtorstoUpdate2.SharedSet_ID) then do: if tDebtorstoUpdate2.SharedSet_ID = 0 or tDebtorstoUpdate2.SharedSet_ID = ? then do: assign vcMessage = trim(substitute(#T-35'The shared set ID for this customer (&1) was not defined.':255(69662)t-35#, trim(string(tDebtorstoUpdate2.DebtorCode)) )) viLocalReturnStatus = -3. <M-25 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-8237':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail> leave CONVERTBLOCK. end. /* if tDebtorstoUpdate2.SharedSet_ID = 0 or */ <Q-26 run DomainBySharedSetDomain (all) (Read) (Cache) (input tDebtorstoUpdate2.SharedSet_ID, (SharedSetId) input 0, (DomainID) input icDomainCode, (DomainCode) output dataset tqDomainBySharedSetDomain) in BDomain > end. /* if first-of(tDebtorstoUpdate2.SharedSet_ID) */ for each tqDomainBySharedSetDomain where tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl: /* ================================================================== */ /* Create or update tls_mstr records based on tDebtorstoUpdate2 */ /* ================================================================== */ if tDebtorsToUpdate2.tc_Status <> 'N' then do: find tls_mstr where tls_mstr.ls_addr = tDebtorstoUpdate2.DebtorCode and tls_mstr.ls_domain = tqDomainBySharedSetDomain.tcDomainCode and tls_mstr.ls_type = "customer":U no-error. end. if not available tls_mstr or tDebtorsToUpdate2.tc_Status = 'N' then do: if tDebtorstoUpdate2.tc_Status = "D" then next. <M-27 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 = tDebtorstoUpdate2.DebtorCode tls_mstr.ls_domain = tqDomainBySharedSetDomain.tcDomainCode tls_mstr.ls_type = "customer":U tls_mstr.tc_Status = (if tDebtorstoUpdate2.tc_Status = "D":U then tDebtorstoUpdate2.tc_Status else tls_mstr.tc_Status). end. /* for each tqDomainBySharedSetDomain: */ end. /* for each tDebtorstoUpdate2 */ end. /* CONVERTBLOCK */ VALIDATEBLOCK: DO: if viLocalReturnStatus < 0 then leave VALIDATEBLOCK. /* ========== */ /* ValidateBC */ /* ========== */ <M-31 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail> if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave VALIDATEBLOCK. /* ================== */ /* Additional Updates */ /* ================== */ <M-32 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BMfgAddressListDetail> if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave VALIDATEBLOCK. /* ======== */ /* DataSave */ /* ======== */ <M-33 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.
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 = "ApiReplicateFromFinancialsDebtor". 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.apireplicatefromfinancialsdebtor.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::icDomainCode = <parameter value>. vhParameter = vhInputDS:get-buffer-handle("tDebtorsToUpdate2"). 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.