project QadFinancials > class BBudget > method ApiGetBudgetWBSSafInfo

Description

This method will return the saf-information for a WBS-node of type SAF that is located on the lowest leaf of the WBS-tree


Parameters


iiBudgetWBSIDinputintegerBudgetWBSID
oiBudgetIDoutputintegerBudget ID
ocBudgetCodeoutputcharacterBudgetCode
oiProjectIDoutputintegerProject ID
ocProjectCodeoutputcharacterProject Code
oiCostCentreIDoutputintegerCostCentreId
ocCostCentreCodeoutputcharacterCost Center Code
oiSafStructureIDoutputintegerSafStructureID
ocSafStructureCodeoutputcharacterSafStructureCode
oiSafConcept1IDoutputintegerSafConcept1ID
ocSafConcept1CodeoutputcharacterSafConcept1Code
oiSaf1IDoutputintegerSaf1ID
ocSaf1CodeoutputcharacterSaf1Code
oiSafConcept2IDoutputintegerSafContept2ID
ocSafConcept2CodeoutputcharacterSafContept2Code
oiSaf2IDoutputintegerSaf2ID
ocSaf2CodeoutputcharacterSaf2Code
oiSafConcept3IDoutputintegerSafConcept3ID
ocSafConcept3CodeoutputcharacterSafConcept3Code
oiSaf3IDoutputintegerSaf3ID
ocSaf3CodeoutputcharacterSaf3Code
oiSafConcept4IDoutputintegerSafConcept4ID
ocSafConcept4CodeoutputcharacterSafConcept4Code
oiSaf4IDoutputintegerSaf4ID
ocSaf4CodeoutputcharacterSaf4Code
oiSafConcept5IDoutputintegerSaf5ConceptID
ocSafConcept5CodeoutputcharacterSaf5ConceptCode
oiSaf5IDoutputintegerSaf5ID
ocSaf5CodeoutputcharacterSaf5Code
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program9/bbudget.p)

