|
Numerous SAP transactions use “table controls” to display data or to let the user enter data in tabular form. With InputAssistant you can create additional columns in a table control, both to display data or to let the user enter additional data to be processed later on in an InputScript. | ||
The technique for displaying data is not particularly complex, but handling data entry requires a little more attention to detail. In this tutorial we first cover read-only; then in the second part the scenario of data entry into our new columns. Our sample application for this tutorial: In transaction VA01 (order entry) we want to offer the user a new button “Show previous order info” that, when clicked, displays the previously ordered quantity for each material entered so far. For each order item we have to read the previous orders for this material from the same customer, using an SAP BAPI call. In the table control we add 3 columns that will be used to display the quantity ordered, the order date and the order number for this material. For producing the images of the example, we used SAP GUI 7.1 on an SAP ERP 2004 IDES system. The example can also be used, without any changes, on previous SAP versions, e.g. on SAP 4.6C with SAP GUI 6.20 or 6.40.
We implement this feature in two steps. First, we implement the new button that displays three new additional table columns: // GuiXT Script SAPMV45A.E4001.TXT // only for transaction VA01, page sales // show button at end of table (right of iconized button “Item details: ..”) // add three new table columns to display previous order quantity for each item endif
The two InputScripts are quite simple: // InputScript VA_show_cols // InputScript VA_hide_cols
It is also possible to display a suitable icon in the column headers. Example:
As usual, this is done with the notation “@xx@text…” where xx is the SAP icon id. In this case we used the icon id @OX@. // add three new table columns with icons to display previous order quantity for each item Finally, we need to put the required data into our new columns. The variables behind the columns are named according to the “name=..” parameter in the Column command, and appended with the row number. Example: row1: V[VA_pq.1] V[VA_pd.1] V[VA_po.1] The row index is valid for the whole table control, not only for the visible part. For example, when the user scrolls the table control to row 4, only the rows shown in blue in the above diagram will be visible on screen. When you set values into the column variables V[VA_pq.1],…, two different approaches are possible. Either you fill all variables at the beginning of the transaction, and do not bother about scrolling. This works fine if the whole table is in readonly mode. In our case it would not be the right approach, since the user can change the material number for each item, or can delete and insert new rows. In such cases it is better to set the column variables each time the screen is displayed, and to set it for the visible (blue coloured) part only. Essentially you need some coding of the following type in order to do this: // loop through all visible table rows Set V[i] 1 // row number on screen (visible part only) label prev_order_beg // valid row left? //process visible row i. The absolute row number is k … Set V[colvar.&V[k]] “some value” // next row label prev_order_end FInally, we need to read the right data within this framework. For this purpose we call “BAPI_SALESORDER_GETLIST” for each line. The input parameters for the BAPI are the customer number, the material number and the sales area. The BAPI then returns a table of order items for the given customer/material/sales area. The orders are sorted according to date, with the most recent one at the top, so the first line of this table will already contain the most recent order. Since the order quantity is returned in packed format, we apply the “-unpack” option of the “Set” command. We also delete leading zeros in the order number, and display the date in format DD.MM.YYYY. The whole script is as follows: // GuiXT Script SAPMV45A.E4001.TXT // only for transaction VA01, page sales // show button at end of table (right of iconized button “Item details: ..”) // add three new table columns to display previous order quantity for each item // loop through all visible lines Set V[i] 1 // delete previous values Set V[customer] “&F[Sold-to party]“ label prev_order_beg // any item left? Set V[matnr] “&cell[All items,Material,&V[i]]” // read order info via SAP BAPI // read first line, it contains the most recent order for this material if Q[ok] // otherwise there is no previous order for this material // now move some fields from the returned BAPI table into our new columns // quantity: The BAPI returns it as ‘packed decimal’ incl. 3 decimal places // date: It comes in format YYYYMM, we use DD.MM.YYYY here // order number: comes with leading 0 that we get rid of with a calculation endif Set V[i] &V[i] + 1 label prev_order_end endif // V[VA_show_cols] endif // VA01 + page=Sales
Our second example deals with data entry in transaction ME51N (Create Purchase Requisition) using additional table columns. In this transaction most of the item information can be entered directly in table columns, but some additional fields require that we open the “Detail” view for the item, click on the right tab in the detail view, and enter the information into a separate field on this tab. Remark: In relatively new SAP systems (e.g. SAP ERP2004 and upwards) , the user can choose between a “grid control” and a “table control” for data entry in ME51N (button “Personal setting” in the toolbar). The technique that we describe here applies to the table control only, not to the grid control.
For one of these fields, the “Purchase Organization” in tab “Source of Supply”, we want to create a new column in the table control where the user can enter the purchase organization for each item directly, without having to open up the detail view for this item.
Compared to other SAP transactions, ME51N has certain idiosyncrasies:
Another difficulty that we may experience here and in numerous other transactions is that the user can “save” on a popup that is displayed when he presses F3, F12 or F15 (Return, Cancel, Leave) in the transaction. We need a way to start our updating InputScript in these cases as well. First let’s look at the GuiXT script: if Q[Transaction=ME51N] // if table is visible (can be hidden by user) // no entries in table? then clear all ME51N_ variables if V[fvr=1] // create new column // Additional column is active
// Additional column is active? else stop of script processing // no entry field in detail screen to avoid synchronization with table column // when saving call own script // when checking call own script // when the user leaves the transaction, handle the “do you want to save” popup endif Some comments on the script:
The “ME51N_leave.txt” script handles the popup that is displayed when the user leaves the transaction: // InputScript “ME51N_leave.txt” // popup screen “do you want to save the document first” It also starts the “save” InputScript, setting the parameter POPUP = “X”. The “save” InputScript first cancels the popup and then runs through the normal “save” procedure. It also handles cases in which the “detail” view is not yet opened by the user, i.e. the InputScript opens the view and closes it at again the end. // InputScript “ME51N_save.txt” // No return on error, otherwise entered data could be lost // A variablle indicates whether the InputScript had to open the “detail view” // started from “do you want to save?” popup? // Set correct title to be displayed during InputScript processing Screen saplmegui.0014 // Item table opened? Screen saplmegui.0014 label item_table_open
// Row index variables // Position details opened? // open position details Screen saplmegui.0014 label position_details_open
GetTableAttribute T[Table] FirstVisibleRow=FVisRow if V[FVisRow=1] // scroll to first line label new_screen
Screen saplmegui.0014 label scroll_beg_done
GetTableAttribute T[Table] FirstVisibleRow=FVisRow LastVisibleRow=LVisRow LastRow=LastRow label new_row
// end of table? // end of screen? Set V[item] “&cell[Table,Requisn. item,&V[relrow]]” Set V[ME51N_EKORG] “&V[ME51N_EKORG.&V[item]]” // no new input? // Save input // Set cursor into row and choose detail view Screen SAPLMEGUI.0014 if F[Purch. organization] // To TAB “Source of Supply” Screen SAPLMEGUI.0014 label screen_EKORG
Set F[Purch. organization] “&V[ME51N_EKORG]“ label end_of_table
// detail view opened? // collapse detail view again Screen SAPLMEGUI.0014 label screen_collapse_done
// Save or check // started from popup? else end of script // back to main screen after popup + save procedure // popup is displayed again (but nothing to save now) -> press “No” to leave the transaction
When you use “goto” and “label” in the script, please observe the difference between the following versions (the correct one and a wrong one): (1) Screen saplmegui.0014 Screen saplmegui.0014 (2) Screen saplmegui.0014 label item_table_open The second version (label before Screen command) would be wrong: no “Enter” is executed for the first “Screen” command, and therefore the InputScript will display the screen and wait for user input instead of continuing. Another possible error would be to include a Screen command into an if..endif clause: Screen saplmegui.0014 // open item table Screen saplmegui.0014 After these negative examples, here is an alternative that will work: You use the “goto” to go back to the same Screen command, after entering a suitable function code to open up the table or detail view. … Screen saplmegui.0014 // Item table opened? // Position details opened? GetTableAttribute T[Table] FirstVisibleRow=FVisRow // scroll to first line label new_screen
Screen saplmegui.0014 label scroll_beg_done
… In this case, it is important that you put the label “main_screen” before the Screen command. If you put it after the Screen command, GuiXT would continue, after the Enter, to execute the script. You would then end up with more than one Enter for one screen, which makes no sense and in fact would lead to a GuiXT syntax error message, and the first “Enter” would be lost. So when you write complex InputScripts please bear in mind that you perform at most one Enter for each Screen, and in most cases exactly one. There are only two cases where it makes sense to have a Screen command without Enter: Either when you want to display the Screen and still stay within the InputScript, a possibility that we used in the “ME51N_leave.txt” InputScript above to handle the popup. Or (a very special case) when you use the “ApplyGUIScript” statement to call up VBScript, and your VBScript program performs an “Enter” action itself (e.g. presses a pushbutton).
|