jeff.gebo

7 Posts

OData Channel API – Implementing Paging of Entity Sets

Take 2 - make sure to read the second code snippet, much improved!

 

This week I am on board the SAP Train Race helping to support the teams that are developing cool apps based on SAP NetWeaver Gateway in hopes of winning some prizes as well as being featured at SAP Teched Madrid. One of the participants asked me how paging was supported in OData Channel API based services. I knew this was possible but I have never actually tried it with OData Channel…so I told him let me code something up as an example for you…I figured it would also make a good blog as I am sure in the future many people will want to implement this behavior.

 

We know that the OData standard supports paging on “Query” aka “retrieveEntitySet” operation via the URL query string parameters $top=x and $skip=y. Where $skip=y means to skip the first y entities, and $top=x means to grab the next x rows proceeding the skipped rows. An example of how this would look on a “Query” URL is this:

http://gateway:port/service_uri/BankSet?$top=5&$skip=15 

In theory, this should result in returning rows 16 to 20, but how to make this happen in the GET_ENTITYSET method of an OData Channel Entity data object?

 

First off, I have to admit, my ABAP skills are still a little rusty...went on a major Java detour for quite a bit of time…but now I am back…let’s see how this goes. J

 

If you look at the signature of the GET_ENTITYSET method you will notice a structure parameter named IS_PAGING. This structure has two attributes, TOP and SKIP...and you guessed it…if the $top and $skip parameters are present on the “Query” URL these values will be pushed into this corresponding structure attributes. So now the trick is how to construct the SELECT statement to use these vales.

 

So here is how I did it, I would be interested to know if you have a better way to go about this!

 

First off, I wanted to still support queries that didn’t pass in $skip and $top…so an if statement checking if $top is greater than zero would suffice (note: if $top and $skip are not set on the URL their values in the IS_PAGING structure will be zero)…if $top is zero, just go thru the old select statement, if $top is greater than zero we are doing some paging of the result set. One last note, I guess I could have supported when $top equals zero and $skip is greater than zero but I didn’t…if you want to do this you should be able to figure it out from the below code example. Ok, that said here is the code snippet from my first attempt (note: you must put this sort of code in the appropriate place of the GET_ENTITYSET method):

 

 

 
 

* Check if we are paging or not

 

 

 

if   ( is_paging-top > 0 ).

 

 

 

* total rowcount to select is skip +   top

 

    rowcount = is_paging-top +   is_paging-skip.

 

 

 

* select the data into an internal   table

 

    SELECT banks bankl banka FROM BNKA

 

           INTO CORRESPONDING FIELDS OF TABLE   lt_bank

 

           UP TO rowcount ROWS

 

           WHERE BANKS IN   lt_range_bank_country.

 

 

 

* make sure the number of rows returned   is greater than the number to skip

 

    if ( sy-dbcnt > is_paging-skip ).

 

 

 

* initialize the skip variable used to   read the proper rows    

 

      skip = is_paging-skip.

 

 

 

* loop over the table top times

 

      do is_paging-top times.

 

 

 

* increment skip - get the next row   after the skip count     

 

        skip = skip + 1.

 

 

 

* read the table starting at row skip +   1

 

        read table lt_bank index skip into   wa_bank.

 

 

 

* get the values we are after into the   return table

 

        ls_bank-id = wa_bank-bankl.

 

        ls_bank-bankcountry = wa_bank-banks.

 

        ls_bank-name = wa_bank-banka.

 

        append ls_bank to et_resulttable.

 

 

 

* see if we stil have more rows in the   internal table

 

* if not exit out of the loop

 

        if ( skip >= sy-dbcnt ).

 

          exit.

 

        endif.

 

      enddo.

 

    endif.

 

  else.

 

 

 

* this is just our standard select   without paging support

 

    SELECT banks bankl banka FROM BNKA

 

           INTO (ls_bank-bankcountry,   ls_bank-id, ls_bank-name)

 

           WHERE BANKS IN   lt_range_bank_country.

 

      append ls_bank to et_resulttable.

 

    ENDSELECT.

 

 

 

  endif.

 

 

 

 

 

 

