project QadFinancials > class BVAT > method ApiStdMaintainTT

Description

This method can create new instances or update existing instances based on the content of the input temp-tables. The action that is passed as a parameter will define if the records are saved, saved as draft or just validated.

With this method you create vat records.


Parameters


tApiVatinputtemp-tableInput temp-table holding the vat data to be created, updated or deleted.
tApiVatRuleinputtemp-tableInput temp-table holding the vat rule data to be created, updated or deleted.
icActioninputcharacterThis parameter defines what should happen with the input data : -SAVE: Save the data if there were no errors, -SAVESTORE : Save the data if there were no errors. If there were errors, save as draft. -STORE : Save the data as draft -VALIDATE : Validate the input data, but do no save the data.
ilAtomicCommitinputlogicalIndicates whether all records should be rolled back if any fail validation.
ocLstPrimKeyoutputcharacterCharacter 4 separated list with the primary keys of the newly created main-table records. The fields of the primary key are separated with Character 2.
ocLstReturnoutputcharacterChar 4 separated list with the return status of the newly created main-table records. Zero means not errors occurred.
ocLstRowidoutputcharacterChar 4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BVAT.ApiCreateNonTaxable


program code (program7/bvat.p)

/* =================================================== */
/* Method Info:                                        */
/* Vat 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-1 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BVAT>

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 vcVatMsg = trim(subst(#T-19'Tax integration: the specified action &1 should be in the list &2.':255(3815)t-19#,trim(icAction),"{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U))
           oiReturnStatus = -1.
           <M-2 run SetMessage (input  vcVatMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QadFin-6081':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT>  
    return.
end. /* if icAction */

/* ======================== */
/* Count main-table records */
/* ======================== */
for each tApiVat no-lock :
    assign viMainTableRecordCount = viMainTableRecordCount + 1.
