Build Custom Selection Screens for Extended Table Maintenance

作者:郑德鼎 约 6 分钟阅读 更新日期:2024-02-22 2 年前更新 标签:ABAP, CO, Data Engineering, FI, MM, PP, SD, WM, 仓库管理, 开发, 数据工程, 物料管理, 生产, 财务, 销售分销

*----------------------------------------------------------------------*

***INCLUDE LZT811FF01.

*----------------------------------------------------------------------*

* Define a custom selection screen.

SELECTION-SCREEN BEGIN OF SCREEN 10.

PARAMETERS p_tab TYPE DBNAM obligatory DEFAULT 'CCSS'.

PARAMETERS p_CYCLE TYPE CYCLE obligatory.

PARAMETERS p_SDATE TYPE SDATE obligatory.

SELECTION-SCREEN END OF SCREEN 10.

* This form is called to restrict the selection

FORM custom_selscreen.

PERFORM GET_DATA_ZT811F.

* Call the custom selscreen as a popup

CALL SCREEN 10 STARTING AT 30 10.

* Define a structured variable to read data

DATA BEGIN OF ls_total.

INCLUDE TYPE zt811f. INCLUDE TYPE vimtbflags.

DATA END OF ls_total.

** If the user didn't enter anything, don't filter

*  CHECK p_TAB IS NOT INITIAL.

IF p_TAB IS NOT INITIAL AND p_CYCLE IS NOT INITIAL

AND p_SDATE IS NOT INITIAL.

* Now apply the filter

LOOP AT total.

*   Move data so it is accessible via structure

ls_total = total.

*   Check if the given BUKRS is contained

IF ls_total-tab = p_tab AND ls_total-CYCLE = p_CYCLE AND ls_total-SDATE = p_SDATE.

ELSE.

*     Filter rows

DELETE total.

ENDIF.
ENDLOOP.

ELSE.

LOOP AT total.

DELETE total.

ENDLOOP.
ENDIF.
ENDFORM.

Admin

CA-DMS

CA-TS

CO

CS

FI

LE

MM-IM

MM-PUR

PM

PP

PS

QM

SD

WM

dev.wb

SAP Developer Workbench

The best resource for SAP and ABAP Knowhow

Blog

SAP Modules

SAP Data Objects

SAP Dictionary

SAP Definitions

Build Custom Selection Screens for Extended Table Maintenance

2014-08-19         ABAP Tables

In another post on the extended table maintenance feature of SAP ERP, I’ll explain today how to use the event AA to build a custom selection screen for extended table maintenance.

The problem with filtering in extended table maintenance

Generated table maintenance dialogs have some filtering capabilities by default. It is possible to restrict the displayed values via the menu entry Selection > By Contents, but the interface is quite complicated and cumbersome.

The standard filtering in extended table maintenance is not very usable.

Wouldn’t it be much nicer if we could just have a selection screen to restrict the displayed values, just like we know from SE16 and any report transaction? Well, we can! SAP provides the event AA: Instead of the Standard Data Read Routine to do just that. Let’s walk through the necessary steps to create a custom selection screen for the SM30 maintenance functionality.

How to build a custom selection screen for SM30

The first step is to add the hook AA to the events overview. If you’ve read my last post about extended table maintenance, you already know how to do this. Open your table and go to the table maintenance generator. Then select Environment > Modification > Events to open the events overview. Add the event AA, enter a FORM name and save.

Adding the event for custom selection screens

Now go to the editor. The first thing we need is, of course, the selection screen that we’re going to show. In my example, I’m defining a simple screen with just the company code as a parameter to restrict the values shown. In code, it looks like this.

* Define a custom selection screen.

SELECTION-SCREEN: BEGIN OF SCREEN 10.

PARAMETERS p_bukrs TYPE bukrs.

SELECTION-SCREEN: END OF SCREEN 10.

Next, we need to define the FORM routine that is called by the event AA.

* This form is called by the event AA

FORM custom_selscreen.

Since we’re implementing our own data reading routine, we would now have to read the data in table ZMYTABLE from the database. We could use OpenSQL for that, but there’s a better way. There are already pre-defined FORM routines that do the data reading job for us. They are:

TABLE_GET_DATA if the underlying object is a table

GET_DATA_<viewname> if the underlying object is a view.

In this case I’m using TABLE_GET_DATA since the maintenance generator is based directly on the data table.

* Read all data into TOTAL first

PERFORM table_get_data.

After executing this call, all the data from the database is in the internal table TOTAL. After that is done, we can show our selection screen. Here it’s done as a modal popup by using the addition STARTING AT, but we could also omit that and display it as full-screen. After the popup has been executed, we have the filter value in the parameter P_BUKRS. I’ve added a statement that doesn’t apply the filter when the value is empty, but that’s optional.

* Call the custom selscreen as a popup

CALL SCREEN 10 STARTING AT 20 10.

* If the user didn't enter anything, don't filter

CHECK p_bukrs IS NOT INITIAL.

Now, all we need to do is loop over the data in the table TOTAL, apply the filter condition, and remove the record from the table if it doesn’t match. In order to have structured access to the table, we need to define a structured variable first that the data is moved into. Remember: the structure of the TOTAL table equals the base table plus the structure VIMTBFLAGS.

* Define a structured variable to read data

DATA BEGIN OF ls_total.

INCLUDE TYPE zmytable.
INCLUDE TYPE vimtbflags.

DATA END OF ls_total.

* Now apply the filter

LOOP AT total.

*   Move data so it is accessible via structure

ls_total = total.

