Share on Facebook12Share on LinkedIn65Tweet about this on TwitterShare on Google+2
Please Share!!

In the previous post on AMDP in SAP HANA , we learned about the basics of AMDP. What is AMDP, How to declare an AMDP class, How to identify an AMDP method? We also consumed the AMDP Class method is our Program and displayed the output.

If you have not visited the earlier article or if you have not worked in AMDP earlier, we would sincerely suggest you have a glance of that topic so that you can understand this and appreciate this article.

In the example demonstrated in the earlier article, all the selection screen elements were PARAMETERS. Using the PARAMETERS in AMDP Method SELECTs were straight forward. Today we would show how we can pass SELECT OPTIONs of the screen to AMDP Methods and use them. Please note, we cannot directly pass SELECT options as is it to AMDP Methods. This is one limitation of AMDP. We need to select the data from the database and then APPLY the Filter using the function APPLY_FILTER.

Let us hit it hard again. AMDP Class-Methods cannot take SELECT OPTIONS as input. So SELECT OPTIONS need to be converted to FILTER STRING using some way and then pass the FILTER STRING as an input PARAMETER of the of the AMDP Method.

The actual syntax to filter the selected data would look like below:

EX_IT_TCODE_ROLE would have all the data and APPLY_FILTER would keep the subset using IP_FILTERS value.

How do we pass IP_FILTERS?
Ans: It has to be passed as STRING.

How do we generate the filter string from SELECT OPTIONS?
Ans: You are the programmer, you find your way to generating the filter. 😀 It should act as the WHERE clause. Or like the FILTER using RANGE table. 🙂

Do not worry, we would show you an easy way. 😛


If S_TCODE and S_ROLE are two SELECT OPTIONS of a program, then the string for AMDP filter can be generated using the class CL_SHDB_SELTAB method COMBINE_SELTABS as shown below.


If the above syntax is little confusing, then check the alternative for the same syntax.

Feeling better now?

Add class CL_SHDB_SELTAB method COMBINE_SELTABS on your cheat sheet. 🙂

Frequently Asked Question on HANASAP HANA for Beginners from a Beginner?

What does the above class method do?
Ans: See it yourself in debug mode. 🙂


I am sure by now you are curious to know how we use it in the Program (after all you are a programmer by heart). 🙂 .

Real Time working Program to show handling of SELECT OPTION in AMDP:

Real AMDP Class Method showing usage of APPLY_FILTER for SELECT OPTIONS:

Also Read: ADBC – ABAP DataBase Connectivity.

Some point for the explorers.

1. If you do not want to use CL_SHDB_SELTAB=>COMBINE_SELTABS to build your Filter String, you can do it yourself using CONCATENATE function.

It is same as ( AUGDT = ‘00000000’ OR AUGDT = ‘20161129’ ).

2. If you think the below syntax to generate the dynamic WHERE CLAUSE string is bit complex, then try to use the alternative.

This alternative shown below is a lengthy approach but might be simple and easy to understand for some of us. After all, everyone has the right to be different. 🙂

Let us see in debug mode, how lty_named_dref look like.


No brainer: Output of lv_where need to be the same.

sap amdp
Huh!! I am sure by now you are convinced that you would rather spend some time understanding new syntax at the top of this article than writing this bunch of redundant codes shown above. 🙂 . Our job was to place all the MENU, it is up to you to decide which one you like. 😛

Read more:  New Age Open SQL ABAP 740

3. If you observe the code for APPLY_FILTER closely, you would notice, filtering is done after we select a bunch of unwanted data and apply the Filter. Doesn’t it impact the performance negatively?

See, we selected everything here.

Then we applied the Filter.

Experts suggest wherever possible, we should apply the filter to the DB table directly and then play around with the resultant data set.

For example, if ip_code_where_clause has S_TCODE select option, then we can directly apply the filter on the database table AGR_1251.

Thus, APPLY_FILTER function can be applied to DB Tables and also it can be applied to Internal Tables.

After the epic is over, let us introduce the main character of our today’s story, i.e. APPLY_FILTER. The function APPLY_FILTER expect two PARAMETERS.

i – Dataset (example AGR_1251 (DB table, CDS View); :ex_it_tcode_role (Internal table)) which needs to be filtered.

ii – Generated WHERE clause which is passed to AMDP method as String.

4. After going through the above information one would have a doubt. Why did SAP not allow SELECT OPTIONS to be directly used in AMDP as in normal ABAP?
Ans: We would request experts to provide some explanation to this query.
We feel SAP deliberately chose this path to push down the select option to database level in accordance with its code to data paradigm shift strategy. AMDPs are executed directly on the database, hence the select options in the form of filter string would be executed on the database. On the other hand SELECT OPTION is just an ABAP language construct which cannot be directly executed on database level

Hope this article is clear enough to demonstrate the concept and usage of APPLY_FILTER in AMDP in ABAP Programs. This post would act as a guide to newbies who want to handle the SELECT-OPTIONS parameters within AMDP.

SAP ABAP for HANA Tutorial. Part XI. Are Native SQL and Open SQL Competitors?

If you want to get such useful articles directly to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.

If you liked this post, please hit the share buttons and like us on facebook.

Do you have anything to add to this article? Have you faced any issue using AMDP? Do you want to share any real project requirement or solutions? Please do not hold back. Please leave your thoughts in the comment section.

Thank you very much for your time!!

Useful Tutorials on SAPYard

1. ABAP for SAP HANA Tutorials
2. ABAP Web Dynpro Tutorials
3. GOS Tutorial
4. OOPs ABAP Tutorial
5. HANA Tutorial
6. SAP Netweaver and OData Tutorial
7. SAP Adobe Form Tutorial
8. SAP Fiori Tutorial
9. SAPUI5 Tutorial

Share on Facebook12Share on LinkedIn65Tweet about this on TwitterShare on Google+2
Please Share!!

About the Author

SAP Yard
SAP Yard
SAPYard is one stop page for all Technical Folks in SAP. You would find un-conventional explanations, tutorials, and tricks. Please like our Facebook Page and also join our LinkedIn Group.

1 Comment on "ABAP on SAP HANA. Part X. AMDP with SELECT OPTIONS"

  1. I try this approach and the thing is doing an aggregated SUM joining 3 tables it’s faster using Advanced OPEN SQL than AMDP.

    The problem with AMDP is that you have to know a lot of SQL, after I read an official SAP documents that state “Imperative Logic prevents Parallel proccesing” I became a sceptic of AMDP.

    All the examples that you can find out there of AMDP are very simple and those are faster using OPEN SQL, some ppl told me if you make the same query using OPEN SQL will be allways faster, that I have to Code Pushdown in AMDP. But then if you start using loops and IF prevents Parallel processing ??? I hope someone can prove I’m wrong and SAP provide solid and good guidelines.

Comments are closed.