tDivision | 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 tDivision) then return. /* ================== */ /* Exception Handling */ /* ================== */ assign oiReturnStatus = -98 viLocalReturnStatus = 0 vlQueryStartedDomainBySharedSet = false vlQueryStartedTranslation = false vcListSbMstr = '':U. CONVERTBLOCK: DO: /* ===================================== */ /* Check which records need to be loaded */ /* ===================================== */ for each tDivision break by tDivision.SharedSet_ID: /* =============== */ /* Start the query */ /* =============== */ if vlQueryStartedDomainBySharedSet = false then do: <Q-1 run DomainBySharedSetDomain (Start) in BDomain > assign vlQueryStartedDomainBySharedSet = true. end. /* if vlQueryStartedDomainBySharedSet = false */ /* ================================================================================================== */ /* Check if the Sub-Account 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(tDivision.SharedSet_ID) then do: <Q-2 run DomainBySharedSetDomain (all) (Read) (Cache) (input tDivision.SharedSet_ID, (SharedSetId) input 0, (DomainID) input icDomainCode, (DomainCode) output dataset tqDomainBySharedSetDomain) in BDomain > end. /* if first-of(tDivision.SharedSet_ID) */ for each tqDomainBySharedSetDomain where tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl: /* ============================================================ */ /* Create a list of all tsb_mstr records that need to be loaded */ /* ============================================================ */ /* NOTE: DIFFERENT APPROACH BECAUSE PRIM-INDEX ALSO INCLUDES ACTIVE FLAG */ <Q-19 run SbMstrBySubDomain (first) (Read) (NoCache) (input tqDomainBySharedSetDomain.tcDomainCode, (Domain) input tDivision.DivisionCode, (Sub) output dataset tqSbMstrBySubDomain) in BMfgSubAccount > find first tqSbMstrBySubDomain where tqSbMstrBySubDomain.tcsb_domain = tqDomainBySharedSetDomain.tcDomainCode and tqSbMstrBySubDomain.tcsb_sub = tDivision.DivisionCode no-lock no-error. if available tqSbMstrBySubDomain then assign vcListSbMstr = vcListSbMstr + (if vcListSbMstr = '':U then '':U else chr(4)) + tqSbMstrBySubDomain.tcsb_domain + chr(2) + tqSbMstrBySubDomain.tcsb_sub + chr(2) + string(tqSbMstrBySubDomain.tlsb_active). end. /* for each tqDomainBySharedSetDomain: */ end. /* for each tDivision */ /* ========================= */ /* Load the tsb_mstr records */ /* ========================= */ if vcListSbMstr <> "":U and vcListSbMstr <> ? then do : <M-4 run DataLoad (input '':U (icRowids), input vcListSbMstr (icPkeys), input '':U (icObjectIds), input '':U (icFreeform), input false (ilKeepPrevious), output viFcReturnSuper (oiReturnStatus)) in BMfgSubAccount> if viFcReturnSuper <> 0 then do: assign viLocalReturnStatus = viFcReturnSuper. leave CONVERTBLOCK. end. /* if viFcReturnSuper <> 0 */ end. /* if vcListSbMstr <> "":U and */ /* =================================== */ /* Convert table tGL to table tsb_mstr */ /* =================================== */ for each tDivision break by tDivision.SharedSet_ID: /* =============== */ /* Start the query */ /* =============== */ if vlQueryStartedDomainBySharedSet = false then do: <Q-5 run DomainBySharedSetDomain (Start) in BDomain > assign vlQueryStartedDomainBySharedSet = true. end. /* if vlQueryStartedDomainBySharedSet = false */ /* ================================================================================================== */ /* Check if the Sub-Account 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(tDivision.SharedSet_ID) then do: if tDivision.SharedSet_ID = 0 or tDivision.SharedSet_ID = ? then do: assign vcMessage = trim(substitute(#T-15'The shared set ID for sub-account (&1) was not defined.':255(69586)t-15#, trim(tDivision.DivisionCode) )) viLocalReturnStatus = -3. <M-6 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-8170':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BMfgSubAccount> leave CONVERTBLOCK. end. /* if tDivision.SharedSet_ID = 0 or */ <Q-7 run DomainBySharedSetDomain (all) (Read) (Cache) (input tDivision.SharedSet_ID, (SharedSetId) input 0, (DomainID) input icDomainCode, (DomainCode) output dataset tqDomainBySharedSetDomain) in BDomain > end. /* if first-of(tDivision.SharedSet_ID) */ for each tqDomainBySharedSetDomain where tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl: /* ==================================================== */ /* Create or update tsb_mstr records based on tDivision */ /* ==================================================== */ find tsb_mstr where tsb_mstr.sb_sub = tDivision.DivisionCode and tsb_mstr.sb_domain = tqDomainBySharedSetDomain.tcDomainCode no-error. if not available tsb_mstr then do: if tDivision.tc_Status = "D" then next. <M-8 run AddDetailLine (input 'sb_mstr':U (icTable), input '':U (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BMfgSubAccount> if viFcReturnSuper <> 0 then do: assign viLocalReturnStatus = viFcReturnSuper. leave CONVERTBLOCK. end. /* if viFcReturnSuper <> 0 */ assign tsb_mstr.oid_sb_mstr = <M-9 GetNextOidValue () in BMfgSubAccount> no-error. if error-status:error then do: assign vcMessage = trim(#T-16'The system cannot retrieve an OID value when replicating accounts.':255(69185)t-16#) + chr(10) + trim(substitute(#T-17'Sub-account: &1.':255(2244)T-17#, trim(tDivision.DivisionCode))) viLocalReturnStatus = -1. if ERROR-STATUS:NUM-MESSAGES > 0 then assign vcMessage = vcMessage + chr(10) + trim(substitute(#T-18'Detailed info: &1 (&2).':255(466)T-18#,ERROR-STATUS:GET-MESSAGE(1),string(ERROR-STATUS:GET-NUMBER(1)))). <M-10 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-8171':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BMfgSubAccount> leave CONVERTBLOCK. end. end. /* if not available tsb_mstr */ else assign tsb_mstr.tc_Status = "C":U. assign tsb_mstr.sb_domain = tqDomainBySharedSetDomain.tcDomainCode tsb_mstr.sb_sub = tDivision.DivisionCode tsb_mstr.sb_desc = tDivision.DivisionDescription tsb_mstr.sb_active = tDivision.DivisionIsActive tsb_mstr.tc_Status = (if tDivision.tc_Status = "D":U then tDivision.tc_Status else tsb_mstr.tc_Status). if vlQueryStartedTranslation = false then do: <Q-21 run TranslationByIDLngParent (Start) in BTranslation > assign vlQueryStartedTranslation = true. end. <Q-22 run TranslationByIDLngParent (all) (Read) (NoCache) (input tqDomainBySharedSetDomain.tiLng_ID, (LngID) input tDivision.Division_ID, (ParentID) input 0, (TranslationID) output dataset tqTranslationByIDLngParent) in BTranslation > find first tqTranslationByIDLngParent no-error. if available tqTranslationByIDLngParent then assign tsb_mstr.sb_desc = tqTranslationByIDLngParent.tcTranslationStringText. end. /* for each tqDomainBySharedSetDomain: */ end. /* for each tDivision */ end. /* CONVERTBLOCK */ /* ============== */ /* Stop the query */ /* ============== */ if vlQueryStartedDomainBySharedSet = true then do: <Q-11 run DomainBySharedSetDomain (Stop) in BDomain > assign vlQueryStartedDomainBySharedSet = false. end. /* if vlQueryStartedDomainBySharedSet = true */ if vlQueryStartedTranslation = true then do: <Q-20 run TranslationByIDLngParent (Stop) in BTranslation > assign vlQueryStartedTranslation = false. end. VALIDATEBLOCK: DO: if viLocalReturnStatus < 0 then leave VALIDATEBLOCK. /* ========== */ /* ValidateBC */ /* ========== */ <M-12 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BMfgSubAccount> if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave VALIDATEBLOCK. /* ================== */ /* Additional Updates */ /* ================== */ <M-13 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BMfgSubAccount> if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then leave VALIDATEBLOCK. /* ======== */ /* DataSave */ /* ======== */ <M-14 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgSubAccount> 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 = "BMfgSubAccount". create ttContext. assign ttContext.propertyName = "methodName" ttContext.propertyValue = "ApiReplicateFromFinancials". 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/bmfgsubaccount.apireplicatefromfinancials.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::icDomainCode = <parameter value>. vhParameter = vhInputDS:get-buffer-handle("tDivision"). 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.