project QadFinancials > class BVATExportListing > method ApiOmzetBelastingNL

Description

This method is used to get a Declaration Export list for Netherlands.


Parameters


iiDeclarationPeriodTypeinputintegerDeclaratioin Period Type.
iiDeclarationYearinputintegerDeclaration Year.
iiDeclarationPeriodinputintegerDeclaration Period.
odTurnOverDueVatoutputdecimalTurn Over Due Vat.
odPreVatoutputdecimalPre Vat Amount.
odSmallEnterpriseAgreementoutputdecimalSmall Enterpise Agreement.
odEstimatePreviousDeclarationoutputdecimalEstimate Previous Declaration.
odEstimateCurrentDeclarationoutputdecimalEstimate Current Declaration.
odTotalToPayReclaimoutputdecimalTotal To Pay Reclaim.
oiCountryIDoutputintegerCountry ID.
tVatDeclarationNLExportoutputtemp-tableTemp table of VatDeclarationNLExport.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bvatexportlisting.p)

/* Comment Out ApiOmzetBelastingNL --> No more country_id field in VAT anymore. */

/*

/* temporary all is assign to country BE, should become  NL*/

empty temp-table tVatDeclarationNLExport.

/* GLOBAL SETTINGS */

assign vcDateTime =  string(year(TODAY),"9999":U) 
                   + "-":U 
                   + string(month(TODAY),"99":U) 
                   + "-":U 
                   + string(day(TODAY),"99":U) 
                   + "T":U + entry(2,STRING(DATETIME(TODAY, MTIME))," ":U)        
       vcDateTime = REPLACE(vcDateTime,",":U, ".":U).