So from the above code in the paging section, you can see we basically just select all the data (up to skip+top number of rows) into an internal table and from there we just get the rows that we actually want based on the top and skip values.

 

Take 2 – so I posted the original blog above only to find out an hour later that a utility class exists that will do the paging over any internal table! ARG!!! If I had only knew about that before…in any case, using this utility class (/IWBEP/CL_MGW_DATA_UTIL) makes life very easy to page over results. All you need to do is pass the static PAGING method the IS_PAGING structure and your internal table you want to page over. Here is the new resulting code using this class:

 

 
 

 

 

* if top is greater than 0 then we only   need

 

* skip + top rows returned – we are   limiting the data

 

* we are pulling from the DB

 

  if ( is_paging-top > 0 ).

 

    rowcount = is_paging-top +   is_paging-skip.

 

    SELECT banks bankl banka FROM BNKA

 

           INTO CORRESPONDING FIELDS OF TABLE   lt_bank

 

           UP TO rowcount ROWS

 

           WHERE BANKS IN   lt_range_bank_country.

 

  else.

 

* if top is equal to zero we need to   get all rows

 

    SELECT banks bankl banka FROM BNKA

 

 

 

 

 

           WHERE BANKS IN   lt_range_bank_country.

 

  endif.

 

 

 

* pass the IS_PAGING structure and   internal table

 

* into the static paging method

 

  CALL METHOD   /IWBEP/CL_MGW_DATA_UTIL=>PAGING

 

    EXPORTING

 

      IS_PAGING = IS_PAGING

 

    CHANGING

 

      CT_DATA   = lt_bank.

 

 

 

* put the data into the return table

 

  loop at lt_bank into wa_bank.

 

    ls_bank-id = wa_bank-bankl.

 

    ls_bank-bankcountry = wa_bank-banks.

 

    ls_bank-name = wa_bank-banka.

 

    append ls_bank to et_resulttable.

 

  endloop.

 

 

 

 

 

The SAP Train Race has been an awesome experience so far...without it I would not have learned of this easy way to page over result sets...its really nice to be working so closely with development here on the train.

I hope this helps you with your OData Channel API coding! 

Gateway as defined by Dictionary.com as any passage by or point at which a region may be entered. I think this aptly describes what SAP NetWeaver Gateway is all about. It’s about providing an entry point into SAP systems for all the millions of developers out there that don’t know SAP. You might have heard that one of SAP’s goals is to reach 1 billion users. SAP isn’t going to reach that goal with the current crop of interfaces into its business systems (think RFC, Enterprise Services), which for the most part require you to be an SAP expert to talk to SAP…not fun for Java/XCode/Perl/etc. developers. With Gateway you will be able to easily expose your SAP business content as simple REST based services.

 

With all this in mind I signed up to do the RIG’s June 1st, 2011 KHNC webinar on the topic of SAP NetWeaver Gateway Overview. My goal was to make this webinar a Gateway for viewers to SAP NetWeaver Gateway. Now I have to admit, the title has “Overview” in it, but I went a bit further than that…in addition to overview type slides I decided to include slides on the ways to generate and test Gateway services…so it’s more than an overview in that it gives you a feel for what it will be like to create and test these Gateway services.

 

If you have the time I hope you can spend it listening to the recorded webinar. Any question that might arise please post them in the comment section of this blog, I will be more than happy to answer.

