API query
Description
Select Query Extended (contains also Dimension details )
Parameters
Internal usage
unused
program code (program1/bfrwanalysiscode.p)
/* Check, if the user enters any filter for Analysis Dimension */
assign vcFilterCOADimension = ?.
find tFilter where
tFilter.tcBusinessFieldName = "tFRWAnCodeElem.FRWAnCodeElemCOAType"
no-error.
if available tFilter
then do:
assign vcFilterCOADimension = tFilter.tcParameterValue.
/* ensure filter parameter string is starting with * */
if vcFilterCOADimension = ? or
vcFilterCOADimension = "":U or
substring(vcFilterCOADimension, 1, 1, "CHARACTER") <> "*":U
then assign vcFilterCOADimension = "*":U + vcFilterCOADimension.
/* ensure filter parameter string is ending with * also */
if substring(vcFilterCOADimension, length(vcFilterCOADimension, "CHARACTER"), 1, "CHARACTER") <> "*":U
then assign vcFilterCOADimension = vcFilterCOADimension + "*":U.
if vcFilterCOADimension = "*"
then assign vcFilterCOADimension = ?.
delete tFilter.
end.
/* Run the main query to get the data from the database */
<Q-82 run api/bfrwanalysiscode/selectfrwancode.p
(input ? (icApiLogin),
input ? (icApiPassword),
input ? (icApiExtra),
input viSessionID (iiApiSessionId),
input 'A':U (icRange),
input ? (icRowid),
input 0 (iiRowNum),
input 0 (iiNumber),
input '':U (icSortColumns),
input false (ilCountOnly),
input true (ilForwardRead),
input 50000 (iiMaximumBrowseRecordsToCount),
input dataset tFilter (izFilterDS),
output viDummy (oiCount),
output vlDummy (olEndOfQuery),
output dataset tSelectFrwAnCode (ozResultsetDS),
output dataset tFcMessages (ozFcMessagesDS),
output oiReturnStatus (oiReturnStatus))>
/* Process readed records */
assign vcFrwAnalysisTypes = {&FRWANALYSISTYPES}
vcFrwAnalysisCOATypes = {&FRWANALYSISCOATYPES}.
for each tSelectFrwAnCode
break by tSelectFrwAnCode.tiFRWAnCode_ID
by tSelectFrwAnCode.tcFRWAnCodeElemCOAType:
/* Get translation for COA element type */
assign vcFrwAnalysisCOATypeTr = "":U.
if tSelectFrwAnCode.tcFRWAnCodeAnalyseType = {&FRWANALYSISTYPE-ANALYSIS} and
tSelectFrwAnCode.tcFRWAnCodeElemCOAType <> ? and
tSelectFrwAnCode.tcFRWAnCodeElemCOAType <> "":U
then do:
do viCounter = num-entries(vcFrwAnalysisCOATypes, chr(2)) to 1 by -2 :
if entry(viCounter, vcFrwAnalysisCOATypes, chr(2)) = tSelectFrwAnCode.tcFRWAnCodeElemCOAType
then do :
assign vcFrwAnalysisCOATypeTr = entry(viCounter - 1, vcFrwAnalysisCOATypes, chr(2)) no-error.
leave.
end. /* if entry */
end. /* do viCounter */
end. /* if tqSelectFrwAnCodeExt.tcFRWAnCodeElemCOAType <> ? and */
/* Group records and construct */
if first-of(tSelectFrwAnCode.tiFRWAnCode_ID)
then do:
create tqSelectFrwAnCodeExt.
buffer-copy tSelectFrwAnCode to tqSelectFrwAnCodeExt.
assign tqSelectFRWAnCodeExt.tcFRWAnCodeElemCOATypes = tSelectFRWAnCode.tcFRWAnCodeElemCOAType
tqSelectFRWAnCodeExt.tcFRWAnCodeElemCOATypesTr = vcFrwAnalysisCOATypeTr.
/* Get translation of Analysis type */
do viCounter = num-entries(vcFrwAnalysisTypes, chr(2)) to 1 by -2 :
if entry(viCounter, vcFrwAnalysisTypes, chr(2)) = tSelectFrwAnCode.tcFRWAnCodeAnalyseType
then do :
assign tqSelectFrwAnCodeExt.tcFRWAnCodeAnalyseTypeTr = entry(viCounter - 1, vcFrwAnalysisTypes, chr(2)) no-error.
leave.
end. /* if entry */
end.
/* Get translation of Controlling Dimension */
if tSelectFRWAnCode.tcFRWAnCodeCtrlCOADim <> '':U and
tSelectFRWAnCode.tcFRWAnCodeCtrlCOADim <> ?
then do:
do viCounter = num-entries(vcFrwAnalysisCOATypes, chr(2)) to 1 by -2 :
if entry(viCounter, vcFrwAnalysisCOATypes, chr(2)) = tSelectFRWAnCode.tcFRWAnCodeCtrlCOADim
then do :
assign tqSelectFRWAnCodeExt.tcFRWAnCodeCtrlCOADimTr = entry(viCounter - 1, vcFrwAnalysisCOATypes, chr(2)) no-error.
leave.
end. /* if entry */
end.
end.
end. /* if first-of(tqSelectFrwAnCodeExt.tiFRWAnCode_ID) */
else do:
if tSelectFrwAnCode.tcFRWAnCodeAnalyseType = {&FRWANALYSISTYPE-ANALYSIS}
then assign tqSelectFrwAnCodeExt.tcFRWAnCodeElemCOATypes = tqSelectFrwAnCodeExt.tcFRWAnCodeElemCOATypes
+ "," + tSelectFRWAnCode.tcFRWAnCodeElemCOAType
tqSelectFRWAnCodeExt.tcFRWAnCodeElemCOATypesTr = tqSelectFrwAnCodeExt.tcFRWAnCodeElemCOATypesTr
+ "," + vcFrwAnalysisCOATypeTr.
end. /* else if first-of(tqSelectFrwAnCodeExt.tiFRWAnCode_ID) */
/* Do additional filtering of the records based on the parameter Dimension */
if last-of(tSelectFrwAnCode.tiFRWAnCode_ID) and
vcFilterCOADimension <> ? and
not tqSelectFrwAnCodeExt.tcFRWAnCodeElemCOATypes matches vcFilterCOADimension
then do:
delete tqSelectFrwAnCodeExt.
end.
end. /* for each tqSelectFrwAnCodeExt */
/* Update sequence of resulting dataset */
assign viFcCount1 = 1.
for each tqSelectFRWAnCodeExt:
assign tqSelectFrwAnCodeExt.ti_sequence = viFcCount1
viFcCount1 = viFcCount1 + 1.
end.
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 = "BFRWAnalysisCode".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "SelectFRWAnCodeExt".
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/bfrwanalysiscode.selectfrwancodeext.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tFilter").
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.