*   Check if the given BUKRS is contained

IF NOT ls_total-bukrs = p_bukrs.

*     Filter row

DELETE total.

ENDIF.
ENDLOOP.

And we’re done! Check out the result of our programming by calling SM30 with your base table as parameter. The popup will look like this.

SM30 custom selection screen

The resulting table view will only contain entries that adhere to the filtering conditions. That concludes today’s post.

Full ABAP Source Code for Custom Selection Screen

This is the entire FORM routine that is needed to implement a custom selection screen for SM30 with the event AA.

* Define a custom selection screen.

SELECTION-SCREEN BEGIN OF SCREEN 10.

PARAMETERS p_bukrs TYPE bukrs.

SELECTION-SCREEN END OF SCREEN 10.

* This form is called to restrict the selection

FORM custom_selscreen.

* Read all data into TOTAL first

PERFORM table_get_data.

* Call the custom selscreen as a popup

CALL SCREEN 10 STARTING AT 20 10.

* If the user didn't enter anything, don't filter

CHECK p_bukrs IS NOT INITIAL.

* Define a structured variable to read data

DATA BEGIN OF ls_total.

INCLUDE TYPE zmytable.
INCLUDE TYPE vimtbflags.

DATA END OF ls_total.

* Now apply the filter

LOOP AT total.

*   Move data so it is accessible via structure

ls_total = total.

*   Check if the given BUKRS is contained

IF NOT ls_total-bukrs = p_bukrs.

*     Filter rows

DELETE total.

ENDIF.
ENDLOOP.
ENDFORM.

All Tags

ABAP ALV Authorization Business Function Classes Classification Control Framework CPM Email Field Symbols File Management HANA HANA Cloud Platform Learn SAP Netweaver Patterns PDF River RDE SAP Demo SAP ERP SAP IMG SAPUI5 Tables Transport System User Exit User Parameters User Status

SAP ERP Dictionary

SAP Transactions

SAP Customer Exits

SAP Tables

SAP Authorization Objects

SAP Authorization Object Classes

SAP Programs

SAP Function Groups

SAP Function Modules

SAP Message Classes

SAP Packages

SAP Search Helps

SAP Master Data

Access Control List

Catalog

Characteristic

Class

Delivery

Material Document

Notification

Purchasing Document

Sales Order

Selected Set

WBS Element

About

Copyright Information

Legal Notice

Privacy Statement

SAP Modules

SAP Data Objects

SAP Dictionary

SAP Developer Workbench

Community

Topics

Answers

Blogs

Events

Programs

Resources

What's New

Home

Community

Blogs

Ask a Question

Write a Blog Post

Former Member

Posted onAugust 22, 2013 3 minute read

Add a Selection Screen to a Table Maintenance Dialog

FollowRSS feedLike

13 Likes 26,043 Views 18 Comments

When end users will maintain a z-table with 100+ rows, it helps to be able to restrict the selection by any number of selection criteria.  This document attempts to define a “best practice” method for calling a table maintenance dialog from a selection screen.

Current Table Maintenance

The standard way to show a table maintenance dialog is via SM30, Call View Maintenance –

– or a custom parameter transaction that calls SM30 for a specific table, with parameters VIEWNAME and UPDATE = ‘X’.

Neither of these provide an initial selection screen.  Entries can be restricted by checking the “Enter conditions” radiobutton, but users are more familiar with selection screens than with the dialog box that pops up.  Therefore it is good UI to use a selection screen instead of the “Enter conditions” radiobutton.

Example Selection Screen Definition

In this example, an executable report has been created with selection screen.

REPORT  z_maintain_mytable.

DATA mytable    TYPE z_mytable.

DATA selections TYPE TABLE OF vimsellist.

DATA selection  TYPE vimsellist.

SELECT-OPTIONS: so_selop1 FOR mytable–myfield1,

so_selop2 FOR mytable–myfield2.

PARAMETERS: p_param1 TYPE z_mytable–myfield3,

p_param2 TYPE z_mytable–myfield4.

Calling Function Modules

When the user clicks execute, the program needs to read their selections and call the table maintenance dialog.  The following code shows how this is easily done by using function modules ‘VIEW_RANGETAB_TO_SELLIST’ and ‘VIEW_MAINTENANCE_CALL’.

START-OF-SELECTION.

DEFINE addsel.

CALL FUNCTION ‘VIEW_RANGETAB_TO_SELLIST’

EXPORTING

fieldname          = &1

append_conjunction = ‘AND’

TABLES

sellist            = selections

rangetab           = &2[].

END-OF-DEFINITION.

DEFINE addparam.

IF &2 IS NOT INITIAL.

CLEAR selection.

selection–viewfield = &1.

selection–value = &2.

selection–and_or = ‘AND’.

selection–operator = ‘EQ’.

APPEND selection TO selections.
ENDIF.
END-OF-DEFINITION.

add_sel ‘MYFIELD1’ so_selop1.

add_sel ‘MYFIELD2’ so_selop2.

add_par ‘MYFIELD3′ p_param1.

add_par ‘MYFIELD4′ p_param2.

CALL FUNCTION ‘VIEW_MAINTENANCE_CALL’

EXPORTING

...

郑德鼎

关于作者:郑德鼎

企业信息化与 SAP 技术顾问,长期专注 SAP ABAP、FI/CO、MM、SD 等模块的技术分享与实战经验总结。查看更多介绍

来源说明:本文内容由「Build Custom Selection Screens for Extended Table Maintenance.docx」整理生成,仅用于内部技术分享与学习交流。