project BLF > class RPCRequestService > method RunAPI


Parameters


izInputDSinputdataset-handle
bzInputOutputDSinput-outputdataset-handle
ozOutputDSoutputdataset-handle
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method RPCRequestService.Main


program code (program1/rpcrequestservice.p)

/* Check if the method that needs to be run exists */
if search("api/" + lc(vcComponentNameRPCRS) + "/" + lc(vcMethodNameRPCRS) + ".p") = ?
then do:
    create tErrors.

    assign tErrors.tcFcMessage   = trim(subst(#T-19'Invalid component (&1) or invalid method (&2).':255(688458247)T-19#, vcComponentNameRPCRS, vcMethodNameRPCRS))
           tErrors.tcFcMsgNumber = "BLF-RPCRS-API-1"
           tErrors.tiFcSeverity  = 3
           tErrors.tcFcType      = "E"
           tErrors.tcFcContext   = trim(#T-937'This message comes from program/RPCRequestService.p.':255(5142)T-937#)
           tErrors.tcFcRowid     = string(rowid(tErrors))
           oiReturnStatus        = -1.

    return.
end.

/* Check Session */
<M-96 run ValidateSession
   (output vlSessionStarted (olSessionStarted), 
    output viFcReturnSuper (oiReturnStatus)) in RPCRequestService>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* Get the signature of the method or query that needs to run */
run value("api/" + lc(vcComponentNameRPCRS) + "/apiinfo.p") (input vcMethodNameRPCRS, output vcSignature) no-error.

if error-status:error or
   error-status:num-messages > 0
then do:
    assign vcFcMaskList   = ""
           oiReturnStatus = -1.

    do viFcCount1 = 1 to error-status:num-messages:
        if viFcCount1 > 1
        then assign vcFcMaskList = vcFcMaskList + chr(2).

        assign vcFcMaskList = vcFcMaskList + error-status:get-message(viFcCount1).
    end.

    create tErrors.

    assign tErrors.tcFcMessage   = trim(subst(#T-34'An error occurred while trying to run &1.':255(912157827)T-34#, "api/" + lc(vcComponentNameRPCRS) + "/apiinfo.p"))
           tErrors.tcFcMsgNumber = "BLF-RPCRS-API-4"
           tErrors.tiFcSeverity  = 3
           tErrors.tcFcType      = "E"
           tErrors.tcFcContext   = trim(#T-78'This message comes from program/RPCRequestService.p.':255(5142)T-78#)
           tErrors.tcFcRowid     = string(rowid(tErrors)).

    if vcFcMaskList <> ""
    then do viFcCount1 = 1 to num-entries(vcFcMaskList, chr(2)):
        create tErrors.

        assign tErrors.tcFcMessage   = entry(viFcCount1, vcFcMaskList, chr(2))
               tErrors.tcFcMsgNumber = "BLF-RPCRS-API-5"
               tErrors.tiFcSeverity  = 3
               tErrors.tcFcType      = "E"
               tErrors.tcFcContext   = trim(#T-94'This message comes from program/RPCRequestService.p.':255(5142)T-94#)
               tErrors.tcFcRowid     = string(rowid(tErrors)).
    end.

    if vlSessionStarted
    then do:
        <I-10 {tFcStopInstance
             &CLASS                = "Session"
             &SESSIONID            = "viSession3ID"}>
    end.
    
    return.
end.

assign viNumParams = num-entries(vcSignature).

/* Create the call */
create call vhCall in widget-pool "non-persistent" no-error.

if error-status:error or
   error-status:num-messages > 0
then do:
    assign vcFcMaskList   = ""
           oiReturnStatus = -1.

    do viFcCount1 = 1 to error-status:num-messages:
        if viFcCount1 > 1
        then assign vcFcMaskList = vcFcMaskList + chr(2).

        assign vcFcMaskList = vcFcMaskList + error-status:get-message(viFcCount1).
    end.

    create tErrors.

    assign tErrors.tcFcMessage   = trim(subst(#T-41'An error occurred while trying to execute '&1'.':255(486722440)T-41#, "create call"))
           tErrors.tcFcMsgNumber = "BLF-RPCRS-API-6"
           tErrors.tiFcSeverity  = 3
           tErrors.tcFcType      = "E"
           tErrors.tcFcContext   = trim(#T-66'This message comes from program/RPCRequestService.p.':255(5142)T-66#)
           tErrors.tcFcRowid     = string(rowid(tErrors)).

    if vcFcMaskList <> ""
    then do viFcCount1 = 1 to num-entries(vcFcMaskList, chr(2)):
        create tErrors.

        assign tErrors.tcFcMessage   = entry(viFcCount1, vcFcMaskList, chr(2))
               tErrors.tcFcMsgNumber = "BLF-RPCRS-API-7"
               tErrors.tiFcSeverity  = 3
               tErrors.tcFcType      = "E"
               tErrors.tcFcContext   = trim(#T-81'This message comes from program/RPCRequestService.p.':255(5142)T-81#)
               tErrors.tcFcRowid     = string(rowid(tErrors)).
    end.

    if vlSessionStarted
    then do:
        <I-56 {tFcStopInstance
             &CLASS                = "Session"
             &SESSIONID            = "viSession3ID"}>
    end.
    
    return.
end.

assign vhCall:call-name      = "api/" + lc(vcComponentNameRPCRS) + "/" + lc(vcMethodNameRPCRS) + ".p"
       vhCall:num-parameters = viNumParams.

/* Set the parameters */
do viFcCount2 = 1 to viNumParams:
    assign vcParam  = entry(viFcCount2, vcSignature).
           vcIO     = entry(2, vcParam, "|").
           vcIOType = if vcIO = "i"
                      then "input"
                      else
                      if vcIO = "o"
                      then "output"
                      else "input-output".
           vcParam  = entry(1, vcParam, "|").

    /* Initialize output dataset if necessary */
    if vcIO                   = "o" and
       ozOutputDS:num-buffers = 0
    then do:
        assign file-info:file-name = "xml/" + lc(vcComponentNameRPCRS) + "." + lc(vcMethodNameRPCRS) + ".o.xsd".

        if file-info:full-pathname = ?
        then do:
            create tErrors.

            assign tErrors.tcFcMessage   = trim(subst(#T-73'Could not fine file &1.':255(935678656)T-73#, "xml/" + lc(vcComponentNameRPCRS) + "." + lc(vcMethodNameRPCRS) + ".o.xsd"))
                   tErrors.tcFcMsgNumber = "BLF-RPCRS-API-8"
                   tErrors.tiFcSeverity  = 3
                   tErrors.tcFcType      = "E"
                   tErrors.tcFcContext   = trim(#T-5'This message comes from program/RPCRequestService.p.':255(5142)T-5#)
                   tErrors.tcFcRowid     = string(rowid(tErrors))
                   oiReturnStatus        = -1.

            if vlSessionStarted
            then do:
                <I-875 {tFcStopInstance
                     &CLASS                = "Session"
                     &SESSIONID            = "viSession3ID"}>
            end.
            
            return.
        end.

        ozOutputDS:read-xmlschema("file", file-info:full-pathname, ?).
    end.

    /* Simple type parameters */
    if num-entries(vcParam, "(") = 1
    then do:
        /* The first 4 parameters are always the same */
        if viFcCount2 <= 4
        then do:
            assign vlReturn = if viFcCount2 = 4
                              then vhCall:set-parameter(viFcCount2, "integer", "input", viSession3ID)
                              else vhCall:set-parameter(viFcCount2, "character", "input", "").

            next.
        end.

        /* Check if the necessary tables are available in the datasets */
        if vcIO = "i" and
           not valid-handle(vhParameterI)
        then do:
            assign vhParameterI = izInputDS:get-buffer-handle("tParameterI").

            if not valid-handle(vhParameterI)
            then do:
                create tErrors.

                assign tErrors.tcFcMessage   = trim(subst(#T-24'The input dataset does not contain a table called &1.':255(72197544)T-24#, "tParameterI"))
                       tErrors.tcFcMsgNumber = "BLF-RPCRS-API-9"
                       tErrors.tiFcSeverity  = 3
                       tErrors.tcFcType      = "E"
                       tErrors.tcFcContext   = trim(#T-28'This message comes from program/RPCRequestService.p.':255(5142)T-28#)
                       tErrors.tcFcRowid     = string(rowid(tErrors))
                       oiReturnStatus        = -1.

                if vlSessionStarted
                then do:
                    <I-150 {tFcStopInstance
                         &CLASS                = "Session"
                         &SESSIONID            = "viSession3ID"}>
                end.
                
                return.
            end.

            assign vlFcOk = vhParameterI:find-first("", no-lock) no-error.

            if not vlFcOk
            then do:
                create tErrors.

                assign tErrors.tcFcMessage   = trim(subst(#T-91'The input dataset does not contain a record in table &1.':255(160755744)T-91#, "tParameterI"))
                       tErrors.tcFcMsgNumber = "BLF-RPCRS-API-10"
                       tErrors.tiFcSeverity  = 3
                       tErrors.tcFcType      = "E"
                       tErrors.tcFcContext   = trim(#T-49'This message comes from program/RPCRequestService.p.':255(5142)T-49#)
                       tErrors.tcFcRowid     = string(rowid(tErrors))
                       oiReturnStatus        = -1.

                if vlSessionStarted
                then do:
                    <I-14 {tFcStopInstance
                         &CLASS                = "Session"
                         &SESSIONID            = "viSession3ID"}>
                end.
                
                return.
            end.
        end.
        else
        if vcIO = "b" and
           not valid-handle(vhParameterIO)
        then do:
            assign vhParameterIO = bzInputOutputDS:get-buffer-handle("tParameterIO").

            if not valid-handle(vhParameterIO)
            then do:
                create tErrors.

                assign tErrors.tcFcMessage   = trim(subst(#T-7'The input-output dataset does not contain a table called &1.':255(537322367)T-7#, "tParameterIO"))
                       tErrors.tcFcMsgNumber = "BLF-RPCRS-API-11"
                       tErrors.tiFcSeverity  = 3
                       tErrors.tcFcType      = "E"
                       tErrors.tcFcContext   = trim(#T-47'This message comes from program/RPCRequestService.p.':255(5142)T-47#)
                       tErrors.tcFcRowid     = string(rowid(tErrors))
                       oiReturnStatus        = -1.

                if vlSessionStarted
                then do:
                    <I-26 {tFcStopInstance
                         &CLASS                = "Session"
                         &SESSIONID            = "viSession3ID"}>
                end.
                
                return.
            end.

            assign vlFcOk = vhParameterIO:find-first("", no-lock) no-error.

            if not vlFcOk
            then do:
                create tErrors.

                assign tErrors.tcFcMessage   = trim(subst(#T-38'The input-output dataset does not contain a record in table &1.':255(659509897)T-38#, "tParameterIO"))
                       tErrors.tcFcMsgNumber = "BLF-RPCRS-API-12"
                       tErrors.tiFcSeverity  = 3
                       tErrors.tcFcType      = "E"
                       tErrors.tcFcContext   = trim(#T-8'This message comes from program/RPCRequestService.p.':255(5142)T-8#)
                       tErrors.tcFcRowid     = string(rowid(tErrors))
                       oiReturnStatus        = -1.

                if vlSessionStarted
                then do:
                    <I-60 {tFcStopInstance
                         &CLASS                = "Session"
                         &SESSIONID            = "viSession3ID"}>
                end.
                
                return.
            end.
        end.
        else
        if vcIO = "o" and
           not valid-handle(vhParameterO)
        then do:
            assign vhParameterO = ozOutputDS:get-buffer-handle("tParameterO").

            if not valid-handle(vhParameterO)
            then do:
                create tErrors.

                assign tErrors.tcFcMessage   = trim(subst(#T-22'The output dataset does not contain a table called &1.':255(854359055)T-22#, "tParameterO"))
                       tErrors.tcFcMsgNumber = "BLF-RPCRS-API-13"
                       tErrors.tiFcSeverity  = 3
                       tErrors.tcFcType      = "E"
                       tErrors.tcFcContext   = trim(#T-51'This message comes from program/RPCRequestService.p.':255(5142)T-51#)
                       tErrors.tcFcRowid     = string(rowid(tErrors))
                       oiReturnStatus        = -1.

                if vlSessionStarted
                then do:
                    <I-1 {tFcStopInstance
                         &CLASS                = "Session"
                         &SESSIONID            = "viSession3ID"}>
                end.

                return.
            end.

            vhParameterO:buffer-create().
        end.

        /* Make sure our parameter is in the parameter table */
        assign vcDataType  = substr(vcParam, 2, 1, "CHARACTER")
               vhParBuffer = if vcIO = "i"
                             then vhParameterI
                             else
                             if vcIO = "b"
                             then vhParameterIO
                             else vhParameterO.

        assign vhField = vhParBuffer:buffer-field(vcParam) no-error.

        if not valid-handle(vhField) or
           error-status:error        or
           error-status:num-messages > 0
        then do:
            assign vcFcMaskList   = ""
                   oiReturnStatus = -1.
        
            do viFcCount1 = 1 to error-status:num-messages:
                if viFcCount1 > 1
                then assign vcFcMaskList = vcFcMaskList + chr(2).
        
                assign vcFcMaskList = vcFcMaskList + error-status:get-message(viFcCount1).
            end.
        
            create tErrors.
        
            assign tErrors.tcFcMessage   = trim(subst(#T-3'An error occurred while trying to locate field &1 in table &2.':255(519859057)T-3#, vcParam, vhParBuffer:buffer-name))
                   tErrors.tcFcMsgNumber = "BLF-RPCRS-API-14"
                   tErrors.tiFcSeverity  = 3
                   tErrors.tcFcType      = "E"
                   tErrors.tcFcContext   = trim(#T-158'This message comes from program/RPCRequestService.p.':255(5142)T-158#)
                   tErrors.tcFcRowid     = string(rowid(tErrors)).
        
            if vcFcMaskList <> ""
            then do viFcCount1 = 1 to num-entries(vcFcMaskList, chr(2)):
                create tErrors.
        
                assign tErrors.tcFcMessage   = entry(viFcCount1, vcFcMaskList, chr(2))
                       tErrors.tcFcMsgNumber = "BLF-RPCRS-API-15"
                       tErrors.tiFcSeverity  = 3
                       tErrors.tcFcType      = "E"
                       tErrors.tcFcContext   = trim(#T-833'This message comes from program/RPCRequestService.p.':255(5142)T-833#)
                       tErrors.tcFcRowid     = string(rowid(tErrors)).
            end.

            if vlSessionStarted
            then do:
                <I-206 {tFcStopInstance
                     &CLASS                = "Session"
                     &SESSIONID            = "viSession3ID"}>
            end.
            
            return.
        end.

        /* Set parameters on call object */
        case vcDataType:
            when "c"
            then assign vcParameter[viFcCount2] = vhField:buffer-value
                        vlReturn                = vhCall:set-parameter(viFcCount2, "character", vcIOType, vcParameter[viFcCount2]).

            when "i"
            then assign viParameter[viFcCount2] = vhField:buffer-value
                        vlReturn                = vhCall:set-parameter(viFcCount2, "integer", vcIOType, viParameter[viFcCount2]).

            when "d"
            then assign vdParameter[viFcCount2] = vhField:buffer-value
                        vlReturn                = vhCall:set-parameter(viFcCount2, "decimal", vcIOType, vdParameter[viFcCount2]).

            when "l"
            then assign vlParameter[viFcCount2] = vhField:buffer-value
                        vlReturn                = vhCall:set-parameter(viFcCount2, "logical", vcIOType, vlParameter[viFcCount2]).

            when "t"
            then assign vtParameter[viFcCount2] = vhField:buffer-value
                        vlReturn                = vhCall:set-parameter(viFcCount2, "date", vcIOType, vtParameter[viFcCount2]).

            when "g"
            then assign vgParameter[viFcCount2] = vhField:buffer-value
                        vlReturn                = vhCall:set-parameter(viFcCount2, "int64", vcIOType, vgParameter[viFcCount2]).

            when "m"
            then do:
                copy-lob vhField:buffer-value to vmParameter[viFcCount2].
                vlmParameterUsed[viFcCount2] = yes.
                assign vlReturn = vhCall:set-parameter(viFcCount2, "memptr", vcIOType, vmParameter[viFcCount2]).
            end.

            when "p"
            then assign vpParameter[viFcCount2] = vhField:buffer-value
                        vlReturn                = vhCall:set-parameter(viFcCount2, "longchar", vcIOType, vpParameter[viFcCount2]).

            when "h"
            then assign vhParameter[viFcCount2] = ?
                        vlReturn                = vhCall:set-parameter(viFcCount2, "handle", vcIOType, vhParameter[viFcCount2]).
        end case.
    end.
    /* Dataset parameters */
    else do:
        /* Build the dataset */
        create dataset vhDataset in widget-pool "non-persistent".

        assign vhDataset:name = entry(1, vcParam, "(")
               vcTables       = entry(1, entry(2, vcParam, "("), ")")
               vhParDS        = if vcIO = "i"
                                then izInputDS
                                else
                                if vcIO = "b"
                                then bzInputOutputDS
                                else ozOutputDS.

        /* Make sure all tables can be found and add them to the dataset */
        do viFcCount3 = 1 to num-entries(vcTables, "^"):
            assign vcTable = entry(viFcCount3, vcTables, "^").
            create temp-table vhTable in widget-pool "non-persistent".

            if vcTable = "tFcMessages"
            then vhTable:create-like(buffer tErrors:handle).
            else do:
                assign vhBuffer = vhParDS:get-buffer-handle(vcTable) no-error.

                if not valid-handle(vhBuffer) or
                   error-status:error         or
                   error-status:num-messages > 0
                then do:
                    assign vcFcMaskList   = ""
                           oiReturnStatus = -1.
                
                    do viFcCount1 = 1 to error-status:num-messages:
                        if viFcCount1 > 1
                        then assign vcFcMaskList = vcFcMaskList + chr(2).
                
                        assign vcFcMaskList = vcFcMaskList + error-status:get-message(viFcCount1).
                    end.
                
                    create tErrors.
                
                    assign tErrors.tcFcMessage   = trim(subst(#T-48'Could not find table &1 in dataset &2.':255(529869278)T-48#, vcTable, vhParDS:name))
                           tErrors.tcFcMsgNumber = "BLF-RPCRS-API-16"
                           tErrors.tiFcSeverity  = 3
                           tErrors.tcFcType      = "E"
                           tErrors.tcFcContext   = trim(#T-16'This message comes from program/RPCRequestService.p.':255(5142)T-16#)
                           tErrors.tcFcRowid     = string(rowid(tErrors)).
                
                    if vcFcMaskList <> ""
                    then do viFcCount1 = 1 to num-entries(vcFcMaskList, chr(2)):
                        create tErrors.
                
                        assign tErrors.tcFcMessage   = entry(viFcCount1, vcFcMaskList, chr(2))
                               tErrors.tcFcMsgNumber = "BLF-RPCRS-API-17"
                               tErrors.tiFcSeverity  = 3
                               tErrors.tcFcType      = "E"
                               tErrors.tcFcContext   = trim(#T-39'This message comes from program/RPCRequestService.p.':255(5142)T-39#)
                               tErrors.tcFcRowid     = string(rowid(tErrors)).
                    end.
                
                    if vlSessionStarted
                    then do:
                        <I-61 {tFcStopInstance
                             &CLASS                = "Session"
                             &SESSIONID            = "viSession3ID"}>
                    end.
                    
                    return.
                end.

                vhTable:create-like(vhBuffer).
            end.

            vhTable:temp-table-prepare(vcTable).

            if vcIO    <> "o" and
               vcTable <> "tFcMessages"
            then vhTable:copy-temp-table(vhBuffer:table-handle).

            vhDataset:add-buffer(vhTable:default-buffer-handle).
        end.

        /* Set dataset on call object */
        assign vhParameter[viFcCount2] = vhDataset
               vlReturn                = vhCall:set-parameter(viFcCount2, "dataset-handle", vcIOType, vhParameter[viFcCount2]).
    end.
end.

/* Invoke the call */
vhCall:invoke() no-error.

if error-status:error         or
   error-status:num-messages > 0
then do:
    assign vcFcMaskList   = ""
           oiReturnStatus = -1.

    do viFcCount1 = 1 to error-status:num-messages:
        if viFcCount1 > 1
        then assign vcFcMaskList = vcFcMaskList + chr(2).

        assign vcFcMaskList = vcFcMaskList + error-status:get-message(viFcCount1).
    end.

    create tErrors.

    assign tErrors.tcFcMessage   = trim(subst(#T-90'An error occurred while trying to run &1.':255(912157827)T-90#, "api/" + lc(vcComponentNameRPCRS) + "/" + lc(vcMethodNameRPCRS) + ".p"))
           tErrors.tcFcMsgNumber = "BLF-RPCRS-API-18"
           tErrors.tiFcSeverity  = 3
           tErrors.tcFcType      = "E"
           tErrors.tcFcContext   = trim(#T-21'This message comes from program/RPCRequestService.p.':255(5142)T-21#)
           tErrors.tcFcRowid     = string(rowid(tErrors)).

    if vcFcMaskList <> ""
    then do viFcCount1 = 1 to num-entries(vcFcMaskList, chr(2)):
        create tErrors.

        assign tErrors.tcFcMessage   = entry(viFcCount1, vcFcMaskList, chr(2))
               tErrors.tcFcMsgNumber = "BLF-RPCRS-API-19"
               tErrors.tiFcSeverity  = 3
               tErrors.tcFcType      = "E"
               tErrors.tcFcContext   = trim(#T-89'This message comes from program/RPCRequestService.p.':255(5142)T-89#)
               tErrors.tcFcRowid     = string(rowid(tErrors)).
    end.

    if vlSessionStarted
    then do:
        <I-30 {tFcStopInstance
             &CLASS                = "Session"
             &SESSIONID            = "viSession3ID"}>
    end.
    
    return.
end.

/* Handle output parameters */
do viFcCount2 = 1 to viNumParams:
    assign vcParam = entry(viFcCount2, vcSignature)
           vcIO    = entry(2, vcParam, "|").

    if vcIO = "i"
    then next.

    assign vcParam = entry(1, vcParam, "|").

    /* Simple type parameters */
    if num-entries(vcParam, "(") = 1
    then do:
        assign vcDataType  = substr(vcParam, 2, 1, "CHARACTER")
               vhParBuffer = if vcIO = "b"
                             then vhParameterIO
                             else vhParameterO
               vhField     = vhParBuffer:buffer-field(vcParam).

        case vcDataType:
            when "c"
            then assign vhField:buffer-value = vcParameter[viFcCount2].

            when "i"
            then do:
                assign vhField:buffer-value = viParameter[viFcCount2].

                if vcParam = "oiReturnStatus"
                then assign oiReturnStatus = viParameter[viFcCount2].
            end.

            when "d"
            then assign vhField:buffer-value = vdParameter[viFcCount2].

            when "l"
            then assign vhField:buffer-value = vlParameter[viFcCount2].

            when "t"
            then assign vhField:buffer-value = vtParameter[viFcCount2].

            when "g"
            then assign vhField:buffer-value = vgParameter[viFcCount2].

            when "m"
            then copy-lob vmParameter[viFcCount2] to vhField:buffer-value.

            when "p"
            then assign vhField:buffer-value = vpParameter[viFcCount2].
        end case.
    end.
    /* Dataset parameters */
    else do:
        assign vcTables = entry(1, entry(2, vcParam, "("), ")")
               vhParDS  = if vcIO = "b"
                          then bzInputOutputDS
                          else ozOutputDS.

        do viFcCount3 = 1 to num-entries(vcTables, "^"):
            assign vcTable = entry(viFcCount3, vcTables, "^").

            if vcTable = "tFcMessages"
            then temp-table tErrors:copy-temp-table(vhParameter[viFcCount2]:get-buffer-handle("tFcMessages"):table-handle).
            else do:
                vhParDS:get-buffer-handle(vcTable):empty-temp-table().
                vhParDS:get-buffer-handle(vcTable):table-handle:copy-temp-table(vhParameter[viFcCount2]:get-buffer-handle(vcTable):table-handle).
            end.
        end.
    end.
end.

/* Clean up */
if valid-handle(vhDataset)
then delete object vhDataset.

if valid-handle(vhTable)
then delete object vhTable.

delete object vhCall.

if vlShutdownSessionRPCRS
then do:
    /* BLF-4122
     * do not report any errors from shutting down the session
     * as the request itself has been processed successfully at this time
     */
    if vcSessionIdRPCRS <> '' and
       vcSessionIdRPCRS <> ?
    then do:
        vlogout = yes.
        <I-4 {tFcOpenInstance
             &CLASS                = "Session"
             &ERROR-STATEMENT      = "vlogout = no. oiReturnStatus = 0."
             &SESSIONID            = "0"}>
        if vlogout
        then do:
            <M-36 run Logout  (output viFcReturnSuper (oiReturnStatus)) in Session>
        end.
        <I-40 {tFcCloseAndStopInstance
             &CLASS           = "Session"
             &ERROR-STATEMENT = "vlogout = no. oiReturnStatus = 0."}>
    end.
    else do:
        <I-55 {tFcStopInstance
             &CLASS                = "Session"
             &ERROR-STATEMENT      = "vlogout = no. oiReturnStatus = 0."
             &SESSIONID            = "0"}>
    end.

    assign vhSessionContext = vhSessionContextDS:get-buffer-handle(1) no-error.

    if vhSessionContext <> ?
    then do:
        create query vhSQuery in widget-pool "non-persistent".
        vhSQuery:forward-only = yes.
        vhSQuery:set-buffers(vhSessionContext).

        vlFcOk = vhSQuery:query-prepare ("for each " + vhSessionContext:name +
                                           " where " + vhSessionContext:name + ".propertyName = 'BLFSessionId'").

        if vlFcOk
        then vlFcOk = vhSQuery:query-open().

        if vlFcOk
        then do:
            vhSQuery:get-first().

            if not vhSQuery:query-off-end
            then vhSessionContext:buffer-delete().
        end.

        vhSQuery:query-close().
        delete object vhSQuery.
    end.
end.
else
if vlSessionStarted
then do:
    assign vhSessionContext = vhSessionContextDS:get-buffer-handle(1) no-error.

    if vhSessionContext <> ?
    then do:
        create query vhSQuery in widget-pool "non-persistent".
        vhSQuery:forward-only = yes.
        vhSQuery:set-buffers(vhSessionContext).

        vlFcOk = vhSQuery:query-prepare ("for each " + vhSessionContext:name +
                                           " where " + vhSessionContext:name + ".propertyName = 'BLFSessionId'").

        if vlFcOk
        then vlFcOk = vhSQuery:query-open().

        if vlFcOk
        then do:
            vhSQuery:get-first().

            if vhSQuery:query-off-end
            then vhSessionContext:buffer-create().

            assign vhSessionContext::propertyQualifier = "QAD"
                   vhSessionContext::propertyName      = "BLFSessionId"
                   vhSessionContext::propertyValue     = string(viSession3ID).

            vhSessionContext:buffer-release().
        end.

        vhSQuery:query-close().
        delete object vhSQuery.
    end.
end.

if oiReturnStatus = 0 and
   can-find(first tErrors)
then assign oiReturnStatus = if can-find(first tErrors where
                                               tErrors.tcFcType <> "W")
                             then -1
                             else 1.

finally:
    do viFcCount2 = 1 to viNumParams:
        if vlmParameterUsed[viFcCount2]
        then set-size (vmParameter[viFcCount2]) = 0.
    end.
end finally.