tApiLayer | input | temp-table | Temporary table used for integration of Posting Layers Fields: - Layer_ID - ID of the Posting layer - LayerDescription - Description of posting layer - LayerCode - Code of Posting layer - LayerTypeCode - Code of Type of Posting layer - LayerIsActive - Is Posting layer active or not? |
icAction | input | character | Action to be done with content of temporary table - {&DAEMONACTION-SAVESTORE} Save as Draft/Submit - {&DAEMONACTION-SAVE} Save as Draft - {&DAEMONACTION-STORE} Submit - {&DAEMONACTION-VALIDATE} Validate |
ocLstPrimKey | output | character | This chr(4) separated list contains CDocument_IDs created during processing of records in input temporary table. Items of list are linked to the same list item in ocLstReturn and ocLstRowid lists. |
ocLstReturn | output | character | List of return statuses populated during processing of imcomming records. List if chr(4) separated. Items of list are linked to the same list item in ocLstPrimKey and ocLstRowid lists. |
ocLstRowid | output | character | List of RowIds of created debtor document records. List is chr(4) separated. Items of list are linked to the same list item in ocLstPrimKey and ocLstReturn lists. |
oiReturnStatus | output | integer | Return status of the method. |
/* =================================================== */ /* Method Info: */ /* Layer 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-34 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BLayer> 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 vcMsg = trim(subst(#T-5'Layer integration: the specified action &1 should be in the list &2.':255(17360)t-5#,trim(icAction),"{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U)) oiReturnStatus = -1. <M-35 run SetMessage (input vcMsg (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QADFIN-4273':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BLayer> return. end. /* if icAction */ /* ======================== */ /* Count main-table records */ /* ======================== */ for each tApiLayer no-lock : assign viMainTableRecordCount = viMainTableRecordCount + 1. end. /* for each */ if viMainTableRecordCount = 0 then do: assign vcMsg = trim(#T-6'Layer integration: no main layer table records found.':255(17361)t-6#) oiReturnStatus = -1. <M-36 run SetMessage (input vcMsg (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QADFIN-4274':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BLayer> return. end. /* if viMainTableRecordCount */ /* ========================= */ /* Start Queries */ /* ========================= */ <Q-37 run LayerPrim (Start) in BLayer > /* ================================ */ /* Start loop on main-table records */ /* ================================ */ for each tApiLayer by tApiLayer.tc_Rowid : MAIN-BLOCK: DO: /* ========== */ /* Initialize */ /* ========== */ assign vcMsg = "":U vcRowID = "":U vlWarningsFound = false vlSaveAsDraft = icAction = {&DAEMONACTION-STORE}. /* =========================================== */ /* Get the Country_ID based on the logical key */ /* =========================================== */ if (tApiLayer.Layer_ID = ? or tApiLayer.Layer_ID = 0) and tApiLayer.LayerCode <> "" and tApiLayer.LayerCode <> ? then do: <Q-38 run LayerPrim (all) (Read) (NoCache) (input tApiLayer.Layer_ID, (LayerId) input tApiLayer.LayerCode, (LayerCode) output dataset tqLayerPrim) in BLayer > find tqLayerPrim where tqLayerPrim.tcLayerCode = tApiLayer.LayerCode no-lock no-error. if available tqLayerPrim then assign tApiLayer.Layer_ID = tqLayerPrim.tiLayer_ID. end. /* ==================== */ /* Load/Create Layer */ /* ==================== */ if tApiLayer.Layer_ID = ? or tApiLayer.Layer_ID = 0 then assign viFcReturnSuper = -4. else do: <M-39 run DataLoad (input ? (icRowids), input string(tApiLayer.Layer_ID) (icPkeys), input ? (icObjectIds), input ? (icFreeform), input false (ilKeepPrevious), output viFcReturnSuper (oiReturnStatus)) in BLayer> end. /* Not if tApiLayer.Layer_ID = ? or */ if viFcReturnSuper = -4 then do: assign viFcReturnSuper = 0. <M-40 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BLayer> if viFcReturnSuper < 0 then assign vcMsg = trim(subst(#T-15'Cannot create a new instance. Error number: &1.':255(308)t-15#, string(viFcReturnSuper))). find first tLayer no-error. end. /* if viFcReturnSuper = -4 */ else do: if viFcReturnSuper < 0 then assign vcMsg = trim(subst(#T-16'Cannot load the instance (error number: &1, instance ID: &2).':255(289)t-16#, string(viFcReturnSuper), string(tApiLayer.Layer_ID))). else do: find tLayer where tLayer.Layer_ID = tApiLayer.Layer_ID no-error. if not available tLayer then assign vcMsg = trim(subst(#T-17'Cannot find the instance after it has been loaded (instance ID: &1).':255(290)t-17#,string(tApiLayer.Layer_ID))). else assign tLayer.tc_Status = "C":U. end. /* Not if viFcReturnSuper <> 0 */ end. /* Not if viFcReturnSuper = -4 */ /* ====================================== */ /* Check for errors in the previous block */ /* ====================================== */ if vcMsg <> "":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-41 run SetMessage (input vcMsg (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QADFIN-4275':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BLayer> leave MAIN-BLOCK. end. /* if vcMessage <> "":U */ /* ====================== */ /* Copy data for Layer */ /* ====================== */ buffer-copy tApiLayer except tApiLayer.Layer_ID tApiLayer.tc_ParentRowid tApiLayer.tc_Rowid tApiLayer.tc_Status tApiLayer.LayerCode to tLayer. if tLayer.tc_Status = "N":U then assign tLayer.LayerCode = tApiLayer.LayerCode. assign vcRowID = tLayer.tc_Rowid tApiLayer.Layer_ID = tLayer.Layer_ID /* Needed to set the 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. /* if vlSaveAsDraft */ /* =============================== */ /* Set Actvity & Validate the data */ /* =============================== */ if can-find (first tLayer where tLayer.tc_Status = "N":U) then assign vcActivityCode = "Create":U. else if can-find (first tLayer where tLayer.tc_Status = "C":U) then assign vcActivityCode = "Modify":U. <M-42 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BLayer> 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. /* if viFcReturnSuper <> 0 */ else if viFcReturnSuper > 0 then assign vlWarningsFound = true. /* ================ */ /* External updates */ /* ================ */ <M-43 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BLayer> 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. /* if viFcReturnSuper <> 0 */ else if viFcReturnSuper > 0 then assign vlWarningsFound = true. /* ============= */ /* Save the data */ /* ============= */ if icAction <> {&DAEMONACTION-VALIDATE} then do : if vlReturnDatasetL then do: <M-51 run GetXmlRepresentationDataset (input '' (icObjectRowId), input false (ilHeaderOnly), input 0 (iiPriority), output vhDatasetToReturnL by-reference (ozXMLDataset), output viFcReturnSuper (oiReturnStatus)) in BLayer> 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-52 run GetKeyFields (input-output vcTableName (bcTableName), output vcPrimKeyL (ocPrimaryKey), output vcDummy (ocAlternateKey), output vcDummy (ocObjectID), output vcDummy (ocObjectStatus), output viFcReturnSuper (oiReturnStatus)) in BLayer> 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-44 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BLayer> 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. /* if viFcReturnSuper <> 0 */ else if viFcReturnSuper > 0 then assign vlWarningsFound = true. end. /* if icAction = {&DAEMONACTION-VALIDATE} */ /* ============================================ */ /* 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(tApiLayer.Layer_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(substr(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 vcMsg = trim(#T-24'Only one draft instance can be created per method call.':255(858)T-24#) + chr(10) + trim(#T-25'This second object will not be stored as a draft instance and so is an error.':255(859)t-25#). <M-45 run SetMessage (input vcMsg (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QADFIN-4276':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BLayer> next. end. /* if vlDraftInstanceCreated = true */ <M-46 run StoreState (input '(':U + string(tLayer.LayerCode) + ') ':U + trim(#T-34'Layer created via an API method.':255(17362)T-34#) (icDescription), input ? (icUIClass), output viFcReturnSuper (oiReturnStatus)) in BLayer> assign vlDraftInstanceCreated = true entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper) entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiLayer.Layer_ID) entry(num-entries(ocLstRowid , chr(4)), ocLstRowid , chr(4)) = vcRowID. end. /* if vlSaveAsDraft and substr */ end. /* for each tApiLayer: */ /* ========================= */ /* Stop Queries */ /* ========================= */ <Q-47 run LayerPrim (Stop) in BLayer > /* ============================================================ */ /* 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 vcMsg = trim(#T-27'Layer integration: incomplete information returned by an API method. See other messages for further details.':200(17363)T-27#) + chr(10) + trim(substitute(#T-28'Main table records: &1.':255(310)T-28#,string(viMainTableRecordCount))) + chr(10) + trim(substitute(#T-29'Return Statuses: &1.':255(311)T-29#,ocLstReturn)) + chr(10) + trim(substitute(#T-30'Primary keys: &1.':255(312)T-30#,ocLstPrimKey)) + chr(10) + trim(substitute(#T-31'Row IDs: &1.':255(313)T-31#,ocLstRowid)). oiReturnStatus = -3. <M-48 run SetMessage (input vcMsg (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QADFIN-4278':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BLayer> 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 do : if index(ocLstReturn,"-":U) <> 0 then do : assign vcMsg = trim(#T-32'An error has occurred while running this API method. See other error messages for more details.':255(301)T-32#) oiReturnStatus = -1. <M-49 run SetMessage (input vcMsg (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input '':U (icRowid), input 'QADFIN-4279':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BLayer> end. /* index(ocLstReturn,"-":U) <> 0 */ else do : assign vcMsg = trim(#T-33'A warning has occurred while running this API method. See other error messages for more details.':255(302)T-33#) oiReturnStatus = +1. <M-50 run SetMessage (input vcMsg (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'W':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QADFIN-4280':U (icFcMsgNumber), input '':U (icFcExplanation), input '':U (icFcIdentification), input '':U (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BLayer> end. /* not if lookup */ end. /* not if ocLstReturn */ if oiReturnStatus = -98 then oiReturnStatus = 0.
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 = "BLayer". 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/blayer.apistdmaintaintt.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::icAction = <parameter value>. vhParameter = vhInputDS:get-buffer-handle("tApiLayer"). 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.