Skip to Content
Author's profile photo Durairaj Athavan Raja

Execute BW query using ABAP Part II

In the Execute BW query using ABAP Part I we have seen how to

execute BW query using ABAP. Now in this part we will see how the result in XML

format can be transformed to internal table format and also sample code for

testing the whole solution.

<!column ><xsl:apply-templates/></column>

<xsl:copy>

    <xsl:apply-templates select=”@||text()”/>

 

<!column ><xsl:apply-templates/></column>

<xsl:copy>

    <xsl:apply-templates select=”@||text()”/>

 

Assigned Tags

      41 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Hi Raja,

      This is really great stuff.

      Can we get the PDF o/p of the query result. I have seen your related articles in the BSP forum, can we use the smart forms functionality along with BW to get the PDF o/p. Also have you tried XSL FO which can produce PDF o/p.

      Thanks.

      -Deepu

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      Hi Deepu,

      thanks for the comments.
      Now that the query results are in a internal table you could generate PDF either using OTF to PDF (Smart form) or spool to PDF.

      I haven't tried XSL FO. Thats my next target, i will post the results once its done.

      Regards
      Raja

      Author's profile photo Former Member
      Former Member

      Dear Raja,I am not getting the values. Can you help me out?

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author

      META table will just have the structre definition of the output. the actual output is in xml_out as xml.Raja

      Author's profile photo Former Member
      Former Member
      Thanks Raja now it is working very well.
      Author's profile photo Former Member
      Former Member
      Raja,  very nice.  I was wondering if it would be possible to make the FM RFC enabled?  We have a need to query data in BW from an R/3 system via ABAP.  Do you have any thoughts on this.  Thanks.
      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      Should not be a problem. Just RFC enable the FM. But the calling system has to be on WAS so that you can use XSLT to parse the resulting XML into itab.

      Regards
      Raja

      Author's profile photo Former Member
      Former Member

      Hi Raja,Sheetal

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      Hi Sheetal,

      Thanks for your comments.

      Its really difficult to address your question with the given explanation. If you just debugg the FM, you yourself will easily resolve the issue.

      Regards
      Raja

      Author's profile photo Former Member
      Former Member
      Sorry for not been clear enough about my problem.
      The values of wa_set-chavl is what i was looking for.
      Thanks again your weblog was very helpful.

      Regards,
      Sheetal.

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author

      modify the FM code as below.Raja

      Author's profile photo Former Member
      Former Member
      Hi raja,

               This is really fantastic. Is it also possible to run a query view using abap and get the XML result?

      Cheers,
      Apurva

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      Yes. but needs little modification.

      The following method will give the view definition.
      CALL METHOD cl_rsz_www_db_interface=>get_view

      this would also return the query of the view.

      Get the query name and then create instance of  cl_rsr_request like below.

        CREATE OBJECT r_request
        EXPORTING i_genuniid = p_genuniid .

      I have checked some of the standard code of SAP this is what they are doing.

      For example you can check out the code at
      IF_SOAP_APPLICATION_RT~EXEC_PROCESSING

      Hope this helps.

      Regards
      Raja

      Author's profile photo Former Member
      Former Member
      This is really great stuff. It is very usefull.
      Author's profile photo Former Member
      Former Member
      Hello,
      please use released BAPI's to get data from a query! Your workaround is not supported by SAP.
      Kind regards
      Michael
      SAP RIG
      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      Thanks for your concerns.
      Are you talking about the BAPI methods of ODBO Reporting? (using MDX). My knowledge of MDX is very poor and transaction MDXTEST dosent help much in generating the required MDX statements.

      The solution talked here is a pure custom one. Which uses the standard classes/methods.

      The closest FM which i found doing this kind of processing is RRW3_GET_QUERY_VIEW_DATA.

      It would be really helpful for us if you could give us the BAPI names which can be used for getting data from query.

      Regards
      Raja

      Author's profile photo Former Member
      Former Member
      Hello Michael,
      Could you please provide the name of BAPI's to get data from a query as you suggested. 
      Thanks,
      Gary Ramage
      Author's profile photo Mahesh Madhavan
      Mahesh Madhavan
      Dear Michael,

      You have left us in a cloud of confusion! Please reveal the names of those released BAPIs you were talking about.

      Thank you for your time.

      Regards,
      Mahesh M.S.

      Author's profile photo Former Member
      Former Member

      Hi raja,Nicola Commari

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      I am on a training course for next 5 days. As i have to simulate your case to see whats going wrong, it would take sometime. In the meantime, you can just debugg and see whats going wrong.

      Regards
      Raja

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      Luckily i was able to spare some time. I have simulated the scenario where i had 0costcenter in one column and a structure for plan/actual/variance colummns. This works fine. i didnt face the problem you are referring to. The only way out is to debugg.

      Regards
      Raja

      Author's profile photo Former Member
      Former Member

      we have a problem with a query where there's a Infoobject with a compound.

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      this is very well handled in the FM. if you look at the code in the Y_EXECUTE_QUERY FM we created from PART I, when i build the meta table , i get the OUTPUTLEN from BAPI_IOBJ_GETDETAIL.
      the details structure returned by this BAPI gives me the right output length. we also have exactly the same scenario (coarea/costcenter)(4+6). this works very well.

      Can you debug and see whats going wrong?

      Regards
      Raja

      Author's profile photo Former Member
      Former Member
      Could you fix your problem? If so, could you please help me, what to do to fix this problem?

      Best Regards
      Stefan

      Author's profile photo Former Member
      Former Member
      Dear Raja

      This is really wonderful and also useful. I tried with very simple query and it worked fine. Now the query which i am trying to download has 2 dates and it is not extracting properly.

      Could you please guide on this.

      Thanks in advance.
      Bharat

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      hi Bharat,

      It should not be a problem, i guess i have tested this scenario as well. Anyhow can you tell me what exactly happenning- what is meant by not extracting properly.

      why dont you just debugg and see where it goes wrong.

      Regards
      Raja

      Author's profile photo Former Member
      Former Member

      Hi Raja<br/><br/>Thanks for reply. I did some amount of debugging abd found that it reads dates properly from query byt while assigning it assigns 10 digits to 8 digits and makes a mess of data.<br/>According to me following code is not working properly on my side..Bharat

      Author's profile photo Former Member
      Former Member

      Hello,<br/>     I am a beginer in XSLT programming. I was reading SAP given transformation STRANSDEMO_FLIGHTS_A2X in was 6.4. Here i was not able to get following statement<br/><xsl:for-each select="asx:abap[1]/asx:values[1]/FLIGHT_LIST[1]/*"><br/>I know that xsl:for-each select is for loop but<br/>wats the output of line <br/>asx:abap[1]/asx:values[1]/FLIGHT_LIST[1]<br/>also here why they have used index .<br/>Even in the example given by you , you have used similar index notation. what is the significance of this.<br/>      Also Sir, I tried to understand xslt through SAP help but as there is not proper documentation for each tag , I wasn't able to understand to greater extent. If you have any better documentation about xslt then please provide the same.<br/>      Thank you.     

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      asx:abap[1]/asx:values[1]/FLIGHT_LIST[1]

      is just to read the first record in the loop.

      XSLT is not different in SAP (SAP has its own transformation based on XSLT call ST -Simple transformation, you can choose to use XSLT or ST).

      as far learning XSLT, this will be a good start
      http://www.w3schools.com/xsl/default.asp

      Regards
      Raja

      Author's profile photo Former Member
      Former Member

      Hello sir,<br/>         Thank you for the reply. I am already reading the documentation given in the link  specified by you. <br/><br/>In the statement below<br/><xsl:for-each select="asx:abap[1]/asx:values[1]/FLIGHT_LIST[1]/"><br/>as we use <xsl:for-each select for loop,<br/>why do we need to need to specify the first line of the table . why cant we simply say /FLIGHT_LIST instead of /FLIGHT_LIST[1]/.<br/>also kindly let me know the significance of prefix asx:abap[1]/asx:values[1]. I know that they are used for accessing abap data but why do we require index in this case.<br/>Awaiting for the favourable response.<br/><br/><br/><br/><br/><br/>   

      Author's profile photo Ashwin Bhaskar
      Ashwin Bhaskar
      Awesome blog ...!! Its has made a lot of things easier for US ...!!!
      Kudos ..!!
      Author's profile photo Former Member
      Former Member
      Hi,
      I want to display the BI report data in bsp or webdynpro abap which is in arabic language.The BI system doesn't support the non-unicode.so i have to get that report data into unicode sytem in webdynpro or bsp and encode that data and pass to Bi system.
      Is there any functionmodule to encode the data?
      How to display that report data in bsp and which UI element support the Browser.

      Please help me in the same.

      Thanking you in advacne..

      Author's profile photo Former Member
      Former Member
      Hi Raja,

      My query is regarding the parameters we are passing to the FM.

      According to the requirement, I have to execute a BI query from CRM system. So I was planning to use the RFC RRW3_GET_QUERY_VIEW_DATA. I have the query name also the variable names. The mandatory parameters to execute the query has multiple values. So my doubt here is it possible to pass the multiple values for a single variable to the input parameter  I_T_PARAMETER of the FM RFC RRW3_GET_QUERY_VIEW_DATA. Please share your thoughts/input.

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      yes its possible. look at the web api documentation.
      you will have to use

      VAR_OPERATOR_1
      VAR_SIGN_1
      VAR_VALUE_LOW_EXT_1
      etc

      Author's profile photo Former Member
      Former Member
      I don't know much about ABAP but have been trying to follow this example. I don't understand how to test it. What am I supposed to do with the last piece of code? Create another FM and run that? I also don't understand how that ties in with the XSLT Program.

      I know this is an old topic but any help would be appreciated

      Richard

      Author's profile photo Mahesh Madhavan
      Mahesh Madhavan
      Dear Durairaj,

      I'm delighted to find that a way exists for reading BW query using ABAP. Now my doubt is, can a BW Workbook be also extracted, just as in the case of a BW query, using ABAP?

      I have been looking all over, but nobody could crack this.

      Thank you for your time.

      Regards,
      Mahesh M.S.

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      This is a very old code. Latest code is available at http://wiki.sdn.sap.com/wiki/display/BI/Expose+BI+Query+as+RESTful+Service
      Author's profile photo Mahesh Madhavan
      Mahesh Madhavan
      Dear Durairaj,

      Thank you so much for your reply!

      In fact I've used a function module RRMX_WORKBOOK_READ to read the above mentioned table for getting the workbook contents. But it's there in a binary format. So using neither the FM nor reading the table directly will make any difference.

      Could you please suggest a way to convert this binary format to the readable format? The conventional FMs for doing this, provided SAP is not yielding any result.

      Thank you again, for you time.

      Regards,
      Mahesh M.S.

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      Dear Mahesh,

      Sorry for the delayed reply. What do you want to do with the read workbook content, open in excel? from where an ABAP program or web app? In my case i have a BSP page which lists the workbook and on clicking it will open the particular workbook in excel. Is this something you would like to do ?

      Author's profile photo Mahesh Madhavan
      Mahesh Madhavan
      Dear Durairaj,

      Thank you for your reply.

      My requirement is to extract the workbook contents into an internal table, just as it appears in the workbook. Is there really a way to do so?

      All my research regarding the extraction of data from a BW workbook into an internal table has so far been futile.

      Is there really a way out?

      Thank you for your time.

      Regards,
      Mahesh M.S.

      Author's profile photo Durairaj Athavan Raja
      Durairaj Athavan Raja
      Blog Post Author
      For extracting the workbooks, you can just read them from the tables

      RSRWBINDEXT = worbooks header table
      RSRWBSTORE   = workbook contents