| tJournalBook | 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 */
/* ====================== */
if not can-find(first tJournalBook)
then return.
/* ================== */
/* Exception Handling */
/* ================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0
vlQueryStartedDomainBySharedSet = false
vlQueryStartedGLCalendarYr = false
vlQueryStartedGLCalendarYrStart = false
vlQueryStartedJournalByJournal = false
vcListNrMstr = '':U.
CONVERTBLOCK:
DO:
/* ===================================== */
/* Check which records need to be loaded */
/* ===================================== */
for each tJournalBook
break by tJournalBook.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 Number Range Man. 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(tJournalBook.SharedSet_ID)
then do:
<Q-2 run DomainBySharedSetDomain (all) (Read) (Cache)
(input tJournalBook.SharedSet_ID, (SharedSetId)
input 0, (DomainID)
input icDomainCode, (DomainCode)
output dataset tqDomainBySharedSetDomain) in BDomain >
end. /* if first-of(tJournalBook.SharedSet_ID) */
for each tqDomainBySharedSetDomain where
tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
/* ============================================================ */
/* Create a list of all tnr_mstr records that need to be loaded */
/* ============================================================ */
<Q-19 assign vlFcQueryRecordsAvailable = NumberRangeBySequenceID (NoCache)
(input icDomainCode, (DomainID)
input tJournalBook.JournalCode, (SequenceID)) in BMfgNRM >
if vlFcQueryRecordsAvailable = true
then assign vcListNrMstr = vcListNrMstr +
(if vcListNrMstr = '':U
then '':U
else chr(4)) +
tqDomainBySharedSetDomain.tcDomainCode +
chr(2) +
tJournalBook.JournalCode.
end. /* for each tqDomainBySharedSetDomain: */
end. /* for each tJournalBook */
/* ========================= */
/* Load the tnr_mstr records */
/* ========================= */
if vcListNrMstr <> "":U and
vcListNrMstr <> ?
then do :
<M-4 run DataLoad
(input '':U (icRowids),
input vcListNrMstr (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BMfgNRM>
if viFcReturnSuper <> 0
then do:
assign viLocalReturnStatus = viFcReturnSuper.
leave CONVERTBLOCK.
end. /* if viFcReturnSuper <> 0 */
end. /* if vcListNrMstr <> "":U and */
/* ======================================== */
/* Convert table tJournal to table tnr_mstr */
/* ======================================== */
for each tJournalBook
break by tJournalBook.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 Daybook 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(tJournalBook.SharedSet_ID)
then do:
if tJournalBook.SharedSet_ID = 0 or
tJournalBook.SharedSet_ID = ?
then do:
assign vcMessage = trim(substitute(#T-15'The shared set ID for daybook (&1) was not defined.':255(69581)t-15#, trim(tJournalBook.JournalCode) ))
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-8185':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgNRM>
leave CONVERTBLOCK.
end. /* if tJournalBook.SharedSet_ID = 0 or */
<Q-7 run DomainBySharedSetDomain (all) (Read) (Cache)
(input tJournalBook.SharedSet_ID, (SharedSetId)
input 0, (DomainID)
input icDomainCode, (DomainCode)
output dataset tqDomainBySharedSetDomain) in BDomain >
end. /* if first-of(tJournalBook.SharedSet_ID) */
for each tqDomainBySharedSetDomain where
tqDomainBySharedSetDomain.tlDomainPropertyIsSetupCompl:
/* ======================================================= */
/* Create or update tnr_mstr records based on tJournalBook */
/* ======================================================= */
find tnr_mstr where
tnr_mstr.nr_seqid = tJournalBook.JournalCode and
tnr_mstr.nr_domain = tqDomainBySharedSetDomain.tcDomainCode
no-error.
if not available tnr_mstr
then do:
if tJournalBook.tc_Status = "D"
then next.
<M-8 run AddDetailLine
(input 'nr_mstr':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BMfgNRM>
if viFcReturnSuper <> 0
then do:
assign viLocalReturnStatus = viFcReturnSuper.
leave CONVERTBLOCK.
end. /* if viFcReturnSuper <> 0 */
assign tnr_mstr.oid_nr_mstr = <M-9 GetNextOidValue () in BMfgNRM> no-error.
if error-status:error
then do:
assign vcMessage = trim(#T-16'Cannot retrieve an oid-value while replicating daybooks.':255(69582)t-16#) + chr(10) +
trim(substitute(#T-17'Daybook: &1.':255(2740)T-17#, trim(tJournalBook.JournalCode)))
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-8186':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BMfgNRM>
leave CONVERTBLOCK.
end.
end. /* if not available tnr_mstr */
else assign tnr_mstr.tc_Status = "C":U.
assign tnr_mstr.nr_seqid = tJournalBook.JournalCode
tnr_mstr.nr_domain = tqDomainBySharedSetDomain.tcDomainCode
tnr_mstr.nr_desc = tJournalBook.JournalDescription
tnr_mstr.tc_Status = (if tJournalBook.tc_Status = "D":U
then tJournalBook.tc_Status
else tnr_mstr.tc_Status).
if tJournalBook.tc_Status = "C":U
then do:
if vlQueryStartedJournalByJournal = false
then do:
<Q-23 run JournalByJournalIDCodeType (Start) in BJournal >
assign vlQueryStartedJournalByJournal = true.
end.
<Q-20 run JournalByJournalIDCodeType (all) (Read) (NoCache)
(input viCompanyID, (CompanyId)
input tJournalBook.Journal_ID, (JournalID)
input tJournalBook.JournalCode, (JournalCode)
input tJournalBook.JournalTypeCode, (JournalTypeCode)
output dataset tqJournalByJournalIDCodeType) in BJournal >
find first tqJournalByJournalIDCodeType where
tqJournalByJournalIDCodeType.tiJournal_ID = tJournalbook.Journal_ID
no-error.
if available tqJournalByJournalIDCodeType
then do:
/* If Daybook Code is inactivated then set the expiry date of the corresponding Number Range Sequence ID */
/* to the system date */
if tJournalBook.JournalIsActive = false and
tJournalBook.JournalIsActive <> tqJournalByJournalIDCodeType.tlJournalIsActive
then assign tnr_mstr.nr_exp_date = today.
/* If Daybook Code is activated then set the expiry date of the corresponding Number Range Sequence ID to ? */
if tJournalBook.JournalIsActive = true and
tJournalBook.JournalIsActive <> tqJournalByJournalIDCodeType.tlJournalIsActive
then assign tnr_mstr.nr_exp_date = ?.
end.
end. /* if tJournalBook.tc_Status = "C":U */
if tJournalBook.tc_Status = "N"
then do:
/* Default the NR year for the sequence to today's year */
assign vcNrYear = string(year(today)).
if vlQueryStartedGLCalendarYr = false
then do:
<Q-25 run GLCalendarYrByDateDomain (Start) in BMfgGLCalendar >
assign vlQueryStartedGLCalendarYr = true.
end.
<Q-21 run GLCalendarYrByDateDomain (all) (Read) (NoCache)
(input tqDomainBySharedSetDomain.tcDomainCode, (DomainCode)
input today, (Date)
output dataset tqGLCalendarYrByDateDomain) in BMfgGLCalendar >
find first tqGLCalendarYrByDateDomain where
tqGLCalendarYrByDateDomain.tcglc_domain = tqDomainBySharedSetDomain.tcDomainCode
no-error.
if available tqGLCalendarYrByDateDomain
then do:
if vlQueryStartedGLCalendarYrStart = false
then do:
<Q-27 run GLCalendarYrStartByDateDomain (Start) in BMfgGLCalendar >
assign vlQueryStartedGLCalendarYrStart = true.
end.
<Q-22 run GLCalendarYrStartByDateDomain (all) (Read) (NoCache)
(input tqDomainBySharedSetDomain.tcDomainCode, (DomainCode)
input tqGLCalendarYrByDateDomain.tiglc_year, (Year)
output dataset tqGLCalendarYrStartByDateDomain) in BMfgGLCalendar >
find first tqGLCalendarYrStartByDateDomain where
tqGLCalendarYrStartByDateDomain.tcglc_domain = tqDomainBySharedSetDomain.tcDomainCode
no-error.
if available tqGLCalendarYrStartByDateDomain
then assign vtGLCalendarYearStartDate = tqGLCalendarYrStartByDateDomain.ttglc_start
vcNrYear = string(tqGLCalendarYrStartByDateDomain.tiglc_year).
else assign vtGLCalendarYearStartDate = date(1,1,year(today)).
end.
else assign vtGLCalendarYearStartDate = date(1,1,year(today)).
assign tnr_mstr.nr_dataset = "Sequence ID":U
tnr_mstr.nr_internal = yes
tnr_mstr.nr_allow_discard = no
tnr_mstr.nr_effdate = vtGLCalendarYearStartDate
tnr_mstr.nr_exp_date = ?
tnr_mstr.nr_seg_min = ",,,000000001,":U
tnr_mstr.nr_seg_max = ",,,999999999,":U
tnr_mstr.nr_seg_ini = ",,,000000001,":U
tnr_mstr.nr_seg_reset = ",,,000000001,":U
tnr_mstr.nr_seg_type = "3,4,4,1,":U
tnr_mstr.nr_seg_format = "Y,,,999999999,":U
tnr_mstr.nr_segcount = 4
tnr_mstr.nr_seg_rank = "0,3,3,2,":U
tnr_mstr.nr_seg_value = vcNrYear
+ ",/,":U
+ tnr_mstr.nr_seqid
+ ",000000001":U.
end. /* if tJournalBook.tc_Status = "N" */
end. /* for each tqDomainBySharedSetDomain: */
end. /* for each tJournalBook */
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 vlQueryStartedJournalByJournal = true
then do:
<Q-24 run JournalByJournalIDCodeType (Stop) in BJournal >
assign vlQueryStartedJournalByJournal = false.
end.
if vlQueryStartedGLCalendarYr = true
then do:
<Q-26 run GLCalendarYrByDateDomain (Stop) in BMfgGLCalendar >
assign vlQueryStartedGLCalendarYr = false.
end.
if vlQueryStartedGLCalendarYrStart = true
then do:
<Q-28 run GLCalendarYrStartByDateDomain (Stop) in BMfgGLCalendar >
assign vlQueryStartedGLCalendarYrStart = false.
end.
VALIDATEBLOCK:
DO:
if viLocalReturnStatus < 0
then leave VALIDATEBLOCK.
/* ========== */
/* ValidateBC */
/* ========== */
<M-12 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BMfgNRM>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave VALIDATEBLOCK.
/* ================== */
/* Additional Updates */
/* ================== */
<M-13 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BMfgNRM>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave VALIDATEBLOCK.
/* ======== */
/* DataSave */
/* ======== */
<M-14 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BMfgNRM>
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 = "BMfgNRM".
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/bmfgnrm.apireplicatefromfinancials.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tJournalBook").
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.