Description
Create, update and delete ConsolidPeriodXref- records in accordance to the user-updated contents of the received temp-table.
Parameters
icConsolidCompanyCode | input | character | |
tUIConsolidPeriodXref | input | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bconsolidperiodxref.p)
assign oiReturnStatus = -98.
<M-1 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
/*===============================================================================================*/
/* Validate input parameters */
/*===============================================================================================*/
if (icConsolidCompanyCode = '' or icConsolidCompanyCode = ?)
then do:
assign vcConsPerXrefMsg = #T-17'You must enter the consolidation entity.':200(1368)T-17#
oiReturnStatus = -1.
<M-16 run SetMessage
(input trim(vcConsPerXrefMsg) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'QADFIN-2333':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
return.
end.
for each tUIConsolidPeriodXref:
if (tUIConsolidPeriodXref.tiPeriodYear = 0 or
tUIConsolidPeriodXref.tiPeriodYear = ? or
tUIConsolidPeriodXref.tiPeriodPeriod = ?)
then do:
assign vcConsPerXrefMsg = #T-18'You must enter the year and GL period for the source entity.':200(1389)T-18#
oiReturnStatus = 1.
<M-12 run SetMessage
(input trim(vcConsPerXrefMsg) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'QADFIN-2325':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
return.
end.
<Q-13 run PeriodPrim (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input ?, (PeriodId)
input tUIConsolidPeriodXref.tiPeriodYear, (PeriodYear)
input tUIConsolidPeriodXref.tiPeriodPeriod, (PeriodPeriod)
output dataset tqPeriodPrim) in BPeriod >
find tqPeriodPrim where
tqPeriodPrim.tiPeriodYear = tUIConsolidPeriodXref.tiPeriodYear and
tqPeriodPrim.tiPeriodPeriod = tUIConsolidPeriodXref.tiPeriodPeriod
no-lock no-error.
if not available tqPeriodPrim
then do:
assign vcConsPerXrefMsg = substitute(#T-19'Period &1/&2 does not exist in the source entity.':200(1390)T-19#,
trim(string(tUIConsolidPeriodXref.tiPeriodYear)),
trim(string(tUIConsolidPeriodXref.tiPeriodPeriod)))
oiReturnStatus = -1.
<M-14 run SetMessage
(input trim(vcConsPerXrefMsg) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'QADFIN-2326':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
return.
end.
end.
/*===============================================================================================*/
/* Get the ConsolidationCompany_ID for better query performance further on. */
/*===============================================================================================*/
<Q-5 run CompanyPrim (all) (Read) (NoCache)
(input ?, (LookupCompanyId)
input icConsolidCompanyCode, (CompanyCode)
output dataset tqCompanyPrim) in BCompany >
find first tqCompanyPrim where
tqCompanyPrim.tcCompanyCode = icConsolidCompanyCode
no-lock no-error.
if not available(tqCompanyPrim)
then do:
assign vcConsPerXrefMsg = substitute(#T-20'Consolidation entity &1 not found.':200(1363)T-20#,
trim(icConsolidCompanyCode))
oiReturnStatus = -1.
<M-6 run SetMessage
(input trim(vcConsPerXrefMsg) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'QADFIN-2284':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
return.
end.
assign viConsolidCompanyID = tqCompanyPrim.tiCompany_ID.
empty temp-table tqCompanyPrim.
/*===============================================================================================*/
/* Load existing ConsolidPeriodXref records into the instance. */
/* Only records for which a corresponding tUIConsolidPeriodXref exists (= a modification was */
/* made to it in the UI) are loaded. */
/*===============================================================================================*/
<Q-2 run ConsolidPeriodXrefByPeriod (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input viConsolidCompanyID, (ConsolidCompanyID)
input '':U, (ConsolidCompanyCode)
input ?, (SourceYear)
input ?, (SourcePeriod)
input ?, (TargetYear)
input ?, (TargetPeriod)
output dataset tqConsolidPeriodXrefByPeriod) in BConsolidPeriodXref>
assign vcXrefIDs = '':U.
for each tqConsolidPeriodXrefByPeriod where
tqConsolidPeriodXrefByPeriod.tiCompany_ID = viCompanyId and
tqConsolidPeriodXrefByPeriod.tiConsolidationCompany_ID = viConsolidCompanyID :
if can-find (first tUIConsolidPeriodXref where
tUIConsolidPeriodXref.tiPeriodYear = tqConsolidPeriodXrefByPeriod.tiPeriodYear and
tUIConsolidPeriodXref.tiPeriodPeriod = tqConsolidPeriodXrefByPeriod.tiPeriodPeriod)
then do:
assign vcXrefIDs = vcXrefIDs + string(tqConsolidPeriodXrefByPeriod.tiConsolidPeriodXref_ID) + chr(4).
end.
end.
if (vcXrefIDs <> '':U)
then do:
substring(vcXrefIDs, length(vcXrefIDs,"CHARACTER":U), 1,"CHARACTER":U) = '':U.
<M-3 run DataLoad
(input ? (icRowids),
input vcXrefIDs (icPkeys),
input ? (icObjectIds),
input '' (icFreeform),
input no (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
end.
empty temp-table tqConsolidPeriodXrefByPeriod.
/*===============================================================================================*/
/* Delete records for which Year and Period are not (= 'no longer') in temp-table. */
/*===============================================================================================*/
for each tConsolidPeriodXref:
find first tUIConsolidPeriodXref where
tUIConsolidPeriodXref.tiPeriodYear = tConsolidPeriodXref.tiPeriodYear and
tUIConsolidPeriodXref.tiPeriodPeriod = tConsolidPeriodXref.tiPeriodPeriod
no-lock no-error.
if not available(tUIConsolidPeriodXref)
then next.
if ((tUIConsolidPeriodXref.tiConsolidPeriodYear = 0 or tUIConsolidPeriodXref.tiConsolidPeriodYear = ?) and
(tUIConsolidPeriodXref.tiConsolidPeriodPeriod = 0 or tUIConsolidPeriodXref.tiConsolidPeriodPeriod = ?))
then do:
assign tConsolidPeriodXref.tc_Status = 'D':U.
next.
end.
end.
/*===============================================================================================*/
/* Update/Create records for which Year and Period are filled in temp-table. */
/*===============================================================================================*/
for each tUIConsolidPeriodXref where
tUIConsolidPeriodXref.tiConsolidPeriodYear <> 0 and
tUIConsolidPeriodXref.tiConsolidPeriodPeriod <> ? and
tUIConsolidPeriodXref.tiConsolidPeriodYear <> 0 and
tUIConsolidPeriodXref.tiConsolidPeriodPeriod <> ? :
find first tConsolidPeriodXref where
tConsolidPeriodXref.tiPeriodYear = tUIConsolidPeriodXref.tiPeriodYear and
tConsolidPeriodXref.tiPeriodPeriod = tUIConsolidPeriodXref.tiPeriodPeriod
exclusive no-error.
/*==========================================================================================*/
/* No changes --> no update neede */
/*==========================================================================================*/
if available(tConsolidPeriodXref) and
tConsolidPeriodXref.tiConsolidPeriodYear = tUIConsolidPeriodXref.tiConsolidPeriodYear and
tConsolidPeriodXref.tiConsolidPeriodPeriod = tUIConsolidPeriodXref.tiConsolidPeriodPeriod
then next.
if not available(tConsolidPeriodXref)
then do:
<M-4 run AddDetailLine (input 'ConsolidPeriodXref':U (icTable),
input ? (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
assign tConsolidPeriodXref.tc_Status = 'N':U
tConsolidPeriodXref.tcConsolidCompanyCode = icConsolidCompanyCode
tConsolidPeriodXref.tiPeriodYear = tUIConsolidPeriodXref.tiPeriodYear
tConsolidPeriodXref.tiPeriodPeriod = tUIConsolidPeriodXref.tiPeriodPeriod.
end.
else do:
assign tConsolidPeriodXref.tc_Status = 'C':U.
end.
assign tConsolidPeriodXref.tiConsolidPeriodYear = tUIConsolidPeriodXref.tiConsolidPeriodYear
tConsolidPeriodXref.tiConsolidPeriodPeriod = tUIConsolidPeriodXref.tiConsolidPeriodPeriod.
end.
/*===============================================================================================*/
/* Validation + AdditionalUpdates + DataSave */
/*===============================================================================================*/
<M-9 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
<M-10 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
<M-11 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BConsolidPeriodXref>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
end.
if oiReturnStatus = -98
then oiReturnStatus = 0.
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 = "BConsolidPeriodXref".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiSetConsolidPeriods".
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/bconsolidperiodxref.apisetconsolidperiods.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icConsolidCompanyCode = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tUIConsolidPeriodXref").
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.