end. /* for each */
if viMainTableRecordCount = 0
then do:
    assign vcVatMsg = trim(#T-20'Tax integration: no main tax table records found.':255(3816)t-20#)
           oiReturnStatus = -1.
           <M-3 run SetMessage (input  vcVatMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QadFin-6082':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT> 
    return.
end. /* if viMainTableRecordCount */

/* ================================================================= */
/*  Start queries                                                    */
/* ================================================================= */

<Q-4 run VATPrim (Start) in BVAT >


/* ================================ */
/* Start loop on main-table records */
/* ================================ */
for each tApiVat by tApiVat.tc_Rowid: 

    MAIN-BLOCK:
    DO:

    /* ========== */
    /* Initialize */
    /* ========== */
    assign vcVatMsg        = "":U
           vcRowID         = "":U
           vlWarningsFound = false
           vlSaveAsDraft   = icAction = {&DAEMONACTION-STORE}.
    
    /* ====================================== */
    /* Get the Vat_ID based on the logical key */
    /* ====================================== */
    if (tApiVat.Vat_ID  = ?   or
        tApiVat.Vat_ID  = 0)  and
        tApiVat.VatCode <> "" and
        tApiVat.VatCode <> ? and
      ((tApiVat.Domain_ID <> ? and
        tApiVat.Domain_ID <> 0) or
       (tApiVat.tcDomainCode <> ? and
        tApiVat.tcDomainCode <> "")) and
        tApiVat.VatInOut <> ? and
        tApiVat.VatInOut <> ""
    then do:
        <Q-5 run VATPrim (all) (Read) (NoCache)
           (input ?, (VatId)
            input tApiVat.VatCode, (VatCode)
            input tApiVat.Domain_ID, (DomainId)
            input tApiVat.tcDomainCode, (DomainCode)
            input tApiVat.VatInOut, (VatInOut)
            output dataset tqVATPrim) in BVAT >
        
        find tqVatPrim where 
             tqVatPrim.tcVatCode = tApiVat.VatCode and
            (tqVATPrim.tiDomain_ID = tApiVat.Domain_ID or
            tqVATPrim.tcDomainCode = tApiVat.tcDomainCode) and
             tqVATPrim.tcVatInOut  = tApiVat.VatInOut
             no-lock no-error.
        if available tqVatPrim
        then assign tApiVat.Vat_ID = tqVatPrim.tiVat_ID.
    end.
    
    assign vhFcComponent = ?.
   

    /* ==================== */
    /* Load/Create Vat  */
    /* ==================== */
    if tApiVat.Vat_ID = ? or
       tApiVat.Vat_ID = 0
    then assign viFcReturnSuper = -4.
    else do:          
        <M-6 run DataLoad
           (input  ? (icRowids), 
            input  string(tApiVat.Vat_ID) (icPkeys), 
            input  ? (icObjectIds), 
            input  ? (icFreeform), 
            input  true (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BVAT>        
    end.
    if viFcReturnSuper = -4
    then do:
        assign viFcReturnSuper = 0.

        if not ilAtomicCommit then do:
            <M-7 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BVAT>
        end.
        else do:
             <M-34 run AddDetailLine
                (input  'Vat':U (icTable), 
                 input  '':U (icParentRowid), 
                 output viFcReturnSuper (oiReturnStatus)) in BVAT>
        end.
        
        if viFcReturnSuper < 0
        then assign vcVatMsg = trim(subst(#T-21'Cannot create a new instance. Error number: &1.':255(308)t-21#, string(viFcReturnSuper))).

        /* This should find the newly created record as it uses the primary 
           index (Vat_ID), the new record should have the highest Vat_ID
        */
        find last tVat no-error.
    end.
    else do:
        if viFcReturnSuper < 0
        then assign vcVatMsg = trim(subst(#T-22'Cannot load the instance (error number: &1, instance ID: &2).':255(289)t-22#, string(viFcReturnSuper), string(tApiVat.Vat_ID))).
        else do:
            find tVat where
                 tVat.Vat_ID = tApiVat.Vat_ID
                 no-error.
            if not available tVat
            then assign vcVatMsg = trim(subst(#T-23'Cannot find the instance after it has been loaded (instance ID: &1).':255(290)t-23#,
                                               string(tApiVat.Vat_ID))).
            else assign tVat.tc_Status = "C":U.
        end.
    end.

    /* ================================================================= */
    /* Check for errors in the previous block                            */
    /* ================================================================= */

    if vcVatMsg <> "":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-8 run SetMessage (input  vcVatMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QadFin-6083':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT>                
        leave MAIN-BLOCK.
    end.

    /* ====================== */
    /* Copy data for Vat  */
    /* ====================== */          
    
    buffer-copy tApiVat
         except tApiVat.Vat_ID
                tApiVat.tc_ParentRowid
                tApiVat.tc_Rowid
                tApiVat.tc_Status  
                tApiVat.VatCode
             to tVat.
    if tVat.tc_Status = "N":U
    then assign tVat.VatCode = tApiVat.VatCode.

    assign vcRowID         = tVat.tc_Rowid
           tApiVat.Vat_ID  = tVat.Vat_ID /*Needed to set the prim-key after the save*/.

    /* Process all Child tables (VatRule) */
    
     <M-9 run ApiStdMaintainTTDetail (input  icAction (icAction), 
                                  input-output ocLstReturn (bcLstReturn), 
                                  input-output ocLstPrimKey (bcLstPrimKey), 
                                  input-output ocLstRowid (bcLstRowid), 
                                  input-output vlSaveAsDraft (blSaveAsDraft), 
                                  output viFcReturnSuper (oiReturnStatus)) in BVAT>
    
    if viFcReturnSuper < 0
    then leave MAIN-BLOCK.
    else if viFcReturnSuper > 0 
    then assign vlWarningsFound = true.

    /* =================================================== */
    /* 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 we're not doing an all or nothing commit then we save each record as we go along */
    if not ilAtomicCommit then do:

        /* =============================== */
    	/* Set Actvity                     */
    	/* =============================== */
        /* It might be possible to remove this piece of code as the Activity is being set near the end of this method */
    	if can-find (first tVat where
    			   		   tVat.tc_Status = "N":U)
    	then assign vcActivityCode = "Create":U.
    	else if can-find (first tVat where
    							tVat.tc_Status = "C":U)
    	then assign vcActivityCode = "Modify":U.
    
        /* ================= */
        /* Validate the data */
        /* ================= */
       <M-10 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BVAT>
       
        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-11 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BVAT>
                
        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:
            <M-12 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BVAT>               
    
            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-38 run ClearData
           (output viFcReturnSuper (oiReturnStatus)) in BVAT>

        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. /* if not ilAtomicCommit */

    /* ============================================ */
    /* 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(tApiVat.Vat_ID)
           ocLstRowid    = ocLstRowid   + chr(4) + vcRowID.            
    
    END. /* MAIN-BLOCK */

    /* ================================================================== */
    /* Handle errors: store if SabeAsDraft 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 vcVatMsg = trim(#T-24'Only one draft instance can be created per method call.':255(13947)T-24#) +
                              chr(10) +
                              trim(#T-25'This second object cannot be stored as a draft instance and so is an error.':255(13879)t-25#).
            <M-13 run SetMessage (input  vcVatMsg (icMessage), 
                      input  '':U (icArguments), 
                      input  '':U (icFieldName), 
                      input  '':U (icFieldValue), 
                      input  'E':U (icType), 
                      input  1 (iiSeverity), 
                      input  '':U (icRowid), 
                      input  'QadFin-6084':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BVAT>
            next.
        end.   
        <M-14 run StoreState
          (input  '(':U + string(tVat.VatCode) + ') ':U + trim(#T-26'Tax created via an API method.':200(1394)T-26#) (icDescription), 
           input  ? (icUIClass), 
           output viFcReturnSuper (oiReturnStatus)) in BVAT>
                    
        assign vlDraftInstanceCreated                                         = true 
               entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper)
               entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiVat.Vat_ID)
               entry(num-entries(ocLstRowid  , chr(4)), ocLstRowid  , chr(4)) = vcRowID.
    end.  /*if vlSaveAsDraft and index*/  
end. /* for each tApiCode */

/* ================================================================= */
/*  Stop queries                                                     */
/* ================================================================= */

<Q-15 run VATPrim (Stop) in BVAT >

/* ============================================================ */
/* 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 vcVatMsg       = trim(#T-27'Tax integration: incomplete information returned by an API method. See other messages for further details.':200(3817)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-16 run SetMessage (input  vcVatMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QadFin-6085':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT> 
    
    return.
end. /* if num-entries */

/* If we're doing an all or nothing commit, then we now need to call the code to save the data */
if ilAtomicCommit then do:

    /* =============================== */
    /* Set Actvity                     */
    /* =============================== */
    if vcActivityCode = '':U or vcActivityCode = ? then do:
        if can-find (first tVat where tVat.tc_Status = "N":U) then 
            assign vcActivityCode = "Create":U.
        else if can-find (first tVat where tVat.tc_Status = "C":U) then 
            assign vcActivityCode = "Modify":U.
    end.

    /* ================= */
    /* Validate the data */
    /* ================= */
   <M-35 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BVAT>
    if viFcReturnSuper <> 0
    then do:
        if index(ocLstReturn,'-':U) = 0
        then assign ocLstReturn = fill(string(viFcReturnSuper) + chr(4),viMainTableRecordCount).
        if viFcReturnSuper < 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            return.
        end. /* viFcReturnSuper < 0 */
    end.
   
    /* ================ */
    /* External updates */
    /* ================ */
    <M-36 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BVAT>
    if viFcReturnSuper <> 0
    then do:
        if index(ocLstReturn,'-':U) = 0
        then assign ocLstReturn = fill(string(viFcReturnSuper) + chr(4),viMainTableRecordCount).
        if viFcReturnSuper < 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            return.
        end. /* viFcReturnSuper < 0 */
    end.
            
    /* ============= */
    /* Save the data */
    /* ============= */
    if icAction <> {&DAEMONACTION-VALIDATE}
    then do:
        <M-37 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BVAT>               
        if viFcReturnSuper <> 0
        then do:
            if index(ocLstReturn,'-':U) = 0
            then assign ocLstReturn = fill(string(viFcReturnSuper) + chr(4),viMainTableRecordCount).
            if viFcReturnSuper < 0
            then do :
                assign oiReturnStatus = viFcReturnSuper.
                return.
            end. /* viFcReturnSuper < 0 */
        end.
    end.

end. /* if ilAtomicCommit */

/* ===================================================== */
/* 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 vcVatMsg      = 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-17 run SetMessage (input  vcVatMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QadFin-6086':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT> 
         
    end. /* if index(ocLstReturn,"-":U) <> 0 */
    else do : 
        assign vcVatMsg     = 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-18 run SetMessage (input  vcVatMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'W':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QadFin-6087':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT> 
    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 = "BVAT".
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/bvat.apistdmaintaintt.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAction = <parameter value>
       vhParameter::ilAtomicCommit = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tApiVat").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tApiVatRule").
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.