Description
Replicate the GL Mask records from Financials to MFG/PRO.
Parameters
tGLMask | input | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bmfgacctsubccproj.p)
/* ====================== */
/* Check input parameters */
/* ====================== */
if not can-find(first tGLMask)
then return.
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0
vcListAscMstr = '':U
vlQueryStartedDomainsPrim = false.
CONVERTBLOCK:
DO:
<M-28 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
assign vcListAscMstr = '':U.
if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave CONVERTBLOCK.
/* ===================================== */
/* Check which records need to be loaded */
/* ===================================== */
for each tGLMask
break by tGLMask.Domain_ID:
if first-of(tGLMask.Domain_ID)
then do:
if vlQueryStartedDomainsPrim = false
then do:
<Q-20 run DomainsPrim (Start) in BDomain >
assign vlQueryStartedDomainsPrim = true.
end. /* if vlQueryStartedDomainsPrim = false */
<Q-15 run DomainsPrim (all) (Read) (NoCache)
(input tGLMask.Domain_ID, (DomainID)
input '':U, (DomainCode)
output dataset tqDomainsPrim) in BDomain >
find tqDomainsPrim where
tqDomainsPrim.tiDomain_ID = tGLMask.Domain_ID
no-lock no-error.
if not available tqDomainsPrim
then do:
assign vcMessage = trim(#T-16'GL Mask could not be replicated to table asc_mstr.':255(70390)T-16#) + chr(10) +
trim(substitute(#T-17'Invalid Domain ID (&1).':255(70391)T-17#, string(tGLMask.Domain_ID) ))
viLocalReturnStatus = -1.
<M-18 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tGLMask.Domain_ID':U (icFieldName),
input string(tglmask.domain_ID) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tGLMask.tc_Rowid (icRowid),
input 'QadFin-8414':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
leave CONVERTBLOCK.
end. /* if not available tqDomainsPrim */
end. /* if first-of(tGLMask.Domain_ID) */
/* ============================================================ */
/* Create a list of all tasc_mstr records that need to be loaded */
/* ============================================================ */
<Q-19 assign vlFcQueryRecordsAvailable = AscMstrByKey (NoCache)
(input tGLMask.tcGLCode, (AscAcc)
input tGLMask.tcDivisionCode, (AscSub)
input tGLMask.tcCostCentreCode, (AscCc)
input tqDomainsPrim.tcDomainCode, (AscDomain)
input tGLMask.tcProjectCode, (AscProj)) in BMfgAcctSubCCProj >
if vlFcQueryRecordsAvailable = true
then assign vcListAscMstr = vcListAscMstr +
(if vcListAscMstr = '':U
then '':U
else chr(4)) +
tqDomainsPrim.tcDomainCode + chr(2) +
tGLMask.tcGLCode + chr(2) +
tGLMask.tcDivisionCode + chr(2) +
tGLMask.tcCostCentreCode + chr(2) +
tGLMask.tcProjectCode.
if length(vcListAscMstr, "CHARACTER") > 10000
then do:
<M-27 run DataLoad
(input '':U (icRowids),
input vcListAscMstr (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
assign vcListAscMstr = '':U.
if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave CONVERTBLOCK.
end. /* if length(vcListAscMstr, "CHARACTER") > 10000 */
end. /* for each tGLMask */
/* ========================== */
/* Load the tasc_mstr records */
/* ========================== */
if vcListAscMstr <> '':U and
vcListAscMstr <> ?
then do:
<M-5 run DataLoad
(input '':U (icRowids),
input vcListAscMstr (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
assign vcListAscMstr = '':U.
if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave CONVERTBLOCK.
end. /* if vcListAscMstr <> '':U */
/* ======================================== */
/* Convert table tGLMask to table tasc_mstr */
/* ======================================== */
for each tGLMask
break by tGLMask.Domain_ID:
if first-of(tGLMask.Domain_ID)
then do:
if vlQueryStartedDomainsPrim = false
then do:
<Q-22 run DomainsPrim (Start) in BDomain >
assign vlQueryStartedDomainsPrim = true.
end. /* if vlQueryStartedDomainsPrim = false */
<Q-23 run DomainsPrim (all) (Read) (NoCache)
(input tGLMask.Domain_ID, (DomainID)
input '':U, (DomainCode)
output dataset tqDomainsPrim) in BDomain >
find tqDomainsPrim where
tqDomainsPrim.tiDomain_ID = tGLMask.Domain_ID
no-lock no-error.
if not available tqDomainsPrim
then do:
assign vcMessage = trim(#T-25'GL Mask could not be replicated to table asc_mstr.':255(70390)T-25#) + chr(10) +
trim(substitute(#T-26'Invalid Domain ID (&1).':255(70391)T-26#, string(tGLMask.Domain_ID) ))
viLocalReturnStatus = -1.
<M-24 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'tGLMask.Domain_ID':U (icFieldName),
input string(tglmask.domain_ID) (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tGLMask.tc_Rowid (icRowid),
input 'QadFin-8419':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
leave CONVERTBLOCK.
end. /* if not available tqDomainsPrim */
end. /* if first-of(tGLMask.Domain_ID) */
/* ================================================== */
/* Create or update tasc_mstr records based on tGLMask */
/* ================================================== */
find tasc_mstr where
tasc_mstr.asc_domain = tqDomainsPrim.tcDomainCode and
tasc_mstr.asc_acc = tGLMask.tcGLCode and
tasc_mstr.asc_sub = tGLMask.tcDivisionCode and
tasc_mstr.asc_cc = tGLMask.tcCostCentreCode and
tasc_mstr.asc_proj = tGLMask.tcProjectCode
no-error.
if not available tasc_mstr
then do:
if tGLMask.tc_Status = "D"
then next.
<M-6 run AddDetailLine
(input 'asc_mstr':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
if viFcReturnSuper <> 0
then do:
assign viLocalReturnStatus = viFcReturnSuper.
leave CONVERTBLOCK.
end. /* if viFcReturnSuper <> 0 */
assign tasc_mstr.oid_asc_mstr = <M-7 GetNextOidValue () in BMfgAcctSubCCProj> no-error.
if error-status:error
then do:
assign vcMessage = trim(#T-12'Unable to retrieve an oid-value while replicating GL Masks.':255(70392)T-12#)
viLocalReturnStatus = -1.
if ERROR-STATUS:NUM-MESSAGES > 0
then assign vcMessage = vcMessage + chr(10) +
trim(substitute(#T-14'Detailed info: &1 (&2).':255(466)T-14#,ERROR-STATUS:GET-MESSAGE(1),string(ERROR-STATUS:GET-NUMBER(1)))).
<M-8 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-8413':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
leave CONVERTBLOCK.
end.
end. /* if not available tasc_mstr */
else assign tasc_mstr.tc_Status = "C":U.
assign tasc_mstr.asc_domain = tqDomainsPrim.tcDomainCode
tasc_mstr.asc_acc = tGLMask.tcGLCode
tasc_mstr.asc_sub = tGLMask.tcDivisionCode
tasc_mstr.asc_cc = tGLMask.tcCostCentreCode
tasc_mstr.asc_proj = tGLMask.tcProjectCode
tasc_mstr.tc_Status = (if tGLMask.tc_Status = "D":U
then tGLMask.tc_Status
else tasc_mstr.tc_Status).
end. /* for each tGLMask */
end. /* CONVERTBLOCK */
/* Stop Queries */
if vlQueryStartedDomainsPrim = true
then do:
<Q-21 run DomainsPrim (Stop) in BDomain >
assign vlQueryStartedDomainsPrim = false.
end. /* if vlQueryStartedDomainsPrim = true */
VALIDATEBLOCK:
DO:
if viLocalReturnStatus < 0
then leave VALIDATEBLOCK.
/* SKIP STANDARD VALIDATIONS AND ADDITIONALUPDATES FOR PERFORMANCE REASONS =====
We need to set vlFcDataValidated to true by our selves to be able to save the data.
*/
assign vlFcDataValidated = true.
/* ======== */
/* DataSave */
/* ======== */
<M-11 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgAcctSubCCProj>
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 = "BMfgAcctSubCCProj".
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/bmfgacctsubccproj.apireplicatefromfinancials.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tGLMask").
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.