/* =============================================== */
    /* Validate input parameters                       */
    /* The WBS should exist and be on the lowest level */
    /* The WBS should be of type SAF                   */
    /* =============================================== */
    if iiBudgetWBSID = 0 or iiBudgetWBSID = ?
    then do :
        assign oiReturnStatus = -3
               vcMessage      = trim(#T-15'You must enter the budget WBS identification (ID) to retrieve the SAF information.':255(548)T-15#).
        <M-1 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-1301':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
        Return.
    end. /* if iiBudgetWBSID = 0 or iiBudgetWBSID = ? */
    <Q-6 assign vlFcQueryRecordsAvailable = BudgetWBSByBudgetIDWBSCode (NoCache)
          (input ?, (BudgetID)
           input ?, (BudgetWBSID)
           input ?, (BudgetWBSCode)
           input iiBudgetWBSID, (ParentBudgetWBSID)
           input ?, (BudgetCode)
           input ?, (BudgetStatus)) in BBudget >
    if vlFcQueryRecordsAvailable <> false
    then do :
        assign oiReturnStatus = -3
               vcMessage      = trim(#T-16'The budget WBS has child nodes: the system cannot return SAF information.':255(549)T-16#) + chr(10) + 
                                trim(substitute(#T-17'Budget WBS ID: &1.':255(550)T-17#,string(iiBudgetWBSID))).
        <M-7 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-1303':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
        Return.
    end. /* vlFcQueryRecordsAvailable <> false */
    <Q-4 run BudgetWBSByBudgetIDWBSCode (all) (Read) (NoCache)
          (input ?, (BudgetID)
           input iiBudgetWBSID, (BudgetWBSID)
           input ?, (BudgetWBSCode)
           input ?, (ParentBudgetWBSID)
           input ?, (BudgetCode)
           input ?, (BudgetStatus)
           output dataset tqBudgetWBSByBudgetID) in BBudget >
    find first tqBudgetWBSByBudgetID where 
               tqBudgetWBSByBudgetID.tiBudgetWBS_ID = iiBudgetWBSID
               no-lock no-error.
    if not available tqBudgetWBSByBudgetID
    then do :
        assign oiReturnStatus = -3
               vcMessage      = trim(#T-18'SAF information cannot be retrieved based on this WBS ID.':255(551)T-18#) + chr(10) + 
                                trim(substitute(#T-19'Budget WBS ID: &1.':255(550)T-19#,string(iiBudgetWBSID))).
        <M-5 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-1302':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
        Return.
    end. /* if not available tqBudgetWBSByBudgetID */
    if tqBudgetWBSByBudgetID.tcBudgetFDSType <> {&BUDGETFDSTYPE-SAF}
    then do :
        assign oiReturnStatus = -3
               vcMessage      = trim(substitute(#T-20'SAF information can only be returned for WBS nodes of type &1.':255(552)T-20#,{&BUDGETFDSTYPE-SAF-TR})) + chr(10) + 
                                trim(substitute(#T-21'Budget WBS code: &1.':255(553)T-21#,tqBudgetWBSByBudgetID.tcBudgetWBSCode)) + chr(10) + 
                                trim(substitute(#T-22'Budget WBS ID: &1.':255(550)T-22#,string(iiBudgetWBSID))).
        <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-1304':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
        Return.
    end. /* if tqBudgetWBSByBudgetID.tcBudgetFDSType <> {&BUDGETFDSTYPE-SAF} */
    
    /* ================================================ */
    /* Assign the output info regarding the budget-data */
    /* ================================================ */
    assign oiBudgetID   = tqBudgetWBSByBudgetID.tiBudget_ID
           ocBudgetCode = tqBudgetWBSByBudgetID.tcBudgetCode.
    <Q-14 run BudgetByBudgetIDCodeStatus (all) (Read) (NoCache)
          (input oiBudgetID, (BudgetID)
           input ?, (BudgetCode)
           input ?, (BudgetStatus)
           input ?, (CompanyId)
           input ?, (ProjectCode)
           input ?, (CostCentreCode)
           input ?, (BudgetIsCheckActualOnLine)
           input ?, (BudgetIsCheckCommitOnLine)
           input ?, (BudgetIsAutoRollUp)
           input ?, (ProjectID)
           input ?, (CostCentreID)
           input ?, (BudgetType)
           output dataset tqBudgetByBudgetIDCodeStatus) in BBudget >
    find first tqBudgetByBudgetIDCodeStatus
               no-lock no-error.
    if available tqBudgetByBudgetIDCodeStatus
    then assign ocProjectCode    = tqBudgetByBudgetIDCodeStatus.tcProjectCode
                oiProjectID      = tqBudgetByBudgetIDCodeStatus.tiProject_ID
                ocCostCentreCode = tqBudgetByBudgetIDCodeStatus.tcCostCentreCode
                oiCostCentreID   = tqBudgetByBudgetIDCodeStatus.tiCostCentre_ID.
    
    /* =============================== */
    /* Check the SAF-depth of the node */
    /* =============================== */
    <Q-9 run BudgetFDSByBudgetIDType (all) (Read) (NoCache)
          (input tqBudgetWBSByBudgetID.tiBudget_ID, (BudgetID)
           input {&BUDGETFDSTYPE-SAF}, (BudgetFDSType)
           input ?, (BudgetFDSID)
           output dataset tqBudgetFDSByBudgetIDType) in BBudget >
    for each tqBudgetFDSByBudgetIDType where
             tqBudgetFDSByBudgetIDType.tiBudget_ID      = tqBudgetWBSByBudgetID.tiBudget_ID and
             tqBudgetFDSByBudgetIDType.tcBudgetFDSType  = {&BUDGETFDSTYPE-SAF}              and 
             tqBudgetFDSByBudgetIDType.tiBudgetFDSSeq  <= tqBudgetWBSByBudgetID.tiBudgetFDSSeq :
        assign viSafDepth = viSafDepth + 1.
    end. /* for each tqBudgetFDSByBudgetIDType */
    
    /* ================================================================================= */
    /* Call repetively a sub-method that returns the saf-data and the higher SAF-parent. */
    /* When viNewSafBudgetWBSID = ? then this means there is no SAF-parent anymore, this */
    /* should only happen in case viSafCounter = 1                                       */
    /* ================================================================================= */
    assign viNewSafBudgetWBSID = tqBudgetWBSByBudgetID.tiBudgetWBS_ID.
    <Q-11 run SafByIdCodeConceptID  (Start) in BSaf > /* Start query used by the sub-method */
    do viSafCounter = viSafDepth to 1 by -1 :
        <M-10 run ApiGetBudgetWBSSafInfoDetails
          (input  viNewSafBudgetWBSID (iiBudgetWBSID), 
           output viSafConceptID (oiSafConceptID), 
           output vcSafConceptCode (ocSafConceptCode), 
           output viSafID (oiSafID), 
           output vcSafCode (ocSafCode), 
           output oiSafStructureID (oiSafStructureID), 
           output ocSafStructureCode (ocSafStructureCode), 
           output viNewSafBudgetWBSID (oiNewSafBudgetWBSID), 
           output viFcReturnSuper (oiReturnStatus)) in BBudget>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0 then leave.
        case viSafCounter :
        when 1 then assign oiSafConcept1ID   = viSafConceptID
                           ocSafConcept1Code = vcSafConceptCode
                           oiSaf1ID          = viSafID
                           ocSaf1Code        = vcSafCode.
        when 2 then assign oiSafConcept2ID   = viSafConceptID
                           ocSafConcept2Code = vcSafConceptCode
                           oiSaf2ID          = viSafID
                           ocSaf2Code        = vcSafCode.
        when 3 then assign oiSafConcept3ID   = viSafConceptID
                           ocSafConcept3Code = vcSafConceptCode
                           oiSaf3ID          = viSafID
                           ocSaf3Code        = vcSafCode.
        when 4 then assign oiSafConcept4ID   = viSafConceptID
                           ocSafConcept4Code = vcSafConceptCode
                           oiSaf4ID          = viSafID
                           ocSaf4Code        = vcSafCode.
        when 5 then assign oiSafConcept5ID   = viSafConceptID
                           ocSafConcept5Code = vcSafConceptCode
                           oiSaf5ID          = viSafID
                           ocSaf5Code        = vcSafCode.
        end case.
        if viSafCounter > 1 and 
           (viNewSafBudgetWBSID = ? or 
            viNewSafBudgetWBSID = 0)
        then do :
            assign oiReturnStatus = -3
                   vcMessage      = trim(#T-23'Internal error: invalid SAF tree detected for WBS node.':255(554)T-23#) + chr(10) + 
                                    trim(substitute(#T-24'Budget WBS ID: &1.':255(550)T-24#,string(iiBudgetWBSID))) + chr(10) + 
                                    trim(substitute(#T-25'Expected SAF depth: &1.':255(555)T-25#,string(viSafDepth))) + chr(10) + 
                                    trim(substitute(#T-26'Current SAF depth: &1.':255(556)T-26#,string(viSafCounter))).
            <M-13 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-1307':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
            Return.
        end. /* if viSafDepth > 1 and  */
    end. /* do viSafCounter = viSafDepth to 1 by -1 */
    <Q-12 run SafByIdCodeConceptID  (Stop) in BSaf > /* Stop query used by the sub-method */
    if oiReturnStatus < 0 then Return.


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 = "BBudget".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetBudgetWBSSafInfo".
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/bbudget.apigetbudgetwbssafinfo.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiBudgetWBSID = <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.