h4. Creating and Managing Local Update Sites for SAP NetWeaver Developer Studio 7.2    Starting with SAP NetWeaver Composition Environment 7.1 the SAP NetWeaver Developer Studio (NWDS) was installed and upgraded from what is called an Update Site. This allowed developers a place to go and find the installation files for NWDS, and in addition enabled them to upgrade their NWDS plug-ins. No longer was it necessary to remove the NWDS and re-install it as it was in the days of NWDS 7.0 and 640. This was a huge improvement.   There is an update site available on the Service MarketPlace (SMP) for both CE 7.1.1 and CE 7.2, you can find them here:    CE 7.1.1 Update Site: https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/nw/711/  (https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/nw/711/)     CE 7.2 Update Site: https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/nw/720/  (https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/nw/720/)    While this is good to know, it is recommended that you create a local update site which would mirror the SMP update site. This local update site is administered by one person and is then made available for all developers to access. To setup an update site on AS Java 7.1 or 7.1.1 you would install the update site Software Components, and from there you could use a configuration template to mirror the SMP update site, thus making the NWDS install and updates available locally. As you will read in this blog the process of creating and managing local update sites in CE 7.2 has changed quite a bit.   For those of you that have used CE 7.1 and/or 7.1.1 it might come as a shock to you that the local NetWeaver Developer Studio (NWDS) update site as you knew it has been deprecated in CE 7.2. Oh, you can find the Software Components to install the update site on CE 7.2, but when you access the update site, you will be greeted with this message:image  The important information is the word Deprecated, which in this case means no longer supported. So you might be wondering at this point whether it is no longer possible to create local update sites. Without local update sites for updating NWDS your developers would have to pull down updates from the update site on the SMP. This would work, but there are a few issues associated with it.    ** Downloading all the installs and updates for NWDS from the SMP update site takes quite a bit of time. Most developers I know don't want to wait that long to install or upgrade NWDS. It would be much more efficient to have one person download everything needed and then share them with everyone else on the local network. ** Every support pack and patch for the NWDS is available on the SMP making it very easy for your developers to download a version of NWDS that isn't the exact same version of the AS Java 7.2 that they will be developing and deploying too (if the AS Java 7.2 is on Support Pack 2, then the NWDS must be on Support Pack 2). So it is much better to maintain your own update site where you are in complete control over the NWDS releases that your developers can access and use.    As of CE 7.2 there is a new process to create and maintain local update sites. You can find some help on this here: http://help.sap.com/saphelp_nwce72/helpdata/en/d2/fd75581d5a4fff8f6369322fd145f8/content.htm  (http://help.sap.com/saphelp_nwce72/helpdata/en/d2/fd75581d5a4fff8f6369322fd145f8/content.htm)     Basically what the help documentation explains is that you now create local update sites from NWDS itself. To get the process started in the NWDS you select menu path +Help > Manage Local Update Sites+.   image  This will launch the following dialog window:image  As you can see, all that needs to be entered is the URL for the source of the update site (the source URL should always point SMP update site), the directory of the target update site where the files will be stored, and the URL of the target update site which will be used by developers to access the updates. Now this is where the fun really begins. What should this target URL be? How can I make it available via the AS Java 7.2? Before we can run this wizard to create a local update site we need to first answer these questions.      *+What should the target URL be for the local update site?+*    There are two options for the target URL. The first option is what I describe in detail here and that is to expose the update site over HTTP. The second option is to use a file share. In the case of using a file share the target URL will look something like this: file:///server_name/updatesite  (file:///server_name/updatesite). Personally I have always shied away from file shares because I have had too many issues when it comes to security on them. That is why I like to expose the update site via HTTP. That said, using a file share is supported and can certainly be made to work.. But what alias should you use? Well that is completely up to you. It will need to be unique. I personally use the alias +downloads/updatesite+. Reason being is that I create an HTTP alias called downloads which allows me to share files over HTTP (files and folders stored under the downloads folder are made accessible via a browser – I wrote a blog  (Create a Simple File Share with AS Java) on how to do this in AS Java 7.0); under this I create the folder updatesite to contain NWDS update files. So that brings the full URL to *+How can I make this URL accessible from an AS Java 7.2?+*   You do this by creating an HTTP alias in the NetWeaver Administrator of the AS Java. In turn the alias points to a folder location on the file system that contains the folders and files you want accessible. The following steps will guide you thru creating an HTTP alias on the AS Java 7.2.      *Creating a Simple File Share with AS Java 7.2*   *1)* Logon to the NetWeaver Administrator of your AS Java 7.2.   *2)* Select +Configuration Management > Infrastructure > *Java HTTP Provider Configuration*+.   *3)* +Optional:+ On the General tab of the HTTP Provider, select the checkbox to allow directory listing. image By enabling Directory List, the AS Java will generate a simple HTML page listing out the contents of the alias, this makes for a simple file share where you can simply copy files to a directory and have them easily available for download over HTTP. See an example of this done in AS Java 7.0 here  (Create a Simple File Share with AS Java).     *4)* Select the +Aliases+ tab.   *5)* Click the +Add Alias+ button. Enter the name of the HTTP alias (in this case "downloads") and the location on the file system where the alias will point to (in this case "D:/downloads"). *+Note+*+: you need to create the folder (in this case D:/downloads) on the file system...entering it here will not create it for you.+ image   *6)* Save your changes by clicking the +Save+ button.   *7)* Folders and files created under D:/downloads will be accessible over the HTTP alias /downloads. All you need to do now is create the updatesite folder under D:/downloads.    Now we are all set to run the Manage Local Update Sites wizard.      *Creating the Local Update Site*   *1)* In NWDS select menu path +Help > Manage Local Update Sites+. Enter in the source URL (always should point at the SMP update site): https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/nw/720/  (https://nwds.sap.com/swdc/downloads/updates/netweaver/nwds/nw/720/)   *2)* Enter in the target directory and URL. image   *3)* Click the +Next+ button. *+Note+*+: At this point you will be asked to enter in a user ID and password. This is the same user ID and password that you use to access the SMP.+   *4)* Select the NWDS Support Pack and patch levels that you want mirrored onto your local update site. image

