| tCopyExchangeRate | 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. |
QadFinancials
/* ====================== */
/* Check input parameters */
/* ====================== */
/* Only replicate Accounting, Statutory Currency, Inventory and intrastat */
for each tCopyExchangeRate where
tCopyExchangeRate.tcExchangeRateTypeCode <> {&EXCHANGERATETYPE-ACCOUNTING} and
tCopyExchangeRate.tcExchangeRateTypeCode <> {&EXCHANGERATETYPE-INTRASTAT} and
tCopyExchangeRate.tcExchangeRateTypeCode <> {&EXCHANGERATETYPE-INVENTORY} and
tCopyExchangeRate.tcExchangeRateTypeCode <> {&EXCHANGERATETYPE-STATUTORY}:
delete tCopyExchangeRate.
end.
if not can-find(first tCopyExchangeRate)
then return.
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0
vlQueryStartedDomainBySharedSet = false
vcListExrRate = '':U.
CONVERTBLOCK:
DO:
/* ===================================== */
/* Check which records need to be loaded */
/* ===================================== */
for each tCopyExchangeRate
break by tCopyExchangeRate.SharedSet_ID:
assign vcERType = <M-32 GetMfgExchangeRateType (input tCopyExchangeRate.tcExchangeRateTypeCode (icExchangeRateType)) in BMfgExchangeRate>.
/* =============== */
/* 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 Exch.Rate 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(tCopyExchangeRate.SharedSet_ID)
then do:
<Q-2 run DomainBySharedSetDomain (all) (Read) (Cache)
(input tCopyExchangeRate.SharedSet_ID, (SharedSetId)
input 0, (DomainID)
input icDomainCode, (DomainCode)
output dataset tqDomainBySharedSetDomain) in BDomain >
end. /* if first-of(tCopyExchangeRate.SharedSet_ID) */
for each tqDomainBySharedSetDomain where
tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
/* ============================================================ */
/* Create a list of all texr_rate records that need to be loaded */
/* ============================================================ */
<Q-19 run ExrRateByKey (all) (Read) (NoCache)
(input tqDomainBySharedSetDomain.tcDomainCode, (Domain)
input tCopyExchangeRate.tcFromCurrencyCode, (Curr1)
input tCopyExchangeRate.tcToCurrencyCode, (Curr2)
input vcERType, (RateType)
input tCopyExchangeRate.ExchangeRateValidDateFrom, (StartDate)
output dataset tqExrRateByKey) in BMfgExchangeRate >
find first tqExrRateByKey where
tqExrRateByKey.tcexr_domain = tqDomainBySharedSetDomain.tcDomainCode and
tqExrRateByKey.tcexr_curr1 = tCopyExchangeRate.tcFromCurrencyCode and
tqExrRateByKey.tcexr_curr2 = tCopyExchangeRate.tcToCurrencyCode and
tqExrRateByKey.tcexr_ratetype = vcERType and
tqExrRateByKey.ttexr_start_date = tCopyExchangeRate.ExchangeRateValidDateFrom
no-error.
if available tqExrRateByKey
then assign vcListExrRate = vcListExrRate +
(if vcListExrRate = '':U
then '':U
else chr(4)) +
tqDomainBySharedSetDomain.tcDomainCode +
chr(2) +
tCopyExchangeRate.tcFromCurrencyCode +
chr(2) +
tCopyExchangeRate.tcToCurrencyCode +
chr(2) +
vcERType +
chr(2) +
string(year(tCopyExchangeRate.ExchangeRateValidDateFrom), "9999") +
string(month(tCopyExchangeRate.ExchangeRateValidDateFrom), "99") +
string(day(tCopyExchangeRate.ExchangeRateValidDateFrom), "99").
end. /* for each tqDomainBySharedSetDomain: */
end. /* for each tCopyExchangeRate */
/* ========================== */
/* Load the texr_rate records */
/* ========================== */
if vcListExrRate <> "":U and
vcListExrRate <> ?
then do :
<M-4 run DataLoad
(input '':U (icRowids),
input vcListExrRate (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BMfgExchangeRate>
if viFcReturnSuper <> 0
then do:
assign viLocalReturnStatus = viFcReturnSuper.
leave CONVERTBLOCK.
end. /* if viFcReturnSuper <> 0 */
end. /* if vcListExrRate <> "":U and */
/* =================================== */
/* Convert table tGL to table texr_rate */
/* =================================== */
for each tCopyExchangeRate
break by tCopyExchangeRate.SharedSet_ID:
assign vcERType = <M-31 GetMfgExchangeRateType (input tCopyExchangeRate.tcExchangeRateTypeCode (icExchangeRateType)) in BMfgExchangeRate>.
/* =============== */
/* 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 Exch.Rate 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(tCopyExchangeRate.SharedSet_ID)
then do:
if tCopyExchangeRate.SharedSet_ID = 0 or
tCopyExchangeRate.SharedSet_ID = ?
then do:
assign vcMessage = trim(#T-15'The shared set ID for this exchange rate was not defined.':255(69613)t-15#) + chr(10) +
trim(substitute(#T-20'Domain: &1.':99(56583)T-20#, trim(tqDomainBySharedSetDomain.tcDomainCode) )) + chr(10) +
trim(substitute(#T-21'From Currency: &1.':255(69615)T-21#, trim(tCopyExchangeRate.tcFromCurrencyCode) )) + chr(10) +
trim(substitute(#T-22'To Currency: &1.':255(69616)T-22#, trim(tCopyExchangeRate.tcToCurrencyCode) )) + chr(10) +
trim(substitute(#T-23'Exch Rate Type: &1.':255(69617)t-23#, trim(tCopyExchangeRate.tcExchangeRateTypeCode) )) + chr(10) +
trim(substitute(#T-24'Date From: &1.':255(69618)T-24#, string(tCopyExchangeRate.ExchangeRateValidDateFrom, "99/99/9999") ))
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-8198':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgExchangeRate>
leave CONVERTBLOCK.
end. /* if tCopyExchangeRate.SharedSet_ID = 0 or */
<Q-7 run DomainBySharedSetDomain (all) (Read) (Cache)
(input tCopyExchangeRate.SharedSet_ID, (SharedSetId)
input 0, (DomainID)
input icDomainCode, (DomainCode)
output dataset tqDomainBySharedSetDomain) in BDomain >
end. /* if first-of(tCopyExchangeRate.SharedSet_ID) */
for each tqDomainBySharedSetDomain where
tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
/* ============================================================= */
/* Create or update texr_rate records based on tCopyExchangeRate */
/* ============================================================= */
find texr_rate where
texr_rate.exr_domain = tqDomainBySharedSetDomain.tcDomainCode and
texr_rate.exr_curr1 = tCopyExchangeRate.tcFromCurrencyCode and
texr_rate.exr_curr2 = tCopyExchangeRate.tcToCurrencyCode and
texr_rate.exr_ratetype = vcERType and
texr_rate.exr_start_date = tCopyExchangeRate.ExchangeRateValidDateFrom
no-error.
if not available texr_rate
then do:
if tCopyExchangeRate.tc_Status = "D"
then next.
<M-8 run AddDetailLine
(input 'exr_rate':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BMfgExchangeRate>
if viFcReturnSuper <> 0
then do:
assign viLocalReturnStatus = viFcReturnSuper.
leave CONVERTBLOCK.
end. /* if viFcReturnSuper <> 0 */
assign texr_rate.oid_exr_rate = <M-9 GetNextOidValue () in BMfgExchangeRate> no-error.
if error-status:error
then do:
assign vcMessage = trim(#T-16'The system cannot retrieve an OID value when replicating exchange rates.':255(69619)t-16#) + chr(10) +
trim(substitute(#T-25'Domain: &1.':99(56583)T-25#, trim(tqDomainBySharedSetDomain.tcDomainCode) )) + chr(10) +
trim(substitute(#T-26'From Currency: &1.':255(69615)T-26#, trim(tCopyExchangeRate.tcFromCurrencyCode) )) + chr(10) +
trim(substitute(#T-27'To Currency: &1.':255(69616)T-27#, trim(tCopyExchangeRate.tcToCurrencyCode) )) + chr(10) +
trim(substitute(#T-28'Exch Rate Type: &1.':255(69617)t-28#, trim(tCopyExchangeRate.tcExchangeRateTypeCode) )) + chr(10) +
trim(substitute(#T-29'Date From: &1.':255(69618)T-29#, string(tCopyExchangeRate.ExchangeRateValidDateFrom, "99/99/9999") ))
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-8199':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgExchangeRate>
leave CONVERTBLOCK.
end.
end. /* if not available texr_rate */
else assign texr_rate.tc_Status = (if texr_rate.tc_Status = "":U
then "C":U
else texr_rate.tc_Status).
assign texr_rate.exr_domain = tqDomainBySharedSetDomain.tcDomainCode
texr_rate.exr_curr1 = tCopyExchangeRate.tcFromCurrencyCode
texr_rate.exr_curr2 = tCopyExchangeRate.tcToCurrencyCode
texr_rate.exr_start_date = tCopyExchangeRate.ExchangeRateValidDateFrom
texr_rate.exr_end_date = if(tCopyExchangeRate.ExchangeRateValidDateTill > 01/01/3999)
then 12/31/3999
else tCopyExchangeRate.ExchangeRateValidDateTill
texr_rate.exr_rate = 1 / tCopyExchangeRate.ExchangeRateScale
texr_rate.exr_rate2 = tCopyExchangeRate.ExchangeRate
texr_rate.exr_mod_userid = vcUserLogin
texr_rate.exr_mod_date = today
texr_rate.exr_ratetype = vcERType
texr_rate.tc_Status = (if tCopyExchangeRate.tc_Status = "D":U
then tCopyExchangeRate.tc_Status
else texr_rate.tc_Status).
end. /* for each tqDomainBySharedSetDomain: */
end. /* for each tCopyExchangeRate */
end. /* CONVERTBLOCK */
/* ============== */
/* Stop the query */
/* ============== */
if vlQueryStartedDomainBySharedSet = true
then do:
<Q-11 run DomainBySharedSetDomain (Stop) in BDomain >
assign vlQueryStartedDomainBySharedSet = false.
end. /* if vlQueryStartedDomainBySharedSet = true */
VALIDATEBLOCK:
DO:
if viLocalReturnStatus < 0
then leave VALIDATEBLOCK.
/* ========== */
/* ValidateBC */
/* ========== */
<M-12 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BMfgExchangeRate>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave VALIDATEBLOCK.
/* ================== */
/* Additional Updates */
/* ================== */
<M-13 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BMfgExchangeRate>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave VALIDATEBLOCK.
/* ======== */
/* DataSave */
/* ======== */
<M-14 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgExchangeRate>
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 = "BMfgExchangeRate".
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/bmfgexchangerate.apireplicatefromfinancials.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tCopyExchangeRate").
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.