11-07-2007 4:06 PM
Hi, has anyone developed any applications with Flex using the QUERY_VIEW_DATA XML Output? If so any chance you might pass it on so I can use for testing?
Thanks, Ken Murray
11-08-2007 2:05 AM
Yup, I've done this before the source is posted below. There are no comments and the code is geared to a query that you don't have on your system but, it should give you a good idea of how to do it.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="454"
creationComplete="onCreationComplete()" height="275">
<mx:Script>
<![CDATA[
import mx.rpc.soap.LoadEvent;
import mx.rpc.AbstractOperation;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.rpc.events.HeaderEvent;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.utils.ArrayUtil;
import mx.utils.XMLUtil;
[Bindable]public var wsdlName:String = "http://localhost:8000/sap/bc/srt/rfc/sap/query_view_data?sap-client=001&wsdl";
[Bindable]public var queryData:XMLList;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var queryViewDataService:WidgetWebService;
public function onCreationComplete():void{
queryViewDataService = new WidgetWebService();
queryViewDataService.wsdl = wsdlName;
queryViewDataService.addEventListener(LoadEvent.LOAD, loadListener);
queryViewDataService.addEventListener(ResultEvent.RESULT, resultTrigger);
queryViewDataService.addEventListener(FaultEvent.FAULT,fault);
queryViewDataService.loadWSDL();
}
public function loadListener(event:LoadEvent):void{
var op:AbstractOperation = queryViewDataService.getOperation("GetQueryViewData");
var input:Object = new Object();
input.ViewId = confXML.viewName;
op.arguments = input;
op.send();
}
public function resultTrigger(event:ResultEvent):void{
var output:XML;
var columnHeaders:Array;
var column:AdvancedDataGridColumn;
var response:XMLList;
var axisData:XMLList;
var axisInfo:XMLList;
var yAxis:XMLList;
var xAxis:XMLList;
var _string:String;
var item:XML;
namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
namespace n0 = "urn:sap-com:document:sap:soap:functions:mc-style";
_string = event.message.body.toString();
var regex:RegExp = new RegExp("soap-env", "g");
_string =_string.replace(regex, "soapenv");
output = new XML(_string);
use namespace soapenv;
response = output.Body;
use namespace n0;
response = response.GetQueryViewDataResponse;
var numHeaderRows:int;
var numRows:int;
var leadCols:int;
var numCols:int;
var row:XML;
var name:String;
var value:String;
var tempIndex:int;
row = <row></row>;
axisData = response.AxisData.item;
axisInfo = response.AxisInfo.item;
numHeaderRows = axisInfo.(Axis == "000").Nchars;
numRows = axisInfo.(Axis == "001").Ncoords;
leadCols = axisInfo.(Axis == "001").Nchars;
numCols = axisInfo.(Axis == "000").Ncoords;
numCols = numCols + leadCols;
numRows = numRows + numHeaderRows;
columnHeaders = new Array();
queryData = new XMLList();
var rowNum:int;
var colNum:int;
for(rowNum = 0;rowNum < numRows; rowNum++){
row = <row></row>;
name = value = "";
for(colNum = 0; colNum < numCols; colNum++){
if (rowNum < numHeaderRows && colNum < leadCols){
column = new AdvancedDataGridColumn();
column.headerText = axisInfo.(Axis == "001").Chars.item[colNum].Caption;
column.dataField =axisInfo.(Axis == "001").Chars.item[colNum].Chanm;
columnHeaders.push(column);
}
if (rowNum < numHeaderRows && colNum >= leadCols){
column = new AdvancedDataGridColumn();
column.headerText = axisData.(Axis == "000").Set.item[colNum - leadCols].Caption;
column.dataField = axisData.(Axis == "000").Set.item[colNum - leadCols].Chavl;
columnHeaders.push(column);
}
if (rowNum >= numHeaderRows){
if (colNum < leadCols){
tempIndex = (( rowNum - numHeaderRows ) * (leadCols)) + (colNum);
value = axisData.(Axis == "001").Set.item[tempIndex].Caption;
name = axisData.(Axis == "001").Set.item[tempIndex].Chanm;
}
else{
tempIndex = (( rowNum - numHeaderRows ) * (numCols - leadCols)) + (colNum - leadCols);
value = response.CellData.item[tempIndex].FormattedValue;
name = AdvancedDataGridColumn(columnHeaders[colNum]).dataField;
}
row.appendChild(<{name}>{value}</{name}>);
}
}
if (row != <row></row>)
queryData += row;
}
dataGrid.columns = columnHeaders;
}
public function fault(event:FaultEvent):void{
var i:Number;
i = 0;
}
]]>
11-08-2007 12:48 PM
Very Cool Stuff, I'm surprised you don't hear more about people doing this as I'm sure you can build some very professional looking applications and dashboards directly with the QUERY_VIEW_DATA Web Service and Flex. I have tooled around and was able to get the xml results to appear, but I'm new to Flex and don't know how to handle the output so I couldn't take it further yet.
Can you give some quick context behind building this like what the level of difficulty was for you and is the code fairly portable to a different query results?
Thanks, Ken Murray
11-13-2007 9:51 PM
> Can you give some quick context behind building this like what the level of difficulty was for
> you and is the code fairly portable to a different query results?
In wasn't terribly hard to write any of this. The hardest thing to do was to parse the xml data and the only reason that was hard was due to the e4x stuff. This wasn't just hard but there was a learning curve associated with it.
In terms of portability between queries you can make the code highly portable but that is up to the developer. The data comes back as a bunch of disparate tables but you can pull them back together again and represent it as a datagrid with some interesting slight of hand. I've done this in ABAP using the same web services but have yet to port the code to AS3.
-d
11-14-2007 9:05 AM
Dan,
Thanks for the sample code. i am having a problem passing parameters table to query_view_data
here is the actionscript code which i had written, do you see a problem with this code?
op = queryViewDataService.getOperation("GetQueryViewData");
var input:Object = new Object();
input.Infoprovider = "CO_M01";
input.Query = "CO_SA_STANDARD_COSTS";
input.Parameter = new Array();
input.Parameter[0] = new Array("VAR_NAME_1", "0H_CCTR");
input.Parameter[1] = new Array("VAR_VALUE_EXT_1","ABC_9999");
input.Parameter[2] = new Array("VAR_NAME_2","0P_FPER");
input.Parameter[3] = new Array("VAR_VALUE_EXT_2","2002001");
input.Parameter[4] = new Array("VAR_NAME_3","ZCOCFI");
input.Parameter[5] = new Array("VAR_VALUE_EXT_3","AB1");
input.Parameter[6] = new Array("VAR_NODE_IOBJNM_3","0HIER_NODE");
op.arguments = input;
op.send();
Thanks in advance.
Regards
Raja
11-14-2007 8:00 PM
11-15-2007 8:04 PM
11-17-2007 6:19 AM
Thank you very much Dan. Finally parameter passing is working fine. here is the code i have used.
op = queryViewDataService.getOperation("GetQueryViewData");
var input:Object = new Object();
input.Infoprovider = "CO_M01";
input.Query = "YCO_STANDARD_COSTS";
var ParameterRow:Object = new Object();
input.Parameter = new Array();
ParameterRow.Name = "VAR_NAME_1";
ParameterRow.Value = "0H_CCTR";
input.Parameter.push(ParameterRow);
ParameterRow = null ;
ParameterRow = new Object();
ParameterRow.Name = "VAR_VALUE_EXT_1";
ParameterRow.Value = "ABC_9999";
input.Parameter.push(ParameterRow);
ParameterRow = null;
ParameterRow = new Object();
ParameterRow.Name = "VAR_NAME_2";
ParameterRow.Value = "0P_FPER";
input.Parameter.push(ParameterRow);
ParameterRow = null;
ParameterRow = new Object();
ParameterRow.Name = "VAR_VALUE_EXT_2";
ParameterRow.Value = "2002001";
input.Parameter.push(ParameterRow);
ParameterRow = null;
ParameterRow = new Object();
ParameterRow.Name = "VAR_NAME_3";
ParameterRow.Value = "ZCOGRP";
input.Parameter.push(ParameterRow);
ParameterRow = null;
ParameterRow = new Object();
ParameterRow.Name = "VAR_VALUE_EXT_3";
ParameterRow.Value = "ABC1";
input.Parameter.push(ParameterRow);
ParameterRow = null;
ParameterRow = new Object();
ParameterRow.Name = "VAR_NODE_IOBJNM_3";
ParameterRow.Value = "0HIER_NODE";
input.Parameter.push(ParameterRow);
ParameterRow = null;
op.arguments = input;
op.send();
Thanks again.
Regards
Raja
09-23-2010 11:57 PM
Hi Guys,
Have you been able to get this code working??? is it possible to have a working sample???.
I'm trying to "save" the returned XML from the Operation GetQueryViewData data into an Object which I can handdle in Charts, Grids Etc.
I'll appreciate any help!
10-09-2010 8:42 AM
11-16-2007 11:32 PM
Hi daniel, I', testing your great post. An issue I found is that Flex 3 Builder says "WidgetWebService not found during compilation".
Please could you check it?
Thanks a lot
Luca
11-17-2007 5:00 AM
Luca,
I had exactly the same issue with flex builder 3 and to over come that.
add the following
import mx.rpc.soap.WebService;
and then cchange queryViewDataService to
private var queryViewDataService:WebService;
Raja
11-18-2007 10:47 PM
Sorry all, didn't expunge all the random stuff from that code. Raja is right in his response, simply use the regular WebService object and all is well. Thanks for the pickup Raja.
11-19-2007 10:44 PM