|
For some of your input fields it can make sense that you implement a foreign key check and an additional text display. This is possible by means of GuiXT; you call up a function module that reads the right SAP table, checks the value entered by the user and returns a suitable text. You can use a general function module for reading all tables (see below).
Let us assume that you have an input field “Customer” where the user enters a customer number: InputField (10,1) “Customer” (10,20) size=10 name=”kunnr” techname=”KNA1-KUNNR”
Since the user can enter the customer number directly, without using F4 search help, we want to check that the key entered is a valid customer number. For this purpose we use a general function module “Z_GUIXT_SELECT_SINGLE” (see below) that reads an SAP table. It suffices to pass the name of the SAP table (in our case “KNA1″) and the “Where” condition to the function module: Call “Z_GUIXT_SELECT_SINGLE” in.TABLENAME=“KNA1″ in.CONDITION=“KUNNR = ‘&V[kunnr]‘” out.FOUND=”found” After performing this call we can query the variable V[found] , for example with // Customer number invalid? This works fine as long as the user enters the customer number including all leading zeros, e.g. “0000002000″. We complete our implementation by adding these zeros automatically, doing some string manipulation in GuiXT: Set V[k10] “0000000000&V[kunnr]“
Set V[p2] Call “Z_GUIXT_SELECT_SINGLE” in.TABLENAME=“KNA1″ in.CONDITION=“KUNNR = ‘&V[k10]‘” out.FOUND=”found” This code can now be used if the user presses “Enter” or “Save” (you can use an Include to avoid redundant coding): On Enter process=”check.txt” In addition to our key check and error message display, we want to position the cursor into the “Customer” field in case the user has entered an incorrect number. It is not possible to use a “SetCursor” command immediately in the InputScript, since we are still on the “old” screen when we check the customer number in the InputScript. Instead, we only set a variable V[setcursor] and we then use “SetCursor” in the GuiXT script: // in InputScript “check.txt” // in GuiXT Script if V[setcursor]
As an additional feature, we want to display the customer name at the right hand side of the input field. The customer name can be read with the same database call that already checks the customer number; we only have to add some parameters: Call “Z_GUIXT_SELECT_SINGLE” in.TABLENAME=“KNA1″ in.CONDITION=“KUNNR = ‘&V[k10]‘” in.FIELDS=“NAME1″ out.FOUND=”found” table.DATA=“data” Here the “FIELDS” parameter contains all required database column names, separated by commas. The returned values for these columns are put into the “DATA” table, using a separate line for each column value. We then put the value into a script variable, e.g. into V[kunnr.name], and display the variable in the GuiXT script with a “Text” command: // in InputScript “check.txt” Set V[kunnr.name] “&text[data]“
If we need more than one database column for displaying a suitable text, e.g. the name (column NAME1) and the city (column ORT01), we use the same procedure: // in InputScript “check.txt” CopyText fromText=“data” toString=“s1″ line=1
Now only a small detail is still missing: After the user has selected a value from the F4 search help list, we want to display the customer name immediately after the user has selected the value, without the need to press “Enter” first. This is possible with the option “searchhelpprocess=…” of the InputField command: InputField (10,1) “Customer” (10,20) size=10 name=”kunnr” techname=”KNA1-KUNNR” searchhelpprocess=”return_kunnr.txt” We read the text fields in the InputScript “return_kunnr.txt” in the same manner as already explained above: // InputScript “return_kunnr.txt”
Set V[k10] “0000000000&V[kunnr]“
Set V[p2] Call “Z_GUIXT_SELECT_SINGLE” in.TABLENAME=“KNA1″ in.CONDITION=“KUNNR = ‘&V[k10]‘” in.FIELDS=“NAME1,ORT01″ out.FOUND=”found” table.DATA=“data” Return It makes sense to use an “Include” here in order to avoid redundant coding.
The function module “Z_GUIXT_SELECT_SINGLE” that we use for the database access can be implemented in any function group of your choice. Please observe that the RFC user needs the View authorization for the table that you want to read, since the function module first performs an authority check.
TYPE ANY, TYPE ANY. ASSIGN WORK TO CASTING TYPE (TABLENAME). * reset output table REFRESH DATA. * reset found-flag FOUND = ”. SELECT SINGLE (FIELDTAB) FROM (TABLENAME) INTO CORRESPONDING FIELDS OF WHERE (CONDITION). IF SY-SUBRC EQ 0. FOUND = ‘X’. LOOP AT FIELDTAB. ASSIGN COMPONENT FIELDTAB-NAME OF STRUCTURE to . IF SY-SUBRC = 0. WRITE TO DATA LEFT-JUSTIFIED. ELSE. DATA = ”. ENDIF. APPEND DATA. ENDLOOP. ENDIF. ENDFUNCTION.
|