Calling
functions from an InputScript is a fast way to get additional data out
of the SAP system. You can use both single fields and tables (arrays
of structured fields). For dynamic data (like texts or a larger number
of objects) the use of tables is the best way to transport the
information to the SAP system, or back to the InputScript.
Here
we present 2 examples. Both can very well be used as a basis for your own
further developments. The second example also demonstrates the creation
of "dynamic" screen elements.
Example 1: Displaying
the material description in VA03
In the order display transaction VA03, we
want to allow the user to doubleclick on the material text in the item
table, and then we display the full material description.
VA03: doubleclick on the material short
text (table column "Description")
The full material description is
displayed
The technique used here is
as follows:
In the GuiXT script,
we catch the doubleclick event using an On "/2"
statement. We then process an InputScript
VA03_doubleclick.txt.
Please note the parameter Fcode="/2" in the
On-statement. Its meaning is that the doubleclick is passed to the
SAP application unless the InputScript issues a different
Enter-statement
In the InputScript we
first determine whether the cursor points to the description
column, using the system variables V[_tabrow] and
V[_tabcol].
If it does not point to this column, we do nothing, so that the
standard doubleclick is performed by the SAP application. If yes,
we take the material number and short text from the selected table
row. We press the "Enter" key in order to avoid standard
doubleclick functionality in this case.
The GuiXT script is
processed again, after the Enter. We call a function module
that returns the full material description. We then display a
textbox with the material description, and finally clear our
material number variable, so that the textbox will disappear with
the next Enter.
GuiXT script
"SAPMV45A.E4001.TXT"
GuiXT
if Q[Transaction=VA03] and Q[Page=Sales]
// On doubleclick
On "/2" Fcode="/2" process="VA03_doubleclick.txt"
// Text display? (after doubleclick)
if V[VA03_DisplayTextMatnr]
Call "ZZ_GUIXT_MATERIAL_TEXT" _
in.artnr="&V[VA03_DisplayTextMatnr]" table.text="matxt"
Text (7,84) "&V[VA03_DisplayTextMatnr]: &V[VA03_DisplayTextDesc]" _
size=40 -border
TextBox (8,84) (14,124) name="matxt" -readOnly
Set V[VA03_DisplayTextMatnr] ""
endif
endif
InputScript "VA03_doubleclick.txt"
GuiXT
// Cursor in "Description" column (internally no 6)?
if V[_tabrow>0] and V[_tabcol=6]
Set V[VA03_DisplayTextMatnr] "&cell[All items,Material,&V[_tabrow]]"
Set V[VA03_DisplayTextDesc] "&cell[All items,6,&V[_tabrow]]"
// Replace "/2" with normal "Enter"
Enter
endif
Function
"ZZ_GUIXT_MATERIAL_TEXT"
ABAP
FUNCTION ZZ_GUIXT_MATERIAL_TEXT.
*"------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(ARTNR) TYPE ARTNR
*" VALUE(LANGUAGE) LIKE SY-LANGU DEFAULT SY-LANGU
*" VALUE(ID) LIKE THEAD-TDID DEFAULT 'GRUN'
*" TABLES
*" TEXT STRUCTURE W3HTML OPTIONAL
*"--------------------------------------
DATA: TNAME LIKE THEAD-TDNAME.
TNAME = ARTNR.
data: lt_stream type w3_html occurs 10.
Refresh text.
DATA: LT_SSTEXT LIKE TLINE OCCURS 0.
CALL FUNCTION 'READ_TEXT'
EXPORTING ID = ID
LANGUAGE = LANGUAGE
NAME = TNAME
OBJECT = 'MATERIAL'
TABLES
LINES = LT_SSTEXT
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
TABLES
ITF_TEXT = LT_SSTEXT
TEXT_STREAM = lt_stream.
LOOP AT lt_stream INTO text.
append text.
ENDLOOP.
ENDIF.
ENDFUNCTION.
Example 2: Suggesting products in order entry
In order entry (transaction VA01), the user
enters a customer number. Based on this customer number, we then suggest some products taken from previous orders. We present the
products as pushbuttons, and a simple click on the pushbutton
automatically enters the material number and the amount into the new
order. We also present 5 pushbuttons representing the the last 5
orders, showing the corresponding order date. Pressing one of these
pushbuttons displays a previous order.
VA01: new pushbutton "Previous
orders"
After entering the customer number, the user
may click on our new pushbutton to get the following information:
5 previous orders
5 products taken
from these orders, with amount, and short text (as a tooltip on
each pushbutton)
If you prefer more than 5 products, you
can display one or more additional button columns. If there is a really
large number of products to be presented, a good way is to use
an html-template and our "Viewer" component. The technique
presented here will remain essentially the same in this case, but the
product buttons would be shown via an html table.
Our additional product info
Clicking on a product
button will enter the product number and amount; clicking on an
order button displays the order (using transaction VA03). When
the window is no longer needed the
user can close it with the red cross.
Automatic entry of a product number and
amount
The scripts (based on an
IDES 4.6D system) are not particularly long, but they nonetheless represent a
fairly advanced level of handling GuiXT, and make use of a dynamic index. When you
modify the examples, please keep in mind the following restrictions
that apply to table transfers with "Call" in scripts:
Use only
character-type fields (no integers or packed decimals) in your
table definition
The standard maximum table
width is 256. Use the width:xxx parameter if you need a larger
table width, e.g. table.ORDERS(width:500)=orders.
Here the maximum value you can specify is 32000
There is no limitation
on the number of lines in the table.
GuiXT script
"SAPMV45A.E4001.TXT"
GuiXT
if Q[Transaction=VA01] and Q[Page=Sales]
if V[VA01_KUNNR=&F[Sold-to party]] and V[VA01_KUNNR]
Offset (7,86)
Box (0,0) (6,44)
// close box
Pushbutton (0,43) "@02@" process="GetOrdersMaterials.txt"
using KUNNR = ""
Text (0,1) "Orders"
// Index
Set V[i] 1
Set V[row] 1
label next_order
if not V[VA01_VBELN&V[i]]
goto end_of_orders
endif
Pushbutton (&V[row],1) _
"@16\QOrder &V[VA01_VBELN&V[i]]@&V[VA01_AUDAT&V[i]]" _
"/OVA03" process="DisplayOrder.txt"
using VBELN = "&V[VA01_VBELN&V[i]]"
Set V[i] &V[i] + 1
Set V[row] &V[row] + 1
if V[i<6]
goto next_order
endif
label end_of_orders
// Index
Set V[i] 1
Set V[row] 1
Text (0,17) "Products"
label next_material
if not V[VA01_MATNR&V[i]]
goto end_of_materials
endif
Pushbutton (&V[row],17) _
"@40\Q&V[VA01_ARKTX&V[i]]@&V[VA01_MATNR&V[i]]" _
process="AddMaterial.txt" size=(1,16)
using MATERIAL = "&V[VA01_MATNR&V[i]]"
using AMOUNT = "&V[VA01_AMOUNT&V[i]]"
Text (&V[row],34) "&V[VA01_AMOUNT&V[i]] &V[VA01_VRKME&V[i]]"
Set V[i] &V[i] + 1
Set V[row] &V[row] + 1
if V[i<6]
goto next_material
endif
label end_of_materials
else
Pushbutton (7,86) "Previous orders" process="GetOrdersMaterials.txt"
using KUNNR = [Sold-to party]
endif
endif
InputScript "DisplayOrder.txt" GuiXT
Parameter VBELN
Screen sapmv45a.0102
Set F[Order] "&U[VBELN]"
Enter
InputScript "AddMaterial.txt" GuiXT
Parameter MATERIAL
Parameter AMOUNT
Set V[i] 1
label next_line
Set V[Material] "&cell[.,Material,&V[i]]"
// empty?
If not V[Material]
Set cell[All items,Material,&V[i]] "&U[MATERIAL]"
Set cell[All items,Order quantity,&V[i]] "&U[AMOUNT]"
Leave
endif
Set V[i] &V[i] + 1
if V[i<20]
goto next_line
endif
Function
"ZZ_GUIXT_CUSTOMER_ORDERS"
ABAP
FUNCTION ZZ_GUIXT_CUSTOMER_ORDERS.
*"*"Local interface:
*" IMPORTING*" VALUE(KUNNR) TYPE KUNNR
*" VALUE(N_ORDERS) TYPE I DEFAULT 5
*" TABLES
*" ORDERS STRUCTURE ZZORDER
*" MATERIALS STRUCTURE ZZMATERIAL
*"----------------------------------------------------------------------
Tables: vakpa, vbap.
* Activate for debugging in RFC mode:
* call function 'SYSTEM_ATTACH_GUI'.
* Break-point.
* add leading 000... for numerical customer numbers
if kunnr co ' 0123456789'.
unpack kunnr to kunnr.
endif.
refresh: orders, materials.
select AUDAT VBELN from vakpa
into corresponding fields of vakpa
up to n_orders rows
where kunde = kunnr and parvw = 'AG'
order by audat descending.
orders-audat = vakpa-audat.
orders-vbeln = vakpa-vbeln.
Append orders.
select MATNR KWMENG VRKME ARKTX from vbap
into corresponding fields of vbap
where vbeln = orders-vbeln.
read table materials with key vbap-matnr.
IF sy-subrc ne 0.
materials-matnr = vbap-matnr.
materials-arktx = vbap-arktx.
materials-vbeln = vakpa-vbeln.
* Use "Write to" instead of "Move" for special fields
Write vbap-kwmeng to materials-menge unit vbap-vrkme.
Write vbap-vrkme to materials-vrkme.
Append materials.
endif.
endselect.
endselect.
endfunction.
InputScript
"GetOrdersMaterials.txt" GuiXT
Parameter KUNNR
// Save customer number
Set V[VA01_KUNNR] "&U[KUNNR]"
// no customer number? Then no action
if not V[VA01_KUNNR]
Leave
endif
// Reset order and material table
Set V[empty] ""
CopyText fromString=empty toText=orders
CopyText fromString=empty toText=materials
Call "ZZ_GUIXT_CUSTOMER_ORDERS" in.KUNNR="&U[KUNNR]" _
table.ORDERS=orders table.MATERIALS=materials
// Index
Set V[i] 1
label next_order
CopyText fromText=orders toString=item line=&V[i]
if not Q[ok]
// Reset Order
Set V[VA01_ORDER&V[i]]
goto materials
endif
Set V[VA01_AUDAT&V[i]] "&V[item](1-4)/&V[item](5-6)/&V[item](7-8)"
Set V[VA01_VBELN&V[i]] "&V[item](9-18)"
Set V[i] &V[i] + 1
if V[i<6]
goto next_order
endif
label materials
Set V[i] 1
label next_material
CopyText fromText=materials toString=item line=&V[i]
if not Q[ok]
// Reset Material
Set V[VA01_MATNR&V[i]]
Leave
endif
Set V[VA01_MATNR&V[i]] "&V[item](1-18)"
Set V[VA01_AMOUNT&V[i]] "&V[item](19-33)"
Set V[VA01_VRKME&V[i]] "&V[item](34-36)"
Set V[VA01_MATVBELN&V[i]] "&V[item](37-46)"
Set V[VA01_ARKTX&V[i]] "&V[item](47-86)"
Set V[i] &V[i] + 1
if V[i<6]
goto next_material
endif