Documente Academic
Documente Profesional
Documente Cultură
My latest project is a program that should verify whether there are any sales orders
that are due for delivery but do not meet certain minimum criteria. Naturally, the
minimum requirements have to be stored in some Z table, so that we don’t have to
change the program should the requirements change. A functional consultant wrote
the specification for me, which included development of a custom transaction to
maintain that Z table. Even though it seemed quite complicated at first, after talking
to the sales folks I figured that they basically wanted to maintain either a minimum
amount (in the US dollars) or a minimum quantity (in the sales units) by material
group (VBAP-MATKL). They did not need any fancy screens, so a generated
maintenance screen would do. The only challenge was to ensure that the users
have access only to the minimum requirements for their sales organization.
The very cool thing is that it also restricts the maintenance to those values. E.g. if
the user has selected sales org Z1 but then tries to add a record with Z2, it will not
allow it (although the error message is kind of generic). Hence all that left for me to
do was to write a very short report with just a selection screen and the FM call.
MANDT
VKORG
MATKL
ZUNIT
ZUNIT is a CHAR field with the domain that limits the values to USD and our sales
units. USD can be used to enter the minimum dollar amount and sales units can be
used to enter the minimum quantity. One unfortunate thing that I found out about
such domains is that SAP is adding a blank value to the list of the allowed values.
This seems to be the standard functionality; I found no way to get rid of it in the
Dictionary except for replacing single values with another table with a foreign key,
which is a hassle (check out this thread in the SDN forum). It’s not a big issue in this
case, because I can just disallow blank units through my ABAP code, but it would be
a major annoyance should anyone decide to use just SM30. Long story short, here is
my report:
REPORT zsd_r_min_order_maintain.
DATA: action.
TABLES sscrfields.
SELECTION-SCREEN SKIP 1.
INITIALIZATION.
AT SELECTION-SCREEN.
IF sscrfields-ucomm = 'MAINT'.
action = 'U'.
ELSE.
action = 'S'.
ENDIF.
* Selection list
CLEAR: i_sellist.
REFRESH: i_sellist.
i_sellist-viewfield = 'VKORG'.
i_sellist-operator = 'EQ'.
i_sellist-value = p_vkorg.
i_sellist-and_or = 'AND'.
APPEND i_sellist.
IF p_usd = space.
i_sellist-operator = 'NE'.
ENDIF.
i_sellist-viewfield = 'ZUNIT'.
i_sellist-value = 'USD'.
APPEND i_sellist.
i_sellist-viewfield = 'ZUNIT'.
i_sellist-operator = 'NE'.
i_sellist-value = space.
APPEND i_sellist.
EXPORTING
action = action
view_name = 'ZSD_MIN_ORDER'
TABLES
dba_sellist = i_sellist.
Like I said, we did not need anything fancy but, as a matter of fact, you can add
more screens and built a very nice program that would look quite sophisticated by
just correctly using this function module.
Just one last thing. At first, I forgot to fill in the field I_SELLIST-AND_OR, which
resulted in a short dump ‘The WHERE condition has an unexpected format’ (runtime
error SAPSQL_WHERE_PARENTHESES, exception CX_SY_DYNAMIC_OSQL_SYNTAX).
This exception should have been caught in the function module but I guess they’ve
missed it, so keep this in mind.
EXPORTING
action = "
* corr_number = ' ' " e070-trkorr Correction Number for Changes Made
* generate_maint_tool_if_missing = ' ' " Flag: Create Maint. Mods. if They do Not Exist
* show_selection_popup = ' ' " Flag: Display Selection Conditions Dialog Box
* rfc_destination_for_upgrade = ' ' " rfcdes-rfcdest RFC Dest. of System for Comparison/Adjustment
* complex_selconds_used = ' ' " tvdir-flag Flag: DBA_SELLIST Contains Complex Selection
Conditions
* check_ddic_mainflag = ' ' " Flag: Check Whether Maintenance is Allowed
* suppress_wa_popup = SPACE " xfeld Flag: Suppress "Specify Work Area" Dialog Box
* TABLES
EXCEPTIONS
. " VIEW_MAINTENANCE_CALL