<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d34883048\x26blogName\x3dYour+Friendly+ABAPer\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://friendlyabaper.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://friendlyabaper.blogspot.com/\x26vt\x3d-4712760677496349421', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Call View Maintenance to the rescue!

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 th users have access only to the minimum requirements for their sales organization.

After some unsuccessful online search, I resorted to debugging the SM30 transaction. This lead me to the function module VIEW_MAINTENANCE_CALL. (You might be laughing already, but only now I’ve noticed that SM30 is actually called “Call View Maintenance”. Oh well...) So I checked out that function module and saw the table dba_sellist in the parameter list – jackpot! Just fill in VIEWFIELD, OPERATOR and VALUE and it will bring up the maintenance screen with only the selected values.

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.

My Z table has the following key fields:
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.
DATA: BEGIN OF i_sellist OCCURS 0.
INCLUDE STRUCTURE vimsellist.
DATA: END OF i_sellist.

TABLES sscrfields.

PARAMETERS: p_vkorg TYPE tvko-vkorg OBLIGATORY,
p_usd RADIOBUTTON GROUP lim, " Limit by USD
p_qty RADIOBUTTON GROUP lim. " Limit by Quantity

SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /1(15) disp USER-COMMAND disp.
SELECTION-SCREEN PUSHBUTTON 20(15) maint USER-COMMAND maint.

INITIALIZATION.
MOVE 'Display' TO disp.
MOVE 'Maintain' TO maint.

AT SELECTION-SCREEN.
* Authority check here
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.
* Disallow blank unit
i_sellist-viewfield = 'ZUNIT'.
i_sellist-operator = 'NE'.
i_sellist-value = space.
APPEND i_sellist.

CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action = action
view_name = 'ZSD_MIN_ORDER'
TABLES
dba_sellist = i_sellist.
In a nutshell, this program provides a simple selection screen with VKORG, radiobutton for either dollar amount or quantity, and two pushbuttons: Display and Maintain. Then the program fills in the action field and the selection table (i_sellilst) according to the user’s selections. When the button is pushed, the screen goes to the same screen as SM30 (sans the first selection screen, of course) and brings up the values that fit the criteria. When the user clicks “back” (green arrow), he/she gets back to my selection screen and can make different selection.

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.

posted by Your Friendly ABAPer @ 21:42,
Direct link to this post

3 Comments:

At 7/8/08 04:32, Anonymous Anonymous said...

good!

 
At 26/4/10 10:49, Blogger Marcelo said...

This comment has been removed by the author.

 
At 26/4/10 10:50, Blogger Marcelo said...

Very Good!!

 

Post a Comment

Links to this post:

Create a Link

<< Home