A large collection of miscellaneous FAQs.
How to Convert an XSTRING into STRING?
For the simple assignment "string = xstring", ABAP defines the rule that each X-character in the XSTRING is mapped onto two hexadecimal characters in the string. To get the expected content conversion, use special classes to handle such conversion. See: CL_ABAP_CONV_IN_CE and CL_ABAP_CONV_OUT_CE.
DATA: Xcontent TYPE XSTRING, content TYPE STRING, conv TYPE REF TO CL_ABAP_CONV_IN_CE, len TYPE I. conv = CL_ABAP_CONV_IN_CE=>CREATE( input = Xcontent ). conv->READ( importing data = content len = len ).
Why does the BSP Application only Work in the Debugger?
Typical problem description: "We have developed a BSP application and we're trying to call some function. It doesn't work. However, if we execute the BSP application in debug mode, everything works fine. Why?"
When you log onto a WebAS system the Dynpro engine is started that contains all the logic to handle interaction with the SAPGUI. For example, things such as rendering controls and doing file upload/download are all available.
When you run an HTTP request into Web AS, a very special "dark" (or background) Dynpro is started. A minimal Dynpro is required to get ABAP up and running. But now there is no SAPGUI available, so no SAPGUI-based service will work. Also little things such as popup windows do not work.
So why does the code work in the debugger? Because, once the debugger is triggered, ABAP realizes that a normal Dynpro is required for the debugger and not the "dark" one. So the full-blown Dynpro engine is started, making all SAPGUI services available.
You can consider finding the code that causes the error and bracket it with IF-statements in this function, so that no SAPGUI interaction is required in the context of a HTTP call.
How to Determine if BSP (HTTP request) Is Active?
Typical question: "For our application, the type of environment being used must be checked so as to remove some code when not running in SAPGUI."
The function group SFES provides at least two interesting functions: GUI_IS_AVAILABLE and GUI_IS_ITS. But to test for BSP, or more exactly for HTTP request processing, the function ICF_IS_PLUGIN_SESSION should be used. The interesting exported parameters are plugin_session (Y/N), and plugin_protocol (1=HTTP, 2=HTTPS).
Why Do My Cookies Not Work?
Ever so often (twice at the time of this writing!) the typical question rolls through our mailboxes: "I get and set cookies like a maniac, but they do not work".
The answer is subtle, very subtle. You must distinguish between the HTTP request (that is sent from the browser to the server), and the HTTP response (that is returned as a reply from the server to the browser). If we want to send a cookie to the browser, we must set the cookie in the response! The request is discarded after it has been processed. If we want to read a cookie from the browser, then look in the request.
It's always:
response->set_cookie( name = 'what_brian_likes' value = 'chocolate chip' ).
And:
request->get_cookie( EXPORTING name = 'what_brian_likes' IMPORTING value = value ).
For the record (for those interested), the set_cookie call places a "Set-Cookie" header field into the HTTP response. The get_cookie reads from the "Cookie" header field in the HTTP request. Having this additional information available makes it easier to understand HTTP traces. See also: Persistent Client State: HTTP Cookies or the new official internet standard RFC 2965.
Why is it possible to do both get and set calls for cookies on both the HTTP request and response? This is because the Web AS can also function as an HTTP client (effectively as a browser), in which case the Web AS is sending out HTTP requests. Then it should be possible to set a cookie in the request.
How to Print a BSP Page?
Question: In my BSP, there is a button used for printing the page. When user clicks on that button, that page should get printed on printer. How can this be achieved?
Answer: A very elegant solution was presented by Raja in SDN. Just add the following code to your BSP page:
<htmlb:button id = "btnPrint" text = "Print" onClientClick = "javascript:window.print()" />
Craig and Maximilian adds the last part of the puzzle: note there are some problems with printing some of the BSP Elements - colours, graphics and things sometimes don't look exactly right. In Internet Explorer, go to menu Extras -> Internet Options -> Advanced. There look for Printing, and the Checkbox "Print background colours and images" - check this setting when/before printing your pages, to make sure you will get the right output.
Handling of Favorites Icon (Favicon)
Favicon is a small image that is displayed left of the URL in the browser's address bar and also with bookmarks. It visualizes the URL to the specific web page with the defined icon. Favicons are images of the size 16x16 or 32x32 pixel in the Icon
format (image/x-icon) and files have an .ico
extension. A favicon has a default name favicon.ico and is by default located in the root folder of the web server. If no favicon is found, the browser sets a default icon.
It is possible to specify a favicon directly in the HTML rendering, so that the browser will retrieve and associate a specific icon with the application. This can be achieved with a <link>
tag inside the <head>
section of the <html>
. For example:
<html> <head> <link rel="SHORTCUT ICON" href="myfavicon.ico" > </head> <body> ... </body> </html>
In an BSP-application using the HMTLB rendering libraries, the favicon can be inserted by using the <htmlb:document*>
tags instead of the <htmlb:page>
tag.
<htmlb:document> <htmlb:documentHead> <link rel="SHORTCUT ICON" href="myfavicon.ico" > <htmlb:headInclude/> </htmlb:documentHead> <htmlb:documentBody> ... </htmlb:documentBody> </htmlb:document>
It is recommended to place the image somewhere in the MIME repository, preferred directly with the application resources, so that relative URL addresses will work in all cases.