Description
apiStdMaintainTT
Parameters
tApiYearClosing | input | temp-table | |
icAction | input | character | icAction |
ocLstPrimKey | output | character | |
ocLstReturn | output | character | |
ocLstRowid | output | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/byearclosing.p)
/* ======================================================= */
/* Method Info: */
/* Year Closing will be loaded based on the Logical Key */
/* ======================================================= */
/* ============================================================================ */
/* Clear the instance: */
/* this will also clear the t_s tables that were filled in ApiMaintainByDataSet */
/* ============================================================================ */
<M-6 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* ==================== */
/* Set Default Return */
/* Parameter Validation */
/* ==================== */
assign oiReturnStatus = -98
vlDraftInstanceCreated = false.
if icAction = ? then assign icAction = "":U.
if icAction <> {&DAEMONACTION-SAVESTORE} and
icAction <> {&DAEMONACTION-SAVE} and
icAction <> {&DAEMONACTION-STORE} and
icAction <> {&DAEMONACTION-VALIDATE}
then do:
assign vcMessage = trim(subst(#T-4'A Year-End Closing Integration error occurred. The specified action (&1) must be in the list: &2.':200(20453)t-4#,trim(icAction),"{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U))
oiReturnStatus = -1.
<M-7 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-4677':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
return.
end. /* if icAction */
/* ======================== */
/* Count main-table records */
/* ======================== */
for each tApiYearClosing no-lock :
assign viMainTableRecordCount = viMainTableRecordCount + 1.
end. /* for each */
if viMainTableRecordCount = 0
then do:
assign vcMessage = trim(#T-5'A Year-End Closing Integration error occurred. The system cannot find the main table record (year-end closing).':200(20461)t-5#)
oiReturnStatus = -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-4678':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
return.
end. /* if viMainTableRecordCount */
<Q-26 run YearClosingPrim (Start) in BYearClosing >
/* ================================ */
/* Start loop on main-table records */
/* ================================ */
for each tApiYearClosing by tApiYearClosing.tc_Rowid:
MAIN-BLOCK:
DO:
/* ========== */
/* Initialize */
/* ========== */
assign vcMessage = "":U
vcRowID = "":U
vlWarningsFound = false
vlSaveAsDraft = icAction = {&DAEMONACTION-STORE}.
/* =============================================== */
/* Get the YearClosing_ID based on the logical key */
/* =============================================== */
if (tApiYearClosing.YearClosing_ID = ? or
tApiYearClosing.YearClosing_ID = 0) and
tApiYearClosing.YearClosingAccountingYear <> 0 and
tApiYearClosing.YearClosingAccountingYear <> ?
then do:
<Q-28 run YearClosingPrim (all) (Read) (NoCache)
(input tApiYearClosing.Company_ID, (CompanyId)
input ?, (YearClosingID)
input tApiYearClosing.YearClosingAccountingYear, (YearClosingAccountingYear)
output dataset tqYearClosingPrim) in BYearClosing >
find tqYearClosingPrim where
tqYearClosingPrim.tiCompany_ID = tApiYearClosing.Company_ID and
tqYearClosingPrim.tiYearClosingAccountingYear = tApiYearClosing.YearClosingAccountingYear
no-lock no-error.
if available tqYearClosingPrim
then assign tApiYearClosing.YearClosing_ID = tqYearClosingPrim.tiYearClosing_ID.
end.
/* ======================= */
/* Load/Create YearClosing */
/* ======================= */
if tApiYearClosing.YearClosing_ID = ? or
tApiYearClosing.YearClosing_ID = 0
then assign viFcReturnSuper = -4.
else do:
<M-29 run DataLoad (input ? (icRowids),
input string(tapiyearClosing.yearclosing_ID) (icPkeys),
input ? (icObjectIds),
input ? (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
end.
if viFcReturnSuper = -4
then do:
assign viFcReturnSuper = 0.
<M-30 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
if viFcReturnSuper < 0
then assign vcMessage = trim(subst(#T-20'The system cannot create a new instance. Error number: &1.':200(20455)t-20#, string(viFcReturnSuper))).
find first tYearClosing no-error.
end.
else do:
if viFcReturnSuper < 0
then assign vcMessage = trim(subst(#T-21'The system cannot load the instance; error number: &1, instance ID: &2.':200(20456)t-21#, string(viFcReturnSuper), string(tApiYearClosing.YearClosing_ID))).
else do:
find tYearClosing where
tYearClosing.YearClosing_ID = tApiYearClosing.YearClosing_ID
no-error.
if not available tYearClosing
then assign vcMessage = trim(subst(#T-22'The system cannot find the instance after loading it. Instance ID: &1.':200(20457)t-22#,
string(tApiYearClosing.YearClosing_ID))).
else assign tYearClosing.tc_Status = "C":U.
end.
end.
/* ================================================================= */
/* Check for errors in the previous block */
/* ================================================================= */
if vcMessage <> "":U
then do:
assign ocLstReturn = ocLstReturn + chr(4) + (if viFcReturnSuper = 0 then "-3":U else string(viFcReturnSuper))
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = false.
<M-31 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-4681':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
leave MAIN-BLOCK.
end.
/* =========================== */
/* Copy data for Year Closing */
/* =========================== */
buffer-copy tApiYearClosing
except tApiYearClosing.YearClosing_ID
tApiYearClosing.tc_ParentRowid
tApiYearClosing.tc_Rowid
tApiYearClosing.tc_Status
tApiYearClosing.YearClosingAccountingYear
tApiYearClosing.Company_ID
to tYearClosing.
if tYearClosing.tc_Status = "N":U
then assign tYearClosing.Company_ID = tApiYearClosing.Company_ID
tYearClosing.YearClosingAccountingYear = tApiYearClosing.YearClosingAccountingYear.
assign vcRowID = tYearClosing.tc_Rowid
tApiYearClosing.YearClosing_ID = tYearClosing.YearClosing_ID /*Needed to set het prim-key after the save*/ .
/* =================================================== */
/* This is where it ends if only SaveAsDraft is needed */
/* =================================================== */
if vlSaveAsDraft
then do:
assign ocLstReturn = ocLstReturn + chr(4) + "-1":U
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U.
leave MAIN-BLOCK.
end.
/* =============================== */
/* Set Actvity */
/* =============================== */
if can-find (first tYearClosing where
tYearClosing.tc_Status = "N":U)
then assign vcActivityCode = "Create":U.
else if can-find (first tYearClosing where
tYearClosing.tc_Status = "C":U)
then assign vcActivityCode = "Modify":U.
/* ================= */
/* Validate the data */
/* ================= */
<M-32 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave main-block.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* ================ */
/* External updates */
/* ================ */
<M-33 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave main-block.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
/* ============= */
/* Save the data */
/* ============= */
if icAction <> {&DAEMONACTION-VALIDATE}
then do:
if vlReturnDatasetYC
then do:
<M-50 run GetXmlRepresentationDataset
(input '' (icObjectRowId),
input false (ilHeaderOnly),
input 0 (iiPriority),
output vhDatasetToReturnYC by-reference (ozXMLDataset),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave main-block.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
assign vcTableName = "".
<M-51 run GetKeyFields
(input-output vcTableName (bcTableName),
output vcPrimKeyYC (ocPrimaryKey),
output vcDummy (ocAlternateKey),
output vcDummy (ocObjectID),
output vcDummy (ocObjectStatus),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave main-block.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
end.
<M-36 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
if viFcReturnSuper < 0
then do:
assign ocLstReturn = ocLstReturn + chr(4) + string(viFcReturnSuper)
ocLstPrimKey = ocLstPrimKey + chr(4) + "*":U
ocLstRowid = ocLstRowid + chr(4) + "*":U
vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).
leave main-block.
end.
else if viFcReturnSuper > 0
then assign vlWarningsFound = true.
end.
/* ============================================ */
/* Indicate that everything was saved correctly */
/* ============================================ */
assign ocLstReturn = ocLstReturn + chr(4) + (if vlWarningsFound = true then "1":U else "0":U)
ocLstPrimKey = ocLstPrimKey + chr(4) + string(tApiYearClosing.YearClosing_ID)
ocLstRowid = ocLstRowid + chr(4) + vcRowID.
END. /* MAIN-BLOCK */
/* ================================================================== */
/* Handle errors: Store if SaveAsDraft is needed */
/* Check: only 1 draft is allowed for a single bus-component instance */
/* ================================================================== */
if vlSaveAsDraft and
index(substring(ocLstReturn,r-index(ocLstReturn,chr(4)) + 1, -1, "CHARACTER":U), "-":U) <> 0 /* Negative return-status for this entry*/
then do:
if vlDraftInstanceCreated = true
then do:
assign vcMessage = trim(#T-23'Only a single draft instance can be created with a single call to an interface method.':200(20458)t-23#) +
chr(10) +
trim(#T-24'This second object will not be stored as a draft instance and will just be considered as an error situation.':200(20459)t-24#).
<M-34 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-4682':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
next.
end. /*if vlDraftInstanceCreated = true*/
<M-35 run StoreState
(input '(':U + string(tYearClosing.YearClosingAccountingYear) + ') ':U + trim(#T-47'The Year-End Closing was created using an API method.':200(20460)t-47#) (icDescription),
input ? (icUIClass),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
assign vlDraftInstanceCreated = true
entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper)
entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiYearClosing.YearClosing_ID)
entry(num-entries(ocLstRowid , chr(4)), ocLstRowid , chr(4)) = vcRowID.
end. /*if vlSaveAsDraft and index(substring*/
end. /* for each tApiCode */
/* ================================================================= */
/* Stop Queries */
/* ================================================================= */
<Q-27 run YearClosingPrim (Stop) in BYearClosing >
/* ============================================================ */
/* Trim the first character of ocLstReturn and primkey */
/* Check for correct number and format of the return-parameters */
/* ============================================================ */
if length(ocLstReturn,"CHARACTER":U) > 1 then assign ocLstReturn = substring(ocLstReturn,2,-1,"CHARACTER":U).
if length(ocLstPrimKey,"CHARACTER":U) > 1 then assign ocLstPrimKey = substring(ocLstPrimKey,2,-1,"CHARACTER":U).
if length(ocLstRowid,"CHARACTER":U) > 1 then assign ocLstRowid = substring(ocLstRowid,2,-1,"CHARACTER":U).
if num-entries(ocLstReturn,chr(4)) <> viMainTableRecordCount or
num-entries(ocLstPrimKey,chr(4)) <> viMainTableRecordCount or
num-entries(ocLstRowid,chr(4)) <> viMainTableRecordCount
then do :
assign vcMessage = trim(#T-40'A Year-End Closing Integration error occurred. The API method returned incomplete information. See other messages for further details.':200(20462)t-40#) + chr(10) +
trim(substitute(#T-41'Main table records: &1.':200(20465)T-41#,string(viMainTableRecordCount))) + chr(10) +
trim(substitute(#T-42'Return statuses: &1.':200(20466)T-42#,ocLstReturn)) + chr(10) +
trim(substitute(#T-43'Primary keys: &1.':200(20467)T-43#,ocLstPrimKey)) + chr(10) +
trim(substitute(#T-44'Row IDs: &1.':200(20468)T-44#,ocLstRowid))
oiReturnStatus = -3.
<M-47 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-4687':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
return.
end. /* if num-entries */
/* ===================================================== */
/* Set global return status based on the individual ones */
/* ===================================================== */
if ocLstReturn = substring(fill("0":U + CHR(4),viMainTableRecordCount),1,length(ocLstReturn,"CHARACTER":U),"CHARACTER":U)
then assign oiReturnStatus = 0.
else do :
if index(ocLstReturn,"-":U) <> 0
then do :
assign vcMessage = trim(#T-45'An error occurred while running this API method. See other error messages for more details.':200(20463)T-45#)
oiReturnStatus = -1.
<M-48 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-4688':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
end. /* if index(ocLstReturn,"-":U) <> 0 */
else do :
assign vcMessage = trim(#T-46'A warning occurred while running this API method. See other error messages for more details.':200(20464)T-46#)
oiReturnStatus = +1.
<M-49 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-4689':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
end. /* not if lookup */
end. /* not if ocLstReturn */
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 = "BYearClosing".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiStdMaintainTT".
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/byearclosing.apistdmaintaintt.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAction = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tApiYearClosing").
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.