project QadFinancials > class BGLMask > method ApiStdMaintainTT


Parameters


tApiGLMaskinputtemp-table
icActioninputcharacter
ocLstPrimkeyoutputcharacter
ocLstReturnoutputcharacter
ocLstRowidoutputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bglmask.p)

/* =================================================== */
/* Method Info:                                        */
/* GLMask 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-2 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BGLMask>

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 vcGLMaskMsg    = trim(subst(#T-34'A GL mask integration error occurred. The specified action (&1) must be in the list '&2'.':255(2209)t-34#,trim(icAction),"{&DAEMONACTION-SAVESTORE},{&DAEMONACTION-SAVE},{&DAEMONACTION-STORE},{&DAEMONACTION-VALIDATE}":U))
           oiReturnStatus = -1.
    <M-3 run SetMessage (input  vcGLMaskMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-2691':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BGLMask>
           
    return.
end. /* if icAction */

/* ======================== */
/* Count main-table records */
/* ======================== */
for each tApiGLMask no-lock :
    assign viMainTableRecordCount = viMainTableRecordCount + 1.
end. /* for each */

if viMainTableRecordCount = 0
then do:
    assign vcGLMaskMsg       = trim(#T-35'A GL mask integration error occurred. The system could not find main table records (GL Mask).':255(2210)t-35#)
           oiReturnStatus    = -1.
    <M-4 run SetMessage (input  vcGLMaskMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-2692':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BGLMask>
    return.
end. /* if viMainTableRecordCount */

/* ================================================================= */
/* Start Queries                                                     */
/* ================================================================= */

<Q-9 run GLMaskPrim (Start) in BGLMask >
<Q-21 run DivisionPrim (Start) in BDivision >
<Q-24 run CostCentrePrim (Start) in BCostCentre >
<Q-26 run ProjectPrim (Start) in BProject >
<Q-28 run GLPrim (Start) in BGL >
 
/* ================================ */
/* Start loop on main-table records */
/* ================================ */
for each tApiGLMask by tApiGLMask.tc_Rowid: 

    MAIN-BLOCK:
    DO:

    /* ========== */
    /* Initialize */
    /* ========== */
    assign vcGLMaskMsg     = "":U
           vcRowID         = "":U
           vlWarningsFound = false
           vlSaveAsDraft   = icAction = {&DAEMONACTION-STORE}.
    
    
    /* =================================================== */
    /* Domain_id should be the same as the viDomainID */
    /* =================================================== */
    if tApiGLMask.Domain_ID <> viDomainId and
       tApiGLMask.Domain_ID <> ?           and
       tApiGLMask.Domain_ID <> 0           
    then do:
        assign vcGLMaskMsg   = trim(substitute(#T-36'Domain ID (&1) does not match the current entity.':200(31308)t-36#, trim(string(tApiGLMask.Domain_ID)) ))
               ocLstReturn   = ocLstReturn  + chr(4) + (if viFcReturnSuper = 0 then "-3":U else string(viFcReturnSuper))
               ocLstPrimKey  = ocLstPrimKey + chr(4) + "*":U
               ocLstRowid    = ocLstRowid   + chr(4) + "*":U 
               vlSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE}).

        <M-18 run SetMessage (input  vcGLMaskMsg (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  1 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-2697':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BGLMask>
        leave MAIN-BLOCK.
    end.

    if (tApiGLMask.Division_ID    = ?    or
        tApiGLMask.Division_ID    = 0)   and
        tApiGLMask.tcDivisionCode <> ?   and
        tApiGLMask.tcDivisionCode <> ""
    then do:
         <Q-55 run DivisionPrim (all) (Read) (NoCache)
            (input viCompanyId, (CompanyId)
             input ?, (DivisionID)
             input tApiGLMask.tcDivisionCode, (DivisionCode)
             output dataset tqDivisionPrim) in BDivision >        
         find first tqDivisionPrim where tqDivisionPrim.tcDivisionCode =  tApiGLMask.tcDivisionCode no-error.
         if available  tqDivisionPrim 
         then assign tApiGLMask.Division_ID = tqDivisionPrim.tiDivision_ID.
    end.

    if (tApiGLMask.CostCentre_ID    = ?   or
        tApiGLMask.CostCentre_ID    = 0)  and
        tApiGLMask.tcCostCentreCode <> ?  and
        tApiGLMask.tcCostCentreCode <> ""
    then do:
         <Q-56 run CostCentrePrim (all) (Read) (NoCache)
            (input tApiGLMask.Domain_ID, (CompanyId)
             input ?, (CostCentreID)
             input tApiGLMask.tcCostCentreCode, (CostCentreCode)
             output dataset tqCostCentrePrim) in BCostCentre >
         find first tqCostCentrePrim where tqCostCentrePrim.tcCostCentreCode = tApiGLMask.tcCostCentreCode no-error.
         if available  tqCostCentrePrim 
         then tApiGLMask.CostCentre_ID = tqCostCentrePrim.tiCostCentre_ID.
    end.

    if (tApiGLMask.Project_ID    = ?   or
        tApiGLMask.Project_ID    = 0)  and
        tApiGLMask.tcProjectCode <> ?  and
        tApiGLMask.tcProjectCode <> ""
    then do:
        <Q-57 run ProjectPrim (all) (Read) (NoCache)
           (input tApiGLMask.Domain_ID, (CompanyId)
            input ?, (ProjectID)
            input tApiGLMask.tcProjectCode, (ProjectCode)
            output dataset tqProjectPrim) in BProject >
        find first tqProjectPrim where tqProjectPrim.tcProjectCode = tApiGLMask.tcProjectCode no-error.
        if available  tqProjectPrim
        then tApiGLMask.Project_ID = tqProjectPrim.tiProject_ID.
    end.

    if (tApiGLMask.GL_ID    = ?   or
        tApiGLMask.GL_ID    = 0)  and
        tApiGLMask.tcGLCode <> ?  and
        tApiGLMask.tcGLCode <> ""
    then do:
        <Q-58 run GLPrim (all) (Read) (NoCache)
           (input tApiGLMask.Domain_ID, (CompanyId)
            input tApiGLMask.tcGLCode, (GLCode)
            input ?, (GLId)
            output dataset tqGLPrim) in BGL >
        find first tqGLPrim where tqGLPrim.tcGLCode = tApiGLMask.tcGLCode no-error.
        if available tqGLPrim 
        then tApiGLMask.GL_ID = tqGLPrim.tiGL_ID.
    end.

    /* ========================================== */
    /* Get the GLMask_ID based on the logical key */
    /* ========================================== */
    if tApiGLMask.GLMask_ID = ?  or
       tApiGLMask.GLMask_ID = 0
    then do:
        <Q-10 run GLMaskPrim (all) (Read) (NoCache)
           (input tApiGLMask.Domain_ID, (DomainId)
            input tApiGLMask.GL_ID, (GLID)
            input tApiGLMask.Division_ID, (DivisionID)
            input tApiGLMask.Project_ID, (ProjectID)
            input tApiGLMask.CostCentre_ID, (CostCentreID)
            input ?, (GLMaskID)
            output dataset tqGLMaskPrim) in BGLMask >
        find tqGLMaskPrim where 
             tqGLMaskPrim.tiDomain_ID     = tApiGLMask.Domain_ID         AND
             tqGLMaskPrim.tiGL_ID         = tApiGLMask.GL_ID             AND
             tqGLMaskPrim.tiDivision_ID   = tApiGLMask.Division_ID       AND
             tqGLMaskPrim.tiProject_ID    = tApiGLMask.Project_ID        AND
             tqGLMaskPrim.tiCostCentre_ID = tApiGLMask.CostCentre_ID
             no-lock no-error.
        if available tqGLMaskPrim
        then assign tApiGLMask.GLMask_ID = tqGLMaskPrim.tiGLMask_ID.
    end.

    /* ==================== */
    /* Load/Create GLMask  */
    /* ==================== */
    if tApiGLMask.GLMask_ID = ? or
       tApiGLMask.GLMask_ID = 0
    then assign viFcReturnSuper = -4.
    else do:  
        <M-11 run DataLoad
           (input  ? (icRowids), 
            input  string(tApiGLMask.GLMask_ID) (icPkeys), 
            input  ? (icObjectIds), 
            input  ? (icFreeform), 
            input  false (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BGLMask>       
    end.
    if viFcReturnSuper = -4
    then do:
        assign viFcReturnSuper = 0.
        <M-12 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BGLMask>                      
        if viFcReturnSuper < 0
        then assign vcGLMaskMsg = trim(subst(#T-37'Cannot create a new instance. Error number: &1.':255(308)t-37#, string(viFcReturnSuper))).
        find first tGLMask no-error.
    end.
    else do:
        if viFcReturnSuper < 0
        then assign vcGLMaskMsg = trim(subst(#T-38'Cannot load the instance (error number: &1, instance ID: &2).':255(289)t-38#, string(viFcReturnSuper), string(tApiGLMask.GLMask_ID))).
        else do:
            find tGLMask where
                 tGLMask.GLMask_ID = tApiGLMask.GLMask_ID
                 no-error.
            if not available tGLMask
            then assign vcGLMaskMsg = trim(subst(#T-39'Cannot find the instance after it has been loaded (instance ID: &1).':255(290)t-39#,
                                               string(tApiGLMask.GLMask_ID))).
            else assign tGLMask.tc_Status = "C":U.
        end.
    end.

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

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

    /* ====================== */
    /* Copy data for GLMask  */
    /* ====================== */          
    
    buffer-copy tApiGLMask
         except tApiGLMask.GLMask_ID
                tApiGLMask.tc_ParentRowid
                tApiGLMask.tc_Rowid
                tApiGLMask.tc_Status
             to tGLMask.

    assign vcRowid              = tGLMask.tc_Rowid
           tApiGLMask.GLMask_ID = tGLMask.GLMask_ID.

    /* =================================================== */
    /* 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 tGLMask where
			   		   tGLMask.tc_Status = "N":U or
                       tGLMask.tc_Status = "C":U)
	then assign vcActivityCode = "MaintainGLMasks":U.

    /* ================= */
    /* Validate the data */
    /* ================= */
    <M-13 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BGLMask>    
    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-14 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BGLMask>            
    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-15 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BGLMask>               
        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(tApiGLMask.GLMask_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 vcGLMaskMsg = trim(#T-48'Only one draft instance can be created per method call.':255(13878)T-48#) +
                                 chr(10) +
                                 trim(#T-49'This second object cannot be stored as a draft instance and so is an error.':255(13879)t-49#).
            <M-50 run SetMessage (input  vcGLMaskMsg (icMessage), 
                      input  '':U (icArguments), 
                      input  '':U (icFieldName), 
                      input  '':U (icFieldValue), 
                      input  'E':U (icType), 
                      input  1 (iiSeverity), 
                      input  '':U (icRowid), 
                      input  'QADFIN-3116':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BGLMask>
            next.
        end. /*if vlDraftInstanceCreated = true*/

        <M-16 run StoreState
           (input  '(':U + string(tGLMask.GLMask_ID) + ') ':U + trim(#T-40'The GL mask was created using an API method.':200(2212)t-40#) (icDescription), 
            input  ? (icUIClass), 
            output viFcReturnSuper (oiReturnStatus)) in BGLMask>
        assign vlDraftInstanceCreated = true
               entry(num-entries(ocLstReturn , chr(4)), ocLstReturn , chr(4)) = string(viFcReturnSuper)
               entry(num-entries(ocLstPrimKey, chr(4)), ocLstPrimKey, chr(4)) = string(tApiGLMask.GLMask_ID)
               entry(num-entries(ocLstRowid  , chr(4)), ocLstRowid  , chr(4)) = vcRowID.
    end. /*if vlSaveAsDraft and index*/  
end. /* for each tApiCode */

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

<Q-17 run GLMaskPrim (Stop) in BGLMask >
<Q-51 run DivisionPrim (Stop) in BDivision >
<Q-52 run CostCentrePrim (Stop) in BCostCentre >
<Q-53 run ProjectPrim (Stop) in BProject >
<Q-54 run GLPrim (Stop) in BGL >

/* ============================================================ */
/* 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 vcGLMaskMsg    = trim(#T-41'A GL mask integration error occurred. An API method returned incomplete information. See other messages for further details.':200(2213)t-41#) + chr(10) + 
                            trim(substitute(#T-42'Main table records: &1.':255(310)T-42#,string(viMainTableRecordCount))) + chr(10) + 
                            trim(substitute(#T-43'Return Statuses: &1.':255(311)T-43#,ocLstReturn))  + chr(10) +
                            trim(substitute(#T-44'Primary keys: &1.':255(312)T-44#,ocLstPrimKey)) + chr(10) +
                            trim(substitute(#T-45'Row IDs: &1.':255(313)T-45#,ocLstRowid)).
           oiReturnStatus = -3.
   
    <M-6 run SetMessage
       (input  vcGLMaskMsg (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  1 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QADFIN-2694':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BGLMask>    
    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 vcGLMaskMsg      = trim(#T-46'An error has occurred while running this API method. See other error messages for more details.':255(301)T-46#)
               oiReturnStatus   = -1.

        <M-7 run SetMessage
           (input  vcGLMaskMsg (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  1 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-2695':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BGLMask>         
    end. /* if index("-":U, ocLstReturn) <> 0 */
    else do : 
        assign vcGLMaskMsg     = trim(#T-47'A warning has occurred while running this API method. See other error messages for more details.':255(302)T-47#)
               oiReturnStatus   = +1.
        <M-8 run SetMessage
           (input  vcGLMaskMsg (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'W':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QADFIN-2696':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BGLMask>
    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 = "BGLMask".
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/bglmask.apistdmaintaintt.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icAction = <parameter value>.

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