Build Custom Selection Screens for Extended Table Maintenance

*----------------------------------------------------------------------* ***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

action                = ‘U’ “for Update

view_name             = ‘Z_MYTABLE’

complex_selconds_used = ‘X’

TABLES

dba_sellist           = selections

EXCEPTIONS

OTHERS                = 1.

IF sy–subrc = 1.

MESSAGE ID sy–msgid TYPE sy–msgty NUMBER sy–msgno

WITH sy–msgv1 sy–msgv2 sy–msgv3 sy–msgv4.

ENDIF.

Horray!  That is all. In only 46 lines (plus two for every select-option or parameter), this will bring the user to from the selection-screen to the table maintenance screen.

This is a collaborative document.  If there are better ways of achieving this functionality don’t hesitate to chime in and contribute!

Alert Moderator

Assigned tags

ABAP Development

abap

selection-screen

table maintenance dialog

table maintenance generator

View more...

Related Blog Posts

When a User Met a Z-Table: 9 Tips & Tricks

By Former Member, Oct 01, 2013

Material Master Maintenance without Dialog

By Sujeet Mishra, Aug 08, 2013

Material Document List (MB51) Selection Screen Enhancement

By Sujeet Mishra, Aug 09, 2013

Related Questions

Table maintenance two step

By Former Member, Apr 05, 2011

Customize Table Maintenance Dialog

By Former Member, May 27, 2008

Table maintenance dialog

By Former Member, Mar 05, 2009

18 Comments

Varun Kumar Sahu

October 17, 2013 at 9:42 am

Nice one. A very good way to add selection screen.

Regards,

Varun Kumar Sahu

Like(0)

Reply

Alert Moderator

Shakeeluddin Khaja

November 20, 2013 at 6:51 am

Thanks for sharing . useful Information.

Regards.

Like(0)

Reply

Alert Moderator

Former Member

December 17, 2013 at 4:15 pm

Excellent article, thank you!

Regards,

Martin

Like(0)

Reply

Alert Moderator

Praveen Nenawa

January 20, 2014 at 2:00 pm

Hi ,

Just a Function module to do the job .... Nice one to know .

Like(0)

Reply

Alert Moderator

Michael Fallenbüchel

February 17, 2014 at 2:06 pm

Great work! But not perfect.

Let's say you have a table with a field type QUAN 13,3.

Now you do your selection in the dynamic selection screen for this field from 1 to 5.

ABAP will dump, saying "ASSIGN_OFFSET_NOTALLOWED".

"Part of the source field "<VALUE>" was assigned to a field symbol,

but this is not allowed for fields of type "P"."

Any one has a solution for this?

Like(0)

Reply

Alert Moderator

Former Member

February 18, 2014 at 12:22 pm

Hi Michael,

I'm dealing with the same problem. For me it seems to be a bug in form TRANSLATE_SELLIST_TO_WHERETAB of program SAPLSVIX.

I tried many things but have no solution yet how to fill DBA_SELLIST.

I'm still working...

Like(0)

Reply

Alert Moderator

Michael Fallenbüchel

February 18, 2014 at 12:27 pm

Correct, the mistake is in TRANSLATE_SELLIST_TO_WHERETAB.

I already made a call at SAP, first they told me VIEW_MAINTENANCE_CALL is not released, I told them it is (see help "The function moduel has been released"), nothing more since last contact yesterday.

If there are any updates I will let you know...

Like(0)

Reply

Alert Moderator

Suhas Saha

February 18, 2014 at 12:30 pm

Hello Michael,

Did you try this method - Using selection-screen in Table Maintenance Generator - ABAP Development - SCN Wiki?

BR,

Suhas

Like(0)

Reply

Alert Moderator

Former Member

August 30, 2016 at 4:12 pm

Dear Michael,

i am also getting same error.Please tell me how you solve this.Please do needful.

Thanks & Regards,

Avinash

Like(0)

Reply

Alert Moderator

Michael Fallenbüchel

August 31, 2016 at 7:19 am

Hi Ramu,

you need to implement note 2007905

Then I have added some coding (function  RS_DS_CONV_IN_2_EX) "in between" to convert my selection values to internal format (decimal point, ...)

Hope this helps

Michael

Like(0)

Reply

Alert Moderator

Former Member

September 3, 2016 at 8:38 am

HI michael

Thank You for reply.and how to edit the values of selection screen like key fields.for example i enter the value in selection screen in output if i am trying to edit the values getting following error.

Specify the key within the work area

Regards,

Ramu

Like(0)

Reply

Alert Moderator

Suhas Saha

February 18, 2014 at 12:29 pm

Hello Eric,

Sorry for seeing this too late

I had a different take on this problem & had documented it as a WiKi - Using selection-screen in Table Maintenance Generator - ABAP Development - SCN Wiki.

BR,

Suhas

Like(0)

Reply

Alert Moderator

Former Member

February 18, 2014 at 12:57 pm

Hello Suhas,

I use function FREE_SELECTIONS_DIALOG to create dynamic selections for a pool of different tables of our application.

Then I convert export parameter EX_FIELD_RANGES to DBA_SELLIST to call VIEW_MAINTENACE_CALL.

For the conversion I use VIEW_RANGETAB_TO_SELLIST and some code of my own, depending on field type.

But that doesn't work for fields of type P.

BR

Frank

Like(0)

Reply

Alert Moderator

Michael Fallenbüchel

February 18, 2014 at 1:07 pm

Same here:

1. FREE_SELECTIONS_INIT

2. FREE_SELECTIONS_DIALOG

3. VIEW_RANGETAB_SO_SELLIST

4. VIEW_MAINTENANCE_CALL

Like(0)

Reply

Alert Moderator

Suhas Saha

February 18, 2014 at 2:16 pm

Hello Gentlemen,

I don't use the VIEW_MAINTENANCE_CALL function. I use the TMG event AA and call the selection-screen in there.

I already made a call at SAP, first they told me VIEW_MAINTENANCE_CALL is not released

Interesting, i thought that the FM is "released". But if you see the date it is blank

Something fishy is going on there

BR,

Suhas

Like(0)

Reply

Alert Moderator

Raymond Giuseppi

February 18, 2014 at 2:26 pm

For it means "has always been released" or "released in time so old that no one in Walldorf remembers" .

You can also check in documentation at help.sap.com that SAP suggest their usage (From Middle level entry - BC Extended Applications Function Library - SAP Library for ERP 6.0 to Middle level entry for good old 4.0)

Regards,

Raymond

Like(0)

Reply

Alert Moderator

Suhas Saha

February 18, 2014 at 2:39 pm

Hello All,

Just to clarify, when i said -

I don't use the VIEW_MAINTENANCE_CALL function

i meant for this scenario. I have used this FM many times & it has always worked like a charm

BR,

Suhas

Like(0)

Reply

Alert Moderator

Former Member Post author

February 18, 2014 at 3:01 pm

Thanks for the feedback everyone!  I'm learning a ton.

I like how Suhas' method uses the standard events instead of slapping an executable report on the front end.  Perhaps we can combine our document and wiki and determine a best practice.

My only concern with his method is the filtering on the application server and not the database - is that the right choice in this scenario?  And does VIEW_MAINTENANCE_CALL do the same thing?

Like(0)

Reply

Alert Moderator

Add Comment

Find us on

Privacy

Terms of Use

Legal Disclosure

Copyright

Trademark

Cookie Preferences

Newsletter

Support

返回ABAP参考资料列表