tApiBusinessRelation | input | temp-table | Temp-table that is the base for the data that will be created via this API method. |
tApiAddress | input | temp-table | Child Temp-table Address for the main temp-table (BusinessRelation) |
tApiContact | input | temp-table | Child Temp-table Contact for the main temp-table (BusinessRelation) |
tApiVatNumber | input | temp-table | Child Temp-table VatNumber for the main temp-table (BusinessRelation) |
tApiBusRelationSafDefault | input | temp-table | temp-table containing the SafDefault information for a BusinessRelation |
icAction | input | character | Action. Possible values; "SAVE":U "SAVESTORE":U "STORE":U "VALIDATE":U |
tApiExtended | output | temp-table | Temp-table containing all rowid and ID information on the newly created records. |
ocLstPrimKey | output | character | LstPrimKey Char4 separated list with the primary keys of the newly created main-table records. The fields of a primkey are separated with Char2. E.g. 1<Char2>2002<Char2>100<Char4>1<Char2>2002<Char2>101 |
ocLstReturn | output | character | LstReturn Char4 separated list with the return-status of the newly created main-table records. Zero means no errors occured. E.g. 0<Char4>-1<Char4>-504<Char4>1<Char4>0 |
ocLstRowid | output | character | LstRowid Char4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records. . E.g. -1<Char2>aox00098001<Char2>-26 |
oiReturnStatus | output | integer | Return status of the method. |
/* ==================================== */ /* Return in case no input is provided */ /* Empty output temp-table tApiExtended */ /* ==================================== */ if not can-find (first tApiBusinessRelation) then return. empty temp-table tApiExtended. /* ================================================ */ /* Set default return-status */ /* ================================================ */ assign oiReturnStatus = -98. /* ============================ */ /* Call method ApiStdMaintainTT */ /* ============================ */ <M-1 run ApiStdMaintainTT (input tApiBusinessRelation (tApiBusinessRelation), input tApiAddress (tApiAddress), input tApiContact (tApiContact), input tApiVatNumber (tApiVatNumber), input tApiBusRelationSafDefault (tApiBusRelationSafDefault), input icAction (icAction), output ocLstPrimKey (ocLstPrimKey), output ocLstReturn (ocLstReturn), output ocLstRowid (ocLstRowid), output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation> if viFcReturnSuper <> 0 then do : assign oiReturnStatus = viFcReturnSuper. if oiReturnStatus < 0 then return. end. /* if viFcReturnSuper <> 0 */ /* ============================================================================================= */ /* If the previuos method was executed correctly, then we have to create tApiExtended records */ /* for all newly created records in the instances. tApiExtended.tcRecordType indicates the table */ /* Note; even if the previous call produced warnings,; we will still continue */ /* ============================================================================================= */ /* ================================================================================= */ /* Compose a list with the BusinessRelation_ID's of the new records */ /* Field tApiBusinessRelation.BusinessRelation_ID was set in method ApiStdMaintainTT */ /* ================================================================================= */ for each tApiBusinessRelation : assign vcBusinessRelationIDList = vcBusinessRelationIDList + chr(4) + string(tApiBusinessRelation.BusinessRelation_ID). end. /* for each tApiBusinessRelation */ if length(vcBusinessRelationIDList,"CHARACTER":U) > 1 then assign vcBusinessRelationIDList = substring(vcBusinessRelationIDList,2,-1,"CHARACTER":U). else do : assign vcMessage = "":L500 oiReturnStatus = -3. if oiReturnStatus < 0 then Return. end. /* Not if length(vcBusinessRelationIDList,"CHARACTER":U) > 1 */ /* ============================= */ /* Re-Load the BusienssRelations */ /* ============================= */ <M-2 run DataLoad (input ? (icRowids), input vcBusinessRelationIDList (icPkeys), input ? (icObjectIds), input '' (icFreeform), input false (ilKeepPrevious), output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation> if viFcReturnSuper <> 0 then do : assign vcMessage = "":L500 oiReturnStatus = -3. if oiReturnStatus < 0 then Return. end. /* Not if length(vcBusinessRelationIDList,"CHARACTER":U) > 1 */ /* ==================================================================== */ /* Go through all records of all loaded instances and fill tApiExtended */ /* ==================================================================== */ for each tBusinessRelation, first tApiBusinessRelation where tApiBusinessRelation.BusinessRelation_ID = tBusinessRelation.BusinessRelation_ID : create tApiExtended. assign tApiExtended.tcRecordType = "BusinessRelation":U tApiExtended.tiSCID = tBusinessRelation.BusinessRelation_ID tApiExtended.tcRowID = tApiBusinessRelation.tc_Rowid tApiExtended.tcParentRowID = tApiBusinessRelation.tc_ParentRowid. /* VAT */ for each tVatNumber where tVatNumber.tc_ParentRowid = tBusinessRelation.tc_Rowid, first tApiVatNumber where tApiVatNumber.tc_ParentRowid = tApiBusinessRelation.tc_Rowid and tApiVatNumber.tcIdentityCountryCode = tVatNumber.tcIdentityCountryCode and tApiVatNumber.VatNumberIdentity = tVatNumber.VatNumberIdentity : create tApiExtended. assign tApiExtended.tcRecordType = "VatNumber":U tApiExtended.tiSCID = tVatNumber.VatNumber_ID tApiExtended.tcRowID = tApiVatNumber.tc_Rowid tApiExtended.tcParentRowID = tApiVatNumber.tc_ParentRowid. end. /* for each tVatNumber */ /* SafDefault */ for each tBusRelationSafDefault where tBusRelationSafDefault.tc_ParentRowid = tBusinessRelation.tc_Rowid, first tApiBusRelationSafDefault where tApiBusRelationSafDefault.tc_ParentRowid = tApiBusinessRelation.tc_Rowid and tApiBusRelationSafDefault.tcSafConceptCode = tBusRelationSafDefault.tcSafConceptCode and tApiBusRelationSafDefault.tcSafCode = tBusRelationSafDefault.tcSafCode : create tApiExtended. assign tApiExtended.tcRecordType = "BusRelationSafDefault":U tApiExtended.tiSCID = tBusRelationSafDefault.BusRelationSafDefault_ID tApiExtended.tcRowID = tApiBusRelationSafDefault.tc_Rowid tApiExtended.tcParentRowID = tApiBusRelationSafDefault.tc_ParentRowid. end. /* for each tBusRelationSafDefault */ /* Address */ for each tAddress where tAddress.tc_ParentRowid = tBusinessRelation.tc_Rowid, first tApiAddress where tApiAddress.tc_ParentRowid = tApiBusinessRelation.tc_Rowid and tApiAddress.tcAddressTypeCode = tAddress.tcAddressTypeCode and tApiAddress.AddressCity = tAddress.AddressCity and tApiAddress.AddressZip = tAddress.AddressZip and tApiAddress.AddressStreet1 = tAddress.AddressStreet1 and tApiAddress.AddressStreet2 = tAddress.AddressStreet2 and tApiAddress.AddressStreet3 = tAddress.AddressStreet3: create tApiExtended. assign tApiExtended.tcRecordType = "Address":U tApiExtended.tiSCID = tAddress.Address_ID tApiExtended.tcRowID = tApiAddress.tc_Rowid tApiExtended.tcParentRowID = tApiAddress.tc_ParentRowid. /* Contact */ for each tContact where tContact.tc_ParentRowid = tApiAddress.tc_Rowid, first tApiContact where tApiContact.tc_ParentRowid = tApiAddress.tc_Rowid and tApiContact.ContactName = tContact.ContactName : create tApiExtended. assign tApiExtended.tcRecordType = "Contact":U tApiExtended.tiSCID = tContact.Contact_ID tApiExtended.tcRowID = tApiContact.tc_Rowid tApiExtended.tcParentRowID = tApiContact.tc_ParentRowid. end. /* for each tContact */ end. /* for each tBusRelationSafDefault */ end. /* for each tBusinessRelation */ /* ============================================= */ /* Unlaod the loaded instances // clear instance */ /* ============================================= */ <M-3 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BBusinessRelation> /* ========================= */ /* Set return-status = OK */ /* ========================= */ assign 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 = "BBusinessRelation". create ttContext. assign ttContext.propertyName = "methodName" ttContext.propertyValue = "ApiStdMaintainTTExtended". 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/bbusinessrelation.apistdmaintainttextended.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::icAction = <parameter value>. vhParameter = vhInputDS:get-buffer-handle("tApiBusinessRelation"). vhParameter:buffer-create(). assign vhParameter::<field-name-1> = <field-value-1> vhParameter::<field-name-2> = <field-value-2> ... vhParameter = vhInputDS:get-buffer-handle("tApiAddress"). vhParameter:buffer-create(). assign vhParameter::<field-name-1> = <field-value-1> vhParameter::<field-name-2> = <field-value-2> ... vhParameter = vhInputDS:get-buffer-handle("tApiContact"). vhParameter:buffer-create(). assign vhParameter::<field-name-1> = <field-value-1> vhParameter::<field-name-2> = <field-value-2> ... vhParameter = vhInputDS:get-buffer-handle("tApiVatNumber"). vhParameter:buffer-create(). assign vhParameter::<field-name-1> = <field-value-1> vhParameter::<field-name-2> = <field-value-2> ... vhParameter = vhInputDS:get-buffer-handle("tApiBusRelationSafDefault"). 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.