Sie sind auf Seite 1von 15

How-to Guide SAP NetWeaver 04

How To Implement a virtual InfoProvider with Services


Version 2.00 March 2005 Applicable Releases: SAP NetWeaver 04

Copyright 2005 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, and Informix are trademarks or registered trademarks of IBM Corporation in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C , World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data

contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. SAP NetWeaver How-to Guides are intended to simplify the product implementation. While specific product features and procedures typically are explained in a practical business context, it is not implied that those features and procedures are the only approach in solving a specific business problem using SAP NetWeaver. Should you wish to receive additional information, clarification or support, please refer to SAP Consulting. Any software coding and/or code lines / strings (Code) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.

1 Scenario
The total booking prices for all posted flights are specified in a query. In doing so, only commercial customers (CUSTTYPE = B) need to be taken into consideration. The query result has to correspond to the online entry. The data is stored in the SBOOK table. The BOOKID (Booking Number), CARRID (Airline Code), CLASS (Class), CONNID (Flight Connection Number), and FLDATE (Flight Date) characteristics are used to ensure the drilldown.

2 Result
The realization occurs by means of a Virtual InfoCube with services. To do this, a customer function module (service) has to be created. This selects the necessary data from the table and transfers it to the Virtual InfoCube interface. A query from the Virtual InfoCube displays the data in the Business Explorer. The drilldown and the transfer of the filter value are supported by the system. Query result:

-1-

3 The Step By Step Solution


3.1 Service Variants
The service variants differ from each other by transfer parameters or types of transfer parameters from the customer function module (service). In this way, they can be differentiated by various degrees of functions when the standard BW features are set, or when the customer development has to be transferred. There are three types of service variants that can be defined by flags in the service definition. The types are: (1) RFC is switched on (2) SID support is switched off (is used in this example) (3) SID Support is switched on You can read more about the different service variants in the BW 3.0B documentation under Virtual InfoCubes with Services.

3.2

Realization

1. Definition of a virtual InfoCube with Service Administrator Workbench Right mouseclick on InfoArea Create InfoCube Entry screen fields: InfoCube: VIRTCUBE1 InfoCube description: Vitual InfoCube InfoCube type: Virtual InfoCube with Services

2. Click on Details:

-2-

3. Fill the input screen with the following parameters: Function Module: Z_VIRT_INFOCUBE_CUBE (implementation see step 5) Set flags: - With Navigation Attributes The interface of the service is described in the documentation. F1 on the specific flag

4. Define, save, and activate the InfoCube Do not forget to assign the characteristics to dimensions

Characteristics:

Key figures:

-3-

Time characteristics:

5. Create the function module with transaction SE37 Z_VIRT_INFOCUBE_CUBE

-4-

6. Attributes of the function module

Create a new function group if none is available. Transaction SE80 Edit Objects Function Group Create 7. Importing parameters and types

8. Exporting parameters and types

9. No changing parameters

-5-

10. Exception parameters

11. Source code: function module (see comments in the code)