Have you or do you have plans for a custom java implementation based on SAP AS Java and using the NetWeaver Development Infrastructure? If so then you will want to join me in the Community Clubhouse for an expert session on how to speed up your Component Build Service (CBS) performance titled "How to speed up your build time with NWDI - Learning common pitfalls". This session is based on a true story; yes I said it, a true story! The customer had a very large custom scenario developed with more than 100 Web Dynpro Development Component (DCs), and numerous other types of DCs (CAF, Java, etc.), and they faced build times of up to 6 hours! What caused this? What was done to resolve it? Come to the session to find out! Why find out the hard way? You can learn from those you went down the path before you.

 

Of course after the session is over I will be free to answer any of your NWDI and / or Java based implementation projects. I look forward to seeing you at the Clubhouse!

Please join me in the Community Clubhouse for an expert session on how to properly use Development Components and Public Parts in SAP NetWeaver Developer Studio called "Be the Expert - Proper Usage of Java Development Component Public Parts". In this session I will cover what Development Components (DCs) and their Public Parts are for, and what they are and do behind the scenes. In addition, you will learn how to avoid some of the most common mistakes out there when it comes to working with DCs.  It is my hope that this session will help you java implementations go smoother today and into the future.

 

Topics to be covered:

  • What are DCs and Public Parts?
  • What is an Assembly Type Public Part?
  • What is a Compilation Type Public Part?
  • What not to do with Assembly Type Public Parts!
  • Improvements that have been made in NWDS 7.1 (and up).
  • What all the dependency types do (Build time, Runtime, Deploy time and Design time).

 

Of course after the session is over I will be free to answer any of your NWDI and / or Java based implementation projects. I look forward to seeing you at the Clubhouse!

Last year I was developing an internal application on the AS Java stack that consisted of Web Dynpro for the UI, EJBs for the business logic and Java Dictionary Tables for the storage of data. Having done a lot of ABAP development in the past I was used to tools that would allow me to look at the table data stored in the tables that I was using. Not only this, but there are also tools in ABAP to transport table data from one system to another. I needed these sort tools for the Java application that I was creating...sure I could survive without them but it would save me a lot of time if I created these tools for myself.

