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

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.
DATA: END OF i_sellist.

TABLES sscrfields.

p_usd RADIOBUTTON GROUP lim, " Limit by USD
p_qty RADIOBUTTON GROUP lim. " Limit by Quantity


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

* Authority check here
IF sscrfields-ucomm = 'MAINT'.
action = 'U'.
action = 'S'.

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

action = action
view_name = 'ZSD_MIN_ORDER'
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

Search help

I was hoping to get more details on the subject but, unfortunately, had to work on something else. If I get a chance to explore this more, I’ll just comment on this post or write a “part II”, as seems to be very fashionable among the SAP webloggers.

One of the sites that we support uses two names on the customer master (XD03). Our customers are only other companies and sometimes trade name and legal name are different. For example, a Joe’s Crab Shack restaurant might legally be an ACME Corporation. There are 2 lines for the name in XD03 (KNA1-NAME1 and KNA1-NAME2 respectively) and most of the sites enter the trade name (Joe’s Crab Shack) in NAME1 but legal name in NAME2. On the invoices (i.e. billing documents) the names are also printed in the same order: first NAME1, then NAME2. (This is just a preamble – hold on, we are getting there.)

But one site, due to the legal requirements in their state, had to print legal name first and trade name second. To avoid changing the invoice form (which is standard for the whole enterprise) we just asked them to enter the names in their order on the Customer Master. Sure thing, pretty soon they started to complain that the customer search in the order entry screen (VA01) only works by NAME1 or by some mysterious “first name”, which we don’t use at all (by the way, when I double-clicked on it, it displayed “Name 2” in the description, but it does not search by NAME2 field).

Honestly, so far I’ve never had anything to do with the search help but I gave it a try. Quick search in SAP Help (by the way, I usually simply use Google for searching – never really warmed up to that SAP help interface) provided some good starting points. First of all, I discovered that there is an elementary search help and a collective search help (collective is actually just a collection of the elementary ones). Then I learned that both are maintained in SE11.

Obviously, next I had to find out which search help is VA01 using for the customer (or, as it’s called there ‘Sold-to Partner’ or ‘Ship-to Partner’). Search by description in SE11 was not very successful, so I did a little debugging and finally found the name SD_DEBI in MC_OBJ field in MV45AF0K_KUNDE_GET_F4HELP.

Then in SE11 I discovered that SD_DEBI is a collective search help, consisting of 4 elementary ones (this might depend on the config, so don’t be surprised if it’s different in your system). Each elementary search help basically translates into a tab on the help screen with the tab names in the ‘Short text’ field.

Much to my surprise, I was able to create my own elementary search help and simply add it to SD_DEBI without any requests for an access key and, in fact, without much hassle. Here are the steps that I have gone through.

1. Create an elementary search help (Z_NAME2). This is quite intuitive: in SE11, select ‘Search help’, enter the name and click [Create] button. Then in the pop-up window select ‘Elementary’. I used the other search helps from SD_DEBI to fill in the details:

Did not quite figure the ‘Selection method’ thing. DEBIA, for example, had selection method M_DEBIA with the description ‘Generated View for Matchcode ID DEBI’. Not sure how they generated it but for now I just out the table name (KNA1) in there and it worked. I’ve chosen the ‘Dialog with value restriction’ option so that my new tab behaves the same way as the other ones. If you chose ‘Display values immediately’, it will display the whole list (which doesn’t make any sense if there are hundreds of items). The third option is somewhere in the middle and basically lets the system to choose between the two options based on the number of entries.

IMP and EXP columns tell what needs to be passed to the search help from the input field (IMP) and back (EXP). If you check IMP then, if a user has entered some value and then clicked on help, that value will be passed to the help screen. If you check EXP, the value will be passed back to the input field. It’s a no-brainer that one field should have EXP checked (I checked both just for the heck of it).

Numbers in the ‘LPos’ column tell in which order the fields will appear on the screen (I out name first). ‘Hot key’, as I figured from the documentation, seems more trouble than it’s worth, so I left it empty. Don’t forget to activate your new search help before leaving the screen.

2. Add your new elementary search help to a collective one. Just to be clear: this is not a required step but I had to do it to add my search to SD_DEBI. Again, in SE11, select ‘Search help’, enter the name and click [Change] button. Then on the ‘Included search helps’ tab add your new help, like this:

The last step is to select the line with your search help and to click on the ‘Parameter assignment’. There was an option to automatically propose the parameter, which I used. This parameter basically tells how the collective and elementary searches are linked together (in my case – by customer number KUNNR). And don’t forget to activate the collective search as well.

After these steps I was able to see the new tab on the customer search help in VA01:

The users, as usually is the case, were happy with my new screen only for the first hour or so and pretty soon came up with the new requirements. Now they wanted to add the Sales Organization (VKORG) field, so that the search is limited to only their customers. This meant that I could not use KNA1 as a search method because it does not include (VKORG). Luckily, there was a view already defined on KNA1 and KNVV (KNA1VV), which I was able to use. So I replaced KNA1 with KNA1VV, added VKORG to the field list and clicked ‘Activate’.

This time the activation did not go as smoothly and I got a warning message ‘Dialog type C makes no sense for search help w/o selection popup window’. Not sure why it was qualified as a warning because the search help was not working until I took care of this problem. Surprisingly, the diagnosis for this error message was very specific and pointed out that all my fields had 0 in the SPos column. Here is the new Z_NAME2:

You might notice that I’ve added the memory ID VKO to the VKORG field so that the users wouldn’t have to type in their sales org all the time. Also when I added VKORG field, it automatically put a check mark in the ‘Modified’ column. I tried to read the documentation for it but the only thing I understood was that I didn’t need that, so I unchecked it.

I’ve also removed unnecessary IMP checkmark and figured out what’s the deal with LPos and SPos columns. Since the users want to search by Sales Org and Name 2, they don’t really care for the Customer [Number] field on the search help tab. But when they enter, say *Crab*, they want to see the list of possible customers with their names and numbers. I’ve achieved that by leaving SPos blank for KUNNR (it removes it from the tab) but setting LPos = 3 (which puts KUNNR on the list of the customers found by search help). Let’s say we have 2 customers: number 700001 (Joe’s Crab Shack) and number 700004 (Jane’s Crab Cakes). The list for *Crab* (Name 2 is case-sensitive for some reason) will displayed like this:

Joe’s Crab Shack 700001
Jane’s Crab Cakes 700004

As you might have noticed, there is also an option to create a search help user exit, but I haven’t gone that far yet.

Just one more thing. From version 4.6 SAP has introduced a central address area. All addresses have a unique ID and are linked to other master data by the field ADRNR. The main address table is ADRC, which also contains NAME1 and NAME2 fields. Fields in KNA1 have length of 35 while fields in ADRC are 40 characters long. If you need to use the whole 40, go with the ADRC table. DEBIX is the elementary search for KUNNR on ADRC, but, as I mentioned, it does not quite work the way we need.

Some links that might be useful:
1. SAP Help article
2. Some minimalistic info on search help (good reference though)
3. SDN topic on the customer search help in VA01
4. Attach a Search Help to the Screen Field (ABAP code)

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