FUNCTION Z_VIRT_INFOCUBE_CUBE. *"--------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(I_INFOPROV) TYPE RSINFOPROV *" REFERENCE(I_TH_SFC) TYPE RSDRI_TH_SFC *" REFERENCE(I_TH_SFK) TYPE RSDRI_TH_SFK *" REFERENCE(I_T_RANGE) TYPE RSDRI_T_RANGE *" REFERENCE(I_TX_RANGETAB) TYPE RSDRI_TX_RANGETAB *" VALUE(I_FIRST_CALL) TYPE RS_BOOL *" VALUE(I_PACKAGESIZE) TYPE I DEFAULT 1000 *" EXPORTING *" REFERENCE(E_T_DATA) TYPE STANDARD TABLE *" REFERENCE(E_END_OF_DATA) TYPE RS_BOOL *" REFERENCE(E_T_MSG) TYPE RS_T_MSG *" EXCEPTIONS *" WRONG_INPUT *" READ_ACCESS_ERROR *"--------------------------------------------------------------------* initialize CLEAR: e_t_data, e_t_msg. * this is specific to infoprovider VIRTCUBE1 CHECK i_infoprov = 'VIRTCUBE1'. FIELD-SYMBOLS: <l_s_sbook> <l_s_data> DATA: l_t_component i_t_sbook * initialize CLEAR e_t_data. * Data selection / only Business Customer select * from sbook INTO CORRESPONDING FIELDS OF TABLE i_t_sbook where custtype = 'B' and LOCCURKEY <> ''. if sy-subrc = 0. " create a working area ASSIGN LOCAL COPY OF INITIAL LINE OF e_t_data TO <l_s_data>. * * get description of components of <L_S_DATA> PERFORM get_type_components(saplrsdrc) USING <l_s_data> CHANGING l_t_component. data transformation move line by line LOOP AT i_t_sbook ASSIGNING <l_s_sbook>. TYPE gt_s_sbook, TYPE ANY.

TYPE abap_compdescr_tab, TYPE gt_t_sbook.

* *

-6-

PERFORM move_sbook_to_data USING <l_s_sbook> i_th_sfc i_th_sfk l_t_component CHANGING <l_s_data>. * append to output data append <l_s_data> to E_T_DATA. ENDLOOP. endif. * all data are selected E_END_OF_DATA = 'X'. ENDFUNCTION.

12. Source code: Perform move_sbook_to_data

(see comments in the code)

*---------------------------------------------------------------------* ***INCLUDE LZVIRTCF02 . *---------------------------------------------------------------------* *&--------------------------------------------------------------------* *& Form move_budget_to_data *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->P_<L_S_BOOK> text * -->P_I_TH_SFC text * -->P_I_TH_SFK text * -->P_L_T_COMPONENT text * <--P_<L_S_DATA> text *---------------------------------------------------------------------* FORM move_sbook_to_data USING i_s_sbook TYPE gt_s_sbook i_th_sfc TYPE RSDRI_TH_SFC i_th_sfk TYPE RSDRI_TH_SFK i_t_component TYPE abap_compdescr_tab CHANGING e_s_data TYPE any. * define FIELD-SYMBOLS FIELD-SYMBOLS: <l_s_component> abap_compdescr, <l_comp_data> <l_s_sfc> <l_s_sfk> * Datadeclaration DATA: l_compno l_t_component l_s_sbook TYPE TYPE ANY, TYPE RSDRI_S_SFC, TYPE RSDRI_S_SFK.

TYPE i, TYPE abap_compdescr_tab, TYPE gt_s_sbook.

* initialize CLEAR e_s_data. l_s_sbook = i_s_sbook. * ******* Transformation of all needed SBOOK Fields **************** * (1) year --------------------------------------------------------IF NOT i_s_sbook-FLDATE IS INITIAL. * get alias name from SFC

-7-

READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = '0CALYEAR'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. move i_s_sbook-FLDATE(4) to <l_comp_data>. ENDIF. ENDIF. ENDIF. * (2) CALDAY----------------------------------------------------------IF NOT i_s_sbook-FLDATE IS INITIAL. * get alias name from SFC READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = '0CALDAY'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. * MOVE move i_s_sbook-FLDATE to <l_comp_data>. ENDIF. ENDIF. ENDIF. * (3) calmonth2-------------------------------------------------------IF NOT i_s_sbook-FLDATE IS INITIAL. * get alias name from SFC READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = '0CALMONTH2'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. * MOVE move i_s_sbook-FLDATE+4(2) to <l_comp_data>. ENDIF. ENDIF. ENDIF.

-8-