So I create this utility that I call the Java Dictionary Table Maintenance Utility Tool. I figured a lot of other Java developers out there could use this tool so I released it on SDN last year. Since then I have received numerous emails about this utility, ranging from feature suggestions, bug fix requests, requests for the source code, to just plain thanks. I really appreciated all of these emails and I wish I could have acted upon them all earlier. That said I recently had time to take heed of all the suggestions that were sent to me and create a version 2.0 of the tool which can be downloaded here. In addition, I updated the help documentation that goes along with the tool which can be accessed here. In the documentation you can learn how to install and run the utility.

I know a lot of you requested the source code for this application. I really wish I could share it with you but for legal reason I currently can't. It sure would be great if the SAP Java development community could start an open source forge where we can together create and improve such tools. We really need to do this. That said, if you are working at SAP and want to contribute anything to this tool please let me know, I could easily add you to the NWDI system so that you can access the development track...just let me know, would be great to have such collaboration going on even if it is only internal at this point in time.

The current state of the tool is that it runs on AS Java 04 and 70. It currently doesn't run on CE 7.1. I might make a new release in the future for CE 7.1 if there are any requests for it. The thing with CE is that is uses the latest Eclipse version (3.3) that comes with some nice plug-ins to view table data...although there is nothing there to export and transport table data into different AS Java's. Anyway, we'll see what happens.

Even though I call this version 2.0 of the tool, it isn't really a major update...more like an Enhancement Pack. Here is a list of the new features:

  • Ability to sort and filter the table data. Quite useful for getting to the rows that you need to work with.
  • Ability to set default values for number of rows returned from the table, and number or rows to display in the Table UI.
  • Add authentication, the user that logs on must be part of the Administrator role on a AS Java only stack, or the GRUP.R3_ROLE_DS.SAP_J2EE_ADMIN role on a AS Java + AS ABAP stack, where AS ABAP user store is used.
  • Fixed bug with FLOAT types.
  • Fixed other random bugs.

I hope you find the tool useful to your development endeavors, and if you run into any problems you can drop me an email at jeff.gebo@sap.com.

Cheers,
Jeff

Create a Simple File Share with AS Java

 

I started using this method of creating a file share a few years back when teaching a class. The students needed to download some files of the network but unfortunately share drives on the version of Windows on my laptop only allowed 10 connections...this caused a lot of issues with trying to get the students the course content they needed. So I used this handy little method that might help you too.

Prerequisites

You need the SAP AS Java up and running. This particular document is based on AS Java 04s (7.00), but the same setup is possible using the 04 (6.40) version as well.

How it Works

You just need to create a folder that contains the content you want to share. Then create an HTTP alias that is mapped to this folder. Once this is done the alias can be accessed by other via a browser.

Browser Share

Steps for creating the share

Step 1

Create a directory somewhere on a hard drive that you want to share the contents of. For instance C:\downloads would work.

Step 2

Start the Visual Administrator and logon to the AS Java, once logged on go to the HTTP Provider service of the server node.

HTTP Provider

Step 3

Select the Runtime tab, and then the General tab. Here you need to check the "Directory List" checkbox. Click the "Save Properties" button.

Directory List

Step 4

Switch to the Aliases tab. Enter the alias name in the Alias textbox. Enter the folder that you want to share in the Path textbox. Click the Add button and then click the Save Properties button.

Aliases

Step 5

You should now be able to browse and download any content that exists in the folder (and any sub folders) that the alias it mapped to. The above alias configuration would be shared out with the following URL: http://:/download

Browser Share

This of course be used for more than just a way to share documents. You could also load static web content into this alias and have your web applications use the images and other content stored there. Web Dynpro does just this...you might notice that a Web Dynpro alias already exists! This is where all the images and other static content is stored and accessed from.

Actions

Filter Blog

By date: