Exercise 1 Linking URLs to SAP Web Lists To link a URL to a specific part of a line in the list generated by executing a report, use function module WWW_SET_URL in your report as follows: 1. Generate the list line with the WRITE statement. 2. Call WWW_SET_URL directly after the WRITE statement. 3. Specify the offset of the desired link in the OFFSET import parameter. 4. Specify the length of the desired link in the LENGTH import parameter. 5. Specify the URL you want to link to as a literal or as a variable in the FUNC import parameter. 6. Pass an empty internal table with structure W3QUERY to the tables parameter QUERY_STRING. When you run the report in the R/3 System, the resulting list has the same appearance as it always does. However, when you start the report from a Web page, the specified part of the list line is presented as a link. If you click on this link, you access the URL address. Example: This report generates a list with the following output line: 'Web Reporting is brought to you by SAP AG ' By calling function module WWW_SET_URL, you link the URL 'http://www.sap-ag.de' to the part of the output line that reads REPORT W3HKTST1. DATA QSTRING LIKE W3QUERY OCCURS 10. DATA URL(100). URL = 'http://www.sap-ag.de'. WRITE: 'Web Reporting is brought to you by SAP AG '. CALL FUNCTION 'WWW_SET_URL' EXPORTING OFFSET = 35 LENGTH = 6 FUNC = URL TABLES QUERY_STRING = QSTRING EXCEPTIONS INVALID_TABLE = 1 OTHERS = 2. ITS Exercises Compiled By: Seetharam Maddali 'SAP AG' If you start the report from the Web with the following URL: /scripts/wgate.dll?~service=XGWFC&_FUNCTION=WWW_GET_REPORT&_REPORT=W3HKTST1 The following list appears in your Web browser: By placing the cursor on SAP AG, you see that the URL specified in the program (http://www.sap-ag.de) is connected to this link. Exercise 2 Linking R/3 Function Calls to SAP Web Lists You can use the technique of linking Web pages to SAP function modules to implement interactive reporting in SAP Web reports. In the R/3 System, interactive reporting allows you to generate drill-down lists from basic lists Since interactive reporting in the R/3 System is such that the system itself stacks the lists created in a report, you may want to program interactive reporting and use the ABAP/4 event concept to react to user actions. However, this is not currently possible for Web Reporting because, the report finishes after sending a basic list to the Web, and cannot react to further user input. ITS Exercises Compiled By: Seetharam Maddali To overcome this obstacle, you can link URLs to list lines that call SAP function modules. Within these function modules, you can then program the task that you want the system to perform after a particular user action on the Web list. Function module WWW_SET_URL creates such URLs automatically and stores line- specific information in a hide area. To implement the call to an SAP function module in the line of a Web list, use function module WWW_SET_URL in your report as follows: 1. Fill an empty internal table of structure W3QUERY with the parameters you want to pass to the function module. Structure W3QUERY has two fields, NAME and VALUE. 2. Create the list line with the WRITE statement. 3. Call WWW_SET_URL directly after the WRITE statement. 4. Specify the offset of the desired link in the OFFSET import parameter. 5. Specify the length of the desired link in the LENGTH import parameter. 6. Specify the function module that you want to call in the URL as a literal or as a variable in the FUNC import parameter. Your function module must have the standardized interface. For more information, see The WebRFC Gateway Interface. 7. Pass the internal table with the parameters to the tables parameter QUERY_STRING. In contrast to standard interactive reporting in ABAP/4, you must use the internal table QUERY_STRING instead of the hide area to store information specific to a list line that you want to use later during an interactive event. For more information, see The Hide Technique. When you start such a report from the Web, the specified part of the list line is actually a link. The URL of this link contains the call to the SAP function module passed in the FUNC parameter and a list of the parameters stored in the internal table passed in the QUERY_STRING parameter. NOTE: For each URL, you can specify different function modules with different parameters. ITS Exercises Compiled By: Seetharam Maddali If you want to allow users who start reports from the R/3 System to perform the same activities as Web users who start reports from the Web, include an interactive event key word in your report program. Lists. With interactive reporting on the Web, you store line-specific information with function module WWW_SET_URL and not with the HIDE statement, so the system does not retrieve this data automatically as it does for standard interactive events. Furthermore, since you want to perform the same task in the R/3 system as from the Web, call the same function modules during an interactive event. The R/3 System provides function module WWW_GET_URL to perform this task. For each interactive list line, this function module returns the same information ( function name and parameters) as that stored with WWW_SET_URL. After calling WWW_GET_URL, you can use the information returned to call the relevant function module from within the R/3 System for each interactive event. Since the interface of Web-enabled function modules is standardized, you need to program only one function call with a dynamic function name. To supply the standardized interface, define two additional internal tables pointing to the ABAP/4 Dictionary structures W3HTML and W3MIME in your program. You can leave these tables empty. ITS Exercises Compiled By: Seetharam Maddali Report Source Code ( Report is connected to the logical database F1S ) REPORT W3HKTST2. TABLES SPFLI. DATA: QSTRING LIKE W3QUERY OCCURS 10 WITH HEADER LINE, MYHTML LIKE W3HTML OCCURS 0 WITH HEADER LINE, MYMIME LIKE W3MIME OCCURS 0 WITH HEADER LINE. DATA FUNCT(100). START-OF-SELECTION. GET SPFLI. * Data is retreived using Key fields. REFRESH QSTRING. QSTRING-NAME = 'CARRID'. QSTRING-VALUE = SPFLI-CARRID. APPEND QSTRING. QSTRING-NAME = 'CONNID'. QSTRING-VALUE = SPFLI-CONNID. APPEND QSTRING. WRITE: / sym_right_hand as symbol HOTSPOT COLOR = 5, SPFLI-CARRID , SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO. CALL FUNCTION 'WWW_SET_URL' EXPORTING OFFSET = 0 LENGTH = 1 FUNC = 'Z_SECONDARY_LIST' TABLES QUERY_STRING = QSTRING EXCEPTIONS INVALID_TABLE = 1 OTHERS = 2. IF SY-SUBRC NE 0. WRITE / 'Error in that line!'. ENDIF. END-OF-SELECTION. AT LINE-SELECTION. IF SY-CUCOL = 2. CALL FUNCTION 'WWW_GET_URL' IMPORTING FUNC = FUNCT TABLES QUERY_STRING = QSTRING EXCEPTIONS OTHERS = 1. IF SY-SUBRC NE 1. CALL FUNCTION FUNCT TABLES QUERY_STRING = QSTRING HTML = MYHTML MIME = MYMIME EXCEPTIONS OTHERS = 1. IF SY-SUBRC = 1. WRITE 'Error !!'. ENDIF. ENDIF. ENDIF. ITS Exercises Compiled By: Seetharam Maddali This report generates a basic list from the database table SPFLI. By calling function module WWW_SET_URL, the first column of each line is linked to a URL. For each URL, function module Z_SECONDARY_LIST is specified. The internal table QSTRING is filled with parameter pairs and passed to WWW_SET_URL. QSTRING is cleared for each new list line. You start the report from the Web with the URL: /scripts/wgate.dll?_~service=xgwfc&_FUNCTION=WWW_GET_SELSCREEN&_REPORT=W3HKTST2 This displays the report selection screen. When you enter selection criteria and run the report, a list similar to the following appears in your Web browser: The URL of the fifth line looks like this: href="/scripts/wgate.dll?_~service=xgwfc&_FUNCTION=SECONDARY_LIST&CARRID=LH&CONNID=2402" This URL includes the name of the function module as well as the parameter pairs for the airline carrier and connection. ITS Exercises Compiled By: Seetharam Maddali The source code of the function module SECONDARY_LIST is as follows: First, this function reads the imported parameters from the internal table QUERY_STRING. Then, it generates an output list in a SELECT loop. Finally, it sends the list to the Web. FUNCTION Z_SECONDARY_LIST. REFRESH HTML. REFRESH MIME. CONTENT_TYPE = 'text/html'. TABLES SFLIGHT. DATA: MY_CARRID LIKE SPFLI-CARRID, MY_CONNID LIKE SPFLI-CONNID. LOOP AT QUERY_STRING. IF QUERY_STRING-NAME EQ 'CARRID'. MY_CARRID = QUERY_STRING-VALUE. ENDIF. IF QUERY_STRING-NAME EQ 'CONNID'. MY_CONNID = QUERY_STRING-VALUE. ENDIF. ENDLOOP. WRITE: MY_CARRID, MY_CONNID. ULINE. SELECT * FROM SFLIGHT WHERE CARRID EQ MY_CARRID AND CONNID EQ MY_CONNID. WRITE: / SFLIGHT-FLDATE, SFLIGHT-SEATSMAX, SFLIGHT-SEATSOCC. ENDSELECT. CALL FUNCTION 'WWW_LIST_TO_HTML' TABLES HTML = HTML. ENDFUNCTION. ITS Exercises Compiled By: Seetharam Maddali If you click on a link in the Web list, the following drill-down list appears in your Web browser: Exercise 3 Starting the Reporting Browser Instead of calling specific reports (with or without selection screens) in URLs, you can enable Web users to browse report trees. Report trees are hierarchical structures that contain SAP reports or your own reports. There can be any number of report trees in an R/3 System and the nodes of each report tree can offer executable reports or pre- generated lists. To allow Web users to access the SAP Reporting Browser, which is the standard hierarchy of reports supplied by SAP, specify a URL that calls the standard function module WWW_GET_TREE_LIST in your Web page. You specify the following URL in your HTML: /scripts/wgate.dll?~service=XGWFC&_FUNCTION=WWW_GET_TREE_LIST ITS Exercises Compiled By: Seetharam Maddali Web users who click on this URL get a list of all report trees currently in the R/3 System. Clicking on one of the report tree names displays the structure for that report tree. You can click on the sub-trees to see subsequent levels and access reports at the lowest level. This produces a page similar to that displayed below. Here, clicking on the node Flight reports produces a list of executable reports (which may or may not have selection screens).