validations: DO:
    
    

    /* Currency should be EUR , get the CurrencyID for EUR */
    <Q-1 run CurrencyPrim (all) (Read) (NoCache)
          (input 'EUR':U, (CurrencyCode)
           input ?, (Currency_ID)
           output dataset tqCurrencyPrim) in BCurrency >
    find first tqCurrencyPrim NO-LOCK no-error.
    if available tqCurrencyPrim
    then assign viExportCurrencyID = tqCurrencyPrim.tiCurrency_ID.
    else do:
        assign vcMessage      = #T-7'The specified currency is not defined in the system.':150(1067)t-7# + ' EUR':U
               oiReturnStatus = -1.
        leave validations.
    end.               
    
    if viCompanyLCId <> viExportCurrencyID
    then do:
        assign vcMessage      = #T-17'The base currency must be EUR.':150(13895)t-17# + ' EUR':U
               oiReturnStatus = -1.
        leave validations.
    end.

    /* Input parameters the should be filled in */
    if  iiDeclarationPeriodType = ?
    or  iiDeclarationYear       = ?
    or  iiDeclarationPeriod     = ? 
    then do:        
        if iiDeclarationYear = ? or iiDeclarationYear = 0
        then do:
            assign vcMessage      = #T-19'You must enter a GL calendar year.':50(14222)T-19#
                    oiReturnStatus = -1.   
        end.
        if  not iiDeclarationPeriodType = 4
        and (iiDeclarationPeriod = ? or iiDeclarationPeriod = ?)
        then do:
            assign vcMessage      = #T-18'You must enter a GL period.':50(14221)T-18#
                    oiReturnStatus = -1.
            leave validations.
        end.



    end.

    assign vifromPeriod = iiDeclarationPeriod
           vitoPeriod   = iiDeclarationPeriod
           viToYear     = iiDeclarationYear.

                

    if iiDeclarationPeriodType = 2 
    then do:
        assign vifromPeriod = iiDeclarationPeriod
               vitoPeriod   = iiDeclarationPeriod
               viToYear     = iiDeclarationYear.    
        .<Q-22 run VATPeriodPrim (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input ?, (VATPeriodID)
           input ?, (Year)
           input ?, (Period)
           output dataset tqVATPeriodPrim) in BVATPeriod >
                    
        
        find first tqVATPeriodPrim where tqVATPeriodPrim.tiVatPeriodPeriod = vifromPeriod
                                     and tqVATPeriodPrim.tiVatPeriodYear   = iiDeclarationYear  no-error.

        if available tqVATPeriodPrim then do:
            assign vitoPeriod   = tqVATPeriodPrim.tiVatPeriodPeriod 
                   vitoYear     = tqVATPeriodPrim.tiVatPeriodYear
                   vitoPeriodID = tqVATPeriodPrim.tiVatPeriod_ID.
            find next tqVATPeriodPrim no-error.
        end.

        if available tqVATPeriodPrim then do:
            assign vitoPeriod   = tqVATPeriodPrim.tiVatPeriodPeriod 
                   vitoYear     = tqVATPeriodPrim.tiVatPeriodYear
                   vitoPeriodID = tqVATPeriodPrim.tiVatPeriod_ID.
            find next tqVATPeriodPrim no-error.
        end.
        if available tqVATPeriodPrim then do:
            assign vitoPeriod   = tqVATPeriodPrim.tiVatPeriodPeriod 
                   vitoYear     = tqVATPeriodPrim.tiVatPeriodYear
                   vitoPeriodID = tqVATPeriodPrim.tiVatPeriod_ID.             
        end.  
    end.
    else if iiDeclarationPeriodType = 4
    then do:
        .<Q-23 run VATPeriodPrim (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input ?, (VATPeriodID)
           input 2005, (Year)
           input ?, (Period)
           output dataset tqVATPeriodPrim) in BVATPeriod >
         find first tqVatPeriodPrim no-error.
         if available tqVatPeriodPrim 
         then
         assign vitoPeriod   = tqVATPeriodPrim.tiVatPeriodPeriod 
                vitoYear     = tqVATPeriodPrim.tiVatPeriodYear
                vitoPeriodID = tqVATPeriodPrim.tiVatPeriod_ID.   
    end.


    if available tVatExport
    and vitoPeriod <> 0
    then assign tVatExport.tiVatPeriodPeriod = vitoPeriod
                tVatExport.tiVatPeriodYear   = vitoYear
                tVatExport.VatPeriod_ID      = vitoPeriodID.
          
    



    /* */
    <Q-? run CompanyPropertiesForInvoice (all)  (input viCompanyId, (CompanyId)
                                                  output table tqCompanyPropertiesForInvoice) in BCompanyProperty >

    
    find first tqCompanyPropertiesForInvoice no-error.
    if available tqCompanyPropertiesForInvoice
    then do:
        <Q-13 run AddressByBusinessRelation (all) (Read) (NoCache)
          (input tqCompanyPropertiesForInvoice.tiBusinessRelation_ID, (BusinessRelationId)
           output dataset tqAddressByBusinessRelation) in BBusinessRelation >

        find first tqAddressByBusinessRelation no-error.
        if available tqAddressByBusinessRelation
        then do:
            assign vcOBNumber = tqAddressByBusinessRelation.tcAddressTaxIDFederal.           
        end.                
    end.
END. /* validations DO: */

