SAP TechEd Blog Posts
Share your experiences about SAP TechEd: Write about your favorite sessions and other conference highlights.
cancel
Showing results for 
Search instead for 
Did you mean: 
craigcmehil
Community Administrator
Community Administrator
365
As we live in a virtual world for the most part these days, there are some things we have grown accustomed to, that we like to see.  We’ve also grown used to the fact that we can receive information of a specific nature whenever and wherever we want.

Wonderful example can be found here, this was an article written by DJ Adams and made available on SDN.

In order for the user to see this data, they must of course have a program that reads the RSS feed, the XML file.

Please also refer to this weblog from Brian McKellar:

 

BSP Programming: RSS = HttpClient + XML + XSLT

Now that we have a basic understanding of RSS and how to create it, provide and read it, we’ll move on to how to get our BSP pages to pull data dynamically from other websites and provide it within our own content.

A very common question that comes into play when talking about this topic is, why? Why should I bother to bring content from another website into my own, everyone has internet why not just give the link and move on. Well for one thing in a manufacturing environment, often times your plant floor has limited, if any, access to the internet at all. In such a case it may be useful to provide those individuals with information present on various Internet sites.

A common example I like to share is from within our own company. Many people actually laugh at me when I share this, but it is the truth. One of our plant locations is the middle of the US. During various times of the year this location is pounded with bad weather, during the summer and well just about all year around you can have such bad storms that tornado’s are present, the winter can lead to blizzards and ice storms and the summer and spring to flooding, fall to wild fires. Sound like a dream location? Well back to the point, this plant needed access to the weather and storm warnings available on the Internet. Well at first they were given the Internet access but when you run 24 hours a day there is always the chance that this access is abused. Which in this case it was abused and thus removed. It became the task of our IT force to provide this information without giving them complete Internet Access. Next attempt was simply allowing the domain through the firewall/proxy and being done with it, but this of course let in tons of extra content that people just sat and read about since it was there. Our final solution and one I think worked the best for everyone was to provide the weather data for that location via our own Intranet. We set up our Intranet server with access to the Internet; programs attached to certain web pages ran and had the server access the Internet and return the data.

The process is rather simple to setup and use and I think by the end of this you will see the benefits and usability as well.

Since we are working within a SAP environment the following example will use a simple WebAS 6.20 server and a BSP.

 


Step 1: Proxy server


If you have a proxy server setup in your company you will need to configure your WebAS server for this. In order to access this setting load the transaction

SICF

, and from the menu at top choose

GOTO – HTTP Client Proxy

. Here you can set the properties for

HTTP

and

HTTPS

for your individual proxy settings. You could also have the individuals responsible set the server itself as being free to go to the Internet without proxy authentication.

 

Step 2. Getting Started


In order to get our BSP started, we’ll need to go to transaction SE80, and create a new BSP page under an existing BSP Application or you’ll need to go through the process of creating a new BSP Application.

Once your page is created and in place, we’ll need to define our data variables for use.
data: client TYPE REF TO if_http_client,

path TYPE STRING,

scheme TYPE i,

off TYPE i,

host TYPE STRING,

port TYPE STRING,

content TYPE STRING.

 

Step 3: HTTP Path


Our path is simply the URL which contains the data we want to retrieve which in this case is from NASDAQ.com, we’ll be retrieving the data for the SAP stock Symbol. So what is SAP worth?
</p><br />
<p><span>path = ‘</span><a class="jive-link-external-small" href="http://quotes.nasdaq.com/asp/SummaryQuote.asp?symbol=SAP‘">http://quotes.nasdaq.com/asp/SummaryQuote.asp?symbol=SAP‘</a><span>. if path(8) = '</span><a class="jive-link-external-small" href="https://">https://</a><span>'. scheme = 2. path = path+8(*). elseif path(7) = '</span><a class="jive-link-external-small" href="http://">http://</a><span>'. scheme = 1. path = path+7(*). else. scheme = 1. endif. if path ca ':'. off = sy-fdpos. host = path+0(off). add 1 to off. path = path+off(*). if path ca '/'. off = sy-fdpos. port = path+0(off). "add 1 to off. path = path+off(*). endif. else. if path ca '/'. off = sy-fdpos. host = path+0(off). "add 1 to off. path = path+off(*). else. host = path. path = '/'. endif. endif. If port is initial. if scheme = 1. port = '80'. else. port = '443'. endif. endif. if path is initial. path = '/'. endif.</span></p><br />
<p>

The code above takes our URL apart and makes sure that it is in the proper format in order to invoke our HTTP Client.

 

Step 4: HTTP Client


The HTTP Client is actually the object which we use to go to the Internet and retrieve our data.
*create client object   
call method cl_http_client=>create
EXPORTING
host = host
service = port
scheme = scheme
IMPORTING client = client.

client->request->set_header_field( name = '~request_uri' value = path ).
client->request->set_header_field( name = '~request_method'

value = 'GET' ).

send and receive
client->send( ).

client->receive( ).

Step 5:  Playing with the String


Once we have our client and have gone to our URL we now can load the content into a string and manipulate it.

 

  • display content


content = client->response->get_cdata( ).

Since we can look at the HTML source we can determine our starting and stopping points in order to retrieve the data we want.

Once we have those start and stop points we can then “play” with the string.

 






$ 39.44


  • Get your data


data: tmp TYPE STRING,

p TYPE STRING.

  • Find start point


tmp = content.

p = '$ '.

FIND p IN tmp MATCH OFFSET off.

  • New content


content = tmp+off.

  • Find end point


tmp = content.

p = '</td>'.

FIND p IN tmp MATCH OFFSET off.

  • New content


content = tmp+0(off).

Step 6: Closing


Remember to close your connection, of course at this point you can also change the URL and then…

style="width:350px;background:lightgrey;background-color:lightgrey;border:thin inset">

client->request->set_header_field( name = '~request_uri'

value = path ).

client->request->set_header_field( name = '~request_method'

value = 'GET' ).

  • send and receive<br>


client->send( ).

client->receive( ).

 

  • display content<br>


content = client->response->get_cdata( ).

Also be sure your path is in the proper format. If you are finished, close it.

style="width:350px;background:lightgrey;background-color:lightgrey;border:thin inset">

  • Close Client<br>


client->close( ).

So as you can see the amount of effort put into making the solution is relatively small, and once the solution is in place a nice BSP Tag could be created to make the implementation into your projects very simple.

So where is the hard part? There is always a hard part, the hard part is making sure the website you are going to doesn’t change it’s format as well as figuring out how to trap just the data you want (start and stop point).

References:

Code samples and links, http://sdn.sap.com

Definitions and format, https://blogging.com/rss-dead/

 

You can alos grab the whole presentation and write-up here (ZIP 332KB)

 
2 Comments