如何在AMDP中使用SELECT-OPTION
来源:互联网 发布:手机短信恢复 软件 编辑:程序博客网 时间:2024/06/05 11:36
转载自:http://www.sapyard.com/abap-on-sap-hana-part-x-amdp-with-select-options/
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:
* Filtration based on Selection screen inputex_it_tcode_role = APPLY_FILTER( :ex_it_tcode_role, :ip_filters );
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.
METHODS get_t_code_role_matrixIMPORTINGVALUE(ip_object) TYPE agobjectVALUE(ip_langu) TYPE menu_sprasVALUE(ip_line) TYPE menu_num_5VALUE(ip_filters) TYPE string " PARAMETER for the SELECT OPTION StringEXPORTINGVALUE(ex_it_tcode_role) TYPE tt_tcode.
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.
DATA(lv_where) = cl_shdb_seltab=>combine_seltabs(it_named_seltabs = VALUE #(( name = 'TCODE' dref = REF #( s_tcode[] ) )( name = 'ROLE' dref = REF #( s_role[] ) )) ).
If the above syntax is little confusing, then check the alternative for the same syntax.
cl_shdb_seltab=>combine_seltabs(EXPORTINGit_named_seltabs = VALUE #(( name = 'TCODE' dref = REF #( s_tcode[] ) )( name = 'ROLE' dref = REF #( s_role[] ) ))RECEIVINGrv_where = DATA(lv_where) ).
Feeling better now?
Add class CL_SHDB_SELTAB method COMBINE_SELTABS on your cheat sheet.
Frequently Asked Question on HANA: SAP 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:
*--------------------------------------------------------------------** Created by: www.sapyard.com* Created on: 29th Nov 2016* Description: This program consumes the AMDP Class/Method and* shows how to send SELECT OPTIONS to AMDP and use* APPLY_FILTER function in AMDP Method.*--------------------------------------------------------------------*REPORT zmm_tcode_role_report NO STANDARD PAGE HEADINGLINE-COUNT 132.*--------------------------------------------------------------------** TABLES*--------------------------------------------------------------------*TABLES: agr_define. *--------------------------------------------------------------------** DATA DECLARATION*--------------------------------------------------------------------** Inline data declaration for the AMDP Class InstanceDATA(lr_data) = NEW zcl_user_role_amdp( ). *--------------------------------------------------------------------** SELECTION SCREEN*--------------------------------------------------------------------*SELECTION-SCREEN: BEGIN OF BLOCK block1 WITH FRAME TITLE text-t01.SELECT-OPTIONS:s_tcode FOR syst-tcode,s_role FOR agr_define-agr_name.SELECTION-SCREEN: END OF BLOCK block1. *--------------------------------------------------------------------** INITIALIZATION.*--------------------------------------------------------------------* *--------------------------------------------------------------------** START-OF-SELECTION.*--------------------------------------------------------------------*START-OF-SELECTION. * Build where clause for data fetching* Class-Method to convert the select options to a dynamic where clause which* will be passed to the AMDP for data filteration after data selectionDATA(lv_where) = cl_shdb_seltab=>combine_seltabs(it_named_seltabs = VALUE #(( name = 'TCODE' dref = REF #( s_tcode[] ) )( name = 'ROLE' dref = REF #( s_role[] ) )) ). * Calling the AMDP method to get the dataCALL METHOD lr_data->get_t_code_role_matrixEXPORTINGip_object = 'S_TCODE'ip_langu = sy-languip_line = '00000'ip_filters = lv_whereIMPORTINGex_it_tcode_role = DATA(it_tcode_role). *--------------------------------------------------------------------** END-OF-SELECTION.*--------------------------------------------------------------------*END-OF-SELECTION. * Publishing the data in an outputcl_demo_output=>display_data(EXPORTINGvalue = it_tcode_rolename = 'AMDP to show APPLY_FILTER function' ).*--------------------------------------------------------------------*Real AMDP Class Method showing usage of APPLY_FILTER for SELECT OPTIONS:
CLASS zcl_user_role_amdp DEFINITIONPUBLICFINALCREATE PUBLIC . PUBLIC SECTION. INTERFACES if_amdp_marker_hdb. TYPES:BEGIN OF ty_tcode,tcode TYPE agval,ttext TYPE ttext_stct,role TYPE agr_name,rtext TYPE agr_title,END OF ty_tcode . TYPES:tt_tcode TYPE STANDARD TABLE OF ty_tcode . METHODS get_t_code_role_matrixIMPORTINGVALUE(ip_object) TYPE agobjectVALUE(ip_langu) TYPE menu_sprasVALUE(ip_line) TYPE menu_num_5VALUE(ip_filters) TYPE stringEXPORTINGVALUE(ex_it_tcode_role) TYPE tt_tcode. PROTECTED SECTION.PRIVATE SECTION. ENDCLASS. CLASS zcl_user_role_amdp IMPLEMENTATION. METHOD get_t_code_role_matrixBY DATABASE PROCEDUREFOR HDBLANGUAGE SQLSCRIPTOPTIONS READ-ONLYUSING agr_1251 tstct agr_texts. ex_it_tcode_role = select a.low,b.ttext,a.agr_name,c.textfrom agr_1251 as ainner join tstct as b on a.low = b.tcodeinner join agr_texts as c on a.agr_name = c.agr_namewherea.mandt = :ip_clientAND a.object = :ip_objectAND b.sprsl = :ip_languAND c.spras = :ip_languAND C.LINE = :ip_lineORDER BY a.low, a.agr_name; * Filtration based on Selection screen inputex_it_tcode_role = APPLY_FILTER( :ex_it_tcode_role, :ip_filters ); ENDMETHOD. ENDCLASS.
- 如何在AMDP中使用SELECT-OPTION
- 如何在AMDP 中定义和使用变量
- Jquery select option在html中使用
- Jquery select option在html中使用
- 如何在select中option添加复选框
- select(poll)在应用程序中如何使用
- select(poll)在应用程序中如何使用
- select 中option的使用以及动态增加select
- select中option解析
- select option的使用
- javascript中如何获取<select>标签中<option>的值
- 如何修改jquery easyui select中option背景颜色
- 如何通过js动态设置select中option选中
- 在javascript中增加select控件的Option选项
- abap-在自定义屏幕中添加 select-option
- abap-在自定义屏幕中添加 select-option
- 【android】在fragment中使用option menu
- 如何在SQL Server中的SELECT TOP 中使用变量
- 17. Letter Combinations of a Phone Number
- MySQL下载与安装
- cogs2632. [HZOI 2016]数列操作d
- 对__stdcall和__cdecl的简单了解
- 实现用鼠标拖动没有标题栏的窗口(窗体的任何部分都可实现拖动效果)
- 如何在AMDP中使用SELECT-OPTION
- Git 分支管理和冲突解决
- Java基础的一些小问题
- JavaWeb中Model1简介
- 设计模式之单例模式三种实现
- Art Gallery POJ
- 1.绪论
- UE4--Log写入到单独文件中
- 分类器性能评价总结