/* THIS IS WHAT IS EXECUTED WHEN LEAVE OF VALIDATIONS */
if vcMessage <> "":U
then do:
<M-8 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QADFIN-3105':U (icFcMsgNumber), 
                     input  '' (icFcExplanation), 
                     input  '' (icFcIdentification), 
                     input  '' (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BVATExportListing>
        assign oiReturnStatus = -1.
        return.
end.   

CREATE tVatDeclarationNLExport.
assign tVatDeclarationNLExport.tcOBNumber          = vcOBNumber
       tVatDeclarationNLExport.tcValutaCode        = "EUR":U
       tVatDeclarationNLExport.tiDeclarationYear   = iiDeclarationYear
       tVatDeclarationNLExport.tiDeclarationPeriod = iiDeclarationPeriod
       tVatDeclarationNLExport.tcMessageID         = vcMessageID 
       tVatDeclarationNLExport.tcTimeCreation      = vcDateTime
       tVatDeclarationNLExport.tcMediumType        = "WEB":U
       tVatDeclarationNLExport.tcContactType       = "BPL":U
       tVatDeclarationNLExport.tcContactID         = vcOBNumber 
       tVatDeclarationNLExport.tcContactName       = vcUserName
       tVatDeclarationNLExport.tcContactTelephone  = "":U.

/* =========================== */
/* Call query using parameters */
/* =========================== */              




 <Q-15 run PostingVatByYearPeriod (all) (Read) (NoCache)
          (input viCompanyId, (CompanyId)
           input ?, (PeriodId)
           input iiDeclarationYear, (PeriodYear)
           input if iiDeclarationPeriodType = 1 then iiDeclarationPeriod else ?, (PeriodPeriod)
           output dataset tqPostingVatByYearPeriod) in BPosting >

for each tqPostingVatByYearPeriod where 
       (if iiDeclarationPeriodType = 2 then tqPostingVatByYearPeriod.tiVatPeriodYear  >= iiDeclarationYear else true)
   and (if iiDeclarationPeriodType = 2 then tqPostingVatByYearPeriod.tiVatPeriodYear  <= viToYear          else true)
   and (if iiDeclarationPeriodType = 2 then tqPostingVatByYearPeriod.tiVatPeriodPeriod >= vifromPeriod    else true)
   and (if iiDeclarationPeriodType = 2 then tqPostingVatByYearPeriod.tiVatPeriodPeriod <= vitoPeriod    else true):

   

    case tqPostingVatByYearPeriod.tcVatTransactionType:
        
        when {&VATTRANSACTIONTYPE-SALES} 
        then do:
            /* tranaction  for customer inland*/
            case tqPostingVatByYearPeriod.tcVatPercentageLevel:
                when {&VATPERCENTAGELEVEL-HIGH} 
                then do:
                    if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
                    then ASSIGN tVatDeclarationNLExport.tdTurnOverHigh     =  tVatDeclarationNLExport.tdTurnOverHigh      + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC
                                tVatDeclarationNLExport.tdTurnOverVatHigh  =  tVatDeclarationNLExport.tdTurnOverVatHigh   + tqPostingVatByYearPeriod.tdPostingLineDebitLC     - tqPostingVatByYearPeriod.tdPostingLineCreditLC.                     
                    else ASSIGN tVatDeclarationNLExport.tdTurnOverHigh     =  tVatDeclarationNLExport.tdTurnOverHigh      + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC
                                tVatDeclarationNLExport.tdTurnOverVatHigh  =  tVatDeclarationNLExport.tdTurnOverVatHigh   + tqPostingVatByYearPeriod.tdPostingLineCreditLC    - tqPostingVatByYearPeriod.tdPostingLineDebitLC   .                     
                end.
                when {&VATPERCENTAGELEVEL-LOW} then do:
                    if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
                    then ASSIGN tVatDeclarationNLExport.tdTurnOverLOw      =  tVatDeclarationNLExport.tdTurnOverLow       + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC
                                tVatDeclarationNLExport.tdTurnOverVatLow   =  tVatDeclarationNLExport.tdTurnOverVatLow    + tqPostingVatByYearPeriod.tdPostingLineDebitLC    - tqPostingVatByYearPeriod.tdPostingLineCreditLC.
                    ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverLOw      =  tVatDeclarationNLExport.tdTurnOverLow       + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  
                                tVatDeclarationNLExport.tdTurnOverVatLow   =  tVatDeclarationNLExport.tdTurnOverVatLow    + tqPostingVatByYearPeriod.tdPostingLineCreditLC    - tqPostingVatByYearPeriod.tdPostingLineDebitLC.
                    
                end.
                when {&VATPERCENTAGELEVEL-ZERO} then do:
                    if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
                    then ASSIGN tVatDeclarationNLExport.tdTurnOverNoVat    =  tVatDeclarationNLExport.tdTurnOverNoVat     + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC. 
                    ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverNoVat    =  tVatDeclarationNLExport.tdTurnOverNoVat     + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC. 
                end.
                otherwise do:
                    put unformatted {&VATTRANSACTIONTYPE-SALES} "|":U {&VATINOUT-INPUT} "|":U tqPostingVatByYearPeriod.tcVatInOut "-":U tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC   "|":U tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC   "|":U tqPostingVatByYearPeriod.tdPostingLineDebitLC   "|":U tqPostingVatByYearPeriod.tdPostingLineCreditLC skip. 
                    if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
                    then ASSIGN tVatDeclarationNLExport.tdTurnOverOther    =  tVatDeclarationNLExport.tdTurnOverOther     + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC
                                tVatDeclarationNLExport.tdTurnOverVatOther =  tVatDeclarationNLExport.tdTurnOverVatOther  + tqPostingVatByYearPeriod.tdPostingLineDebitLC     - tqPostingVatByYearPeriod.tdPostingLineCreditLC. 
                    ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverOther    =  tVatDeclarationNLExport.tdTurnOverOther     + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC
                                tVatDeclarationNLExport.tdTurnOverVatOther =  tVatDeclarationNLExport.tdTurnOverVatOther  + tqPostingVatByYearPeriod.tdPostingLineCreditLC    - tqPostingVatByYearPeriod.tdPostingLineDebitLC. 
                end.
            end case.
        end. /* when {&VATTRANSACTIONTYPE-SALES} */
        
        when {&VATTRANSACTIONTYPE-PURCHASE} 
        then do:
            /* tranaction  for suppliers inland*/
            if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
            then ASSIGN tVatDeclarationNLExport.tdTurnOverTransferred      =  tVatDeclarationNLExport.tdTurnOverTransferred    + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC
                        tVatDeclarationNLExport.tdTurnOverVatTransferred   =  tVatDeclarationNLExport.tdTurnOverVatTransferred + tqPostingVatByYearPeriod.tdPostingLineDebitLC     - tqPostingVatByYearPeriod.tdPostingLineCreditLC. 
            ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverTransferred      =  tVatDeclarationNLExport.tdTurnOverTransferred    + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  
                        tVatDeclarationNLExport.tdTurnOverVatTransferred   =  tVatDeclarationNLExport.tdTurnOverVatTransferred + tqPostingVatByYearPeriod.tdPostingLineCreditLC.   - tqPostingVatByYearPeriod.tdPostingLineDebitLC.     
        end. /* when {&VATTRANSACTIONTYPE-PURCHASE} */

        /* Foreign Transaction by you*/
        when {&VATTRANSACTIONTYPE-EXPORT} 
        then do:
            /* transaction to customer outside EG                    */
            if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
            then ASSIGN tVatDeclarationNLExport.tdTurnOverOutsideEUExport  =  tVatDeclarationNLExport.tdTurnOverOutsideEUExport + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC.
            ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverOutsideEUExport  =  tVatDeclarationNLExport.tdTurnOverOutsideEUExport + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC.
                   
        END. /* when {&VATTRANSACTIONTYPE-EXPORT} */
        
        WHEN {&VATTRANSACTIONTYPE-SUPPLY} 
        then do:
            /* transaction to customer between 2 countries inside EG */
            IF tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
            THEN ASSIGN tVatDeclarationNLExport.tdTurnOverInsideEUExport   =  tVatDeclarationNLExport.tdTurnOverInsideEUExport  + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC.
            ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverInsideEUExport   =  tVatDeclarationNLExport.tdTurnOverInsideEUExport  + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC.
        END. /* WHEN {&VATTRANSACTIONTYPE-SUPPLY} */    
        
        /* Foreign Transaction to you*/
        when {&VATTRANSACTIONTYPE-IMPORT} 
        then do:
            
            /* transaction by supplier outside EG */
            if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
            then ASSIGN tVatDeclarationNLExport.tdTurnOverOutsideEUImport    =  tVatDeclarationNLExport.tdTurnOverOutsideEUImport    + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC
                        tVatDeclarationNLExport.tdTurnOverVatOutsideEUImport =  tVatDeclarationNLExport.tdTurnOverVatOutsideEUImport + tqPostingVatByYearPeriod.tdPostingLineDebitLC    - tqPostingVatByYearPeriod.tdPostingLineCreditLC. 
            ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverOutsideEUImport    =  tVatDeclarationNLExport.tdTurnOverOutsideEUImport    + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  
                        tVatDeclarationNLExport.tdTurnOverVatOutsideEUImport =  tVatDeclarationNLExport.tdTurnOverVatOutsideEUImport + tqPostingVatByYearPeriod.tdPostingLineCreditLC    - tqPostingVatByYearPeriod.tdPostingLineDebitLC. 

        end. /* when {&VATTRANSACTIONTYPE-IMPORT} */

        when {&VATTRANSACTIONTYPE-ACQUISITION} 
        then do:    
            /* transaction by supplier between 2 countries inside EG */
            if tqPostingVatByYearPeriod.tcVatInOut = {&VATINOUT-INPUT}
            then ASSIGN tVatDeclarationNLExport.tdTurnOverInsideEUImport    =  tVatDeclarationNLExport.tdTurnOverInsideEUImport    + tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC - tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC
                        tVatDeclarationNLExport.tdTurnOverVatInsideEUImport =  tVatDeclarationNLExport.tdTurnOverVatInsideEUImport + tqPostingVatByYearPeriod.tdPostingLineDebitLC    - tqPostingVatByYearPeriod.tdPostingLineCreditLC. 
            ELSE ASSIGN tVatDeclarationNLExport.tdTurnOverInsideEUImport    =  tVatDeclarationNLExport.tdTurnOverInsideEUImport    + tqPostingVatByYearPeriod.tdPostingVatBaseCreditLC - tqPostingVatByYearPeriod.tdPostingVatBaseDebitLC  
                        tVatDeclarationNLExport.tdTurnOverVatInsideEUImport =  tVatDeclarationNLExport.tdTurnOverVatInsideEUImport + tqPostingVatByYearPeriod.tdPostingLineCreditLC    - tqPostingVatByYearPeriod.tdPostingLineDebitLC. 
        end. /* when {&VATTRANSACTIONTYPE-ACQUISITION} */
    end case.    
end.


<Q-20 run CountryPrim (first) (Read) (NoCache)
          (input ?, (CountryId)
           input 'BE':U, (CountryCode)
           output dataset tqCountryPrim) in BCountry >
find first tqCountryPrim no-error.
if AVAILABLE tqCountryPrim
then assign oiCountryID = tqCountryPrim.tiCountry_ID.  

/* Calculation */
assign tVatDeclarationNLExport.tdTurnOverDueVat                  =   tVatDeclarationNLExport.tdTurnOverVatHigh  
                                                                   + tVatDeclarationNLExport.tdTurnOverVatLow    
                                                                   + tVatDeclarationNLExport.tdTurnOverVatOther                                                                     
                                                                   + tVatDeclarationNLExport.tdTurnOverVatPrivate  
                                                                   + tVatDeclarationNLExport.tdTurnOverVatTransferred  
                                                                   + tVatDeclarationNLExport.tdTurnOverVatOutsideEUImport  
                                                                   + tVatDeclarationNLExport.tdTurnOverVatInsideEUImport 
       odTurnOverDueVat                                          = tVatDeclarationNLExport.tdTurnOverDueVat                 
       tVatDeclarationNLExport.tdPreVat                          = odPreVat
       tVatDeclarationNLExport.tdSmallEnterpriseAgreement        = odSmallEnterpriseAgreement    
       tVatDeclarationNLExport.tdEstimatePreviousDeclaration     = odEstimatePreviousDeclaration 
       tVatDeclarationNLExport.tdEstimateCurrentDeclaration      = odEstimateCurrentDeclaration  
       
       tVatDeclarationNLExport.tdTotalToPayReclaim               =   tVatDeclarationNLExport.tdTurnOverDueVat
                                                                   - odPreVat
                                                                   - odSmallEnterpriseAgreement   
                                                                   - odEstimatePreviousDeclaration
                                                                   + odEstimateCurrentDeclaration
       odTotalToPayReclaim                                       =  tVatDeclarationNLExport.tdTotalToPayReclaim.

*/


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 = "BVATExportListing".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiOmzetBelastingNL".
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/bvatexportlisting.apiomzetbelastingnl.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiDeclarationPeriodType = <parameter value>
       vhParameter::iiDeclarationYear = <parameter value>
       vhParameter::iiDeclarationPeriod = <parameter value>.

/* 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.