* (4) CARRID----------------------------------------------------------IF NOT i_s_sbook-CARRID IS INITIAL. * get alias name from SFC READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = 'CARRID'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. * MOVE move i_s_sbook-CARRID to <l_comp_data>. ENDIF. ENDIF. ENDIF. * (5) CLASS----------------------------------------------------------IF NOT i_s_sbook-CLASS IS INITIAL. * get alias name from SFC READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = 'CLASS'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. * MOVE move i_s_sbook-CLASS to <l_comp_data>. ENDIF. ENDIF. ENDIF. * (6) CONNID----------------------------------------------------------IF NOT i_s_sbook-CONNID IS INITIAL. * get alias name from SFC READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = 'CONNID'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>.

-9-

MOVE move i_s_sbook-CONNID to <l_comp_data>. ENDIF. ENDIF. ENDIF.

* (7) BOOKID----------------------------------------------------------IF NOT i_s_sbook-bookid IS INITIAL. * get alias name from SFC READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = 'BOOKID'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. * MOVE move i_s_sbook-BOOKID to <l_comp_data>. ENDIF. ENDIF. ENDIF. * (8) LOCCURKEY-------------------------------------------------------IF NOT i_s_sbook-LOCCURKEY IS INITIAL. * get alias name from SFC READ TABLE i_th_sfc ASSIGNING <l_s_sfc> WITH TABLE KEY chanm = '0CURRENCY'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfc>-CHAALIAS. IF sy-subrc = 0. * number of target data component l_compno = sy-tabix. * get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. * MOVE move i_s_sbook-LOCCURKEY to <l_comp_data>. ENDIF. ENDIF. ENDIF. * (10) LOCCURAM ------------------------------------------------------IF NOT i_s_sbook-LOCCURAM IS INITIAL. * get alias name from SFC READ TABLE i_th_sfk ASSIGNING <l_s_sfk> WITH TABLE KEY kyfnm = 'LOCCURAM'. IF sy-subrc = 0. * get number of target column READ TABLE i_t_component ASSIGNING <l_s_component> WITH KEY name = <l_s_sfk>-kyfalias. IF sy-subrc = 0. * number of target data component

- 10 -

l_compno = sy-tabix. get target data component ASSIGN COMPONENT l_compno OF STRUCTURE e_s_data TO <l_comp_data>. * MOVE <l_comp_data> = i_s_sbook-LOCCURAM. ENDIF. ENDIF. ENDIF. * ENDFORM. " move_budget_to_data

13. Source code Main program: Goto Main program

*************************************************** **************** * System-defined Include-files. * *************************************************** **************** INCLUDE LZVIRTCTOP. " Global Data INCLUDE LZVIRTCUXX. " Function Modules *************************************************** **************** * User-defined Include-files (if necessary). * *************************************************** **************** * INCLUDE LZVIRTCF... " Subprograms * INCLUDE LZVIRTCO... " PBOModules * INCLUDE LZVIRTCI... " PAIModules

(see comments in the code) 14. Source code: INCLUDE LZVIRTCTOP Global data declaration

INCLUDE LZVIRTCF02. FUNCTION-POOL ZVIRTC. "MESSAGE-ID .. Tables: sbook. TYPE-POOLS: rs, rsd, rsdd, rsdpm, rsdpr, rsdu. TYPES:

(see comments in the code)

* Structure * types BEGIN OF gt_s_sbook, CARRID TYPE S_CARR_ID, CONNID TYPE S_CONN_ID, CLASS TYPE S_CLASS, FLDATE TYPE S_DATE, BOOKID TYPE S_BOOK_ID, CUSTTYPE TYPE S_CUSTTYPE, LOCCURAM TYPE S_L_CUR_PR, LOCCURKEY TYPE S_CURRCODE, END OF gt_s_sbook, * internal SBOOK Table gt_t_sbook TYPE STANDARD TABLE OF gt_s_sbook WITH DEFAULT KEY INITIAL SIZE 10.

- 11 -

15. Query definition Supress Result Rows is set to Always in the characteristic properties

- 12 -

www.sdn.sap.com/irj/sdn/howtoguides

Das könnte Ihnen auch gefallen