project QadFinancials > class BPosting > method ApiGetSafStructuresForPosting
Description
Retrieves the saf structures for a posting line based on the gl code
Parameters
iiCompanyID | input | integer | |
icGLCode | input | character | |
icCostCenterCode | input | character | |
icProjectCode | input | character | |
tApiSafStructuresForPosting | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bposting.p)
/* Exception handling */
assign oiReturnStatus = -98.
/* Empty the result table - output of this method */
empty temp-table tApiSafStructuresForPosting.
/* Normalize input paramters */
if iiCompanyID = ? or
iiCompanyID = 0
then assign iiCompanyID = viCompanyId.
/* Retrieve GL information */
<Q-7 run GLForPostingLineCreation (all) (Read) (Cache)
(input iiCompanyID, (CompanyID)
input icGLCode, (GLCode)
input ?, (GLId)
output dataset tqGLForPostingLineCreation) in BGL >
find first tqGLForPostingLineCreation no-error.
if not available tqGLForPostingLineCreation
then do:
<Q-64 run CompanyPrim (all) (Read) (NoCache)
(input iiCompanyID, (LookupCompanyId)
input ?, (CompanyCode)
output dataset tqCompanyPrim) in BCompany >
find first tqCompanyPrim no-error.
if available tqCompanyPrim then
assign vcTempCompanyCode = tqCompanyPrim.tcCompanyCode.
if available tPosting and
available tPostingLine
then do:
assign vcMsgExplanation = <M-21 GetErrorExplanation
(input tPosting.tc_Rowid (icPostingRowId),
input tPostingLine.tc_Rowid (icPostingLineRowId),
output viFcReturnSuper (oiReturnStatus)) in BPosting>.
end.
else
assign vcMsgExplanation = ''.
assign vcMessage = trim(substitute(#T-6'The GL account &1 cannot be found (Entity &2).':150(105376771)T-6#, icGLCode,vcTempCompanyCode))
oiReturnStatus = -3.
<M-2 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-5846':U (icFcMsgNumber),
input vcMsgExplanation (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
return.
end. /* if not available tqGLForPostingLineCreation */
/* Safs for costcentres */
if tqGLForPostingLineCreation.tlGLIsCostCentreAccount = true and
icCostCenterCode <> ? and
icCostCenterCode <> "":U
then do:
<M-3 run GetSafStructureForCostCentre
(input iiCompanyID (iiCompanyId),
input tqGLForPostingLineCreation.tiGL_ID (iiGLId),
input tqGLForPostingLineCreation.tcGLCode (icGLCode),
input ? (iiCostCentreId),
input icCostCenterCode (icCostCentreCode),
output viSafStructureID (oiSafStructureId),
output vcSafStructureCode (ocSafStructureCode),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
if viSafStructureId <> ? and
viSafStructureId <> 0 and
vcSafStructureCode <> ? and
vcSafStructureCode <> "":U
then do:
create tApiSafStructuresForPosting.
assign tApiSafStructuresForPosting.tiPostingSafStructureId = viSafStructureId
tApiSafStructuresForPosting.tcPostingSafStructureCode = vcSafStructureCode
tApiSafStructuresForPosting.tcPostingSafParentType = {&POSTINGSAFPARENTTYPE-COSTCENTRE}.
end. /* if viSafStructureId <> ? and */
end. /* if tqGLForPostingLineCreation.tlGLIsCostCentreAccount ... */
/* Safs for projects */
if tqGLForPostingLineCreation.tlGLIsProjectAccount = true and
icProjectCode <> ? and
icProjectCode <> "":U and
(tqGLForPostingLineCreation.tcGLAnalysisLimitation <> {&GLANALYSISLIMITATION-EXCLEACHOTHER} or
icCostCenterCode = ? or
icCostCenterCode = "":U)
then do:
<M-4 run GetSafStructureForProject
(input iiCompanyId (iiCompanyId),
input tqGLForPostingLineCreation.tiGL_ID (iiGLId),
input tqGLForPostingLineCreation.tcGLCode (icGLCode),
input ? (iiProjectId),
input icProjectCode (icProjectCode),
output viSafStructureId (oiSafStructureId),
output vcSafStructureCode (ocSafStructureCode),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
if viSafStructureId <> ? and
viSafStructureId <> 0 and
vcSafStructureCode <> ? and
vcSafStructureCode <> "":U
then do:
create tApiSafStructuresForPosting.
assign tApiSafStructuresForPosting.tiPostingSafStructureId = viSafStructureId
tApiSafStructuresForPosting.tcPostingSafStructureCode = vcSafStructureCode
tApiSafStructuresForPosting.tcPostingSafParentType = {&POSTINGSAFPARENTTYPE-PROJECT}.
end. /* if viSafStructureId <> ? and */
end. /* if (tqGLForPostingLineCreation.tcGLAnalysisLimitation <> {&GLANALYSISLIMITATION-EXCLEACHOTHER} ... */
/* Safs for GL itself */
if tqGLForPostingLineCreation.tlGLIsSafAccount
then do:
<Q-5 run GetSafStructureLinkForGL (all) (Read) (Cache)
(input tqGLForPostingLineCreation.tiGL_ID, (GL_ID)
output dataset tqSafStructureLinkForGL) in BSafStructureLink >
find first tqSafStructureLinkForGL no-error.
if available tqSafStructureLinkForGL
then do:
create tApiSafStructuresForPosting.
assign tApiSafStructuresForPosting.tiPostingSafStructureId = tqSafStructureLinkForGL.tiSafStructure_ID
tApiSafStructuresForPosting.tcPostingSafStructureCode = tqSafStructureLinkForGL.tcSafStructureCode.
tApiSafStructuresForPosting.tcPostingSafParentType = {&POSTINGSAFPARENTTYPE-GL}.
end. /* if available tqSafStructureLinkForGL */
end. /* if tqGLForPostingLineCreation.tlGLIsSafAccount */
/* Exception handling */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.
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 = "BPosting".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiGetSafStructuresForPosting".
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/bposting.apigetsafstructuresforposting.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiCompanyID = <parameter value>
vhParameter::icGLCode = <parameter value>
vhParameter::icCostCenterCode = <parameter value>
vhParameter::icProjectCode = <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.