You are on page 1of 315

GuiXT WS

Developer Guide (WS 1.2.146.0)

Copyright (c) 1998 - 2012 Synactive, Inc

WS/64 Developer Guide

Contents
1.0 Introduction to Webscript ....................................................................................................................... 5 Overview ................................................................................................................................................... 5 2.0 WS Installation........................................................................................................................................ 6 System Requirements................................................................................................................................ 6 Required Files ........................................................................................................................................... 6 Installing WS/64 ...................................................................................................................................... 7 3.0 Configuration ........................................................................................................................................ 12 Guixt.sjs Parameters................................................................................................................................ 13 Guixt.sjs Naming Conventions ............................................................................................................... 15 Changing Directories and Script Files .................................................................................................... 16 Licensing ................................................................................................................................................. 17 4.0 WS Commands ..................................................................................................................................... 21 appendfile ................................................................................................................................................ 23 applyguiscript .......................................................................................................................................... 24 box........................................................................................................................................................... 29 boxsize .................................................................................................................................................... 32 buttonsize ................................................................................................................................................ 34 call ........................................................................................................................................................... 36 checkbox ................................................................................................................................................. 39 clearscreen............................................................................................................................................... 44 closefile ................................................................................................................................................... 46 column..................................................................................................................................................... 47 columnheader .......................................................................................................................................... 55 columnorder ............................................................................................................................................ 57 columnsize .............................................................................................................................................. 59 columnwidth ........................................................................................................................................... 61 comment .................................................................................................................................................. 63 copytext ................................................................................................................................................... 64 del............................................................................................................................................................ 79 dropdownlist ........................................................................................................................................... 86 enter......................................................................................................................................................... 89 fieldsize ................................................................................................................................................... 92 file ........................................................................................................................................................... 94 getfieldattribute ....................................................................................................................................... 95 gettableattribute....................................................................................................................................... 99 globaltextreplace ................................................................................................................................... 101 image ..................................................................................................................................................... 107 inputfield ............................................................................................................................................... 112 leave ...................................................................................................................................................... 137 load........................................................................................................................................................ 138 localvaluehelp ....................................................................................................................................... 139 Loops..................................................................................................................................................... 142 do - while .......................................................................................................................................... 142 for ...................................................................................................................................................... 144 goto - label ........................................................................................................................................ 146 if - else .............................................................................................................................................. 148 message ................................................................................................................................................. 151 nodropdownlist ..................................................................................................................................... 153 noinput .................................................................................................................................................. 155 2

WS/64 Developer Guide

noscrollbar............................................................................................................................................. 158 onmessage ............................................................................................................................................. 160 onscreen ................................................................................................................................................ 161 onUIEvents ........................................................................................................................................... 162 openfile ................................................................................................................................................. 166 pos ......................................................................................................................................................... 167 pushbutton ............................................................................................................................................. 172 radiobutton ............................................................................................................................................ 182 readfile .................................................................................................................................................. 189 removefile ............................................................................................................................................. 192 return ..................................................................................................................................................... 193 rfcconnect .............................................................................................................................................. 196 set .......................................................................................................................................................... 198 setcursor ................................................................................................................................................ 208 statusmessage ........................................................................................................................................ 213 switchto ................................................................................................................................................. 218 table ....................................................................................................................................................... 221 text......................................................................................................................................................... 226 textbox................................................................................................................................................... 235 tip .......................................................................................................................................................... 240 title ........................................................................................................................................................ 246 versionnumber....................................................................................................................................... 249 view ....................................................................................................................................................... 250 windowsize ........................................................................................................................................... 258 ws<command> ...................................................................................................................................... 260 wsmessage............................................................................................................................................. 262 ws_ ........................................................................................................................................................ 264 ws_log ............................................................................................................................................... 264 ws_WS .............................................................................................................................................. 266 ws_vap .............................................................................................................................................. 267 5.0 Web Server Commands ...................................................................................................................... 268 htmlnode ............................................................................................................................................... 268 usecss .................................................................................................................................................... 271 usejs....................................................................................................................................................... 272 6.0 WS System Variables ......................................................................................................................... 273 _ashost................................................................................................................................................... 273 _client .................................................................................................................................................... 273 _database ............................................................................................................................................... 273 _dynpro ................................................................................................................................................. 274 _language .............................................................................................................................................. 274 _listfirstvisiblerow ................................................................................................................................ 274 _listlastvisiblerow ................................................................................................................................. 274 _liststring............................................................................................................................................... 274 _message ............................................................................................................................................... 275 _page.exists ........................................................................................................................................... 275 _program ............................................................................................................................................... 276 _title ...................................................................................................................................................... 276 _transaction ........................................................................................................................................... 276 _user ...................................................................................................................................................... 276 7.0 Appendices.......................................................................................................................................... 277 Appendix I: Feature/Interface Comparison........................................................................................... 277 3

WS/64 Developer Guide

Appendix II: Version History ............................................................................................................... 279 Appendix III: Relative Positioning ....................................................................................................... 282 Alternate Syntax ............................................................................................................................... 283 Examples........................................................................................................................................... 284 Appendix IV: Combining Screens in WS ............................................................................................. 288 MM01 Transaction ........................................................................................................................... 288 Appendix V: Standard Javascript Functions ......................................................................................... 292 Appendix VI: Custom Functions .......................................................................................................... 293 ActiveXObject .................................................................................................................................. 294 WS Office Functions ........................................................................................................................ 296 Appendix VII: Displaying Unicode in Console .................................................................................... 313 Appendix VIII: Icon Library ................................................................................................................. 315

WS/64 Developer Guide

1.0 Introduction to Webscript


Overview
WS/64 is the next generation product from Synactive, Inc. WS/64 is a scalable, multi-thread engine capable of running in UNIX, Linux and Windows environments. WS/64 offer the ability to add features that tightly integrate with Web 2.0 (eg. YouTube videos or Google maps). WS/64 also introduces an entirely new scripting language. GuiXT WS is built on the Synactive implementation of Javascript, called Webscript (WS). All scripting is done using this powerful, ECMAScript-based language. Webscript uses the concept of object-oriented programming embedded in this language to enable developers to build powerful, portable scripts. Webscript is best described as a superset of Javascript - while it does not include all the functionality built into Javascript, it does include some functionality not found in the standard implementation in order to handle the specific object types found in SAP. Utilizing the Javascript-based Webscript, customers can create better customization and streamlining of SAP business processes. With Webscript, WS/64 better integrates with SAP ERP, development tools and the Java stack. Webscript also introduces the ability to re-use blocks of code and the concept of object-based scripting as opposed to the procedural-based model employed in the current release of GuiXT. Webscript, like the JavaScript upon which it is based, is an object-oriented language. In other words, everything in Webscript is treated as a separate object. Object-oriented programming, at its most basic, simply combines data and the operations that act upon that data into a single commodity. This differs for procedural languages where everything is centered around the actions that are performed and the data is more of a secondary concern. Applied to GuiXT, object-oriented programming enables users to create guixt scripts that are reusable and which contain objects and functions that can be shared between multiple scripts.

WS/64 Developer Guide

2.0 WS Installation
System Requirements
The system requirements for GuiXT WS/64 are as follows: Windows XP, Windows Vista, Windows 7, Windows Server 2003 or Windows 2008 Server System must meet SAP 7.10 system requirements For the system requirements for the supported Windows platforms, please see the Microsoft website. For the SAP system requirements, please consult the SAP website.

Required Files
The wizard installs the following files into your SAPGUI directory. By default, this is usually the following: C:\Program Files\SAP\FrontEnd\SAPgui guixt.sjs: Configuration file where users can specify script folders, change parameters etc. guixt.dll: Contains the functions called by the GuiXT executable. It is also used by Designer. Users must have the correct DLL in order to use WS/64. webscript.dll: Contains the Javascript parser, allowing the client-side Javascripts to communicate with the server-side C++ code.

WS/64 Developer Guide

Installing WS/64
There are two methods for installing WS, as follows: Install Wizard Manual Install

Install Wizard
To install WS/64 with the provided Installer, please do the following: 1. Close all active SAP sessions, including the login window. 2. Double-click on the file you downloaded (GuiXTWSSetup.exe). The InstallShield Wizard will appear as shown below. Click Next:

3. The End User License Agreement (EULA) window will display. Read the agreement and click the 'I accept...' button as shown below:

WS/64 Developer Guide

4. The Destination Folder window will display. Synactive recommends not changing the default location unless so instructed by a Synactive representative. Click Next.

5. The Ready to Install window will display. Click Install to being installing WS/64. 8

WS/64 Developer Guide

6. The Install Progress window will display.

7. When the InstallShield wizard completes, you will see the XXX window. Click Finish to exit the Install wizard. 9

WS/64 Developer Guide

10

WS/64 Developer Guide

Manual Install
It is also possible to install GuiXT WS manually without using the Install Wizard. Tio manuall;y install GuiXT WS, please do the following: 1. Obtain the following files from Synactive: guixt4web.dll guixt.sjs webscript.dll 2. Assuming the use of SAPGUI, place these files in the following SAP directory: C:\Program Files\SAP\FrontEnd\SAPgui. 3. Rename the current file guixt.dll to old_guixt.dll. 4. Rename the file guixt4web.dll to guixt.dll. 5. Open the guixt.sjs file in Notepad and add the path to the script directory as shown below:

11

WS/64 Developer Guide

3.0 Configuration
All configuration for GuiXT WS is performed in the guixt.sjs file unless either Web Server or GuiXT Server is involved. In the case of the GuiXT Server, please see the GuiXT Server documentation. For GuiXT Web Server, please consult the Web Server documentation. Licenses must be installed in each relevant guixt.sjs file for each product in order for everything to function as designed. In other words, the GuiXT Server license must be placed in the GuiXT Server guixt.sjs file - it cannot be housed in the main WS guixt.sjs file. A sample guixt.sjs file appears below:

12

WS/64 Developer Guide

Guixt.sjs Parameters
The guixt.sjs file contains a number of parameters, which are defined as follows: directory1 - directory4 = "C:\\directory\\directory"; This entry defines the script directories where GuiXT WS will search for script files. Users can have up to four directories specified and these are searched in order. The directories can be either local directories or network/HTTP/FTP/SAPWR shares. The types of syntax are as follows: o Local directories: directory1= "C:\\guixt\\scripts"; o Network shares: directory1 = "\\\\server\\directoryName"; o HTTP shares: directory1 = "http://server//directoryName"; o FTP shares: directory1 = "ftp://server//directoryName"; o SAP Web Repository: directory1 = "sapwr:z.guixt.demo" License Key: The license that enables Designer to function. Please note that there are two different license key types, as follows: o Pre-March 2011 Web Server Releases: For these releases, the actual license key for the various components would be entered following the 'Key' parameter in the guixt.sjs file. This parameter is not used in post-March 2011 releases. Please consult the Licensing section of the WS Install Guide or the WS Reference Library for more information. The format is shown below: Key = "Synactive.xxx.xxxxxx" o Post March 2001 WS Web Server Releases: For all WS releases subsequent to March 2011, the license key will be in the array format. Multiple individual license keys can be included in this format. Please consult the Licensing section of the WS Install Guide or the WS Reference Library for more information. The format is shown below. license = [ ]; license.push({"license":"x-xxxx-xxxxx-x-xxxx-xxxxx-xxxxx", "data":{"company":"company1", "systemid":["systemid1"]}}); license.push({"license":"x-xxxx-xxxxx-x-xxxx-xxxxx-xxxxx", "data":{"company":"company2", "systemid":["systemid2"]}});

historyononlyguixt = true; When this option is present, popup history will function only on GuiXT-created controls. Native controls will exhibit the default behavior only. If this option is not present, popup history will be available for both SAP and GuiXT controls. This option's syntax is as follows: historyononlyguixt = true; historyonrightbutton = true/false; The localvalue help parameter specifying that the given control's popup history appears on a mouse right-button click. The syntax is shown below: historyonrightbutton=true; domains = "sapwr:z.domain"; Any localvaluehelp domains would be specified in this parameter. An example is as follows: domains = "sapwr:z.domain" enablesystem: This option specifies that only the listed SAP system will be active. If a single system is listed, a statement is used as in the following example: enablesystem = "XXX"; However, if multiple systems are listed, an array will be used as shown below: 13

WS/64 Developer Guide

enablesystem ["XXX", "YYY", "ZZZ"]; trimlabels=false; This option is for ensuring that when a screen control is moved closer to the label, the label is not overlapped by the screen control. This is particularly important for edit fields. Trimlabels are turned on by default in WS, but if a user wishes to turn it off, he or she can turn off trimlabels by adding the 'trimlabels=false;' parameter to the guixt.sjs file as shown below: trimlabels=false; replication: The replication parameter specifies if file replication is active or not. File replication will function by copying files located on a central server onto a local machine. The first time this local file copy is accessed during a new SAP session, GuiXT will check the time stamp and compare it with the update time on the server. If the server file is newer, the file will be re-loaded from the server. But on all subsequent occasions that the file is accessed during the session, it will be read locally. To activate file replication, users can specify either 'yes' or 'no' as shown in the following examples: replication = "yes"; replication = "no"; rfcconnect: Array holding the RFC information for either a single user or multiple users. Please see the rfcconnect section of the WS Reference Library for more detailed information. The rfcconnect array will take precedence over either the guixt.sjs RFC single user entry explained below or over a RFCUser statement contained in a call command. The call command usage is explained in the WS Reference Library. rfcconnect: String holding data for single RFC user. This is the weakest of the three RFC calls both the array explained previously and any RFC user data contained in a Call command will take precedence over the single RFC user data. This has three components, which are as follows: o rfcuser = "xxx"; RFC username in plain text. o rfcpassword = "xxx"; RFC password in plain text if it is not encrypted. o rfcpasswordenc = "xxx"; If the RFC password is encrypted, it will be here in encrypted format. switchto: The switchto command enables users to map a user's individual guixt.sjs file to a main guixt.sjs file hosted on a server. Switchto is more fully defined in the WS Reference Library. components = {"component1":1, "Component2":1, "Component3":1}; List of installed components. Any installed component will be in this list and marked '1' to indicate that it is present and active. Please note that this parameter is not necessary for post-March 2011 WS releases. TRACEFLAGS: These are used for developer debugging. It should normally be set to 'FLG_REDIRECT_CONSOLE' in order to display logs. An example is shown below: TRACEFLAGS = FLG_REDIRECT_CONSOLE; FLG_REDIRECT_CONSOLE = 0x00008000;

14

WS/64 Developer Guide

Guixt.sjs Naming Conventions


Please note that there was a change in how Synactive names options in the guixt.sjs file. This change in the naming convention took effect in the following builds: WS: 1.2.106.0 Web Server: 1.2.106.0 Wescript.dll: 1.0.79.0 sapproxy: 3.4.339.0 The change is as follows: All options will be written in lowercase only No underscores will be used in options The TRACEFLAGS option is the only exception - it will remain in all uppercase Three new option shave been added, as follows. These new options are explained in the guixt.sjs parameters section above. o 'trimlabels' o 'enablesystem' o 'replication' The following table displays the changes: Old Option Name HistoryOnRightButton RfcUser RfcPassword rfcConnect Replication EnableSystem _switchto _lic_license TRACEFLAGS domains directory0 directory1 directory2 directory3 directory4 history New Option Name historyonrightbutton rfcuser rfcpassword rfcconnect replication trimlabels enablesystem switchto license TRACEFLAGS domains directory0 directory1 directory2 directory3 directory4 history

15

WS/64 Developer Guide

Changing Directories and Script Files


In previous versions of GuiXT WS, it was necessary to define script directories manually in the guixt.sjs file. Once a new directory was specified in the guixt.sjs file, users would have to stop GuiXT WS and then restart it for the changes to take effect. However, in all WS releases post build 1.1.98.0, this is no longer necessary. In current releases of WS, users can specify a new script directory by typing the following code into the transaction field:
/nva01/d0=c:\guixt\newdirect4

The script directory is specified by the 'd0=' part of the code where 'd' is set to 0-4. The numbers specify the directories as in the following examples:
/nva01/d0=c:\guixt\newdirectory0 /nva01/d1=c:\guixt\newdirectory1 /nva01/d2=c:\guixt\newdirectory2 /nva01/d3=c:\guixt\newdirectory3 /nva01/d4=c:\guixt\newdirectory4

In SAP GUI, this would look as shown in the following example:

The command can also be used to specify a new script for a given transaction, as in the following example for the VA01 transaction:
/nva01/f=newva01.sjs

This functionality is available anywhere so it can also be performed as an enter command within a script as shown in the following example: onscreen 'SAPMV45A.0101' /nva01/f=newva01.sjs Enter();

16

WS/64 Developer Guide

Licensing
Each Synactive product requires a license in order to operate. While GuiXT WS itself does not require a license, all other members of the GuiXT solution suites do require licenses. If you do not have a license, please see the Requesting New Licenses section below. WS licenses only work with WS environments, so users must have a WS-specific license.

Importing Licenses The GuiXT License Manager tool is what you will use to install, update, validate and remove licenses for your Synactive product. You can install a license by doing the following: 1. Locate the license file you received from Synactive. 2. Go to Start > Program Files > Synactive Inc and choose the appropriate product. 3. Click on LicenseManager. 4. Click the 'Import License File' button at the bottom of the License Manager window. 5. Choose the license file referenced in Step 1 above and click 'Open'. 6. The file will be imported into the product's License Manager. 7. It is necessary to manually import the license for each Synactive product separately. Adding and Removing Licenses License Manager can be used to add individual licenses and also remove licenses that have expired. To add a license, please do the following: 1. Open License Manager. 2. Click the Add button. 3. Input the license to be added to the License Manager. To remove a license, do the following: 1. Open License Manager. 2. Highlight the license to be removed. 3. Click the Remove button.

17

WS/64 Developer Guide

4. The license will be removed from License Manager. Validating Licenses To verify that your license is valid, do the following: 1. Click the 'Validate' button on the right sidebar of the License Manager. 2. The tool will check the installed licenses and return a dialog box showing the expiration dates of your licenses. Using the GuiXT.sjs File Once the new license has been received, users should place all relevant licenses into the guixt.sjs configuration file. This file can be found in the following directory: C:\Program Files\SAP\FrontEnd. Open the file in Notepad or some other script editor and do the following: 1. In the 'License' section of the guixt.sjs file, input the following: license = [ ]; license.push ({"license":"x-xxxx-xxxxx-x-xxxx-xxxxxxxxxx","data":{"company":"company","systemid":[ "systemid"]}}); 2. If multiple system IDs are necessary, the entry would look as follows: license = [ ]; license.push ({"license":"x-xxxx-xxxxx-x-xxxx-xxxxxxxxxx","data":{"company":"company","systemid":["systemid", "systemid", "systemid"]}}); 3. Licenses can also be entered based on the installation number. In this case, the entry in the guixt.sjs file would look as follows: license = [ ]; license.push ({"license":"x-xxxx-xxxxx-x-xxxx-xxxxxxxxxx","data":{"company":"company","installation":["xxxxxxxxxx"]} }); 4. The previous formats for both the Key and Test Keys are no longer supported in the guixt.sjs file and can be eliminated. In addition, if there is an entry in guixt.sjs for Components can also be eliminated - it is no longer necessary for WS. Requesting New Licenses Requesting new licenses can be done directly from within the License Manager. To request a new license, please do the following: 1. Click the 'Request New' button in License Manager:

18

WS/64 Developer Guide

2. The License Manager will redirect the requester to the www.guixt.com web site . Click the 'Customers' link in the menu bar (shown below):

3. On the ensuing page are two options on the right sidebar as shown below:

19

WS/64 Developer Guide

4. Please select the type of license to be requested from the following list: Designer License Production License 5. Follow the onscreen instructions. Both the Designer and the Production License should be received in approximately two business days.

You can also email info@guixt.com for a new license.

20

WS/64 Developer Guide

4.0 WS Commands
In this section we will cover the available commands that can be used to act upon SAP screen elements in WS. These commands can serve as both properties or methods for the screen element objects. They are mostly listed in alphabetical order though some commands that are used for related operations may be grouped as in the case of the commands for file or table operations. WS is case-sensitive and all commands must be written exactly as shown in the examples when being used in an actual script.

The available commands for WS are as follows. appendfile ................................................................................................................................................ 23 applyguiscript .......................................................................................................................................... 24 box........................................................................................................................................................... 29 boxsize .................................................................................................................................................... 32 buttonsize ................................................................................................................................................ 34 call ........................................................................................................................................................... 36 checkbox ................................................................................................................................................. 39 clearscreen............................................................................................................................................... 44 closefile ................................................................................................................................................... 46 column..................................................................................................................................................... 47 columnheader .......................................................................................................................................... 55 columnorder ............................................................................................................................................ 57 columnsize .............................................................................................................................................. 59 columnwidth ........................................................................................................................................... 61 comment .................................................................................................................................................. 63 copytext ................................................................................................................................................... 64 del............................................................................................................................................................ 79 dropdownlist ........................................................................................................................................... 86 enter......................................................................................................................................................... 89 fieldsize ................................................................................................................................................... 92 file ........................................................................................................................................................... 94 getfieldattribute ....................................................................................................................................... 95 gettableattribute....................................................................................................................................... 99 globaltextreplace ................................................................................................................................... 101 image ..................................................................................................................................................... 107 inputfield ............................................................................................................................................... 112 leave ...................................................................................................................................................... 137 load........................................................................................................................................................ 138 localvaluehelp ....................................................................................................................................... 139 Loops..................................................................................................................................................... 142 do - while .......................................................................................................................................... 142 for ...................................................................................................................................................... 144 goto - label ........................................................................................................................................ 146 if - else .............................................................................................................................................. 148 message ................................................................................................................................................. 151 nodropdownlist ..................................................................................................................................... 153 noinput .................................................................................................................................................. 155 21

WS/64 Developer Guide

noscrollbar............................................................................................................................................. 158 onmessage ............................................................................................................................................. 160 onscreen ................................................................................................................................................ 161 onUIEvents ........................................................................................................................................... 162 openfile ................................................................................................................................................. 166 pos ......................................................................................................................................................... 167 pushbutton ............................................................................................................................................. 172 radiobutton ............................................................................................................................................ 182 readfile .................................................................................................................................................. 189 removefile ............................................................................................................................................. 192 return ..................................................................................................................................................... 193 rfcconnect .............................................................................................................................................. 196 set .......................................................................................................................................................... 198 setcursor ................................................................................................................................................ 208 statusmessage ........................................................................................................................................ 213 switchto ................................................................................................................................................. 218 table ....................................................................................................................................................... 221 text......................................................................................................................................................... 226 textbox................................................................................................................................................... 235 tip .......................................................................................................................................................... 240 title ........................................................................................................................................................ 246 versionnumber....................................................................................................................................... 249 view ....................................................................................................................................................... 250 windowsize ........................................................................................................................................... 258 ws<command> ...................................................................................................................................... 260 wsmessage............................................................................................................................................. 262 ws_ ........................................................................................................................................................ 264 ws_log ............................................................................................................................................... 264 ws_WS .............................................................................................................................................. 266 ws_vap .............................................................................................................................................. 267

22

WS/64 Developer Guide

appendfile
In order to add a new record to an existing file in WS, users can utilize the appendfile command. This command enables users to quickly add data to a SAP screen or record using an external source. The syntax is as follows: appendfile("filename", {"var1":true, "var2":true, "var3":true, "var4":true}); When appending or writing to a file, the flag 'output' must be set to 'true' when opening a file. Each variable to be added is declared and then is marked true or false in the code as shown above. Those variables marked as being 'true' will be appended to the file in question. If a variable is marked false, it will not be appended to the record in question. The supported file types are as follows: .csv .txt .xls

Options
The appendfile command takes the following options: user-selected variable: This is chosen by the user depending on how the information in the file is categorized. By listing the variables, the user specifies what data will be appended. Please see the examples below for demonstrations on some of the possible usages.

Example
In the following example, we will append a record to the file "filename". Open the script file and add the following lines of code: openfile("filenames.txt", {"delimiter":";", "output":true}); name1 = "John"; name2 = "Nancy"; name3 = "Alexander"; appendfile("filenames.txt", {"name1":true, "name2":true, "name3":true}); closefile("filenames.txt"); We have now added the records for John, Nancy and Alexander to the file 'Filename.csv'.

23

WS/64 Developer Guide

applyguiscript
The applyguiscript command is used primarily to pass variables from a WS script to a Visual Basic Script (VBScript). This is useful primarily when a user is dealing with special controls such as grids or ActiveX controls. The syntax is as follows: applyguiscript('filename.vbs'); applyguiscript('C:\\guixt\\vbscripts\\filename.vbs'); As shown above, either the full path or the relative path for the VBScript file can be used. In our example we are using the relative path, meaning that the command will look only in the designated script directory.

Options
The applyguiscript command takes the following option: template: Enables users to execute a pre-made template with the particular variables from the individual screen.

template
The template option used with applyguiscript enables a user to create a VBS file which is then called with the applyguiscript command. When applyguiscript is invoked, the template is copied into a temporary file and all variables in the template are replaced with the actual values from the screen in question. The VBS file then executes using these variables. This is very useful when a number of different values must be operated on in a similar manner. One script only needs to be written, but it can be called any time necessary. The syntax for this is as follows: applyguiscript("filename", {"template":true});

Examples
In the following example, we will use a pushbutton to execute a process that includes calling a VBScript. The VBScript is named 'test_apgs1.vbs' and will be placed in the designated script directory. We will then create a custom function that will include the applyguiscript commend to call the VBS script. The screen is displayed as shown below:

24

WS/64 Developer Guide

The code is as follows: for(a=firstChild; a!=null; a=a.nextSibling) a.del(); pushbutton([3,17],"Display Image in Attachment" , "/niw22",{"process":iw21_displayatt,"size":[1,30]}); function iw21_displayatt(){ onscreen 'SAPLIQS0.0100' set("F[Notification]" , "10008358"); enter(); onscreen 'SAPLIQS0.7200' applyguiscript('test_apgs1.vbs'); onscreen '*' onscreen 'SAPLIQS0.7200' enter("/n"); } Once the name of the VBS script has been passed to GuiXT, users can employ the applyguiscript command to call the specified VBScript as shown in the preceding example. A dialog box as shown below will notify the user that a script is trying to attach to the SAP GUI:

25

WS/64 Developer Guide

Once the user clicks OK, the script will execute. In this case the VBScript is what will actually display the specified image in an attachment.

26

WS/64 Developer Guide

Using a Template
In the following example, we have created a VBS script template, called 'Script1_ih06_1vbs_txt'. This will be executed from the IH06 Display Functional Location screen and is called by pressing the 'TEST SCRI' pushbutton shown below:

Once the user presses this pushbutton, the template will be copied into a temporary file, the variables will be replaced and the file will then execute. The code for this is as follows: pushbutton([3,85], 'TEST SCRIPT', {"process":Script1_ih06_1vbs_txt}); function Script1_ih06_1vbs_txt(){ onscreen 'riiflo20.1000' set("V[grid_row]", '8'); applyguiscript("Script1_ih06_1.vbs",{"template":true}); } The IH06 screen is shown below in its initial state:

After the process has executed, the screen will display as in the following example:

27

WS/64 Developer Guide

28

WS/64 Developer Guide

box
The box command enables users to create boxes for either s single screen element or a group of elements. This command is very useful when a user wishes to create a cleaner interface and enclose SAP elements into a single group. The box object includes properties specifying the parameters of the box, as well as starting and ending position. Other properties associated with the box command include the start row, end row, starting column and ending column. To use the box command, the syntax is as follows: box([row_start,column_start],[row_end,column_end], "Field label");

Options
The box command takes the following option: offset: This option specifies by how many rows and columns the box will be offset. Offset is relative to the screen margin so we need to specify by how much the box will be offset from the screen margin. The syntax is as follows: box( {"offset":[row_start,column_start]}, {"offset":[row_end,column_end]}, "Label");

Example
If we wanted to draw a box on the Easy Access screen, the first thing we would do is delete the existing elements, using the For loop shown below: for(a=firstChild; a!=null; a=a.nextSibling) a.del( ); What we want to do is draw a box entitled 'Quick Links'. In the script file 'SAPLSMTR_NAVIGATION.E0100.sjs', type the following: box( {"offset":[8,4]}, {"offset":[16,50]}, "Quick Links"); The Easy Access screen will now appear as shown in the example below:

29

WS/64 Developer Guide

What we have done is to create a box beginning at coordinates row 8 and column 4 and ending at coordinates row 16 and column 50. The box is entitled 'Quick Links'. It is not linked to any SAP transactions - it is merely a placeholder container for other elements. If the user wishes to include other elements in the box, it is possible to do that very simply. In the following example, we will add a pair of pushbuttons to the box, linked to methods calling particular transactions. To create the pushbuttons, add the following lines to the SAPLSMTR_NAVIGATION.E0100.sjs file: pushbutton( {"offset":[10,6]}, "View Notifications", "iw30"); pushbutton( {"offset":[12,6]}, "View Work Orders", "iw33"); We are using the 'offset' option to specify how far from the margin the new pushbuttons should be placed. Offset is relative to the box, not to the screen margin. Thus we still need to specify the starting and ending rows and columns for our new screen elements. The pushbutton name is the next element in the script (eg. View Notifications). Finally, the SAP transaction code that the pushbutton will call is included in the script (eg. iw30). This is important as without it, the pushbutton will not be able to function. The script file should now look like this: for(a=firstChild; a!=null; a=a.nextSibling) a.del( ); box( {"offset":[8,4]}, {"offset":[16,50]}, "Quick Links"); pushbutton( {"offset":[10,6]}, "View Notifications", "iw30"); pushbutton( {"offset":[12,6]}, "View Work Orders", "iw33"); The Easy Access screen will now appear as in the example below: 30

WS/64 Developer Guide

31

WS/64 Developer Guide

boxsize
The boxsize command is used to resize native screen controls - it cannot be used for user-created screen controls. The syntax for boxsize is as follows: boxsize("G[Box_name]",[rows,columns]);

Options
The boxsize command does not take any options.

Example
In this example, we are changing the size of the 'Organizational Data' groupbox screen control. The field is to change to something larger, without altering the field. We can use boxsize to accomplish that change. The original screen would appear as shown in the example below:

The altered screen is as displayed in the following example:

32

WS/64 Developer Guide

The code we used is the following: boxsize("G[Organizational Data]", [10, 50]);

33

WS/64 Developer Guide

buttonsize
The buttonsize command enables users to change the size of a given SAP pushbutton. The buttonsize command enables both width and height of a given button to be changed. the syntax is as follows: buttonsize("P[buttonName]", [rows, columns]); The buttonsize command can only be used on native pushbuttons - it does not work on usercreated GuiXT pushbuttons.

Options
The buttonsize command does not take any options.

Example
The rows and columns in the syntax above define the size of the button, not the starting row or column numbers. In the following example, we will navigate to the VA02 transaction in SAP and use the buttonsize command to change the height and width of the Search button on the screen. The default SAP screen appears as follows:

Once the button's attributes have been changed using the buttonsize command, the modified screen appears as shown in the below example:

34

WS/64 Developer Guide

The code to perform the modifications is shown below: buttonsize("P[Search]", [2,25]);

35

WS/64 Developer Guide

call
The call statement is used to call a function in WS. The function thus called will be a SAP function module on the SAP server itself. The call command is useful when users need to use a standard BAPI or when a user wishes to link a screen element to an action to be executed. This method also works well with functions. To use the call statement, we would use the following syntax: call('function_name', {"in.parameter":"value", "out.parameter":"value", "table.parameter":"value", "currentuser":true});

Options
The call command takes the following options: in.parameter: The parameter being sent to the BAPI by the call command. The syntax is: {"in.parameter":"value"} out.parameter: The parameter or parameters being returned from the BAPI. The syntax is: {"out.parameter":"value"} currentuser: Specifies that the RFC information for the current user's logon data will be used instead of the RFC logon information contained in the guixt.sjs configuration file. The syntax is as follows: {"currentuser":true} table.parameter: If value returned from BAPI is formatted as a table structure, then table parameter is used. The syntax is: {"table.parameter(width:value)":"value"}

These options are more fully explained below.

in.parameter
This option is used to specify the data table from which information is to be called. Typically, only a single in parameter would be included in the call command. In the below example, we are calling the user credentials from the USERNAME table, so the code would be as follows: call("BAPI_USER_GET_DETAIL",{"in.USERNAME":"&V[_user]","table.RETURN(w idth:3000)":"zguixt_return"});

out.parameter
This option is used to specify the values returned from the data table and to identify the variable where that value will be stored. Multiple out parameters could be returned, as in the following example: call("BAPI_USER_GET_DETAIL", {"in.USERNAME":"&V[_user]", "out.ADDRESS":"address", "out.COMPANY":"company", "table.RETURN(width:3000)":"zguixt_return", "currentuser":true});

currentuser
The call command can also be used to send the current SAP user's RFC credentials instead of the RFC data in the guixt.sjs configuration file. When used, this method will take precedence over an entry in the guixt.sjs for a single RFC user, but in turn is subordinate to an entry in the guixt.sjs configuration file for an rfcconnect array.

36

WS/64 Developer Guide

table.parameter(width:xxxx)
This will specify the table that will be accessed. The value of each row in the table is stored into an array. Width option is used to get the value of each row in the table structure if the total characters in a single row is more than 255 characters. In the following example, we will return data from the table 'RETURN' into the variable 'zguixt_return' and we will specify that we will return row values up to 3000 characters in width: call("BAPI_USER_GET_DETAIL",{"in.USERNAME":"&V[_user]","table.RETURN(w idth:3000)":"zguixt_return"});

Example
In the following example, we are creating a pushbutton that, when pressed, will make a call to a BAPI function. We will also create an inputfield to display the resulting message. The code for the pushbutton is as follows: del("X[IMAGE_CONTAINER]"); pushbutton([2,1] , "Call Example" ,{"process":test_call}); inputfield([2,20],"1.Message", [2,50], {"name":"z_type", "size":"70"}); The resulting screen is as follows:

The code for the function being called is shown below: function test_call(){ call("BAPI_USER_GET_DETAIL",{"in.USERNAME":"&V[_user]","table.RET URN(width:3000)":"zguixt_return"}); println("return:"+zguixt_return); for(i=0; i<zguixt_return.length; i++){ zguixt_var = zguixt_return[i].toString(); println("TYPE:"+zguixt_var.substring(0,1)); println("ID:"+zguixt_var.substring(1,21)); println("NUMBER:"+zguixt_var.substring(21,24)); println("MESSAGE:"+zguixt_var.substring(24,244)); } set("V[z_type]" , zguixt_return[0].toString().substring(24,244)) } 37

WS/64 Developer Guide

In the preceding example, we are making a call to the BAPI function 'USER_GET_DETAIL'. The input is the username, which in turn is pulled from a SAP table containing the user details. Once the requested data is returned, the function then prints out the user information in the console and will also display a message on the screen as shown below:

38

WS/64 Developer Guide

checkbox
Checkboxes in SAP are used when it is necessary to have users select options for particular screen elements. The checkbox command can be used to create or modify checkboxes on SAP screens. The syntax for using the checkbox command is as follows: checkbox([row,col], 'Label', {"name":"internal_name_of_checkbox"});

Options
The checkbox command takes the following options: default name offset readonly

default
The default option on a checkbox marks it as the default selection if more than one checkbox are present in a group. The syntax is as follows: "default":"X" In the following example, we will add three checkboxes, marking one as the default. The code is as follows: checkbox([15,9], "Check3"); checkbox([14,9], "Check2"); checkbox([13,9], "Check1",{ "default":"X"});

name
The 'name' option specifies the actual name of the checkbox that is created. This is not the onscreen label, but rather the unique name by which the SAP scripts will refer to the new screen element. The syntax is as follows: checkbox([13,9], "LABEL", {"name":"z_chkbx1","default":"X"});

offset
The 'offset' option is used to position the checkbox relative to another screen element. The syntax is as follows: checkbox({"field":"G[Organizational Data]", "offset":[8,5]}, "Check");

readonly
This option will make the checkbox appear to be grayed out and no data entry is possible. The syntax is as shown below: checkbox([15,9], "Check3", {"name":"z_chkbx3", "readonly":true});

39

WS/64 Developer Guide

Examples
On the VA01 screen, the default screen currently appears as shown below:

To add a checkbox, we would first open the SAPMV45A.E0101.sjs file and add a checkbox by adding the following line to the script file: checkbox([11,15], "Check1", {"name":"z_chkbx1"}); The 'Check1' is the onscreen label and the actual name of the new checkbox is 'z_chkbx1'. The VA01 screen should now appear as shown in the following example:

40

WS/64 Developer Guide

In the preceding example, the checkbox is not checked. However, you can set the checkbox value to either 'checked' or 'unchecked' by adding the 'default' option to the code. In the following example, we will add two more checkboxes, and set the top one as the default. the code will be as follows: checkbox([11,15], "Check1", {"name":"z_chkbx1", "default":"x"}); checkbox([13,15], "Check3", {"name":"z_chkbx2"}); checkbox([12,15], "Check2", {"name":"z_chkbx3}); If the default value is set to 'x', then the VA01 screen will appear as shown below:

41

WS/64 Developer Guide

To make one or more checkboxes as read-only, add the readonly option. The code would now be as follows: checkbox([11,15], "Check1", {"name":"z_chkbx1", "readonly":true, "default":"x"}); checkbox([13,15], "Check3", {"name":"z_chkbx2", "readonly":true}); checkbox([12,15], "Check2", {"name":"z_chkbx3", "readonly":true}); The VA01 screen now appears as follows:

42

WS/64 Developer Guide

43

WS/64 Developer Guide

clearscreen
The clearscreen command is used to delete all the screen objects on a given SAP screen. It can be used instead of the del command. This is particularly useful when preparing a given screen for a custom appearance as in the case of a Mobile application. The syntax is as follows: clearscreen();

Options
The clearscreen command does not take any options.

Example
The clearscreen command offers users a simpler method of clearing all existing screen elements for a SAP screen as opposed to using a for loop with the del command as described in the 'for loop' section of this document. In the following example, we will use the clearscreen command to delete all elements on the default MM01 screen. The default screen appears as in the following example:

To delete the existing elements, we will add the following code to the SAPMV45A.E0100.sjs script file: clearscreen(); The MM01 screen will now appear as shown in the following example:

44

WS/64 Developer Guide

All native elements have now been removed and the screen is ready for a user to add custom GuiXT elements.

45

WS/64 Developer Guide

closefile
Once a file has been read, users can apply the Closefile command to close the file. The syntax is as follows: closefile("filename");

Options
The closefile command does not take any options.

Example
In the following example, we will close the file we used in the previous examples. The code would be as follows: closefile("file2.txt"); The file is now closed for reading or editing.

46

WS/64 Developer Guide

column
The Column command is used to define and specify column controls in GuiXT WS. This command can add columns to an existing table or change existing columns in a given table. Within the command, users can specify the column headings, widths, positions within the table and other options for new columns. The syntax is as follows: column("heading", {"size":x, "name":"column_name", "option":value}); In addition to being capable of operating on a native SAP table control, the Column command also can be used in conjunction with the WS table command to create new columns in a user-created table, as shown in the following example. First we will use the table command to create a new table: table([2,1], [20,50], {"name":"va01_lnitms", "title":"All Items", "rows":100}); Then we will use the Column command to add columns to our new table control as follows: column('Item', {"size":5, "name":"va01_clitm", "position":1}); column('Material', {"size":18, "name":"va01_clitm", "position":2}); column('Quantity', {"size":10, "name":va01_clitm", "position":3}); column('Item Category', {"size":10, "name":va01_clitm", "position":4});

47

WS/64 Developer Guide

Options
There are several options that can be used in conjunction with a new column. These options are as follows: alignright: The field value will be aligned to the right if this is set to 'true'. This option only works if the field is also in readonly mode. The syntax is: {"alignright":true} checkbox: The column value will be displayed as a checkbox if this option is set 'true'. Possible values are 'X' and ' '. The syntax is: {"checkbox":true } intensified: The field value is displayed in a color other than black if this option is set to 'true'. The default color is red. This option cannot be used with the 'readonly' option and the syntax is: {"intensified":true} keycolumn: If the user adds or deletes rows in a SAP table, the 'absrow' row number can change. The matching index will also disappear in this case, so the 'keycolumn' option is used to relate the new column to another column in order to create a consistent reference. If this option is used, automatic indexing of the custom column will be based on the value of the assigned keycolumn. If no keycolumn is assigned, the column will be appended to the end of the table. The syntax is: {"keycolumn":"XYZ"} This option can only be used with a native SAP table.

name: Specifies the name of the column. This is not the label visible to the user but rather the internal name of the column by which scripts may refer to it. The syntax is as follows: {"name":"Xxx"} numerical : Only numerical input is allowed if this option is set to 'true'. This option cannot be used with the 'uppercase' option and the syntax is: {"numerical":true} position: Specifies the position of the column within the table. If the position option is left unspecified, the new column will be the last column in the table. The syntax is: {"position":x} readonly: Specifies that the new column will be non-editable and no input will be allowed. The syntax is: {"readonly":true} size: Specifies the size in number of characters where 'x' will be replaced by a number. The syntax is: {"size":x} searchhelp: Defines the searchhelp (F4) for the new column. The syntax is as shown below: {"searchhelp":"value"}

48

WS/64 Developer Guide

table: Specifies the table in which the column will be created. This option is only necessary if more than one table are present on the given screen. The syntax is: {"table":"T[table_name]"} techname: Defines the technical name of the column. The syntax is as follows: {"techname":"table_tech_name"} uppercase: Only uppercase input is allowed for the column if this option is set 'true'. This option cannot be used with the 'numerical' option and the syntax is shown below: {"uppercase":true}

49

WS/64 Developer Guide

Examples
Creating a new column
In the following example, we will create a new column in the table 'All items', on the screen using some of the options previously introduced. The code would be as follows: column("MyOrders", {"table":"All items", "size":5, "name":"z_mycol", "techname":"VBAP_MATNR"}); The column created by the above code is added to the existing table on the given screen and is shown in the following example:

50

WS/64 Developer Guide

Using keycolumn
If a user wishes to tie a new column to an existing column in a table, the keycolumn option can be used. In the following example, we will use the 'Material' column as the keycolumn and add a new column beside it. In addition, we will apply the intensified and size options. The code is as follows: column("MyOrders", {"table":"All items", "size":5, "name":"z_mycol", "techname":"VBAP_MATNR", "keycolumn":"Material", "postion":5, "size":5, "intensified":true}); The table now displays as shown below:

51

WS/64 Developer Guide

Using a checkbox
With the 'checkbox' option, a column can be converted into a checkbox as in the following example. We will convert our new column into a checkbox with the following code: column("MyOrders", {"table":"All items", "size":5, "name":"z_mycol", "techname":"VBAP_MATNR", "checkbox":true}); The screen now displays as follows:

52

WS/64 Developer Guide

searchhelp
To add searchhelp to an user-created column in the All items table,users would add the following code: column("Test Column", {"table":"All items", "size":10, "name":"z_testcol", "position":1, "searchhelp":"S_MAT1", "shname":"MATNR", "shname1":"VBAB_MATNR", "shdest1":"V[z_testcol_desc]"}); The table would now appear as shown below:

When a user clicks on the searchhelp beside the newly created table column 'Test Column', the following searchhelp will appear:

53

WS/64 Developer Guide

54

WS/64 Developer Guide

columnheader
The columnheader command can change the column headers in a table control in an SAP screen. Please note that it can only be used on native SAP table columns, not on user-created columns. This command can also be used to add an icon and tooltip to a table header. There are two possible syntaxes, which are as follows. The second is used only when there is more than one table on the screen in question: columnheader("Col_name", "new_Col_Name"); columnheader("[table_name, Col_Name]", "new_Col_Name"); columnheader("table_name, column_name", "new_Col_name"); This command can only be used with native SAP tables.

Options
The columnheader command does not take any options.

Examples
Changing column headings
In the following example, we will use the columnheader command to change the heading of the column 'Material' to 'Test Material'. The code is as follows: columnheader("Material", "Test Material"); The resulting screen is shown below:

55

WS/64 Developer Guide

Inserting tooltips
The columnheader command can also be used to insert a tooltip into a column header, as shown in the following example: columnheader("Material","@\\QTooltip for test column@Test column"); In the preceding example, the tooltip is specified by the '@\\QTooltip for test column' and the new column name is designated by the '@Test Material' code. If a user hovers the cursor over the column, the screen will display as shown below:

56

WS/64 Developer Guide

columnorder
The columnorder command can define the position of a column in a given table, but it cannot be used on user-created columns. There are two possible syntaxes. For a single table on a given screen, the syntax is as follows: columnorder("[Material]" ,position); If multiple tables exist on a screen, the syntax must include the table name as shown below: columnorder("[table_name, column_name]", position); columnorder("table_name, column_name", position);

The first example above is used if there is a single table on the given screen. In this case, it is necessary only to specify the column name and the value to be populated. However, if there are multiple tables on a screen, the user must specify which table is to be referenced, in addition to the column name and the value to be populated. The syntax for this is as follows:

Options
The columnorder command does not take any options.

Examples
Moving an existing column
To move an existing column, we must specify either the label or the name of the column. The values that are populated can be either of the following: Actual string Variable string In the following example, we are moving the column 'Material' to a new position with the table 'All items'. The code will be as follows: columnorder("[Material]", 5); The results are shown below:

57

WS/64 Developer Guide

58

WS/64 Developer Guide

columnsize
The columnsize command sets the size of a given column in a table by specifying the actual size in pixels. The value must be set to less than the default size of the column as it is used primarily to restrict entry. The size cannot be set to a value greater than the column's original size. This command can be used either on native SAP columns or on user-created columns. The columnsize command differs slightly from the columnwidth command described below although they are very similar in function. The major difference is that with the columnwidth command, the column size can be changed in a script with the 'size' option. However, once a size is set with columnsize, it cannot be changed in a script. There are two syntaxes, which usage depends on whether there are multiple tables on a screen. For a single table, the syntax is as follows: columnsize("colName", value); For multiple tables, the syntax would be either of the two syntaxes shown below: columnsize("[table_name, column_name]", value); columnsize("table_name, column_name", value); If the value is set to zero (0), the column itself will be deleted. This command works only with native SAP table columns.

Options
The columnsize command does not take any options

Examples
Resizing table columns
In the following example, we will alter the previously created column by applying the columnsize command. The code would be as follows: columnsize("Material", 15); The newly resized column is shown as follows:

59

WS/64 Developer Guide

Hiding columns
If the value is set to zero (0), the column will be made invisible. To hide the 'Material' column, the code would be as follows: columnsize("[Material]", 0); The table would now appear as follows:

60

WS/64 Developer Guide

columnwidth
The columnwidth command can set the width of a column by specifying the width in pixels. There are two possible syntaxes. If there is only a single table on a screen, the syntax is as follows: columnwidth("[column_name]", value); If multiple tables exist on a screen, the syntax would be as shown below: columnwidth("[Table_name, column]", value); columnwidth("table_name, column_name", value); This command can only be used with native SAP tables.

Options
The columnwidth command does not take any options.

Example
In the following example, we are using columnwidth to resize the column 'SU' in the 'All items' table on the SAPMV45A.E4001 screen. The code is as follows: columnwidth("[All items, Material]", 3); The table with the resized column is shown below:

To change the width to fifteen pixels, we would change the code as shown below: columnwidth("[All items, Material]", 15);

The 'Material' column would now appear as follows:

61

WS/64 Developer Guide

Removing columns
By setting the width to zero (0), it is possible to hide or remove a column. In the following example, we will remove the 'Material' column. The code is as follows: columnwidth("[All items, Material]", 0); The table appears as follows. Note the Material column has been deleted.

62

WS/64 Developer Guide

comment
The comment command is used to create blue-colored text, indicating that the text in question is a comment. The on-screen position of the text can also be specified with the comment command. The syntax for the command is as follows: comment([startRrow,startCol], "text");

Options
The comment command takes no options.

Example
In the following example, we are adding a comment to the initial Create Sales Order screen to notify the user that he or she must enter a valid order type as shown below:

The code is as follows: comment([0,1], "Please fill out all required fields!"); Comments can be added to any screen and can be set as conditions by using conditional statements such as If statements.

63

WS/64 Developer Guide

copytext
The copytext command is used primarily to copy text between files, screen areas or text variables. The available syntaxes are as follows: Syntax Description Copies from one text box to another. copytext({"fromtext":"textbox_name", Textboxes can be native SAP elements "totext":"textbox_name"}); or user-created elements. copytext({"fromtext":"textbox_name", Copies text from a textbox to a string "tostring":"variable_name", "line":x}); variable. copytext({"fromtext":"textbox_name", Copies text from a textbox to a screen "toscreen":"X[area_name]"}); element such as a long text field. Copies text from a string variable to a copytext({"fromstring":"variable_name", screen element such as a long text "toscreen":"X[area_name]"}); field. copytext({"fromstring":"variable_name", Copies text from a string variable to a "tostring":"variable name"}); different string variable. copytext({"fromstring":"variable_name", Copies text from a string variable to a "totext":"textbox name"}); text box. copytext({"fromscreen":"X[area_name]", Copies text from a screen element such "totext":"textbox_name"}); as a long text field to a text box. copytext({"fromscreen":"X[area_name]", Copies text from a screen element such "tostring":"textbox_name"}); as a long text field to a string variable. The options in copytext specify the source and the destination to where the given text will be copied. The copytext command can be used to copy text from any of the following sources: Screens: Text can be copied from a native SAP screen element using the 'fromscreen' syntax. Please note that the copy action actually will occur when the screen in question is displayed or upon the ensuing 'enter' command in a script. Textboxes: Text can be copied from user-created textboxes using the 'fromtext' syntax. Variables: Text can be copied from a string variable using the 'fromstring' syntax. In addition, copytext can copy text into the following areas: Screens: Text can be copied into a SAP screen element using the 'toscreen' syntax. The area into which the text will be copied must be specified in the command. See the examples for additional information. Textboxes: Text can be copied into a user-created textbox using the 'totext' syntax. Variables: Text can be copied into any string variable using the 'tostring' syntax.

64

WS/64 Developer Guide

Options
The copytext command has several options that can be used with the command. fromtext: Specifies that the text will be copied from a native or user-created textbox on a SAP screen. Syntax is: {"fromtext":"textbox_name"} fromstring: Specifies that the text will be copied from a string variable. Syntax is: {"fromstring":"var_name"} fromscreen: Specifies that the text will be copied from a user-specified screen element such as a long text field. Syntax is: {"fromscreen":"X[area_name]"} totext: Specifies that the text will be copied into a user-created or a native SAP textbox on a SAP screen. The 'append' and 'appendline' options can be used in this case. Syntax is: {"totext":"textbox_name"} tostring: Specifies that the text will be copied into a string variable. Syntax is: {"tostring":"var_name"} toscreen: Specifies that the text will be copied into a user-designated screen element such as a long text field. The 'append' and 'appendline' options can be used in this case. Syntax is: {"toscreen":"X[area_name]"} append: When the append option is used, the text will be appended to the end of the last line in the target text. The syntax is: {"append":true} appendline: This option works very similarly to the 'append' option, but will add the source text to the destination text as a new line. The syntax is: {"appendline":true} delimiter: This option specifies the character used to separate text to be copied. The character to be used as a delimiter would be placed in the quotes. The syntax is: {"delimiter":""} line: This option enables users to specify the number of the desired line to be copied into the string, starting with '1'. This option can only be used when copying to a string. The syntax is as follows: {"line": X}

65

WS/64 Developer Guide

Examples
Copying to and from Strings
In the following example, we are copying the text from the textbox 'z_copytext' shown below into the string 'z_copystring'. The string can then be used to copy into some other area, such as another textbox or even into a table cell, though not directly with the copytext command.. In our example, we first create an inputfield on the VA01 screen with the following code: textbox([1,90], [2,110],{ "name":"z_copytext", "textfont":"Arial", "textheight":"12", "textweight":"5"}); We then create a pushbutton since we will trigger our copy operation manually. The code is as follows: pushbutton([TOOLBAR],"Replace","/nmm01",{"process":copy_test}); Textboxes are explained in more detail in the textbox section. Here we will input some text into the textbox and then place that text into the designated table cell. The function code for this is as follows: function copy_test(){ onscreen 'SAPMV45A.4001' copytext({"fromstring":"z_copytext","tostring":"z_copystring"}); set('cell[All items,Material,1]', '&V[z_copystring]'); set('cell[All items,Order Quantity,1]', '1'); enter(); } On the relevant screen, we can enter the material in a textbox and then copy it into the relevant table field. The results are shown below:

66

WS/64 Developer Guide

Copying to long text fields


In the following example, we will copy text to some long text fields in the IW32 transaction. We have created some inputfields and added some long text to the SAPLCOIH.3000 screen as shown below:

The code is as follows: textbox([2,87], [7,117],{ "name":"iw32_text", "textfont":"Arial", "textheight":"12", "textweight":"5"}); pushbutton([TOOLBAR], "Screen Copy",{ "process":copy_test}); function copy_test(){ onscreen 'SAPLCOIH.3000' copytext({"fromstring":"iw32_text","toscreen":"X[LTEXT]"}); enter(); } We will now input some text into the newly created textbox and press the pushbutton to trigger the operation that will overwrite the long text that currently exists. The screen now appears as follows:

67

WS/64 Developer Guide

To append text, we would alter our function code as follows: function copy_test(){ onscreen 'SAPLCOIH.3000' copytext({"totext":"iw32_text","fromscreen":"X[LTEXT]", "append":true}); enter(); } After performing the copytext operation, the screen will now appear as shown below:

68

WS/64 Developer Guide

To append on a new line, we would replace the 'append' option with the 'appendline' option: function copy_test(){ onscreen 'SAPLCOIH.3000' copytext({"totext":"iw32_text","fromscreen":"X[LTEXT]", "appendline":true}); enter(); } The results appear below:

69

WS/64 Developer Guide

70

WS/64 Developer Guide

Appending text
To append text, we have created a third textbox, which is defined as follows: textbox([16,1], [18,117], { "name":"z_append", "textfont":"Arial", "textheight":"12", "textweight":"5"}); We will then create a toolbar pushbutton that will call a function to actually perform the appending operation. The code for the pushbutton is as follows: pushbutton([TOOLBAR], "Append",{ "process":append_test}); The actual function called by the pushbutton is as follows: function append_test(){ println("Appending content!"); copytext({"fromtext":"z_append","totext":"z_copyto", "appendline":true}); println("Content appended!"); enter(); } The text to be appended is pulled from the inputfield we have created. The result of the appending operation is shown below:

71

WS/64 Developer Guide

Reading text
To demonstrate how to use the copytext command to print out some text that is read, we created a readonly field directly below the Append text field using the 'readonly' option. We also created an inputfield to specify the line to be read. The code is as follows: inputfield([19,1], "Read Text", [19,20], {"name":"z_read", "readonly":true, "size":20}); inputfield([19,42],{"name":"z_line","size":2,"nolabel":true}); text([19,46],"Enter line number for the text"); To trigger the operation, we have created a toolbar pushbutton, as follows: pushbutton([TOOLBAR], "Read", {"process":read_test}); When the 'Read' toolbar button is pressed, the text corresponding to the line number entered by the user will be placed into the readonly field using the following function: function read_test() { println("Reading content!"); if(z_line == void 0 || z_line == "") { return("Please enter line number."); } set("V[z_temp]" , "&V[z_line]"); copytext({"fromtext":"z_copyfrom","tostring":"z_read","line":z_te mp}); println("Content read!"); } The results are shown below:

72

WS/64 Developer Guide

Copying Full Text


If the append or appendline options are not used, copytext will overwrite the contents of the destination field. In this example we will use the copytext command to copy the contents of the first text field and replace the contents of the second text field. The code is as follows: pushbutton([TOOLBAR}, "Copy Full Text", "/nmm01", {"process":test_copy"}); function text_copy() { copytext({"totext":"z_totext", "fromtext":"z_text"}); } When the 'Copy Full Text' button is pressed the contents of the first field are overwritten by the contents of the second. The results are shown below:

73

WS/64 Developer Guide

Populating text to screen blocks


Please note that if a user tries to populate text into a screen block following the block in which the control is located, it is necessary to use 'fromstring' instead of 'fromtext'. The reason for this is that if 'fromtext' is used, the scope of the control will change and it will become a variable string instead of a text, resulting in the operation's failure. In our example, we are copying text from a user-created textbox to a long text field on the IW32 screen, which is named 'SAPLCOIH.3000'. The script code is as shown below: textbox([2,87], [5,121],{ "name":"iw32_text", "textfont":"Arial", "textheight":"12", "textweight":"5"}); pushbutton([TOOLBAR], "Screen Copy",{ "process":copy_test}); function copy_test(){ onscreen 'SAPLCOIH.3000' copytext({"fromstring":"iw32_text","toscreen":"X[LTEXT]"}); enter(); } The resulting screen would appear as in the following example:

In order to copy text from a screen block, the following syntaxes would be used: copytext({"tostring":"iw32_text","fromscreen":"X[LTEXT]"}); copytext({"totext":"iw32_text","fromscreen":"X[LTEXT]"}); Users can also employ a variable to specify the line number. In the following example, we are looping through each line in the textbox and copying the value to a variable. We then use a trim function to trim the whitespace and place the value into an array, from whence it will be moved into the All Items table with the set command. The code is as follows: textbox([7,82], [11,113],{ "name":"z_copytext","textfont":"Arial","textheight":"12", "textweight":"5"}); pushbutton([TOOLBAR], "Screen Copy",{ "process":copy_test}); function isBlank(jvar) { 74

WS/64 Developer Guide

if (typeof jvar == 'string'){ jvar = jvar.trim(); } return(jvar == null || jvar=="" || jvar == void 0); } String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); } function var var var for copy_test(){ z_str = ""; arMaterial = []; lastIndex = 2; (var loop = 1; loop <lastIndex; loop++){ copytext({"fromtext":"z_copytext", "tostring":"z_str", "line":loop}); if (isBlank(z_str)){ break; } arMaterial.push(z_str.trim()); lastIndex++; } relrow=1; absrow=1; row_max=0; materialvalue=""; gettableattribute("T[All items]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LastRow"}); new_screen: enter('/ScrollToLine=&V[absrow]', {"table":"T[All items]"}); //scroll the table to the absolute row onscreen '*' println("Inside 2nd Screen Block"); gettableattribute("T[All items]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LastRow"}); println("After get table attribute"); relrow=1; new_row: if (row_max == arMaterial.length){ goto end_of_table; } if(absrow>LVisRow) { //

75

WS/64 Developer Guide

end of screen? goto new_screen; } //set("cell[All items,Material,&V[relrow]]", "&V[materialvalue]"); set("cell[All items,Material,&V[relrow]]", arMaterial[row_max]); set("cell[All items,Order Quantity,&V[relrow]]", 1); set("V[tmp1]", "&cell[All items,Material,&V[relrow]]"); set("V[tmp2]", "&cell[All items,Order Quantity,&V[relrow]]"); println('**********tmp1 and tmp2 = ' + tmp1 + ' & ' + tmp2); enter(); onmessage if (_message){ //.... error handling } onscreen 'SAPLATP4.0500' next_stock_item:; onscreen 'SAPLATP4.0500' goto next_stock_item; onscreen 'SAPMV45A.4001' row_max++; absrow=absrow+1; relrow++; goto new_row; end_of_table:; enter('/ScrollToLine=1', {"table":"T[All items]"}); }

76

WS/64 Developer Guide

Using the delimiter


The delimiter option specifies a character that will be used to stop the copying operating. In other words, the copytext operation will process up to the specified character and will then stop, copying only the text preceding the delimiter character. The 'line' option can be used in conjunction with the delimiter to further restrict the copied text to a particular line. In the following example, we will put some text into the first textbox as shown below.

We will then specify the line to be copied and copy all the text preceding the first comma. The code is as follows: textbox([2,1], [8,117], { "name":"z_copyfrom", "textfont":"Arial", "textheight":"12", "textweight":"5"}); textbox([9,1], [15,117], { "name":"z_copyto", "textfont":"Arial", "textheight":"12", "textweight":"5"}); inputfield([19,42],{"name":"z_line","size":2,"nolabel":true}); text([19,45],"Enter line number for the text"); pushbutton([TOOLBAR], "Read", {"process":read_test}); function read_test() { println("Reading content!"); if(z_line == "") { return("E: Please enter line number."); } set("V[z_temp]" , "&V[z_line]"); copytext({"fromtext":"z_copyfrom", "totext":"z_copyto", "line":z_temp, "delimiter":","}); println("Content read and copied!"); } The resulting screen will appear as follows: 77

WS/64 Developer Guide

78

WS/64 Developer Guide

del
The del command is used to remove screen elements from a SAP screen. The syntax for using the del command is as follows: del("[screen_element]", {"option":true}); Elements that can be removed using del are listed in the following table. The syntax for each is shown in the following table: del("F[Inputfield]"); del("P[Tab]"); del("G[Group box]"); del("P[Application Toolbar Button]"); del("M[Menu label]"); del("S[Tab Strip]"); del("M[/Menu function del("T[Table]"); key]"); del("P[Pushbutton]"); del("X[Grid]"); del("R[Radiobutton]"); del("C[Checkbox]");

Options
The del command can be used with the following option: box: This option is used only with groupboxes. It specifies that only the surrounding box will be deleted. Any elements inside the box will remain on the screen. The syntax is: {"box":true} text: The text option is also restricted to use with input fields. This option is used to specify that only the text associated with an input field will be deleted. The syntax is: {"text":true} triple: This option is specific to input fields and is used to specify that any additional text fields behind the entry field will also be deleted. The syntax is: {"triple":true} value: Like the triple and text options, this is specific to input fields. It is used to specify that only actual entry field will be deleted. The syntax is: {"value":true} withBox: This option is used to remove any elements associated with tabstrips. This is only applicable for tabstrips it is not applicable with any other controls.. The syntax is case-sensitive and would be as follows: {"withBox":true}

79

WS/64 Developer Guide

Examples
Deleting single elements
To delete a single element, users would use the del command to remove the element. Using the SAP transaction IW30, we will remove the 'Partners' inputfield. The original Notification screen is shown below:

In the script file RIQMEL10.E1000.sjs, add the following line: del("F[Partners]"); The screen should now appear as shown below:

80

WS/64 Developer Guide

81

WS/64 Developer Guide

Deleting tab strips


In this example, we would be removing the tab strip 'SALES' and would also remove the accompanying box, since the Boolean value is marked as being 'true'. If the value was marked 'false' the box would remain although the tabstrip itself would be removed. The code is as follows: del("T[SALES]", {"withbox":true}); The screen now appears as shown below:

82

WS/64 Developer Guide

Deleting group boxes


In this example, we would be removing the group box 'Organizational Data' on the VA01 initial screen. The code is as follows: del("G[Organizational Data]", {"box":true}); The screen now appears as shown below:

83

WS/64 Developer Guide

Deleting field values


In this example, we would be removing the group box 'Organizational Data' on the VA01 initial screen. The code is as follows: del("F[Sales Organization]", {"value":true}); The screen now appears as shown below:

84

WS/64 Developer Guide

Using del as a method


In addition to being used as a standalone command, del can also be used as an object method to remove elements of that object. If the command is being used as a method, the syntax would be as follows: var objectName = <'[screen_control]'>; objectName.del( ); In the example, we will use create an object and then use del as a method to delete all objects contained on the Easy Access screen. To do this, we will add the following code in the SAPLSMTR_NAVIGATION.E0100.sjs script file: for(a=firstChild; a!=null; a=a.nextSibling) a.del( ); In the preceding example, we have declared an object 'a', and then used the method 'del' to delete all objects on the screen. The Easy Access screen will now appear as follows:

85

WS/64 Developer Guide

dropdownlist
The dropdownlist command, also sometimes referred to as the combobox command, displays a dropdown list, from which users can trigger actions. Once an action is triggered, the combobox can populate ensuing screens or controls with the values that the user inputs on the original screen. The syntax is as follows: set(V[variable],value); dropdownlist([18,0], "variable" ,{"refer":"V[z_variableselected]", "width":30,"process":process_name,"textfont":"verdana","textheight":13 ,"textweight":6});

Options
The dropdownlist command takes several options. All options employ a similar syntax, as follows: {"option":"stringValue"} ("option":BooleanValue} {"option":numericalValue} The available options for dropdownlist are as follows. process: The process option enables users to call a process from a dropdownlist. refer: This option enables users to pass a the selected option from the dropdownlist into another screen or screen element. textfont: This option enables users to specify the font to be used for the options listed in the dropdownlist. textheight: This option enables users to specify the font to be used for the options listed in the dropdownlist. textweight: This option enables users to specify the font to be used for the options listed in the dropdownlist. width: This option enables users to specify the actual width of the dropdownlist that will be created. The width is specified in onscreen columns.

Example
Data used in the dropdown list can be drawn either from a text variable or from a textbox. In the following example, we are pulling data from a text variable and using a dropdownlist to display that data. Users can enter the following code into the MM01 script file: set("V[mylist]", "=--- Select Industry Type ---;B=Beverage;C=Chemical Industry;M=Mechanical Engineering;"); dropdownlist([10, 0], "mylist", {"refer":"F[Industry sector]", "width":30, "process":test_dropdown}); function test_dropdown(){ set("F[Industry sector]", z_ordertypeselected); set("F[Material Type]", "FERT"); enter(); } What we are doing is creating the dropdownlist by specifying the variables, specifying to what field the values will be passed and then finally specifying a process that will run and actually pass those values to the field in question. The screen would appear as shown below:

86

WS/64 Developer Guide

Clicking on the dropdownlist would produce the following result:

87

WS/64 Developer Guide

In our example, we have a dropdown list containing three different options as follows: Beverage (tcode B) Chemical (tcode C) Mechanical Engineering (tcode M) When a user selects an option from the dropdownlist, the process executes, entering the values chosen into the specified field and the SAP process continues. If no process were specified, users can still manually execute the operation by pressing Enter.

88

WS/64 Developer Guide

enter
The enter command is used to simulate user actions within SAP screens. Enter can be used to trigger function codes (fcodes), SAP transactions, functions, and other such actions. This command is usually used in conjunction with the 'onscreen' command. The syntax is as follows: enter('action');

Parameters
The value passed to the command can be any one of the following: Function key code: For example, to perform the F3 key command, the following syntax is used: enter('/3'); SAP Transaction code: For example to launch the VA01 transaction in SAP, the following code is used: enter('/nva01'); Function code associated with a pushbutton or menu item: For example, to trigger a function entitled 'HEAD', the following code is used: enter('=HEAD'); Launch SYSTEM > STATUS window: The following code is used: enter('?STAT'); No parameters: Perform a simple enter command with no parameters being passed. The code is as follows: enter(); scrolltoline: Scroll to a specific line in a given table. The code is as follows: enter('/scrolltoline=19', {"table":"T[TABLE]"}); Tab code: Navigating to a specific tab on a screen. The tab is identified by its number as shown below and the following code is used: enter('=SP19'); It is also possible to use the alternate code shown below to navigate to a given tab. The code is as follows: enter('=T\\03'); Menu Items: The enter command can be used to navigate to a given menu item by specifying its position on a particular screen. For example, to specify the Log off command on the VA01 screen, the code is as follows: enter('/Menu=5,13');

89

WS/64 Developer Guide

Options
The enter command takes the following option: table: This designates a table control that we will be operating upon. The syntax is as follows: {"table":"T[table_name]"} An example is shown below: enter('/Scrolltoline=19', {"table":"T[All items]"}); The table scrolltoline option will not work on empty tables.

Examples
In this section, we will show real-world examples of some of the more common of the above use cases.

Sending a function code


In the following example, we are sending the code for the function key F11, which is signified by the code '/11'passed to the Enter command: onscreen 'SAPLCORU_S.0100' enter('/11');

Triggering a SAP Tcode


However, the Enter command can also be used to trigger a SAP transaction code or tcode. In the following example, we are passing the tcode to the Enter command, which then executes the specified transaction: enter('/nco11n');

Calling a function
Enter can also be used to call a function on any given screen or transaction. In the following example, we will use Enter to trigger a particular process: onUIIevents['Enter']={"fcode":"/nva02", "process":testUIEvent}; The code for the function 'testUIEvent' is as follows: function test_UIEvent() { onscreen 'SAPMV45A.0102' set("F[Order]", "14200"); enter(); onscreen 'SAPMV45A.4001' enter(); } When the user presses enter on the initial screen, the code executes and the results would appear as shown below:

90

WS/64 Developer Guide

91

WS/64 Developer Guide

fieldsize
The fieldsize command is used to restrict the character input in a given SAP field. This command works both on native SAP fields and on user-created fields. It is restricted to standard SAP editable fields. Please keep in mind that this command cannot be used to increase a field's size to be greater than the original size - it can only be used to make a field smaller. The syntax is as follows: fieldsize("F[fieldName]", n);

Options
The fieldsize command takes the following option: {"scrollable":true} The scrollable option specifies if the resized field will or will not be scrollable by the user. What this means in practice is that if the field is originally 20 characters and the user specifies that the new fieldsize will be only ten, applying the scrollable options enables the user to enter up to the original twenty characters.

Example
In the following example, we will resize the Material field on the MM01 screen, which is shown below in the default condition:

We will add the following code to the MM01 script file: fieldsize("F[Material]", 5); The resized field will now appear as in the following example:

92

WS/64 Developer Guide

In the following screen, we have applied the 'scrollable' option. Although the visible field length is only five characters, we can enter up to the original field capacity and then scroll on the field to read every character as shown below:

93

WS/64 Developer Guide

file
The file command is used to assign short names - also called aliases - to a script housed in a SAP Web Repository. This command is very useful since SAP Web Repositories (SAPWR) set a limit of thirty characters on a filename. The syntax is as follows: file("long_filename" , {alias:"short_filename"}); The file command is placed in the esession.sjs file if such a file is present. If the scripts are housed in SAPWR, the rfcconnect command must include a 'Client=' statement in the guixt.sjs file.

Options
The file command takes a single option, as follows: alias: This is used to specify the short filename that will be used instead of the original filename. The syntax is as follows: {"alias":"shortFilename"}

Examples
In the following example, we have a script file housed in the SAP Web Repository that is named as follows: 'an_extremely_lengthy_script_filename.sjs' To assign an alias or short name to the file, we would use the following code: file("an_extremely_lengthy_script_filename.sjs" , {alias:"longFile.sjs"}); The command can be used with either regular expressions or with strings. In the following example, we have a file named 'ZGUIXT.E0100.sjs' and we want to rename it to 'sessmgr.sjs'. We will use a regular expression to perform this change as shown below: file(/Z.GUIT.SAPLSMTR_NAVIGATION.E0100/, {"alias":"sessmgr"}); In the following example, we will use a simple string instead of a regular expression to perform the same operation. The code is as follows: file("Z.GUIXT.SAPLSMTR_NAVIGATION.E0100.sjs", {"alias":"sessmgr"});

94

WS/64 Developer Guide

getfieldattribute
The getfieldattribute command is used primarily to get the attributes both of a given native SAP screen element and of a user-created GuiXT screen element. The getfieldattribute command uses the following syntax: getfieldattribute(fieldName, {"option":value); The fieldname is the name of the element. For example, if we have a field 'F[Materials]', the field name would be 'F[Materials]'. This is used to define which screen element's attributes are being returned.

Options
The getfieldattribute command, as the syntax example above demonstrates, also takes a number of options, which are explained as follows: row: Specifies the row number of the text area for the given text field. Syntax is: {"row":"row_number"} column: Specifies the column number of a text area for the text field. Syntax is: {"column":"column_number"} columnnumber: Specifies the ID of a given column in a table.Syntax is: {"columnnumber":"number"} textrow: Specifies the row number of the label for a screen element. Syntax is: {"textrow":"text_row_number"} textcolumn: Specifies the column number of a screen element's label. Syntax is: {"textcolumn":"text_column_number"} name: Specifies the onscreen label for a given screen element.Syntax is: {"name":"name"} size: Specifies the number of characters a text field can contain. Syntax is: {"size":"size"} techname: Specifies the technical name of a screen element (eg. VBKD-BSTKD). Syntax is: {"techname":"technical_name"} header: Specifies the header if the element is a table column.Syntax is: {"header":"header_name"} displaycolumnnumber: Specifies the screen display number for columns in a table. Syntax is: {"displaycolumnnumber":"number"} width: Specifies the width for columns in a table. Syntax is: {"width":"width"} isprotected: Specifies if a given screen element is active or not. For edit fields, radiobuttons and checkboxes, '1' equals read-only and '0' equals editable. For pushbuttons, '1' equals inactive and '0' equals active. For all elements, 'null' equals not found. Syntax is: {"isprotected":1,0} 95

WS/64 Developer Guide

Four of these options are specific to tables (columnnumber, header, displaycolumnnumber and width). For these, the syntax would be the following if only a single table exists on the given screen getfieldattribute("[columnName]", {columnnumber: number, header: headerName, displaycolumnnumber: fdisplaycolumnnumber, width: fwidth); However, if there are multiple tables on a given screen the following syntax should be utilized: getfieldattribute("[tableName, columnName]", {columnnumber: number, header: headerName, displaycolumnnumber: fdisplaycolumnnumber, width: fwidth); In addition, properties of the field object can be used as options in the fieldname command. For example, the name property in a pushbutton has several sub-properties, which are as follows: name.label: This specifies the onscreen label of a given pushbutton or other screen element. Columns in a table are excluded. name.icon: For pushbuttons, this specifies the icon ID. name.tip: For pushbuttons, this specifies the tooltip. These properties will be demonstrated in the following examples.

96

WS/64 Developer Guide

Examples
Pushbuttons
In the following example, the getfieldattribute command is used within a function to return the icon ID, tooltip and label of a pushbutton. In this example, we are finding the attributes of the 'Display doc. header details' pushbutton on the VA01 overview screen. The code is as follows: function printButton(buttonName){ getfieldattribute(fieldName, {"name.icon":"fbuttonicon", "name.tip":"fbuttontip", "name.label":"fbuttontext"}); println("\t fbuttonicon = " + fbuttonicon); println("\t fbuttontip = " + fbuttontip); println("\t fbuttontext = " + fbuttontext); } printButton("P[Display doc.header details]"); The resulting output in the Console is shown below:

Other Screen Elements


The preceding example is specific to pushbuttons. However, the following example shows how getfieldattribute can be used for other screen elements. Using this method, we can return the attributes of either pushbuttons or non-pushbutton elements. In our example, we will get the attributes of the 'Order Type' field on the initial VA01 screen. The code is as follows: function printInfo(){ println("Executing getfieldattribute command"); getfieldattribute("F[Order Type]", {"name":"fname", "textrow":"ftextrow", "textcolumn":"ftextcolumn", "row":"frow", "column":"fcol", "techname":"ftechname", "size":"fsize", "isprotected":"fprotected", "header":"fheader", "columnnumber":"fcolumnnumber", "displaycolumnnumber":"fdisplaycolumnnumber", "width":"fwidth"}); println("Printing Field attributes!"); println("\t fname = " + fname); 97

WS/64 Developer Guide

println("\t println("\t println("\t println("\t println("\t println("\t println("\t println("\t println("\t println("\t println("\t } printInfo();

ftextrow = " + ftextrow); ftextcolumn = " + ftextcolumn); frow = " + frow); fcol = " + fcol); ftechname = " + ftechname); fsize = " + fsize); isprotected = " + fprotected); fheader = " + fheader); fcolumnnumber = " + fcolumnnumber); fdisplaycolumnnumber = " + fdisplaycolumnnumber); fwidth = " + fwidth);

If desired, the script progress can be viewed in the console.

98

WS/64 Developer Guide

gettableattribute
Tables are an integral part of using SAP. It is therefore necessary to understand how to manipulate tables and both add and extract data from those tables. We will learn how to manipulate the columns of a table using the columnsize and columnwidth methods. However, there are additional aspects to tables as well. To fully utilize the tables in SAP, it is important to know the properties and attributes of a given table; without knowing the attributes and properties it is not possible to edit tables or the data contained therein. The gettableattribute command allows SAP users to display both the attributes and the properties of a selected table. The syntax is as follows: gettableattribute("T[Table_name]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LastRow"});

Options
The gettableattribute command has the following required arguments: firstvisiblerow: This specifies the first visible row in a given table. The syntax is as follows: {"firstvisiblerow":"varName"} lastvisiblerow: This specifies the last visible row in a given table. The syntax is as follows: {"lastvisiblerow":"varName"} lastrow: This specifies the actual last row, visible or not, of a given table. The syntax is as shown below: {"lastrow":"varName"}

Example
If a user wishes to display the attributes of a given table either on a SAP screen or in some other method, it is helpful to use the gettableattribute command within a function that will both extract the data from the table in question and also output it to the specified location. In the following example, we will use a pushbutton to call a function that will pull data from the table T[All items] in the VA02 transaction and then output that data to the console. In order to execute this function, we will first open the script file for the screen in question and add the following lines of code: pushbutton([TOOLBAR], "Test Loop", {"process":test_loop}); function test_loop(){ onscreen 'SAPMV45A.0102' set("F[Order]" , "14200"); enter(); onscreen 'SAPMV45A.4001' gettableattribute("T[All items]", {"firstvisiblerow":"FVisRow","lastvisiblerow":"LVisRow","lastrow":"LRo w"}); absrow = 1; relrow = 1; if (FVisRow == 1){ goto new_row; } else{ enter("/scrolltoline=1",{"table":"T[All items]"}); goto new_screen 99

WS/64 Developer Guide

} new_screen: onscreen 'SAPMV45A.4001' gettableattribute("T[All items]",{"firstvisiblerow":"FVisRow","lastvisiblerow":"LVisRow","lastr ow":"LRow"}); relrow =1; new_row: if (absrow > LVisRow) { enter("/scrolltoline=&V[absrow]",{"table":"T[All items]"}); goto new_screen } if (absrow > LRow){ goto table_end; } set("V[z_temp]" , "&cell[All items, Material,&V[relrow]]"); println(absrow + ".----------Material is: " + z_temp); absrow++; relrow++; goto new_row; table_end: enter("/n"); } If necessary, the script progress can be viewing in the console.

100

WS/64 Developer Guide

globaltextreplace
The globaltextreplace command is used to replace text throughout an SAP environment. This command can be used either to perform the replacement on all screens, or users can specify screens that can be either included or excluded from the replacement process. There are two basic syntaxes that can be employed, as follows: globaltextreplace(/TextToBeReplaced/, 'ReplacementText', {"ocx":true, "listscreen":false, "screen":"DynProName"}); globaltextreplace(/TextToBeReplaced/, 'ReplacementText', {"ocx":true, "listscreen":false, "screen":["DynProName1", "DynProName2"]}); The first syntax is for a single screen. In this case, the user will specify the screen name. In the second case, multiple screens are included, and the user would employ an array to list all the designated screens that will be affected. To perform a text replace on all screens in SAP, do not include the 'screen' option. In order to use globaltextreplace, the wsoffice.dll must be installed. This command does not support replacing a short word with a longer word.

Options
The command takes the following options: zeus: This is an option that will apply the globaltextreplace operation to large RFC packets that cannot otherwise be handled. The command switch to turn this option on or off resides in the guixt.ini file and the syntax is as follows: zeus=on Any value other than 'on' will disable the zeus option. To apply zeus, open the 'guixt.ini' file in the SAPgui directory (C:\Program Files\SAP\FrontEnd\SAPgui). If no such file exists, create one. Inside the file, input the following: [system] zeus=on ocx: This option is a Boolean that is used to determine if the global text replace will affect the ActiveX controls. When OCX is used, the 'screen' and 'listscreen' options cannot be applied. The syntax is as follows: "ocx":true listscreen: The listscreen option is a Boolean that specifies whether or not the list screens will be affected. If it is not included in the script, the command will automatically assume that the listscreens will be affected. The listscreen syntax is as follows: "listscreen":false screen: The screen option designates the screens that will be affected. There are three possible uses of this option, which are as described below: o "screen":"SAPMV45A.0101" : This is used when a single screen is designated for globaltextreplace. o "screen":["SAPMV45A.0101"] : This is also used to designate a single screen to be affected by the globaltextreplace. 101

WS/64 Developer Guide

"screen":["SAPMV45A.0101", "SAPLMGMM.0060"] : This is used when multiple screens are to be included in the text replacement operation.

Examples
Single-screen replace
In the following example, we will replace all instances of the term 'Order' with the term 'Request' for the VA01 overview screen. The default screen appears as follows:

In our script file, we will create a process function and a toolbar pushbutton by including the following code: pushbutton([TOOLBAR], "Text Replace", {"process":do_gtr}); function do_gtr() { set("F[Sold-to party]", "1460"); set("F[Ship-to party]", "1460"); load("wsoffice.dll"); globaltextreplace(/Order/, 'Request', {"ocx":true, "listscreen":false, "screen":"SAPMV45A.4001"}); } Once the pushbutton is pressed, the screen will now appear as in the following example:

102

WS/64 Developer Guide

103

WS/64 Developer Guide

Multi-screen replace
To do a replacement on more than one screen, but not globally throughout SAP, users can specify more than one screen to perform the text replace. The code would be as follows: pushbutton([TOOLBAR], "Text Replace", {"process":do_gtr}); function do_gtr() { set("F[Sold-to party]", "1460"); set("F[Ship-to party]", "1460"); load("wsoffice.dll"); globaltextreplace(/Order/, 'Request', {"ocx":true, "listscreen":false, "screen":["SAPMV45A.4001", "SAPMV45A.0101"]}); } The screens in question appear as shown below: SAPMV45A.0101:

SAPMV45A.4001:

104

WS/64 Developer Guide

105

WS/64 Developer Guide

OCX Replace
To apply the globaltextreplace command to an OCX field, use the OCX option. When OCX is used, the 'screen' and 'listscreen' options cannot be applied. In the following example, we are applying globaltextreplace to the Service: Attachment list in the IW32 transaction. This is an OCX control. The code is as follows: globaltextreplace(/AttachmentFor000000825525/, 'Request', {"ocx":true}); The resulting screen appears as shown below:

106

WS/64 Developer Guide

image
The image command is used primarily to display an image in a SAP screen. This is useful to create a recognizable context for users, to orientate users within a given screen, to personalize a particular screen. Images can also contain a variety of information, particularly if the image is data-dependent. The basic syntax for this is as follows: image([startRow, startCol], "image_filename", {"options":"value"}); Images are always positioned starting with the top left, so the startRow and startCol coordinates will identify where the upper left corner of the image will be anchored on the SAP screen. An optional pair of coordinates for the lower right corner can also be shown as in the example below: image([1, 10], [5, 20], "image_filename", {"nostretch":true}); In this case, the image will be automatically resized to fit the specified dimensions unless the 'nostretch' option is used as is the case in our example. If the image is hosted on a network share, the full file path must be included. Variables can be used in the filenames as well as shown in the following example wher we will use the value entered into the 'F[Material]' field to specify the filename. If the user enteres the value '12345', for example, then the filename would be 'img12345.jpg. the code is as follows: image([1,1], "C:\guixt\img&F[Material].jpg Image supports the following file types: BMP GIF JPG In general, we recommend using the BMP format for smaller images (e.g. icons) and the GIF format for larger images.

107

WS/64 Developer Guide

Options
The use of the Image command is restricted to design scripts - it will not be available in functions. The Image command has a number of options that can also be applied to an image displayed in SAP GUI. These options are as follows: [TOOLBAR]: This option will place an image on the SAP toolbar. In the following example, we will add the following code to the SAPMV45A.E0101.sjs script file: image([TOOLBAR], "test3_toolbar.jpg"); Please note that the image must be pre-sized since the [TOOLBAR] placement offers no options for resizing to fit the toolbar. The Easy Access screen will now appear as shown below:

nobuffer: The image will be read from the file system each time it is displayed instead of being held in a buffer. This is useful if new versions of the image are being provided from external file systems such as SAP itself. The syntax is as follows: {"nobuffer":true} nostretch: Maintains the height-to-width proportions of the original image, regardless of the size specified by the user. The syntax is: {"nostretch":true} plain: No three-dimensional (3D) frame will be displayed around the given image. The syntax is: {"plain":true} start: This option enables users to launch a website or an executable file from an image. If an executable is to be launched, the file must be either a EXE or a BAT. Only these types are supported. There are two possible syntaxes, which are as follows: {"start":"C:\\directory\\filename"} {"start":"http://www.guixt.com"}

108

WS/64 Developer Guide

Viewhelp options
viewhelp: When a user clicks on the image, a viewhelp window is created as shown below. This window is used to display help for a given field or screen that is contained in an external location. Currently we support HTML and RTF documents. Viewhelp can only be used in a local environment with SAP GUI - it cannot be utilized in a server-based environment. viewhelp_height: Specifies the height of the window to be displayed. The syntax is: {"viewhelp_height":x} viewhelp_width: Specifies the width of the window to be displayed. The syntax is: {"viewhelp_width":x} viewhelp_position: Specifies the position on the screen where the viewhelp window will be displayed. The syntax is as follows: {"viewhelp_position":x}

Examples
Displaying an image
In the following example, we are simply displaying an image in the SAP screen 'Change Sales Order'. The screen will appear as follows:

To achieve this result, the following code should be entered into the script file, : image([14,1],[20, 20],"test.gif");

109

WS/64 Developer Guide

Using viewhelp
Images can be used to launch a specified URL by embedding the URL within the code attached to the image in question. viewhelp. As previously mentioned, the following fiel types are supported: HTML RTF HTML viewhelp In the following example, we will display an HTML help document on the Easy Access screen. The code is as follows: image([4,2], "GuiXTLogo_2008.JPG" ,{"viewhelp":"help.html", "viewhelp_width":30, "viewhelp_height":15, "viewhelp_position":[5,30]}); The resulting Easy Access screen with HTML help appears as follows:

110

WS/64 Developer Guide

RTF viewhelp The code for an RTF viewhelp is as follows: image([4,2], "GuiXTLogo_2008.JPG" ,{"viewhelp":"help.rtf", "viewhelp_width":30, "viewhelp_height":15, "viewhelp_position":[5,30]}); The resulting screen appears as follows:

111

WS/64 Developer Guide

inputfield
The inputfield command is one of the most useful commands in WS and will be usable on most screens users will access. Editable fields on SAP screens are created and modified using the inputfield command. The syntax for this command is as follows: inputfield([startrow,startcol], "Field name", [endrow, endcol], {"option":value});

Options
There are a number of options that can be attached to inputfields. These are as follows: alignright date default invisible maxlength name nolabel numerical readonly required searchhelp uppercase In addition to the options listed above, there are also other elements that can be associated with inputfields using GuiXT WS. These are as follows: Tool tips and icons Variables Smart attributes

112

WS/64 Developer Guide

Examples
The following examples will cover the usage of the options listed above.

alignright
Aligns the value entered in a field with the right-hand edge of the field in question. The syntax is as follows: {"alignright":true} In the following example, we will set the input to the right edge of the field by entering the following code in the SAPLSMTR_NAVIGATION.E0100.sjs script file: inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1", "size":14, "alignright":true}); The Easy Access screen will now appear as shown below:

If the alignright option is either omitted or set to 'false', the field value will align by default with the lefthand edge of the field as shown below:

113

WS/64 Developer Guide

date
The F4 function key usually calls the searchhelp associated with a given inputfield. However, it is also possible to call a calendar by executing an F4 command on an inputfield. To enable the calendar to appear, it is necessary to designate the inputfield as one containing a date. This can be done by using the Date option. the code would be as follows: inputfield([15,1], "Calendar Test", [15,25], {"name":"z_date", "date":true}); A user would click in the field to display the F4 option beside the field as shown below:

By clicking the icon or by pressing the F4 key, a calendar will be called as in the following example:

114

WS/64 Developer Guide

115

WS/64 Developer Guide

default
This option will add default text to the inputfield in question. Users can edit the text or replace it with their own entry. The two possible syntaxes are as follows: {"default":"string"} {"default":value} Either a string or a numerical value can be used as shown in the two examples below: String default: inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1", "size":14, "default":"12345"}); The resulting screen appears as follows:

Numerical default: inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1", "size":14, "default":12345}); The screen now displays as shown below:

116

WS/64 Developer Guide

invisible
Hides the input field's output from a user. The invisible option will replace the input field's output with a row of asterisks. The syntax is as follows: {"invisible":true} In the example below, we will make the input in our example inputfield invisible by entering the following line of code into the SAPLSMTR_NAVIGATION.E0100.sjs script file. inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1", "size":14, "invisible":true}); After saving the changes in the script file, the inputfield will now appear as shown below:

117

WS/64 Developer Guide

maxlength
Users can utilize the Maxlength option to define the maximum length of the input field. This is useful to make the inputfield scrollable. The syntax is as follows: {"maxlength":value} Users can enter or display as many characters as are specified in the maxlength option.

If the size option is used, it will over-ride the maxlength option.

In the following examples, we will create an inputfield with a maxlength of '20' by adding the following code to the Easy Access script file: inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1", "maxlength":20}); The screen will now display as shown below. Note that the field allows up to 20 characters by using the maxlength option. We then entered 'abcdefghijklmnopqrst' in the field and can scroll from beginning to end.

118

WS/64 Developer Guide

name
A variable name for the field is defined by using the name option. The syntax is shown below: {"name":"field_variable_name"} In the following example, we will add a field with a predefined variable name to the Easy Access screen. The code is as follows: inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1"); This will enable users to refer to the field by its name in a script and pass the values to other screens or functions. The field name is not the on-screen label, but rather the internal variable name of the field.

119

WS/64 Developer Guide

nolabel
The nolabel option removes the label from an inputfield. The syntax is as follows: {"nolabel":true} In the following example, we will remove the label from our example inputfield by entering the following line of code into the Easy Access script file. inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1","size":14, "nolabel":true}); The Inputfield Test inputfield on the Easy Access screen will now appear as shown in the example below:

120

WS/64 Developer Guide

numerical
The Numerical option restricts the input of a field to numerical characters only numbers in an inputfield. This option restricts data to numerical characters for the given inputfield. the syntax is as follows: {"numerical":true} In the following example, we will make our example inputfield as a numerical entry only by adding the following line of code into the SAPLSMTR_NAVIGATION.E0100.sjs script file. inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1","size":14, "numerical":true}); The Easy Access screen with the Inputfield Test inputfield will now appear as shown below:

121

WS/64 Developer Guide

readonly
This option disables data entry for a given inputfield. Data can be read but not edited. The syntax is as follows: {"readonly":true} In the following example, we will make an inputfield read-only by entering the following line of code into the Easy Access script file. inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1","size":14, "readonly":true}); After entering the code and saving the changes, the Easy Access screen will appear as shown in the following example:

122

WS/64 Developer Guide

required
This option makes the inputfield a required element, meaning that users must enter data in the field in order to proceed to the next screen. The syntax is as follows: {"required":true} In the following example, we will make our example inputfield on the Easy Access screen required by adding the following code to the SAPLSMTR_NAVIGATION.E0100.sjs script file. inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1", "size":14, "required":true}); The inputfield 'Inputfield Test' that we added to the Easy Access screen will now appear as shown in the following example:

123

WS/64 Developer Guide

searchhelp
Searchhelp is an aid to users looking for a specific value to enter into a field. When the user invokes the input help for a given field or screen, the system will typically return all of the available values for that field or screen in SAP. Searchhelp can be customized to be field-dependent. In other words, the values displayed by searchhelp can be customized depending on what values are entered by users in other fields. The syntax is as follows: {"searchhelp":"searchhelp_table", "searchhelp_option":"value"} Available options The following options are available for use with searchhelp: fname0: Specifies that data other than the default value will be displayed in the designated destination. shname1-9: Specifies up to nine fields that will be populated. shdest1-9: Specifies up to nine descriptions that will be displayed

124

WS/64 Developer Guide

Examples The following examples will demonstrate the available features of GuiXT searchhelp.

searchhelp - shname1, shdest1 By using the shname and shdest values, we can specify where any additional information associated with the searchhelp will be displayed. In the following example, we will create an inputfield and once the user selects the entry from the searchhelp, we will use the text command to display the description will be displayed beside the inputfield. The code will be as shown below: inputfield([15,1], "Sales Org", [15,25], {"name":"z_sorg", "size":10, "searchhelp":"H_TVKO", "shname1":"VTEXT", "shdest1":"V[z_sorg_desc]"}); text([15,39], "&V[z_sorg_desc]");

The VA01 screen after the user entry would then appear as follows:

125

WS/64 Developer Guide

searchhelp - shselname1-9, shselvalue1-9 Up to nine matchcodes can be supported in searchhelp and are defined by means of the 'shselname' and 'shselvalue' options. These matchcodes refer to other fields, thus if a value is entered in one of these fields, the resulting searchhelp can be restricted or customized to a specific dataset. In this example, we are creating some additional GuiXT inputfields and restricting the searchhelp depending on the user entry in each field by means of the 'shselvalue' option. The code is as follows: inputfield([12,1], "Sales Org", [12,25], {"name":"z_sorg", "size":10, "searchhelp":"H_TVKO", "shname":"VKORG", "shname1":"VTEXT", "shdest1":"V[z_sorg_desc]"}); text([12,39], "&V[z_sorg_desc]");

inputfield([13,1], "Dist Chnl", [13,25], {"name":"z_dchnl", "size":4, "searchhelp":"H_TVKOV", "shname":"VTWEG", "shselname1":"VKORG", "shselvalue1":"V[z_sorg]", "shname1":"VTEXT", "shdest1":"V[z_sdchnl_desc]", "shname2":"VKORG", "shdest2":"V[z_sorg]"}); text([13,39], "&V[z_sdchnl_desc]"); inputfield([14,1], "Div", [14,25], {"name":"z_div", "size":4, "searchhelp":"H_TVTA", "shname":"SPART", "shselname1":"VKORG", "shselvalue1":"V[z_sorg]", "shselname2":"VTWEG", "shselvalue2":"V[z_dchnl]", "shname1":"VTEXT", "shdest1":"V[z_div_desc]", "shname2":"VKORG", "shdest2":"V[z_sorg]", "shname3":"VTWEG", "shdest3":"V[z_dchnl]"}); text([14,39], "&V[z_div_desc]"); This code will produce the following search help results on the SAP screen. If no value' is entered in the 'Sales Ord' field, then the searchhelp for the Distribution field will be as shown below:

126

WS/64 Developer Guide

However, if a value ('1000' in our example) is entered in the 'Sales Ord' field, then the searchhelp for the Distribution field will be restricted accordingly and will appear as follows:

127

WS/64 Developer Guide

The same process will take place for the other fields - depending on which values are entered in which fields, the entries for the other fields will be restricted accordingly. Shown below are the values available for the 'Div' field if the value '10' is entered in the 'Dist Chnl' field:

128

WS/64 Developer Guide

However, if no value is entered in the 'Dist Chnl' field, the searchhelp for the 'Div' field would be as follows:

129

WS/64 Developer Guide

130

WS/64 Developer Guide

searchhelp - fname01 The value entered in the field is usually the shname value, which is in the 'SOrg' field in the following example. However, by using the 'fname0' option, the description (in the 'Name' column in the following example) instead can be entered into the field. In the following example, we will create an inputfield and enter the description instead of the value in the field. The code is as follows: inputfield([12,1], "Sales Org", [12,25], {"name":"z_sorg", "size":10, "searchhelp":"H_TVKO", "fname0":"VTEXT", "shname":"VKORG", "shname1":"VTEXT", "shdest1":"V[z_sorg_desc]"});text([12,39], "&V[z_sorg_desc]");

The resulting searchhelp screen is shown below:

If we select the '001 - Sales Org. Germany' value pair, the text 'Sales Org. Germany' will be entered into the field instead of the code '0001'. The resulting screen appears as shown below: 131

WS/64 Developer Guide

132

WS/64 Developer Guide

uppercase
This option specifies that any input in the inputfield will be displayed in uppercase. If the default option is used, that text also will display in uppercase. The syntax is as follows: {"uppercase":true} In the following example, we will make any input into our example field uppercase by adding the following code to the SAPLSMTR_NAVIGATION.E0100.sjs. script file. inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_1","size":14,"uppercase":true}); The inputfield on the Easy Access screen will now appear as shown in the example below:

133

WS/64 Developer Guide

Tool tips and icons


It is possible both to add a tool tip to an inputfield and also to define an icon for the tool tip. The syntax is as follows: inputfield([startRow, startCol], "@iconID\\tooltip text@Label", [endRow, endCol], {"option":value}); In the following example, we will add a tool tip and an icon by entering the following line of code into the script file. inputfield([4,5], "@G9\\QA tooltip and icon test@Inputfield Test", [4,20], {"name":"inpfld_1","size":14}); The inputfield will now appear as shown below. Hovering the mouse over the icon will result in displaying the tooltip as in the example.

134

WS/64 Developer Guide

Variables
There are two types of variables that can be used with inputfields - global variables and screen variables. As their names imply, screen variables are specific only to a single screen, while global variables can be used throughout a SAP script.

Global variables
It is possible to utilize a global variable as an option. In the following example, we set a global variable and display the value contained in the variable in the input field. To set a global variable as the inputfield name, first enter the following line of code into the script file. It will be necessary to use the Set command to declare the global variable. inputfield([4,5], "Inputfield Test", [4,20], {"name":"inpfld_MaterialNumber","size":14}); set("V[inpfld_MaterialNumber]", "1000"); Now we will display the value contained in the global variable in the inputfield. The Easy Access screen will now appear as shown in the following example:

135

WS/64 Developer Guide

Screen variables
Global variables can be used throughout a SAP script, regardless of the screen. Screen variables are applicable only to a specific screen. However, screen variables also can be assigned as inputfield names. To assign a screen variable to an inputfield, add the following line of code to the script file. var mrp_type = "Material"; inputfield([4,5], "&V[mrp_type]", [4,20], {"name":"inpfld_1","size":14}); The screen will now appear as shown below:

136

WS/64 Developer Guide

leave
leave is actually a custom function but behaves like a standard WS command. It is used to stop a process flow in a script. When the script has been stopped, the user will be retained on the page from which he or she is located when the script stops. The syntax is as follows: leave();

Options
The leave command takes no options.

Example
In the following example, we have initiated an input script on the VA01 screen. However, within the script, we have placed a leave command. Once this command has been reached, the script will stop and the user will remain on the VA01 initial screen. The code is as follows: onscreen 'SAPMV45a.0101' enter(); leave(); onscreen 'SAPMV45A.4001' println("-=-----Inside SAPMV45A.4001----"); enter(); In the preceding example, the user will never be transported to the VA01 Overview screen and the println statement will never display in the Console as the script stops executing following the leave command.

137

WS/64 Developer Guide

load
The Load command is used to load an external file. Once this file is loaded, anything included in the file will be available for global use in WS scripts. Currently only the following file types are supported: sjs dll The basic syntax is as follows: load("filename"); Files can be loaded from any of the following locations: Local directories: When loading a local file in the script directory, the syntax would be: load("filename"); To load a file that is not in the same directory, the path must be specified as follows: load("C:\\guixt\\test"); Network shares: When loading a file on a network share, the following syntax is necessary: load("\\\\company.com\\directory\\filename"); SAP Web Repositories: When loading a file from SAPWR, the following syntax is used: load("SAPWR:Z.GUIXT.SAPLSMTR_NAVIGATION.0100.sjs"); Users can also use the file command to give the file an alias if it exceeds the 30-character limitation on SAPWR file names. See the section on the file command for more details.

Options
The load command takes no options.

Example
In the following example, we will load the 'wsoffice.dll' so as to enable calls to such applications as Word, Excel or to the system itself. load("wsoffice");

138

WS/64 Developer Guide

localvaluehelp
The localvaluehelp command enables users to access help for possible input sets for SAP fields when the user performs a right-click on the field in question. The syntax is as follows: localvaluehelp("[screen_element]", {"option":value}); The localvalue help command can be used only on inputfields. To enable localvalue help, the following entries must be entered in the guixt.sjs configuration file: historyonrightbutton = true; domains = "directory" The 'historyonrightbutton' parameter enables the domain list box to display when the user right-clicks. The 'domains' parameter specifies what history will be searched. The directory path can be any of the following formats: Local directory: The file path is written as follows: C:\\directoryName Network share: The directory name is written as follows: \\\\network\\directory Web share: The directory name is written as follows: http://directoryName SAPWR: The name is written as follows: sapwr:z.domain

Options
The localvluehelp command takes the following options: domain: Can be used to specify the domain from which the localvaluehelp will be called. This domain is specified in the domains entry in the guixt.sjs file and will be the source from whence the localvaluehelp is obtained.. The syntax is as follows: {"domain":"domain_name"}

139

WS/64 Developer Guide

Examples
Creating localvaluehelp
In the following example we will create some localvaluehelp for a GuiXT-created inputfield. The code is as follows: inputfield([4,1],"Material",[4,10],{"name":"z_material","size":20}); localvaluehelp("F[Material]",{"domain":"MATR"}); text([4,35],"This example will display material values for this edit field on right click."); text([5,35],"Domain will be read from dom.Text.E.txt file"); The file from which the localvaluehelp is being read is specified in the guixt.sjs file as follows: historyonrightbutton=true; domains = "\\\\company.com\\localvaluehelp"; Right-clicking on the field will now display the available inputsets for that field as shown below:

Once the configurations are applied in the guixt.sjs file as described above, localvalue help can be invoked in a variety of ways. Methods include the following: Assigning domains to SAP fields Assigning domain names to SAP fields using coordinates Assigning names to GuiXT fields Assigning domain names to GuiXT fields using the Nolabel parameter Using WS objects These are demonstrated in the following examples:

Assigning Domain Names to SAP Fields


The basic syntax for assigning a domain name to a SAP field is as follows: localvaluehelp("F[Label]", {domain:"domain"}); In this example, we are assigning localvaluehelp to a the field titled 'Material' and setting the search domain to 'MATR'.

140

WS/64 Developer Guide

Assigning Domain Names to SAP Fields Using Coordinates


There may be times when the name of a particular field may not be easily accessible. However, it is still possible to assign localvaluehelp to a given field by specifying the field's coordinates as opposed to the field name. The basic syntax for assigning a domain name to a SAP field using coordinates instead of a field name is as follows: localvaluehelp("#[row, column]", {domain:"domain"}); In this example, we are specifying that localvaluehelp will be available for the field located at row 3 and column 22 on the screen. The search domain for the localvaluehelp will be 'MATR'. The code for this is as follows: localvaluehelp("#[3,22]", {domain:"MATR"});

Assigning Domain Names to GuiXT Fields


User-created fields with GuiXT perform essentially the same way as do the native SAP screens and it is similarly possible to assign localvaluehelp to these user-created fields. The basic syntax for assigning a domain name to a GuiXT field is as follows: inputfield([startRow, startColumn], "Label", [endRow, endColumn], {"name":"name"}); localvaluehelp("F[Label]", {domain:"domain"});

Assigning Domain Names to GuiXT Fields with No Label


It is sometimes desirable to create unlabeled inputfields. However, whether or not the field has a label, it is still possible to assign localvaluehelp to the field in question. The basic syntax for assigning a domain name to a GuiXT field without a label is as follows: inputfield([row, column], {"name":"name", "nolabel":true, "size":"size"}); localvaluehelp("F[name]", {domain:"domain"});

Domain Inputsets
For localvaluehelp, it is necessary that there be a directory that contains the inputsets that will be displayed when a user triggers the field's localvaluehelp. Fields will only display localvaluehelp if a domain is mapped to it as described in the previous section. The file that contains the inputsets must be named in the following format: dom.<languageKey>.<domainName>.txt If there is no domain mapped to the field, then instead of the 'dom.<languageKey>.<domainName>.txt file, a different file will be read. This alternate file is usually named in the following format: dom.TEXT.<language code>.txt The inputsets will be stored inside this alternate file. If no domain name is specified, then the domains will be read from this file.

141

WS/64 Developer Guide

Loops
Loops are a means of executing a repetitive statement based on one or more conditions. Loops can have multiple decision paths based on a variety of these conditions. Loops are extremely useful in WS scripting, as there may be many tasks that must be performed multiple times, and it may also be necessary to repeatedly iterate through a SAP screen. There are four main loop statements that are usable in WS. These three loop statements are as follows: do-while: for goto-label if-else

do - while
The Do-while loop is one method of executing a repetitive process. While the for loop executes for as many times as the specified conditional expressions dictate and the if-else loop can describe multiple differing conditions depending if the statement is true or false, the do-while loop is used to repeat as long as the specified condition is true. The syntax is as follows: do { //some action here while (condition); Please keep in mind that the nature of all do-while loops is to always read the first value, and then execute. This means that the do-while loop will read one more time than the index specifies so it is recommended to put a break statement inside all do-while loops. The do-while loop and the for loop which we will explain later can perform many of the same functions and they are often used interchangeably.

Options
The do-while loop is a statement used for executing operations. As such it does not take any options as a command might.

Example
In the following example we will use a do-while loop to create a series of inputfields on a given screen. The screen appears as follows:

142

WS/64 Developer Guide

The code is shown below: for(a=firstChild; a!=null; a=a.nextSibling) a.del(); i=0; do { inputfield([i,1], "&V[i].Field", [i,10], {"name":"z-test_&V[i]", "size":10}); } while(i < 9); pushbutton([TOOLBAR], "Go back to main menu", "/n");

143

WS/64 Developer Guide

for
For loops are used in WS to perform operations in which it is necessary to iterate through a section of code multiple times. The for loop sets a group of particular conditions and as long as those conditions are valid, it will repeat the requisite section of code. Essentially, what a for loop does is to set up a situation where as long as the stated conditions are true, the expression will continue to execute. For loops can be very useful when repetitive actions must be executed, as it is possible to construct a single statement to perform those actions instead of writing them as single statements. A for loop is very useful for example in preparing a given screen for customization. However, please note that screen statements cannot be used in for loops. The basic syntax is as follows: for([starting expression]; [condition]; [ending expression]) statement;

Screen statements cannot be used in for loops.

Options
The for loop is a statement used for executing operations. As such it does not take any options as a command might.

Example
In the example below, we will use two for loops. the first one will delete all the existing screen elements and the second will draw a set of fields on the VA02 screen as shown below. We will also add a pushbutton on the toolbar to return the user to the main screen:

The code is as follows: for (a=firstChild; a!=null; a=a.nextSibling)

144

WS/64 Developer Guide

a.del(); put.

//since only one line gets executed, "{" might not be

for (i=0; i<10; i++){ inputfield([i,1],"&V[i].Field",[i,10],{"name":"z_test_&V[i]","siz e":10}); } pushbutton([TOOLBAR],"Go back to Main Menu","/n");

145

WS/64 Developer Guide

goto - label
This method is used to control the function process flow in WS. Although For loops or If/Else/Endif loops can replace it in many instances, the goto - label statement is still very important for creating repetitive tasks where multiple screen blocks are included. You can also create multiple fields using the Goto - label construction. The syntax is as follows: goto - label

Options
The goto-label is a statement used for executing operations. As such it does not take any options as a command might.

Example
In the following example, we are using the goto-label structure together with the gettableattribute command to perform multiple actions on a table. We have first created a pushbutton that will call the process as shown below:

The script contains three labels, and conditional statements (in this case an if-else statement) are used to direct the process flow to each section as needed while the function executes. The process execution can be viewed in the console and the code would look as follows: pushbutton([1,1] , "Goto-Label/gettableattribute Example" ,"/nva02",{"process":test_loop}); function test_loop(){ onscreen 'SAPMV45A.0102' set("F[Order]" , "14200"); enter(); onscreen 'SAPMV45A.4001'

146

WS/64 Developer Guide

gettableattribute("T[All items]",{"firstvisiblerow":"FVisRow","lastvisiblerow":"LVisRow","lastr ow":"LRow"}); absrow = 1; relrow = 1; if (FVisRow == 1){ goto new_row; } else{ enter("/scrolltoline=1",{"table":"T[All items]"}); goto new_screen } new_screen: onscreen 'SAPMV45A.4001' gettableattribute("T[All items]",{"firstvisiblerow":"FVisRow","lastvisiblerow":"LVisRow","lastr ow":"LRow"}); relrow =1; new_row: if (absrow > LVisRow) { enter("/scrolltoline=&V[absrow]",{"table":"T[All items]"}); goto new_screen } if (absrow > LRow){ goto table_end; } set("V[z_temp]" , "&cell[All items, Material,&V[relrow]]"); println(absrow + ".----------Material is: " + z_temp); absrow++; relrow++; goto new_row; table_end: enter("/n"); } In the preceding example, we get the attributes of a particular row in the table 'All items'. The script will then scroll through the table and print the materials contained on the Console. Once all materials contained in the table have been printed to the console, the script will go to the 'table_end' and terminate.

147

WS/64 Developer Guide

if - else
The if / else loop constructions are extremely useful for making a script dependent on given conditions. This construction is often used to replace the Goto -Label construction, as it is more robust and easily portable. The syntax is as follows: if( "V[z_temp]") { \\some logic here } else( ) { \\ some logic here } endif } The If statement is usually employed to initiate some action if the condition in the If statement is true. However, users can make the If statement into a negative - essentially making it an 'if-not' statement - by adding the logical not operator '!' as in the following example: if(!z_temp) { \\some logic here } The If statement can also be changed into a negative by using the '!=' operator in place of the usual '=' operator as in the below example: if(z_temp != value) { \\ some logic here }

Options
The if-else loop is a statement used for executing operations. As such it does not take any options as a command might.

Example
In the following example, we are using the if/else loop to discover if the screen in question is the main VA01 screen Then, depending on whether or not it is, we will perform some logic based on that screen. We use the 'else' statement to set the current transaction to VA01 if it is not already. The resulting screen will be the VA01 default with the Order Type field set to 'OR' or Standard Order as shown below:

148

WS/64 Developer Guide

The code is as follows: if(_transaction=="VA01") { set("F[Order Type}", "OR"); } else { enter('/VA01') } If/else loops are also useful for setting multiple conditions by using the if/else if format. Here it is possible to set a number of conditions and execute whichever one is true. In the following example, we will do precisely that: if(_transaction=="VA01) { set("F[Order Type]", "OR); } else if(_transaction=="VA02") { set("F[Order]", "13408"); } else enter('/"VA01'); If the current screen is the VA01 Create Sales Order screen, then the Order Type field will be set to 'OR' or Standard Order. If the screen is the VA02 Change Sales Order screen however, the Order field will be populated with the number of a previously created order - in this case 13408. The screen would then display as shown below:

149

WS/64 Developer Guide

If the current screen were neither VA01 or VA02, then the screen would be set to VA01 without any data, as shown below:

150

WS/64 Developer Guide

message
It is sometimes very useful to display messages on the screen, either for educational or troubleshooting purposes. The Message command can be used to display these messages on any screen in WS. Messages displayed can be either custom messaged defined by the users or captured system messages. The syntax for utilizing system messages is as follows: message(_variable); To display a custom message, a user would first define the message and then display it as a string. This syntax is as follows: var z_msg = "A message example." message("This message is: " +z_msg); Message types can be combined. In other words, users can define a custom message that displays a captured system message. In the following example, we will display a string within a custom message. Open the script file SAPLIQS0.E0100.sjs and add the following lines of code to the script file: var z_va01 = "Demonstrating the message command!" message("S: The custom message is: " +z_va01); It is also important to be aware of the icons that are available for use with messages. There are three basic icon types that are available. These are as follows: S: Success messages. These are marked with a green checkmark E: Error messages. These are marked with a red exclamation mark. W: Warning messages. These are marked with a yellow exclamation mark.

Options
There are no options used with the message command.

Examples
Displaying a custom message
In the following example, we will create a custom message and then display it on the initial VA01 screen using the 'S' icon. The code is as follows: var z_va01 = "Demonstrating the message command!" message("S: The custom message is: " +z_va01); The resulting message would appear on the bottom of the screen as shown in the example below:

151

WS/64 Developer Guide

Displaying a system variable


To display a system variable, we would use the following code: message("The transaction ID is >>> " +_transaction); The screen will now display as follows:

152

WS/64 Developer Guide

nodropdownlist
The nodropdownlist command is used to change a dropdown list into an input field. This is especially useful if users prefer direct input into SAP fields. By using this command, users can change the screen element into a direct-entry field. The syntax is as follows: nodropdownlist("F[screenElementName]");

Options:
The nodropdownlist command does not take any options.

Example
In the following example, we will change the dropdown list on the MM01 screen into an entry field. The default screen, with the dropdown list, appears as shown below:

To eliminate the dropdown list, we will add the following code to the SAPLMGMM.E0060.sjs script file: nodropdownlist("F[Material Type]"); The Material Type dropdown list will be converted into a standard entry field and the screen will now appear as follows:

153

WS/64 Developer Guide

154

WS/64 Developer Guide

noinput
Just as the Readonly option used with input fields restricts users from entering any data in that particular field, the Noinput option also makes a SAP screen element into a read-only element. Noinput can be used with any SAP screen that allows input. The command cannot be used on user-defined fields. The syntaxes would be as follows: Syntax Description noinput("F[inputfield]"); noinput("C[checkbox]"); noinput("[table_name, col_name]"); noinput("[table_name, col_no]"); Used to make a single inputfield uneditable. Used to make a single checkbox uneditable. Makes a table column uneditable. Makes a table column uneditable, using the column number (an integer) instead of the column name. Alternate syntax to make a table column uneditable. Uses column name, not the position.

noinput("All items, col_name");

Options
The noinput command does not take any options.

Examples
No input operates slightly differently when used on the different screen elements. In the examples, we will demonstrate how to use noinput both on a standard screen element such as an inputfield and also how to use it on a table element.

Inputfields
If we wished to make a field on the Create Sales Order screen to be read-only, we must first open the SAPMV45A.E0100 script file. We would then add the following line of code: noinput("F[Sales Organization]"); The Sales Organization screen is now read-only. Therefore, the 'Create Sales Order' screen would now appear as shown in the example below:

155

WS/64 Developer Guide

This process wotrks for checkboxes as well. The only different is in the elelemtn designation.

Table columns
The noinput command does not work on individual table cells, only on table columns, So if a user wished to utilize noinput on the 'Material' column in the All Items table in the VA01 transaction, we would either of the two following code samples to the VA01 script file: noinput("[All items, Material]"); noinput("[All items, 2]"); Both of these code samples will work exactly the same way and the screen would now appear as shown below:

156

WS/64 Developer Guide

157

WS/64 Developer Guide

noscrollbar
The noscrollbar command is used to suppress or hide scrollbars within a specified area in a SAP screen. This is very useful if a user has deleted a large number of fields or other elements, making a scrollbar unnecessary. The scrollbar at the right-hand edge of the screen is the lone exception to the command - it is not suppressed when using the noscrollbar command. The syntax is as follows: noscrollbar(); Options: The noscrollbar command does not take any options. Examples: In the following example, we will use the noscrollbar command on the VD01 transaction's General Data screen. In the following screenshot, we will display the General Data screen in its default format.

In the SAPMF02D.E7000 script file, we will now add the following code: noscrollbar(); After saving our changes to the script file, we will log out of SAP and then log back in. The screen will now appear as in the following example:

158

WS/64 Developer Guide

159

WS/64 Developer Guide

onmessage
The onmessage command is used to trigger an action if a message is returned from SAP. This command behaves as an independent screen block, similar to the onscreen command. The syntax is as follows: onmessage

Options
The onmessage command does not take any options.

Examples
In the following example, we will demonstrate the onmessage command. We are creating an inputfield on the initial VA01 screen where a user will enter the sold-to party. If the user enters incorrect sold-to party information, the onmessage block will capture the system error message, display it on the screen and then return the user to the point where the action was initiated. The code would be as follows: inputfield([3,1] , "Sold-to" , [3,22],{"name":"z_va01_soldto","size":10}); onUIEvents['Enter'] = va01_entersoldto; function va01_entersoldto(){ onscreen 'SAPMV45A.4001' set("F[Sold-to party]" , "&V[z_va01_soldto]"); enter(); onmessage message("E:" + _message); enter("/nva01"); } We will then press enter on the VA01 Overview screen with an incorrect value in the Sold-to field. The resulting screen would display as shown below:

160

WS/64 Developer Guide

onscreen
The onscreen command is used to specify the screen blocks that are used when combining operations from multiple screens into a single script. This command is especially useful for executing operations that are initiated on a different screen as it is possible to initiate an action in one transaction and have it take place in a different transaction. This command is also used to write a single script that contains actions that take place on all necessary screens of a single transaction. The syntax is as follows: onscreen 'SAP Dynpro Name'

Options
The onscreen command does not take any options

Example
In the following example, we will use the onscreen command to initiate an action from the Easy Access screen that will then execute in the VA01 transaction. Specifically, we will set certain fields on the SAPMV45A.0101 and SAPMV45A.E4001 screens in a script that is entirely housed in the SAPLSMTR_NAVIGATION.E0100.sjs script file. We will trigger this action with an onUIEvents command and use the onscreen command to specify what actions occur on which screens. The code is as follows: onUIEvents['Enter']{"fcode":"/nva01","process":z_test}; function z_test() { onscreen 'SAPMV45A.0101' set("F[Order Type]", "OR); set("F[Sales Organization]", "1000"); set("F[Sales Distribution]", "10"); set("F[Division]", "00"); enter(); onscreen 'SAPMV45A.4001' set("F[Sold-to party]", "1460"); enter(); } When the process has executed, the user will be located on the following screen, ready to enter material details in the All items table as shown below:

161

WS/64 Developer Guide

onUIEvents
The onUIEvents command is used to trigger processes or function codes. It is applicable to any action a user will perform in a SAP screen with the sole exception of pushbutton clicks. There are a number of possible ways of writing this command, as shown in the examples below. The possible syntaxes are as follows: Syntax onUIEvents["action"]=process_na me; onUIEvents["action"]={ "process":function_name}; onUIEvents["action"]={ fcode:"fcode", "process":function_name}; onUIEvents["action"]={ fcode:"f code", "process":function_name, "using":{ parameter:"Parameter_value"}}; Description Launches a process upon the specified user action. Launches a process upon the specified user action. Transports the user to the specified transaction, where the process will then execute. Transports the user to the specified transaction, executes the specified process using the previously specified parameters.

Options
The onUIEvents command takes the following options: fcode: This option is used to send a function code. The code can be either a SAP transaction code or a function key code. The syntax is as follows: {"fcode":"functionCode"} process: This option is used to specify a process that will be triggered. The syntax is as follows: {"process":function_Name} using: This specifies a parameter that will be employed in the designated process. It is very useful to send a value to the process function, which can then be passed to SAP. The syntax is as shown in the two examples below: "using":{parameter:"stringValue"} "using":{param:numericalValue}

162

WS/64 Developer Guide

Examples
Executing a process
In the following example, we are going to use the onUIEvents command to trigger a process based on a user action. The transaction where the process will occur is specified using the 'fcode' option. Specifically, when a user presses the enter key, the user will be transported to the VA02 transaction and a function will execute. We have created a customized screen that will appear as follows:

The code for the process that will be initiated from the previous screen is as follows: onUIEvents['Enter']={"fcode":"/nva02","process":test_UIEvent}; text([4,1],'This example includes the execution of UI action Enter. Hit Enter to execute process'); function test_UIEvent(){ onscreen 'SAPMV45A.0102' set("F[Order]" , "14200"); enter(); onscreen 'SAPMV45A.4001' enter(); } When the relevant data is input, an Enter command will cause the specified process to be called. The code for this would be as follows: onUIEvents['Enter']={"fcode":"/nva02","process":test_UIEvent}; The function test_UIEvent will then execute, taking the user to the initial VA02 screen, populating the 'Order' field and then taking the user to the Overview screen, which appears as shown below:

163

WS/64 Developer Guide

164

WS/64 Developer Guide

Passing parameters
An example employing the 'using' option explained above is shown here. In this case, we would utilize the "using" command. In the following example, we are employing the 'using option to set a parameter equal to a particular order number. When the process executes, the order number is passed to the custom screen and the order will display. The code is as follows: onUIEvents['Enter']={"fcode":"/nva02","process":test_UIEvent, "using":{param_1:15965}}; text([4,1],'This example includes the execution of UI action Enter. Hit Enter to execute process'); function test_UIEvent(param){ onscreen 'SAPMV45A.0102' set("F[Order]" , param.param_1); enter(); onscreen 'SAPMV45A.4001' enter(); } The resulting VA02 screen will be as shown below:

165

WS/64 Developer Guide

openfile
It is sometimes necessary to open an external file to extract data. The openfile command is used to perform this action. This command typically creates a new file with the specified name. If a file with that name already exists, the command will delete the file, The syntax is as follows: openfile("filename" {"output":true, "delimiter":";"}); The supported file types are as follows: .csv .txt .xls

Options
The available options are as follows: output: The output option specifies an existing file with the same name will be deleted and replaced with a new empty file using the same name. delimiter: The delimiter option identifies the character used to separate between data entries in a file. In our example above, we are specifying the delimiter as the semicolon character. When appending or writing to a file, the flag 'output' must be set to 'true' when opening a file.

Example
In the following example, we are using openfile to open an external file containing some usernames we want to add to the database. The code is as follows: openfile("filenames.txt", {"delimiter":";", "output":true}); The file is now open and ready to use.

166

WS/64 Developer Guide

pos
It is often useful to move SAP screen elements around and re-organize screens. This may occur when elements are grouped together, or when it is necessary to add or delete elements for user convenience. The pos command is used to move or reposition screen elements. The pos command functions on most native SAP screen elements, including ActiveX controls, input fields, pushbuttons, radiobuttons and tabs. The syntax is as follows: pos("F[screen_element]". [row,col], {"option":true); The pos command cannot be used on GuiXT controls.

Options
The pos command takes the following options: field: This option is used to specify the field that will be used to offset a given screen control. This option must be used together with the 'offset' option and the syntax is as follows: {"field":"[element_name]", "offset":"[rows, cols]"} offset: This option is used to offset a screen control based on the position of a another control. This option must be used together with the 'field' option and the syntax is as follows: {"field:"[element_name]", "offset":"[rows, cols]"} text: This option is used to specify that only the onscreen text label of a control will be moved. The control itself will remain in its previous position. The syntax is as follows: {"text":true} value: This option specifies that only the actual screen control will be moved - the label will remain in its original position. The syntax is: {"value":true}

The 'text' and 'value' options cannot be used together.

167

WS/64 Developer Guide

Examples
Moving a field
In the following example, we will re-position the 'Sales Organization' field on the initial VA01 screen displayed below:

To change this screen, we would first open the script file and add the following lines of code. pos("F[Sales Organization]", [5,30]); The SAP screen will now appear as shown in the following example:

168

WS/64 Developer Guide

Moving a field label


In the previous example, we used the 'value' option to move the 'Sales Organization' field alone - the label did not accompany it. To move the label alone, we will change the code as shown below: pos("F[Sales Organization]", [5,30], {"text":true }); The screen will now appear as shown below:

169

WS/64 Developer Guide

Moving a field
To move only the actual field of an inputfield, we would use the 'value' option. To move only the actual field of the 'Sales Organization' inputfield, we would use the following code: pos("F[Sales Organization]", [5,30], {"value":true}); The screen would appear as follows:

170

WS/64 Developer Guide

Using field and offset options


One of the great strengths of the pos method, is that it is not restricted to moving screen elements to different positions - it can also be used in repositioning the parts of a screen element in relation to each other. Therefore it is possible to move the label of an input field, for example, in relation to a the field, or move the field in relation to the label. For example, in our original example, we moved both the field and the label for the 'Sales Organization' input field to a new position on the screen outside of the group box. However, it is also possible to reposition the screen element in relation to other elements, just as we saw with input fields earlier. To do this, we will first enter the following code into the script file: pos("F[Sales Organization]", {"field":"F[Distribution Channel]", "offset":[0,30]}); This will move the 'Sales Organization' field down and place it immediately adjacent to the 'Distribution Channel' field as shown in the following example:

171

WS/64 Developer Guide

pushbutton
Pushbuttons are some of the most useful and powerful screen elements users can take advantage of with WS and SAP. .It is primarily useful for creating pushbuttons on SAP screens. Pushbuttons can be tied to functions, SAP transaction codes, processes, menu options. The following table displays the syntaxes for using the pushbutton command in WS: Syntax Description pushbutton([TOOLBAR], "Label", "/n[tcode]", {"separator":true}); pushbutton([startRow, startCol], "Label", "/n[tcode]", {"process":process_name, "using":{"param1":"value"}}) Specifies a toolbar pushbutton and assigns a transaction code that will be called when the button is pushed. Specifies a pushbutton that has a process attached. A parameter value will defined to be passed to the function.

172

WS/64 Developer Guide

Options:
Pushbuttons can take the following options: fcode / tcode: This is not an option, but is an additional modifier that can be used with a pushbutton command. This can refer either to a particular transaction code or to an actual function key on the user's keyboard. If a transaction code is used, it must be preceded by the characters '/n', but if a function code is included, it does not need these characters. The fcode or tcode will be placed outside the curly brackets containing the options and the syntax is as follows: pushbutton([1,1], "Label", [1,10], "fcode/tcode", {"option":value}); T-codes (transaction codes) refer to SAP transaction codes. F-codes (function codes) can refer to either a transaction code or to a function key on a user's keyboard.

process: Will launch a function when the pushbutton is clicked. The syntax is as follows: {"process":process_name} size: Specifies the size of the pushbutton in rows and columns. The syntax is as follows: {"size":[rows,cols]} Toolbar: Places the pushbutton on the toolbar of a given SAP screen. Neither the size nor the position needs to be specified for a toolbar pushbutton. The syntax is as follows: pushbutton([TOOLBAR], "Label", {option":value}); using: Users can pass values to the processes called by the pushbuttons with the 'using' option. The syntax is as follows: {"using":{"param1":"value", "param2":"value"}}

173

WS/64 Developer Guide

Examples
Creating launchpads
We have already seen how pushbuttons can be used in one format. We used pushbuttons when we originally modified the Easy Access screen and replaced the menu with a group of pushbuttons tied to common SAP transaction codes (T-codes). To create the pushbuttons, we first entered the following code into the SAPLSMTR_NAVIGATION.sjs script file: for(a=firstChild; a!=null; a=a.nextSibling) a.del( ); box( {"offset":[8,4]}, {"offset":[16,50]}, "Quick Links"); pushbutton( {"offset":[10,6]}, "View Notifications", "/niw30"); pushbutton( {"offset":[12,6]}, "View Work Orders", "/niw33"); pushbutton( {"offset":[14,6]}, "Create Sales Order", "/nva01"); pushbutton( {"offset":[10,28]}, "Display Sales Order", "/nva03"); pushbutton( {"offset":[12,28]}, "Change Sales Order", "/nva02"); pushbutton( {"offset":[14,28]}, "Create New Material", "/nmm01"); The Easy Access screen now appears as shown in the following example:

174

WS/64 Developer Guide

Calling processes
In the preceding example, we used the pushbuttons to navigate to a specific SAP transaction. However, pushbuttons can do far more than merely help users navigate to their requisite transactions. Pushbuttons can also be used to trigger a complete process which may involve multiple screens and data entry points. We will cover advanced processes later in the book, but we will demonstrate one here. The process will set the order type to 'OR'. First it is necessary to enter the following code into the SAPMV45A.E0101.sjs script file: pushbutton( {"offset":[12,2]}, '@2L@Save Restriction Codes', {"size":[2,25], "process":setOrderType}); function setOrderType() { set("F[Order Type]", "OR"); } This creates a new button on the 'Create Sales Order' screen, as shown in the following example:

However, the button is tied to the 'setOrderType' process so when the button is pushed, it results in the following screen being displayed:

175

WS/64 Developer Guide

What happened is that the button causes the order type to be set to 'Standard Order' resulting in the type of order to be created being set to 'Standard'. It is possible to add additional parameters to a button and execute a more complex process, which we will cover later in this section. The code can be broken down as follows: pushbutton( {"offset":[12,2]}, '@2L@Save Restriction Codes', {"size":[2,25], "process":setOrderType}); In this section of code, we are creating a new pushbutton, and offsetting it by 12 rows and 2 columns from the left border. The button label is "@2LSave Restriction Codes", the size is set to 2 rows and twelve columns and the button will call the specified process "setOrderType", which is a function defined later in the script. function setOrderType() { set("F[Order Type]", "OR"); } In the preceding bit of code, we are defining the function that the pushbutton '@2LSave Restriction Codes" will call when pushed. The function name is 'setOrderType', and it performs the basic operation of opening the 'Standard Order Type' screen. The value 'OR' defines what type of order to create'. Every time this button is pushed, the attached operation will be performed.

176

WS/64 Developer Guide

Passing parameter values


In the following section, we will demonstrate how to pass a parameter to a function that is called by a pushbutton. This process works essentially the same regardless of what type of screen element is being used - parameters can be passed to a variety of screen elements. In the following example, we will pass the parameter 'z_ord' to the function called by the pushbutton. The parameter can either be defined in the script or can be something entered by a user. Both scenarios will be demonstrated. Defining parameters in the script In the following example, we will pass the parameter 'param1' to the function that is called when the user presses the button. The code would be as follows: pushbutton([1,1], "@2L\\QLaunch VA01@VA01", "/nva01", {"size":[1,10], "process":test1, "using":{"param1":"OR"}}); function test1(param) { onscreen 'SAPMV45A.0101' set("F[Order Type]", param.param1); enter(); } The Easy Access screen now displays as follows:

Once a user presses the pushbutton, the process will execute, taking the user to the VA01 Overview screen. The parameter has been passed to the function, specifying that the Order Type field on the initial VA01 screen is set to 'OR'. The resulting screen is displayed below:

177

WS/64 Developer Guide

Obtaining parameters from users The 'using' option can also be used to pass user-entered data to the process that will be executed. In the following example, we will create a textbox where the user will enter the order type. This value will then be passed to the function. The code is as follows: pushbutton([1,1], "@2L\\QLaunch VA01@VA01", "/nva01", {"size":[1,10], "process":test1, "using":{"param1":"&V[z_ord]"}}); textbox([2,12], [3,24], {"name":"z_ord"}); function test1(param) { onscreen 'SAPMV45A.0101' set("F[Order Type]", param.param1); enter(); } The resulting screen displays as follows:

If a user enters 'RO' in the textbox and presses the button, the RO overview screen will display as follows:

178

WS/64 Developer Guide

179

WS/64 Developer Guide

Toolbar Pushbuttons and Separators


Pushbuttons can also be placed on the toolbar and separated from other toolbar elements. In the following example, we will add the previously created pushbutton to the toolbar. To do this, we will add the following code to the MM01 script file: pushbutton( [TOOLBAR], "Process",{"separator":true, "process":setMatType}); function setMatType() { set("F[Industry Sector]", "C"); set("F[Material Type]", "FERT"); } The screen is shown below:

180

WS/64 Developer Guide

Tooltips and icons


Just as users can assign tooltips and icons to inputfields, so they can also be assigned to pushbuttons. The syntax is as follows: pushbutton([rows, cols], "@iconID\\QTooltip text@Label", "/ntcode", {"option":value}); In the following example, we will assign the icon for 'Save' and a tooltip to a new pushbutton on the Easy Access screen. The code is as follows: pushbutton([1,1], "@2L\\QTooltip text here@Label", [1,10], "/nva01", {"process":test}); When the user hovers over the button, the screen now appears as shown below:

181

WS/64 Developer Guide

radiobutton
Like pushbuttons, radiobuttons are used to simplify the user interface. Radiobuttons can be used for many purposes, such as replacing a set of input fields with default data sets. Users can employ radiobuttons to specify various fields and values that will be populated when the user selects the radiobutton. The syntax is as follows: radiobutton([row,col], 'DisplayName', {"option":value}); To refer to a field on the same screen, users can specify that field in the radiobutton as shown below: radiobutton([row,col], "DisplayName", {"F[field_name]":"value"}); Radiobuttons have two possible states that can be associated with them, as follows: If set to 'X', the radiobutton will be in the selected state. If set to '' or null, the radiobutton will be in the unselected state. These states can be used to determine which value will be passed, as will be demonstrated in the examples.

Options
The radiobutton command takes the following option: default: This sets the radiobutton on which this option is used as the default. If the 'default' option is used, setting a radiobutton or a checkbox as the default on a given screen will automatically deactivate the other checkboxes or radiobutton in that grouping. The syntax is: {"default":true} name: This option enables users to assign a GuiXT name to a radio button. This name can then be used to refer to the radiobutton. The syntax is: {"name":"z_radiobutton"} readonly: With this option, users can make a radiobutton as uneditable, or read-only. This may be useful if a particular option is not intended for use. The syntax is: {"readonly":true} value: With this option, users can assign a value to a given radiobutton. This is very useful when assigning field values to radiobuttons or for passing parameters to other screens. The syntax is: {"value":"value"}

182

WS/64 Developer Guide

Examples
Passing values on the same screen
In the following example, we will use a set of radiobuttons to pass values to the Order Type field on the VA01 initial screen. To do this, we will also need to employ the set command. See the set section for additional information on using set. Each radiobutton will have a value; that value will be placed into the 'Order Type' field. We area also making the Standard Order as the default selection. Once a user selects a radiobutton and presses enter, the associated value will be placed in the Order Type field. The code is as follows: radiobutton([12,0],"Standard Order", {"[Order Type]":"OR"}); radiobutton([13,0],"Returns", {"[Order Type]":"RE"}); radiobutton([14,0],"Promotions", {"[Order Type]":"AA"}); radiobutton([15,0], Rush Order", {"[Order Type]":"RO"}); The resulting screen will display as shown below:

Once a user selects a radiobutton and presses enter, the associated value of the selected radiobutton will be passed to the designated inputfield.

183

WS/64 Developer Guide

Passing values to a different screen


In the following example, we are passing a value from a user-selected radiobutton on the VA01 initial screen to the VA01 overview screen. The set command will also be necessary in this implementation as well. The code is as follows: radiobutton([12,0],"Customer 1460" , {"name":"z_cust", "value":1460}); radiobutton([13,0],"Customer 1480" , {"name":"z_cust", "value":1480}); onscreen 'SAPMV45A.4001' set("F[Sold-to party]", "&V[z_cust]"); set("F[Ship-to party]", "&V[z_cust]"); enter(); The resulting screen would appear as shown below:

Once the user selects the radiobutton in question, the Overview screen would display with the customer already filled in as shown below:

184

WS/64 Developer Guide

185

WS/64 Developer Guide

Selecting Radiobuttons
In the following example, we have two radiobuttons on the Easy Access screen, each containing a unique value but with the same variable name. In the target screen, we have corresponding radiobuttons, which will be selected based on the user's action on the initial screen. Therefore we will set the state of the target radiobuttons based on which radiobutton the user selects on the initial screen. The code is as follows: pushbutton([TOOLBAR],"Movement Type","/nmb1c",{"process":z_test}); radiobutton([1,25],"Indvidual Slip" , {"name":"z_radio", "value":"A"}); radiobutton([2,25],"Collective Slip" , {"name":"z_radio", "value":"B"}); function z_test() { onscreen 'SAPMM07M.0400' if(z_radio=="A") { set("R[Individual Slip]","X"); } if(z_radio=="B") { set("R[Collective Slip]","X"); } } The resulting screen is shown below:

When the process has run, the target screen will appear as shown below:

186

WS/64 Developer Guide

187

WS/64 Developer Guide

Using the value property


The value property displays an interesting behavior when it is used with radiobuttons. This is due to the way in which Synactive handles the values associated with radiobuttons. These values are treated as a simple string before the object is created in a screen block. However, once the screen element object has been created, the value associated with the radiobutton is stored in the '.value' property. Therefore, once a radiobutton is defined in a script, it becomes a screen element object and as such, the 'value' property can be used to return the values of that object. In the following example we will demonstrate by creating three radiobutton objects: radiobutton([11,25], "Hour", {"value":"H", "name":"z_act_unit"}); radiobutton([11,37], "Day", {"value":"DAY", "name":"z_act_unit"}); radiobutton([11,49], "Each", {"value":"EA", "name":"z_act_unit"}); The values are set using the 'value' option previously described. However, the objects associated with a particular screen are automatically destroyed once a user departs from the screen and at that point the values are once again stored in strings, making it impossible to use the '.value' property to return those values - for example in a println statement as shown below:
println("****************activity unit Value (Outside) = " + z_act_unit.value);

The solution to this is for a user to remember that while a radiobutton is created as an object, the value property can be returned using the '.value' property. However, outside of the object, it must be returned using a string - the '.value' property will not return the actual value of the radiobutton. An example of the two different methods for returning the radiobutton value is shown below: function process_enter() { println("****************activity unit Value (Outside) = " + z_act_unit.value); println("****************Allocation Cost Element Value (Outside) = " + z_cost_elem.value); onscreen "SAPLKMA6.0299" println("-----------------------------Activity unit Value (Inside) = " + z_act_unit); println("-----------------------------Cost Element Value (Inside) = " + z_cost_elem); As shown above, if the radiobutton is used within a function, the value property can be used to return the radiobutton value. However, if the value is outside of a function or on a different screen from the one where the object occurs, a string must be used as it is in the preceding example.

188

WS/64 Developer Guide

readfile
Once a file is open, users can take advantage of the readfile command to read a record into a variable in the WS environment. Currently only the following file type is supported: .csv The syntax is shown below: readfile("filename");

Options
The readfile command does not take any options.

Example
Once the value is read into the variable, it can be used in WS just like any other variable. In the following example, we will read the values contained in the file "file2.csv" into an IW21 transaction. The code will be as follows: function isBlank(jvar){ return(jvar == null || jvar == "" || jvar == void(0)); } for(a=firstChild; a!=null; a=a.nextSibling){ a.del(); } pidx = 0; idx=0; text([0,0], "Material" , {"size":20}); text([0,22], "Item" , {"size":20}); text([0,44], "Description" , {"size":20}); create:{ inputfield([pidx + 1,0], {"size":20, "readonly":true, "name":"z_first_&V[pidx]" ,"nolabel":true}); inputfield([pidx + 1,22], {"size":20, "readonly":true, "name":"z_second_&V[pidx]" ,"nolabel":true}); inputfield([pidx + 1,44], {"size":20, "readonly":true, "name":"z_third_&V[pidx]" ,"nolabel":true}); } set("V[z_checkfld]", "&V[z_first_&V[pidx]]"); if(isBlank(z_checkfld)) { println("<<<<<<<<<CHECK FIELD>>>>>>>>>>" + z_checkfld); goto end_create; } pidx = pidx + 1; goto create; end_create: 189

WS/64 Developer Guide

onUIEvents['Enter'] = {"process":iw21_readfile, "fcode":"/niw21"}; function iw21_readfile(){ println("<<<<<<<<<<<<INITIAL VALUE>>>>>>>> :" + idx); openfile('file2.csv', {"delimiter":","}); read:{ println("<<<<<<<<<<<<READING VALUES>>>>>>>> :" ); readfile('file2.csv', {"z_first_&V[idx]":true, "z_second_&V[idx]":true, "z_third_&V[idx]":true}); } set("V[z_currField]" , "&V[z_first_&V[idx]]"); println("<<<<<<<<<<<<<<<<<Current Field>>>>>>>>>>>>>>" + z_currField); if(isBlank(z_currField)) { println("<<<<<<<<<<<<<<GOING END>>>>>>>>>>>>>>"); goto end; } idx++; println("<<<<<<<<<<<<THE IDX VALUE>>>>>>>> :" + idx); goto read; end: closefile('file2.csv'); } The file itself will contain the following values, which we will read into the requisite screen: 1030,10,valve 1 1030,20,15 inch TV 1030,30,monitor 2120,10,door handle 2120,20,paper clips 2120,30,mouse 3650,10,TV set 3650,20,remote control 4400,10,round cable 4400,20,starter 5003,10,test 5003,20,test The resulting IW21 screen will appear as shown below:

190

WS/64 Developer Guide

191

WS/64 Developer Guide

removefile
When a file is no longer needed, use the Removefile command to delete the file. It is necessary to use the full path of the file. The syntax is as follows: removefile("filename");

Options
The closefile command does not take any options.

Example
In the following example, we will use closefile to delete the sample file we used in the previous examples. The code would be as follows: removefile("file2.txt"); The file is now deleted.

192

WS/64 Developer Guide

return
The return command enables users to return values or messages from actions and then display those values or messages on a SAP screen. The most common usage is to send an error message to a user when an invalid action occurs and then to end the script. The return command can be executed in WS to perform any of the following actions: Convey users back to the initial screen of a SAP transaction. Display a message on a SAP screen. When screen combinations are done, the return command should be used before any screen blocks. The syntax for using Return in WS scripts is as follows: return("string"); Variables can also be used in return commands. To use a variable, such as a user-created variable or a system variable, the syntax would be as follows: return(_systemVariable); Variables and strings can also be combined. To combine a variable and a string, the following syntax would be used: return("string" +_variable);

Options
The return command does not take any options.

Example
In the following examples, we will demonstrate how the return command can be used in SAP screens.

Conveying users to a SAP transaction


As previously stated, the return command is almost always used to throw an error message and then end the script. In this example, we will return a message and take users back to the initial SAP Easy Access screen, if no tcode is entered in the GuiXT field. Otherwise, we will take users to the transaction selected. We will first create a pushbutton and a process call, as follows: pushbutton([2,1], "Execute Return", "/n&V[fcode]", {"process":z_return, "size":[1,30]}); inputfield([2,32], {"name":"fcode", "size":10, "nolabel":true}); The SAP window will now appear as follows:

193

WS/64 Developer Guide

The process called is the following function: function z_return() { if(fcode == "") { return("E: Please enter a transaction code - ex. va01, mm01..."); } onscreen 'SAPLSMTR_NAVIGATION.0100' enter("/n&V[fcode]"); } If the user does not enter a transaction code, the return command will return an error and end the script as shown below:

194

WS/64 Developer Guide

195

WS/64 Developer Guide

rfcconnect
The rfcconnect command is housed in the guixt.sjs configuration file and is used to send a connection string specifying the SAP ERP system to which the RFC user will connect. The syntax for a typical rfcconnect single entry will look as shown in the following example: rfcconnect="IFDATABASE=XXX,LANG=E,CLIENT=xxx,ASHOST=SAP_system,SYSNR=0 0,LCHECK=0,USE_SAP GUI=0,USER=rfc_user, PASSWD=rfc_password"; If the password is encrypted, the plain text password will be replaced in the 'PASSWD' parameter by an encrypted string. The rfcconnect command can be used to connect with either a Message Server or with an Application Server. In addition, the password can be either in plain text or encrypted. The example string above contains a number of parameters. Some of the parameters are used regardless of whether the RFC connection is being made to a message server or to an application server. However, there are certain unique parameters that are specific to a Message Server. The Message Server parameters are as follows: MSHOST: The SAP Message Server to which the connection is being made. R3NAME: The name of the SAP ERP system to which the connection is being made. This is important as the message server needs to know the specific SAP ERP system to which the connection will be passed. GROUP: The SAP group to which the user belongs. If a message server is used, there are additional parameters that must be included in the message server configuration file. Please see the GuiXT Server documentation for additional information. An example of an rfcconnect statement that includes these parameters is shown below: rfcConnect="IFDATABASE=XXX,MSHOST=message_server,R3NAME=sap_SYSTEM_NAM E, GROUP=group_name, LANG=E,CLIENT=000, SYSNR=00,LCHECK=0,USE_SAP GUI=0,USER=rfc_user, PASSWD=rfc_password" ; The Applications Server parameters are as follows: ASHOST: The SAP application server being used for the connection. SYSNR: The system number of the SAP instance to which the user will connect. There can be multiple instances in a single connection. The system number is typically a two-digit number and can be obtained from the SAP ERP system properties. The parameters that are common to both Message Servers and to Application Server are as follows: IFDATABASE: The SAP ERP system that is currently connected. This parameter must be specified in the connection string in order for the connection to occur. LANG: The default language to be used. 'E' is the language code for English. CLIENT: The client to which the user is connecting. The standard SAP client is always '000', therefore it is very important to specify which client the user will connect to. LCHECK: Boolean parameter that signifies if a logon check is performed at time of opening. '0' indicates that no check will be performed; '1' specifies that a check will be performed. USE_SAP GUI: Specifies whether the SAP GUI is to be used or not in the relevant connection. Set to '0' if SAP GUI is not to be used; set to '1' if SAP GUI is to be utilized. By default it should be set to '0'. USER: The username of the RFC user. PASSWD: The password for the specified RFC user. This can be in two separate formats - either an unencrypted plain text string or an encrypted string. 196

WS/64 Developer Guide

It is important to note that the RFC data can be invoked in two other ways - either from the RFC parameters in the guixt.sjs file as explained in the GuiXT.sjs Parameters section or from a call command as explained in the call section. In order of precedence, the rfcconnect array takes precedence, followed in order by the call command and finally the single RFC user entry in the guixt.sjs file.

Examples
Using a single rfcconnect command
If only a single server is to be the target, we can use a single rfcconnect command as shown in the following example: rfcconnect = "IFDATABASE=XXX,LANG=E,CLIENT=100,ASHOST=system,SYSNR=00,LCHECK=0,USE_ SAPGUI=0,USER=WSUSR,PASSWD=password";

Using an rfcconnect array


If we need to connect to multiple SAP systems, then we can use an array with the rfcconnect command as shown below: rfcconnect = [ "IFDATABASE=AD4, CLIENT=600, ASHOST=TEST4.SAMPLE.NET, SYSNR=00", "IFDATABASE=AD2, CLIENT=600, ASHOST=TEST04.SAMPLE.NET, SYSNR=02", "IFDATABASE=AT4, CLIENT=600, ASHOST=TEST6.SAMPLE.NET, SYSNR=04", "IFDATABASE=XXX, CLIENT=100, ASHOST=SYSTEM, SYSNR=00", "IFDATABASE=AT7, CLIENT=600, ASHOST=TEST6.SAMPLE.NET, SYSNR=02"];

Connecting to an Application Server


In the following example, we will connect to a simple SAP application server. The string would be as follows: rfcconnect = [ "IFDATABASE=XXX,LANG=E,CLIENT=100,ASHOST=system1,SYSNR=00,LCHECK=0,USE _SAPGUI=0,USER=WSUSR,PASSWD=password" ];

Connecting to a Message Server


In the below example, we are connecting to a SAP message server. The rfcconnect string would appear as follows: rfcConnect=[ "IFDATABASE=XXX,MSHOST=message_server,R3NAME=sap_SYSTEM_NAME, GROUP=group_name, LANG=E,CLIENT=000, SYSNR=00, LCHECK=0, USE_SAPGUI=0, USER=rfc_user, PASSWD=rfc_password"] ;

197

WS/64 Developer Guide

set
The set command is one of the most useful and powerful commands in WS. Set is used for a wide variety of actions but the primary purpose is to assign a value either to a variable or to a field in a SAP screen. The fields can either be generated from GuiXT or native SAP fields, although the usage of the set command is different when a SAP element is involved as opposed to when a GuiXT element is used. There are several different possible syntaxes for set, which are shown in the table below: Syntax Description set("cell[table, column, row]", "abc"); set("cell[table, column, row]", "&V[z_var]""); set("F[name]", "abc"); set("F[name]", "&V[z_var]"); set("R[radiobutton]", "X" set("C[checkbox]", "X"); set("C[checkbox]", " "); set("V[z_var]", "&cell[table, col, row]"); set("V[z_var]", "&F[inputfield]"); set("V[z_var]", "&R[radiobutton]"); Sets a value into a specified cell in a table. Sets a value from a variable into a specified cell in a table. Sets a specified value into a SAP inputfield. Sets the value of a variable into the specified field. Sets the specified SAP radiobutton as the default selection. Marks the specified checkbox as being checked. Marks the specified checkbox as being unchecked. Sets a variable with the value contained in the specified table cell. Sets a variable with the value contained in the specified inputfield. Reads the radiobutton selection and sets the variable with the radiobutton value. If the radiobutton is selected, the value will be "X" otherwise the value will be blank. Sets a value of one variable into a different variable. Reads the checkbox selection and sets the variable with the checkbox value. If the checkbox is selected, the value will be "X" otherwise the value will be blank. Sets the specified value into a variable. Sets the value of a system variable into a variable.

set("V[z_var]", "&V[param]"); set("V[z_var]", "&C[checkbox]");

set("V[z_var]", "abc"); set("V[z_var]", "&V[_systemVariable]");

198

WS/64 Developer Guide

Options
There are currently two options supported with the set command, which are as follows: search: Specifies that a given string will be searched in the relevant text. The 'z_var' variable refers to the text that will be searched, which in this case is drawn from the _message system variable. The text case will be ignored. There are multiple syntaxes possible and these are as follows: set("V[z_var]" , value ,{"search":"string"}); set("V[z_var]" , "",{"search":"string"}); set("F[Field]" , "&V[z_var]",{"search":"string"}); set("V[z_var]" , "&F[Field]" , {"search":"string"}); When using the search option, the text returned should be the first string following the term specified in the search statement. The search option currently works with the following uses of set: o set("F[fieldName]", "abc"); o set("F[fieldName]", "&V[z_var]"); o set("V[z_var]", "&F[fieldName]"); o set("V[z_var]", "abc"); o set("cell[table, col, row]", "abc"); uppercase: Specifies that the value being set will be put into uppercase. The syntax is as follows: set("V[z_var]", value, {"uppercase":true}); The uppercase option is implemented in all releases of WS subsequent to the 2 1.2.141.0 release from April 2012. This option will work with the following usages of set: o set("F[fieldName]", "abc"); o set("F[fieldName]", "&V[z_var]"); o set("V[z_var]", "&F[fieldName]"); o set("V[z_var]", "abc"); o set("cell[table, col, row]", "abc");

199

WS/64 Developer Guide

Examples
The following examples will demonstrate some of the more common or convenient uses of the set command. Please note that the order in which the set command is written is very important - inverting it will change the meaning of the command. The value to be set will always follow the element or variable into which it will be stored.

Setting a value to a screen element


In this example, we will assign a value to a SAP screen element. With this usage, both string and numeric values can be assigned. In this example we will assign values to several fields on the VA01 initial screen. The code is as follows: set("F[Order Type]", "OR"); set("F[Sales organization]", "1000"); set("F[Distribution Channel]", "10"); set("F[Division]", "00"); enter(); The resulting screen is shown below:

Setting a value to a table cell


syntax, the variable will be assigned to the specified screen element. For example, it is possible to assign a variable to a specific table cell. In this case, we will assign values to the Materials and Order Quantity fields in the All items table on the overview screen of the VA01 transaction. The code would be as follows: set("cell[All items,Material,1]", "t-bw03-05"); set("cell[All items,Order Quantity,1]", "1"); The value 't-bw03-05' will now be placed in the specified table cell as shown below:

200

WS/64 Developer Guide

It is also possible to do the reverse operation, or assign the value from a given table field to a variable. If we wished to assign the value contained in the Material cell in the first row of the All items table to the variable 'z_mat2', the code would be as follows: set('V[z_mat2]', '&cell[Table,column,row]); In this case, the value contained in the actual table cell is being stored in the variable, which is why the ampersand precedes the cell specifications.

Setting values from variables


In the following example, we will use set to assign a value from one variable to another variable, which will then be used in an operation on another screen. Both string and numeric values can be assigned to and from the variables in question. The code will be placed in the SAPMV45A.E0101 script file and is as follows: inputfield([12,0], "Customer", [12,11], {"name":"z_cust", "size":10}); onscreen 'SAPMV45A.4001' set("F[Sold-to party]", "&V[z_cust]"); set("F[Ship-to party]", "&V[z_cust]"); This will place the value from the inputfield 'Customer' into the specified Sold-to and Ship-to fields on the ensuing screen. The SAPMV45A.E4001 screen is shown below with the values passed to the relevant fields.

201

WS/64 Developer Guide

This same process can be used for setting table cells as well. In this case, if we wanted to place the value from the GuiXT field into a table cell, the code would be as follows: inputfield([12,0], "Material", [12,11], {"name":"z_mat", "size":10}); onscreen 'SAPMV45A.4001' set("cell[All items, Material, 1]", "&V[z_mat]"); set("cell[All items, Order Quantity, 1]", "1"); enter();

Setting a field with a variable


In the following example, we will perform several operations by means of a function. We will first set the value of the Order Type field into a variable, which is then transferred to a custom field we will create on the ensuing SAPMV.4001 screen. The code is as follows: pushbutton([TOOLBAR], "Set", {"process":z_process}); function z_process() { set("V[z_order]", "&F[Order Type]"); onscreen 'SAPMV45A.4001' inputfield([1,40], "Order", [1,56], {"size":10}); set("F[Order]", "&V[z_order]"); } After the custom field has been populated, the VA01 overview screen appears as shown below:

202

WS/64 Developer Guide

Setting a default radiobutton or checkbox


To make a radiobutton or checkbox as the default selection, we will turn to the MB1C transaction, which is shown below in its default state:

203

WS/64 Developer Guide

Here we have a set of three radiobuttons, as well as a single checkbox. To mark the 'Print' checkbox and set the Individual Slip radiobutton as default, we will write the following code: pushbutton([TOOLBAR], "Set", "/nmb1c", {"process":z_process}); function z_process() { onscreen 'SAPMM07M.0400' set("R[Individual Slip]", "X"); set("C[Print]", "X"); } The screen will now appear as follows:

We can use this same screen to pass values or parameters from a GuiXT checkbox or radiobutton as well. In the following case, we have created a set of radiobuttons on the Easy Access screen and we will pass the values selected to the elements on the MB1C screens. The modified Easy Access scren appears as follows:

204

WS/64 Developer Guide

The code used is shown below: set("V[z_movtype]","101"); radiobutton([12,52],"101 Movement Type" , {"name":"z_movtype", "value":101}); radiobutton([13,52],"102 Movement Type" , {"name":"z_movtype", "value":102}); onscreen 'SAPMM07M.0400' set("F[Movement Type]", "&V[z_movtype]"); The screen is now shown as it appears after this operation has been executed:

205

WS/64 Developer Guide

Using the search option


When using the search option with the set command, users can use the different syntaxes to search different sources. In all cases, the search will return the text immediately following the search term. An example is shown below, where we will enter the following code into the VA01 script file: pushbutton([TOOLBAR] , "test" , "/nva01" ,{"process":va01_test}); function va01_test(){ onscreen 'SAPMV45A.0101' set("F[Order Type]" , "OR"); enter(); onscreen 'SAPMV45A.4001' set("F[Sold-to party]" , "1460"); enter(); onscreen 'SAPMV45A.4001' println("----After entering sold-to party----"); enter("/11"); onscreen 'SAPMV45A.4001' if(_message){ set("V[z_message]","&V[_message]",{"search":"Order"}); println("After z_message>>>" +z_message); } enter("/nva01"); message(z_message); } Once the user presses the 'test' button on the Toolbar, the script will execute, and the text searched will be returned in the status bar as shown below:

206

WS/64 Developer Guide

Using set to check values for indexed variables


If a user tries to check the value of an indexed variable, it is necessary to use the set command in order to obtain the value of that variable as shown in the following example. The code would be as follows: set("V[z_temp]" , "&V[z_variable&V[idx]]"); if (z_temp == "value") { println("The value of z_temp is>>>" +Z_temp); }

207

WS/64 Developer Guide

setcursor
The setcursor command can be used to place the cursor into an inputfield, a table cell or a position on a list of your choice. There are several possible syntaxes for the setcursor command which are as follows: Sets the cursor into a field whose setcursor([row,col]); coordinates are known. Sets the cursor into a specified setcursor("F[Name]"); inputfield. Sets the cursor into a specified cell setcursor("cell[tableName, col, row]"); in a table. The column can be identified either by the column number or by the column name as in the following examples: setcursor("cell[Data Entry Area, 5, 10]"); setcursor("cell[Data Entry Area, Subobject, 4]"); In addition, the row number can be specified by a variable as in the following example: znum = 1; setcursor("cell[Data Entry Area, 3, &V[z_num]]"); Please note that in the case of a table command, the column must always be listed before the row as in the previous example. In addition, the setcursor command will not work for any row other than the first if the table is empty.

Options
The setcursor command takes the following option: offset: The offset option will offset the cursor from the left margin of the field in which it will be placed. The syntax is as follows, with 'x' being replaced by a number: {"offset":x} Currently, the offset option can only be used with a field name - it doesn't work with the field's coordinates. This option also is not available for table cells.

208

WS/64 Developer Guide

Examples
Placing cursor in table cells
In the following example, we will set the cursor into the second row of the All items table in the VA01 Overview screen. The code is as follows: pushbutton([TOOLBAR], "SetCursor", "/nva01", {"process":z_setcursor}); function z_setcursor() { onscreen 'SAPMV45A.0101' set("F[Order Type]", "OR"); set("F[Sales Organization]", "1000"); set("F[Distributions Channel]", "10"); set("F[Division]", "00"); enter(); onscreen 'SAPMV45A.4001' set("F[Sold-to party]", "1460"); set("F[ship-to party]", "1460"); set("cell[All items, Material,1]", "t-bw05-03"); set("cell[All items, Order Quantity, 1]", "1"); setcursor("cell[All items, Order Quantity, 2]"); enter(); } When the operation is complete, the screen will appear as shown below:

209

WS/64 Developer Guide

Placing cursor in lists


If we wanted to place the cursor at a predetermined spot in the list on the Create Sales Order screen, for example next to the Distribution Channel field, we would first find the coordinates of the spot we wished to place the cursor. Once the coordinates have been identified, we would enter the following code into the SAPMV45A.E0101.sjs script file, replacing the 'x' and 'y' coordinates with the actual values of the designated spot on the screen. When using setcursor with coordinates, the cursor must be placed in a field - it cannot be positioned in a spot where no field exists If we wanted to place the cursor in the Distribution Channel field on the initial VA01 screen, the code would be as in the following example: setcursor([5, 11]); The screen would now look as displayed in the below example:

In order to place the cursor into the Order Type field, we would add the following code to the script file for the Create Sales Order screen: setcursor("F[Order Type]"); The Sales Order screen would now appear as shown below:

210

WS/64 Developer Guide

Using setcursor with a list screen


In the following example we will set the cursor into a list screen in the ME5A transaction. The code in the RM06BL00.E0120.sjs script file would be as follows: setcursor([2,21]); The resulting screen would be as shown below:

211

WS/64 Developer Guide

Using setcursor with GuiXT fields


To set the cursor into a GuiXT field, it is necessary to use the field name - using the coordinates is not currently supported. in the following example, we will create three inputfields on the main Easy Access screen and place the cursor into the third field. The code would be as follows: inputfield([0,1], "TEST1", [0,10], {"name":"z_test1", "size":10}); inputfield([1,1], "TEST2", [1,10], {"name":"z_test2", "size":10}); inputfield([2,1], "TEST3", [2,10], {"name":"z_test3", "size":10}); setcursor("F[TEST3]"); The screen would then appear as shown below:

212

WS/64 Developer Guide

statusmessage
The statusmessage command is used when it is necessary to view messages relating to the status of a particular SAP session or connection. The command is typically executed within a function and produces the following outcomes: Display a status message list box Display custom messages Display system messages Display IDs for system messages The syntax to define the onscreen box that will contain the status message is as follows: statusmessage({"title":"Title", "size":[rows, cols], "position":[startRow, startCol]});

213

WS/64 Developer Guide

Options
The command takes the following options: addstring: Adds a custom message within the dialog box (listbox). Variables can be used with this option to pass content to the statusmessage. The syntax is: {"addstring":"new message string"} If a variable is used, the syntax would be as follows: {"addstring":variable_name} position: Specifies the onscreen position of the listbox. The syntax is: {"position":[startRow, startCol]} remove: Removes the listbox from the screen. Do not use this in the initial statusmessage command or the listbox will disappear even as it is called. The syntax is: {"remove":true} size: Specifies the size of the onscreen listbox in rows and columns. The syntax is: {"size":[rows,cols]} title: Creates the title of an onscreen listbox. As in the case of the addstring option, variables can be used to pass content to the status message. The syntax is: {"title":"title_string"} If a variable is used, the syntax would be as follows: {"title":variable_name} These options are more fully explained and examples are provided in the following sections.

214

WS/64 Developer Guide

Examples
Creating a statusmessage window To call a basic status message window, we would add the following code to the VA01 script file: statusmessage({"title":"Status", "size":[4,10]}); The resulting window is as follows:

215

WS/64 Developer Guide

Using addstring
The basic function of 'addstring' is to add a custom message to a listbox. The syntax is as follows: statusmessage({"addstring":"This is a sample message!"}); Messages can be added at any time during the execution of the function, either inside or outside a given screen block. It is also possible to include variables in the addstring option, such as the example shown below: var z_msgtitle = "Test Listbox"; statusmessage({"addstring":z_msgtitle}); In the following example, we will invoke a statusmessage listbox on the Easy Access screeen. The code is as follows: var z_msgtitle = "Sample StatusMessage Listbox"; var z_msg = "This is a sample message for the statusmessage command!"; pushbutton([TOOLBAR], "Test StatMsg", {"process":z_statmsg}); function z_statmsg() { statusmessage({"remove":true}); statusmessage({"title":z_msgtitle, "size":[10,40], "position":[5,10], "addstring":z_msg}); message("S: The message was displayed!"); } The resulting screen is shown below:

216

WS/64 Developer Guide

Displaying multiple messages in a listbox


In the first example, all system messages have been turned on, so any relevant system message will display in the listbox. In the second example, only certain types of system messages are enabled, restricting the number and type of system messages that will display in the listbox. In the following example, we will display a listbox containing four separate status messages, generated from several different screens n the VA01 transaction. The code is as follows: var z_msgtitle = "Sample StatusMessage Listbox"; var z_msg = "Statusmessage command example!"; var z_msg2 = "This is another statusmessage example!"; pushbutton([TOOLBAR], "Test StatMsg", {"process":z_statmsg}); function z_statmsg() { onscreen 'SAPLSMTR_NAVIGATION.0100' statusmessage({"title":z_msgtitle, "size":[10,60], "position":[5,10], "addstring":z_msg}); statusmessage({"addstring":"Navigating to VA01!"}); enter('/nva01'); onscreen 'SAPMV45A.0101' set("F[Order Type]", "OR"); enter(); statusmessage({"title":z_msgtitle, "size":[10,60], "position":[5,10], "addstring":"VA01 Overview screen!"}); statusmessage({"addstring":z_msg2}); } The resulting screen is shown below:

217

WS/64 Developer Guide

switchto
The switchto command is used principally to map a user's individual guixt.sjs file to a main guixt.sjs file hosted on a server. This objective is useful for enabling users to see configuration changes without the necessity of making changes to a local profile. There are two possible syntaxes, depending if a single statement or an array containing multiple locations is to be used. The array syntax is as follows: switchto = [ "\\\\customer.com\\GUIXT\\guixt1.sjs", "\\\\customer.com\\GUIXT\\guixt2.sjs", "\\\\customer.com\\GUIXT\\guixt3.sjs", ]; The locations can also use system names, as in the following example: switchto = [ "\\\\COMPUTER\\GUIXT\\guixt1.sjs", "\\\\COMPUTER\\GUIXT\\guixt2.sjs", "\\\\COMPUTER\\GUIXT\\guixt3.sjs", ]; The syntax for a single statement is as follows: switchto = ["\\\\company.com\\guixt\\guixt1.sjs"]; If no sjs file in the array is specified as being active WS will parse and select the first available location. If both a single statement and an array are contained within a given guixt.sjs file, the array will take precedence. The storage location can be one of the following: local directory Network share SAP Web Repository An example of these three options in a single array is shown below:
switchto = [ "c:\Test\Main.sjs", "SAPWR:Z.Test.GUIXT.SJS", "\\\\netshare\\PERSONAL\\User\\GUIXT\\&V[_database]guixt.ini" ]

When specifying a network share, it is important to make sure that each element is separated by two backslashes - Webscript has problems reading it otherwise. For the SAP Web Repository, the file location syntax must be written as follows: "SAPWR:Z.Test.GUIXT.SJS"

218

WS/64 Developer Guide

Options
The switchto command does not take any options.

Recursive Deployment
Switchto enables recursive deployment. What this means is that if there are multiple guixt.sjs files and each one contains a switchto statement, the last valid file will be the one used. For example, if the first guixt.sjs file resides on the local system and contains a switchto statement specifying two guixt files, the switchto command will parse the paths and proceed to the first valid file. In our example, this file would be 'C:\\text\guixt\\guixt1.sjs. However, within this new guixt.sjs file there is also a switchto command, listing three more directories. The first one proves to be invalid - perhaps it is missing a script directory or maybe the RFC user information is incorrectly defined. So the second guixt.sjs file is selected. In our example, this new guixt.sjs file is '\\\\netshare\\guixt\\guixt2.sjs'. The guixt.sjs file on netshare contains a valid script directory, so at that point, the switchto command ceases looking for additional guixt.sjs files. This process is illustrated in the following diagram:

219

WS/64 Developer Guide

Examples
Using SAPWR
If a user wishes to switch to a SAPWR directory, it is necessary to have valid rfcuser and rfcconnect statements in the guixt.sjs file. For more information on using rfcconnect, please see the rfcconnect and GuiXT.sjs Parameters sections. A sample rfcconnect statement and the corresponding switchto entry are shown below: rfcconnect ="IFDATABASE=XXX,LANG=E,CLIENT=800,ASHOST=test.company.com,SYSNR=11,LC HECK=0,USE_SAPGUI=0,USER=test,PASSWD=test1"; switchto = [ "SAPWR:Z.Test.GUIXT.SJS"; ]

Using variables
The switchto command is able to pick the filename from a variable. When used on the local system or on a network share, users can define a variable and pass the name of the database to be used. System variables can also be used to pass the directory name to the command. These are three separate cases, and for each the syntax and usage is different as well. Using a system variable When a system variable is used to define the directory, the syntax is as follows: switchto = ["\\\\directory\\&V[_variableName].guixt.sjs"]; In this case, we are using the [_database] system variable to specify the directory. For more information about system variables, please see the WS System Variables section. An example is shown below: switchto = ["\\\\server\\test\\&V[_database]guixt.ini"]; Currently the only supported system variable is [_database] Using a local variable If the user specifies a variable, the syntax would be as follows: var z_filename = "test_guixt.sjs "; switchto = [z_filename]; Here we have declared a local variable and assigned a file path to it. We can then use the variable in the switchto command instead of the file path. For local variables, either the path or the file may be specified. If only the filename is specified and the user wishes to add it to an existing path in the switchto command,, the requisite code would be as follows: var z_filename = "test_guixt.sjs"; switchto = ["C:\\guixt\\" +z_filename]; If the user wishes to store an entire path in a variable, the code would look as follows: var z_filename = ["C:\\guixt\\test\\test_guixt.sjs"]; switchto = [z_filename];

220

WS/64 Developer Guide

table
The table command is used to create a new table control on any SAP screen. This command is used in conjunction with the column command to create tables, with which SAP users can pass data to native or GuiXT-created controls. The syntax is as follows: table([2,1], [20,50], {"name":"va01_1nitms", "title":"All Items", "rows":100}); Once a table has been created, the column command can be used to add columns as in the following example. column('Item', {"size":5, "name":"va01_clitm", "position":1}); column('Material', {"size":18, "name":"va01_clitm", "position":2}); Columns are always added to the preceding table command unless the user specifies a different table with the table option as shown in the following example: column('Test', {"size":3, "name":"z_test", "postion":5, "table":"T[All Items]", "uppercase":true, "intensified":true, "alignright":true, "proportionalfont":true, "checkbox":true});}); Please see the column section for a more complete explanation of the column command and some examples of its other uses. In addition to using the column command to create columns for a newly-created table control, users can employ the 'setcursor' command to place the cursor in a table control. Please see the setcursor section for more detailed information regarding the setcursor command. The table command can take the following parameters from a GuiXT table control: name: The name of a GuiXT table control. title: The title of a GuiXT table control. rows: The number of rows in a GuiXT table control.

Options
The command also has the following options that can be used: fixedcolumns: The number of columns that will be fixed during a horizontal scrolling operation. 'X' is the column count. The syntax is: {"fixedcolumns":X} rowselection: One or more rows in the table can be selected. The syntax is: {"rowselection":true} singlerowselection: A single row in the table can be selected. The syntax is below: {"singlecolumnselection":true} columnselection: One or more columns in a table can be selected. The syntax is: {"columnselection":true} singlecolumnselection: A single column in the table can be selected. The syntax is: {"singlecolumnselection":true} Please note that the Table command allows for both row and column selection to be executed together. This is useful when a user wishes to select rows and columns and retrieve data from the cells at the intersection of the designated rows and columns. The code is as follows: table([2,1], [20,50], {"name":"va01_lnitms", "title":All Items", "rows":100, "fixedcolumns":2, "rowselection":true}); 221

WS/64 Developer Guide

table([2,1], [20,50], {"name":"va01_lnitms", "title":"All Items", "rows":100, "fixedcolumns":2, "columnselection":true});

System Variables
In addition to these properties and variables, there are also some system variables that can be used with tables created using this command. These system variables can be used to retrieve data contained in any cell. The system variables available for use with the Table command are as follows: _tabrow: Retrieves the number of rows in the table. An example is shown below: println("The number of rows is >> " +_tabrow); _tabcol: The number of columns in a table. An example is as follows: println("The table columns are >> " +_tabcol); _cursortabname: Retrieves the title of the table. See following example: println("Table title is: " + _cursortabname); _cursortabtechname: Retrieves the name of the table in question. This is defined in the 'name' option introduced earlier. An example is below: println("Table name is: " +_cursortabtechname); _cursorcolname: Retrieves the title of a column in the table. This value is set via the 'title' option of a column keyword. An example follows: println("Column title is: " +_cursorcolname); _cursorcoltechname: Retrieves the column name. This is set with the 'name' option of a column keyword. An example is below: println("Column name is: " +_cursorcoltechname); _tabrowabs: Retrieves the absolute cursor row number in a GuiXT table if there is a scroll operation. An example follows: println("Absolute cursor row is: " +_tabrowabs); _cursorrow: Retrieves the row value where the table control starts. An example is below: println("Row where table begins: " +_cursorrow); _cursorcol: Retrieves the column value where the table control starts. Syntax is as follows: println("Column where table begins: " +_cursorcol); These variables are particularly useful for querying the cursor position in a given table.

Scrolling
Table controls created using the Table command automatically support vertical scrolling. If more than one table is created, then scrolling will be enabled for whichever table wherein the cursor currently resides. If the cursor does not rest in any tables, then scrolling will be enabled for the first table displayed on the screen. Horizontal scrolling is supported with the 'fixedcolumn' option. If a user defines a value for the 'fixedcolumn', then the 'firstvisiblecolumn' will automatically contain the value immediately following the value defined for 'fixedcolumn'.

Examples
Creating a new table

222

WS/64 Developer Guide

In the following example, we will use the table command to create a new table on the Easy Access screen. Immediately following the table command, we will use the column command to add new columns to the newly-created table. The code is as follows: table([1,1], [12,48], {"name":"proj", "title":"All items", "rows":10}); column('Material', {"size":30, "name":"matnr", "position":1, "table":"T[All items]"}); column('Quantity', {"size":10, "name":"qty", "position":2, "table":"T[All items]"}); The resulting screen appears as follows:

Selecting rows in the table


To select a specific row in the table we just created, we would need to designate the row index and use the following syntax: Table_name.selectedrows[col_index] = "X";

So, to select row three (3) in the table we have created, we would add the following code:
proj.selectedrows[3] = "X";

Selecting columns in the table


To select a specific column in the table we just created, we would need to designate the row index and use the following syntax: Table_name.selectedcols[col_index] = "X";

So, to select column three (3) in the table we have created, we would add the following code:
proj.selectedcols[3] = "X";

Setting values in a GuiXT table


To set a value in a particular field in a GuiXT table, we use the following syntax: 223

WS/64 Developer Guide

Table_name.Col_name[row_index] = "xyz"; To set the value '12' into row four in the column 'qty', we would thus use the following code: proj.qty[4] = "xyz"; The table now appears as follows:

To set values into all rows in a given column, we must specify how many rows exist in the column. We then use a for loop to populate the values. If we wanted to populate ten rows in the 'qty' column we can use the following code: var l; for(l=0; l<10; l++) proj.qty[l] = l; The table now appears as follows:

224

WS/64 Developer Guide

Retrieving first and last visible row in a table


To retrieve the first and last visible rows in a given table, we can use the following code. Our example will be the 'proj' table: println(" firstvisiblerow " + <'T[All items]'>.firstvisiblerow); println(" lastvisiblerow " + <'T[All items]'>.lastvisiblerow);

Retrieving column cell values in a script


To retrieve the cell values of a given column, we can use the following code. Our example will be to retrieve values from the 'matnr' and 'qty' columns in the 'proj' table. The code is as follows: var i,j; for(i=0; i < proj.matnr.length; i++) println("proj.matnr.[" + i + "] " + proj.matnr[i]); for(j=0; j < proj.qty.length; j++) println("proj.qty.[" + j + "] " + proj.qty[j]);

Retrieving selected rows and column in a script


To retrieve the values of a specified row and column in a GuiXT WS script, we can use the following example. Here we are retrieving the values of any rows and columns that we previously marked as being selected. We are using a for loop to iterate through the rows and columns. The code is as follows: var k,l; for(k=0; k < proj.selectedrows.length; k++) println("-----proj.selectedrows.[" + k + "] " + proj.selectedrows[k]); for(l=0; l < proj.selectedcols.length; l++) println("-----proj.selectedcols.[" + l + "] " + proj.selectedcols[l]);

225

WS/64 Developer Guide

text
The text command is used to perform the following actions: Display any given text on a SAP screen Change a field name Change the name of a pushbutton, radiobutton, tab or checkbox. The syntax for using the text command is as follows: text([row_number, col_number], "Text Label", {option:"optionvalue"});

Options
The text command has three available Boolean options that can be applied. These options are shown in the following table: comment: Changes both the default font and the default color, resulting in a fixed-font, blue color. The syntax is: {"comment":true} fixedfont: Changes the font to a fixed-width font. The syntax is: {"fixedfont":true} intensified: Changes the text color to blue. The syntax is: {"intensified":true}

226

WS/64 Developer Guide

Examples
Adding text to a screen
To add text to a screen, we will use the initial VA01 screen. First open the SAPMV45A.E0101 script file and add the following code: text([12,4], "This is an example of the text command without the 'intensified' option applied."); The VA01 screen will now appear as in the following example:

227

WS/64 Developer Guide

Displaying text from a variable


The content of variables can also be displayed using the text command. In the following example, we have assigned a string to a variable and then outputted it on the screen using the text command. The code is as follows: var z_txt = "This is some text!"; text([12,4], " The variable is>>:" +z_txt); The screen displays as follows:

228

WS/64 Developer Guide

Using the intensified option


Using the intensified option changes the text color to blue as in the following example. The code is as follows: text([12,4], "This is an example of the text command with the 'intensified' option applied.", {"intensified":true});

The resulting screen is shown below:

229

WS/64 Developer Guide

Using the fixedfont option


The fixedfont option will display the specified text using a fixed-pitch font. The code would be as follows: text([12,4], "This is an example of the text command without the 'intensified' option applied.", {"fixedfont":true}); The resulting screen is as shown below:

230

WS/64 Developer Guide

Using the comment option


The comment option changes the text color to blue and reformats the string into a blue-colored, fixed-font display. The code is as follows: text([12,4], "This is an example of the text command with the 'comment' option applied.", {"comment":true}); The resulting screen is displayed below:

231

WS/64 Developer Guide

Changing a screen element name


The text command may also be used to change the name of an existing field, pushbutton or radiobutton. For example, if we wanted to change the name of the 'Sales Organization' inputfield using the Text command, we would enter the following code: text("F[Sales Organization]", "Sales Org."); The screen would now appear as shown below:

232

WS/64 Developer Guide

Changing a tab
The text command may be used for changing tab names within groupboxes and tabstrips as well. In the following example, we will change the name of the Sales tab on the VA02 Overview screen from 'Sales' to 'Renamed'. The code would be as follows: text("P[Sales]", "Renamed"); The screen would then appear as follows:

233

WS/64 Developer Guide

Using icons
Using icons with the text command is supported as well. In the following example, we will add an icon to the Sales tab on the VA02 Overview screen. The following elements are supported when using icons with the text command: Tabs Pushbuttons When using icons with a tab, the code is as follows: text("P[Sales]", "@12@Renamed"); The screen would now appear as shown below:

To rename and add an icon to the Search pushbutton on the initial VA02 screen, the code would be as follows: text("P[Search]", "@12@Order Search"); The revised pushbutton appears as follows:

234

WS/64 Developer Guide

textbox
The textbox command is used to display and edit text in a SAP screen. The syntax is as follows: textbox([startRow, startCol], [endRow, endCol], {"name":"name", "option":"option"});

Options
The textbox command has the following options that are available: readonly: Any default text in the textbox cannot be changed by a user.The syntax is: {"readonly":true} nowordwrap: The text will not wrap. This option requires users to press 'Enter' to begin a new line. The syntax is: {"nowordwrap":true} textfont=: Specifies the selected font. If this option is not specified, defaults to Arial. The syntax is: {"textfont":"font_name"} textheight=: Sets the text height in pixels. The default is 16. Te syntax is: {"textheight":x} textweight=: Specifies text height from 1 (thin) to 9 (heavy). Default is set at 5 and bold default is 7. The syntax is: {"textweight":x}

235

WS/64 Developer Guide

Examples
Creating textboxes
In this example, we will create two large textboxes on the MM60 transaction screen. The code is as follows: textbox([1,2], [10, 100],{" name":"z_text"}); textbox([1,2], [10, 100],{" name":"z_totext"}); The resulting screen is shown below:

Using readonly option


To make a textbox read-only, add the following to our example code: textbox([1,2], [10, 100],{" name":"z_totext", "readonly":true}); The second textbox now appears as follows:

236

WS/64 Developer Guide

nowordwrap
To prevent users from wrapping text and requiring the Enter key top be pressed in order to start a new line, the following can be added to the textbox command. textbox([1,2], [10, 100],{" name":"z_totext", "nowordwrap":true}); The textbox with text will now display as follows:

237

WS/64 Developer Guide

textfont, textweight & textheight


Users can vary the height, weight and font of the text used in a textbox with these options. To use them, see the following example: textbox([1,2], [10, 100],{" name":"z_totext", "textfont":"Times", "textweight":8, "textheight":18}); The textbox now appears as shown below:

238

WS/64 Developer Guide

239

WS/64 Developer Guide

tip
The tip command only operates on native SAP controls. It is very useful for adding a tip - very similar to the Tooltip option available for GuiXT inputfields - to any native SAP screen element. The syntax is as follows: tip("F[ScreenElement]", "This is a tip"); The tip command is available for use with any of the following type of screen elements: Inputfields:Syntax is as follows: tip("F[field_name]", "tip goes here"); Pushbuttons: Syntax is as shown below: tip("P[pushbutton_name]", "tip goes here"); Radiobuttons: Syntax as follows: tip("R[radiobutton_name]", "tip goes here"); Checkboxes: Syntax is as described below: tip("C[checkbox_name]", "tip goes here"); Group Boxes: Syntax as follows: tip("G[group_box_name]", "Tip goes here");

Options
The Tip command does not take any options.

240

WS/64 Developer Guide

Examples
Inputfields
In the following example, we will add a tip to the 'Sales Organization' inputfield on the VA01 screen. To add a tip, we would add the following line to the SAPMV45A.E0101.sjs script file: tip( "F[Sales Organization]", "Enter the Sales Organization code (eg. 1000)"); The screen will now appear as in the following example:

241

WS/64 Developer Guide

Pushbuttons
On the Finished Product screen of the MM01 transaction, there is a pushbutton called 'Basic Data Text'. To add a tip to this pushbutton, we would add the following code to the SAPLMGMM.4004 script file: tip("P[Basic Data Text]", "This pushbutton will launch a screen where users can view or enter long text about basic data."); The resulting tip displays as shown below:

242

WS/64 Developer Guide

Radiobuttons
In the following example, we will add a tip to the Individual Slip radiobutton on the MB1C transaction initial screen. The code is as follows: tip("R[Individual Slip]", "This is the Individual Slip radiobutton."); The resulting screen appears as shown below:

243

WS/64 Developer Guide

Groupboxes
In the following example, we will add a tip to the Sales Organization group box on the VA01 initial screen. The code is as follows: tip("G[Organizational Data]", "Fields for sales data"); The resulting screen displays as shown below:

244

WS/64 Developer Guide

Checkboxes
In the following example, we will add a tip to the 'Print' checkbox on the Enter Other Goods Receipt initial screen in the MB1C transaction. The code in the SAPMM07M.E0400.sjs script file is as follows: tip("C[Print]", "Check this to print."); The resulting screen appears as follows:

245

WS/64 Developer Guide

title
The title command is used to change the title of the SAP title bar. The syntax is as follows: title("string"); If a variable is used, the syntax would be either title("String" +variable); or the syntax would be: title(variable); This command is very useful in customizing existing screen titles after they have been customized, or for titling new user-defined screens.

Options
The title command does not take any options.

Example
In the following example, we are on the screen 'Create Sales Order', and the title bar is displayed as follows:

To change the title bar, it is necessary to enter the following code into the SAPMV45A.E0101.sjs script file: title("Welcome to SAP: VA01 Initial Screen"); The SAP screen now will appear as shown below:

246

WS/64 Developer Guide

Using variables in screen titles


Users can use a variable in the title string as well, as shown in the following example. In this case we will use a system variable to obtain the actual transaction name and then place it into the title. the code is as follows: var z_screentitle = [_transaction]; title("SAP " +z_screentitle); The SAP Easy Access screen will now display as follows:

Users can also use the variable directly as shown below: title(z_screentitle); 247

WS/64 Developer Guide

The screen would now appear as follows:

248

WS/64 Developer Guide

versionnumber
The versionnumber command is used principally to reduce web traffic when scripts are hosted in a SAP web repository, a FTP shared directory or a HTTP web share. In action, the versionnumber command adds a version number to any scripts cached from SAPWR. If the versionnumber is updated, then SAP will access SAPWR to re-cache scripts that are stored there. This version number can be assigned as the user wishes and operates by causing the both the logon script and the session script to be loaded each time from the designated script directory. The syntax for the command is as follows: versionnumber("string", {"option":value}); By adding the version number to the names of the script files that are to be called for a given operation, users can cause the logon and session scripts to be loaded from the designated Web Repository or Web share, while the scripts that have had the version number added to their names will be called from the local script directory. This reduces the web traffic for a given operation. The version number strings used for the SAP system IDs may contain only alphanumeric characters - no other character types are permitted. A sample version number is as follows: ab20

Options
The versionnumber command does not take any options.

Example
In the following example, we will demonstrate the versionnumber command in action. First, we will add the following entry to the guixt.sjs file: directory0 = "C:\\guixt\\versions"; For versionnumber to function correctly, users must have one of the two following files: elogon.sjs esession.sjs In this case we have the elogon.sjs file so we will add the following entry: versionnumber("000"); Any time the user increments the version number, the SAPWR directory will be accessed and new versions of the scripts will be cached.

249

WS/64 Developer Guide

view
The view command in WS is used to enable users to view files within native SAP screens. Supported file formats that can be viewed in this manner are the following: GIF JPG HTML RTF The syntaxes are as follows: Syntax view([startRow, startCol], [endRow, endCol],"fileName",{"option":value }); view("fileName.html", "option":value});

Description Displays an image file inside SAP screens, specifying the starting and ending points for the viewing window. Displays an image file inside a non-SAP application window.

The view command requires the file 'pinnacle.dll' to be installed in the same directory as the executable of the application in which view is to be used.

Options
The options associated with the command are as follows: floating: The window floats and can be moved into a position above the main SAP window. The syntax is: {"floating":true} maximize: Usually used in conjunction with the floating option, this specifies that the window is maximized to fill the screen.The syntax is as follows: "maximize":true returnwindow: Creates a variables that contains the internal window handle of the created view window. The syntax is as follows: "returnwindow":"&V[winName]"} See the following example: view([10,10], [20,20], "&V[fileName]", {"floating":true, "returnwindow":"&V[winName]"}); closewindow: Closes the created window. The syntax is as follows: {"closewindow":true} template: Uses a template file into which variables can be populated. This file is then displayed on the screen. The syntax is: {"template":"template_filename"}

250

WS/64 Developer Guide

Examples
Viewing files in outside of SAP
In the following example, we will view a GIF image inside a non-SAP window that we will call from the script. The code is shown below: view('test.gif'); Since we are not specifying any on-screen coordinates, the image will be displayed in the application that the OS specifies for that type of file. Since the image is a JPG, it will be displayed in Windows Picture and Fax Viewer as shown below:

251

WS/64 Developer Guide

Viewing files in SAP


In the following example, we will display the same file in SAP. The code would be as follows: view([4,4], [6,22], "GuiXTLogo.JPG"); The resulting screen would appear as shown below:

The coordinates are used to draw the View window wherein the designated file will be displayed.

Data dependent view


With the data-dependent viewing ability, a user might have a number of files, named with different names. If a user enters a value in a given field, the file linked to that field would be displayed. For example, if a user has a file named 'img000500187.rtf' and the user enters the number 00500187 in the Material number field, the file 'img00500187.rtf' would be displayed. The code is as follows: view([4,80], [12,20], {"file":C:\guixt\img&[Materialnumber].rtf"});

252

WS/64 Developer Guide

Viewing multiple files on the same screen


It is possible to have multiple view commands in a single screen. In the following example, we are displaying the contents of a RTF file, a GIF image and a HTML document all within the same screen. The code is as follows: for(a=firstChild; a!=null; a=a.nextSibling) a.del( ); view([1,0], [3,18], 'GuiXTLogo.JPG'); view([5,0], [13,25], 'help.html'); view([1,30], [8,70], 'help.rtf');

The resulting screen would appear as shown below:

253

WS/64 Developer Guide

SAP URLs
This action can populate the data from a HTML page into a SAP screen. Both inputsets and process execution are possible. An inputset is defined as a set of values to be input into SAP. SAPurls are displayed using the view command and appear within a SAP screen. In this case we are displaying them in the VA01 screen. The code is as follows: view([0,84],[24,131], "SAPLinks.htm"); The resulting screen is shown below::

The code that creates these SAPurls is contained within an HTML document that is called using the view command and is as follows. Please note that the following examples will only work if the user is logged into SAP when the links and buttons are clicked. The examples are as follows: 1) Launch VA01 - 1: Clicking on the link will navigate the user to the SAP Create Sales Order screen and will input the 'OR' value into the Order Type field. It will then execute an Enter command to proceed to the ensuing screen: <a href="SAP://OrderType:OR">Launch VA01 - 1</a><br> 2) Launch MM01: The user will navigate to the MM01 transaction, though no value will be input into any fields. The code is as follows: <a href="SAP://OK:/nMM01">Launch MM01</a><br> 3) Launch IW21 - 1: Clicking the link will result in the IW21 transaction launching in SAP and inputting the value 'M1 and calls the process 'd. The code is as follows: <a href="SAP://OK:/nIW21, process=executeIw21">Launch IW21 1</a><br><br>

254

WS/64 Developer Guide

The function that is called is not stored in the HTML file, but rather in the transaction script file. This function is as follows: function executeIw21( ) { onscreen 'SAPLIQ50.0100' set("F[Notification type]", "M1"); enter( ); } 4) Launch IW21 - 2: Clicking on the link will launch the IW21 transaction and then proceed to launch the IW32 transaction. The code is as follows: <a href="SAP://OK:/nIW21">Launch IW 21 - 2</a><br><br> 5) Launch IW21 - 3: Clicking on the link will launch the IW21 transaction, calls the 'executeIw21' function described in Example 3 above and then proceeds to stop and go to the IW32 transaction. The code is as follows: <a href="SAP://OK:/nIW21, process=executeIw21">Launch IW21 3</a><br><br> 6) Launch VA01 (image): Clicking this image will launch VA01 and input the value 'OR' into the Order type field. The code is as follows: <a href="SAP://OrderType:OR;OK"> <img src="va01.gif" alt="Launch VA01" width="60" height="20"><BR> </a> 7) Launch MM01 (image): Clicking this image will launch the MM01 transaction. NO data will be input. the code is as follows: <a href="SAP://OK:/nmm01"> <img src="mm01.gif" alt="Launch MM01" width="60" height="20"><BR> </a> 8) Launch IW21 (image): Clicking this image will launch the IW21 transaction and call the 'executeIw21' process defined in Example 3 above. the code is as follows: <a href="SAP://OK:/nmm01"> <img src="mm01.gif" alt="Launch MM01" width="60" height="20"><BR> </a> 9) Launch VA01 (button): Clicking this button will launch the VA01 transaction and call a function named 'launchVA01. The function will ... The code is as follows: <form> <input type="button" value="Launch VA01 " onclick="launchva01()" /><br> </form> The function is shown below: function launchva01() { window.location = "SAP://OrderType:OR;OK"; } 10) Launch MM01 (button): Clicking this button will launch the MM01 transaction and call a function named 'launchMM01. The function will ... The code is as follows: 255

WS/64 Developer Guide

<form> <input type="button" /><br> </form>

value="Launch MM01 " onclick="launchmm01()"

The function is shown below: function launchmm01() { window.location = "SAP://OK:/nMM01"; } 11) Launch IW21 (image): Clicking this button will launch the IW21 transaction and call a function named 'launchiw21' that will call the function in the 'executeIw21.txt' file explained in Example 3 earlier. The code is as follows: <form> <input type="button" value="Launch IW21 " onclick="launchiw21()" /><br> </form>

256

WS/64 Developer Guide

Using templates
Users can create standard files in which variables are defined. These files can be called by the view command and the variables will then be replaced by the data the user has entered in the corresponding SAP GUI screen Both HTML and RTF files are supported. The basic syntax is as follows: view([row1,column1], [row2,coloumn2] , {"template":"template file"}); Both RTF and HTML formats are supported for template files. The specific syntaxes are shown below. HTML: view([1,1], [100,100], 'onur.html', {"template":"temp.html"}); RTF: view([1,1], [100,10], 'onur.rtf', {"template":"temp.rtf"});

Templates can be used in the view command in order to enable objects to be dynamically changed based on the variables entered by a user. See the following example where the template file contains a list of variables which will be populated by the corresponding SAP values. The template file appears as follows: Order Type: &[Order Type] Sales Organization: &[VBAK-VKORG] Distribution Channel: &[Distribution Channel Division: &#[7,22] The screen would then appear as shown below:

257

WS/64 Developer Guide

windowsize
The windowsize command is used to re-size or re-position onscreen popup windows in SAP. The syntax is as follows: windowsize([startRow, startCol, width, height]);

Options
The windowsize command does not take any options.

Examples
Resizing a popup window
In the following example, we will resize the popup called from the Easy Access screen by entering '/o' in the transaction field. The resulting popup window initially appears as follows:

We will enter the following code in the RSM04000_ALV.E2000.sjs script file: windowsize([4,4,10,10]); The window now appears as shown below:

258

WS/64 Developer Guide

Repositioning a popup window


The windowsize command can also be used to re-position a popup window by manipulating the start row and start column parameters in the command. In the following example, we will move the window from the row 4, column 4 starting position. The code would be as follows: windowsize([10,10,12,12]); The resulting window would appear as follows:

259

WS/64 Developer Guide

/ws<command>
This command will execute a Webscript command directly from the transaction field in SAP - there is no need to put it in a script. The syntax is as shown below. The <command> section will be replaced by the actual command the user wishes to execute: /ws<command>("screen_control")

Options
The 'ws<command> is executed from the transaction field and does not take any options.

Example
In actual usage, the 'command' part of the code is replaced by an actual command, such as 'set' or 'del'. The "screen_control" parameter is replaced by the actual name of the screen control to be operated on. For example, to set the Order Type field on VA01 to 'OR', we would use this command as follows: /wsset("F[Order Type]", "OR") The initial VA01 screen with the command in the transaction field appears as follows:

The resulting VA01 screen is shown below:

260

WS/64 Developer Guide

261

WS/64 Developer Guide

/wsmessage
The 'wsmessage' command is used to display various attributes relating to the current build of WS. It can also be used to encrypt the RFC password. The syntax is as follows: /wsmessage(parameters) Once entered, the resulting attributes will be displayed at the bottom of the SAP GUI window as shown below:

The parameters are as follows:

_guixtdll
Displays the full path, including the filename, to the currently active GuiXT engine. There are three parallel builds of WS that can be running - Desktop, Server and Access. For Desktop, the path will point to the guixt.dll file. For Server, it will point to the sapproxy.exe file and for Access it will point to the guixt4web.dll file. AN example is shown below:

_guixtsjs
Displays the full path, including filename, to the SJS profile file being used. An example is displayed below:

_version
Displays the version number of the current GuiXT WS build. An example is shown below:

262

WS/64 Developer Guide

_builddate
Displays the actual date the build was made. See the following example:

encrypt
The Encrypt parameter for the /wsmessage command will encrypt the RFC password for WS. The syntax is as follows: /wsmessage(encrypt('password'),1); This results in a window on the SAP screen containing the newly-encrypted password as shown below:

The password is then entered into appropriate place in the guixt.sjs file as explained in the rfcConnect section.

263

WS/64 Developer Guide

/ws_
The 'ws_' command is coupled with a number of options to perform several very useful tasks. In this section, we will cover each of the variations that can be formed using the 'ws_' command and demonstrate how each is utilized. These ws_ commands can be executed directly from the transaction box. The available commands are as follows: /ws_log=: Creates a log at runtime. /ws_WS=: Turns WS on or off at runtime. /ws_vap=: Turns Visble Processing on or off at runtime. These are more fully explained and demonstrated in the individual sections below.

/ws_log
WS users can create logs at any time by using the ws_log command in the transaction field in SAP. All log files are saved in .TXT format. Log files are created by default in the following directory: C:\Documents and Settings\[userName]\Local Settings\Temp The file name will be in the following format: WS_MMDDYY_HHMMSS_computerName_userFirstName.userLastName_.log The HHMMSS section n the filename is defined as follows: HH = Hours MM = Minutes SS = Seconds

Options
The /ws_log command takes no options.

Examples
There are two possible flavors to this command, which are shown below. To create a log, type the following in the transaction field: /ws_log=true To turn WS logging off, please type the following in the transaction field: /ws_log=false Both when starting and stopping WS logging by entering the ws_log command, the log file location will display in the status bar at the bottom of SAP GUI as shown below:

264

WS/64 Developer Guide

265

WS/64 Developer Guide

/ws_WS
This command can be entered directly into the transaction field in the SAP GUI. The syntax is as follows: /ws_WS=value The ws_WS command is used to turn WS on or off at runtime. There are two values that can be entered as follows: 0: Turns WS off at runtime. 1: Turns WS on at runtime

Options
The /ws_WS command does not take any options.

Examples
To turn WS on at runtime, enter the following into the transaction field: /ws_WS=1 To turn WS off at runtime, enter the following in the transaction field: /ws_WS=0 Once WS is turned off, any WS scripts will immediately cease to take effect.

266

WS/64 Developer Guide

/ws_vap
The ws_vap command is used to turn visible processing on and off. Visible processing is useful as it enables users to follow the actual process of a script step by step. The syntax is as follows: /ws_vap=value The ws_vap command is used to turn visible processing on or off at runtime. There are two values that can be entered as follows: 0: Turns visible processing off at runtime. 1: Turns visible processing on at runtime.

Options
The /ws_vap command does not take any options.

Example:
To turn visible processing on or off, users can enter either '0' or '1' as the value. To turn visible processing on, a user would enter the '/ws_vap' command in the transaction field in any transaction. To turn on visible processing, the command would be as follows: /ws_vap=1 To turn visible processing off, the command would be: /ws_vap=0

267

WS/64 Developer Guide

5.0 Web Server Commands


The Web Server is the heart of the WebUI interface for the WS platform. This component has some unique commands and methods that function only on the web server - they do not apply to a deployment where users will be connecting directly to SAP GUI. In this section we will discuss these commands and provide real-life examples of how they work in conjunction with WS and SAP ERP. The commands are as follows: htmlnode usecss usejs

htmlnode
The htmlnode command is used to read or to display HTML on SAP screens in WS. This can be very useful when users want to view images in Web Server or implement a Google map, to name only two possible uses of the Htmlnode command. The syntax to display or read HTML in WS is as follows. The parameter '101' in the syntax example refers to the type of control - in this case it references an entry field. htmlnode('101', [row,col], "html string");

Options
The htmlnode command does not take any options.

Examples
Two of the most common uses for htmlnode, as mentioned above, are viewing images and using Google Maps. In the following sections, we will demonstrate how to use htmlnode to perform these two actions in the WS Web Server.

Viewing images in Web Server


In the above example, we will display an image in a window 301 pixels wide by 245 pixels high. The image's relative path is './demo_img/branding-image.gif' and it will be displayed in an area beginning at Row 5, Column 70 and ending at Row 10 and Column 90 on the SAP screen. The parameter '200' indicates that the type of control is a custom control - specifically an 'htmlnode' control. Any HTML code is supported with the htmlnode command. The code is as follows: htmlnode(200, [5,70], [10,90], "<image src='./demo_img/brandingimage.gif' width='301' height='245'>");

Implementing Google Maps in Web Server


It is possible in WS to implement Google Maps in the WS Web Server. The process of implementing a Google map requires a more complex formation than if a user is simply viewing an image. In the above example, we are displaying a map based on the customer location, which is retrieved from the SAP screen. The location parameters are passed to an HTML tag using the encodeURIComponent function. The HTML code itself is then stored in a global variable which in turn is used in the htmlnode function to display the map inside a frame in the GuiXT user interface. To perform this action, it is necessary to input the following code into the script file: In the following example we are using the fields in the VD02 transaction to provide the data required to generate the map. Using the <marquee></marquee> tag, we then will scroll the customer name at the bottom of the map. The code is as follows: // Trim spaces for string string.prototype.trim = function ( ) { 268

WS/64 Developer Guide

return this.replace(/^\s+|\s+$/g,""); } // Variables we use to store values from the SAP screen var street; var district; var city; var state; var country; var zipcode; var customer; // Use the set command to copy the value of the SAP fields to the GuiXT variables set("V[street]", "&F[Street/House Number]"); set("V[customer]", "&F[Customer.text]"); set("V[district]", "&F[District]"); set("V[city]", "&F[ADDR1_DATA-CITY1]"); set("V[state]", "&F[ARRD_DATA-REGION]"); set("V[country]", "&F[ADDR1_DATA-COUNTRY]"); set("V[zipcode]", "&F[ADDR1_DATA-POST_CODE1]"); // Generate the iframe that will go into the HTML node in GuiXT var z_sold_to_address = "<iframe scrolling=no width=100% height=360 frameborder=0 src=\"http://www.agawarehouse.com/tools/map/?address="+encodeURICompon ent(street.trim( ))+"%20"+encodeURIComponent(district.trim( ))+ "%20"+encodeURIComponent(city.trim( ))+ "%20"+encodeURIComponent(state.trim( ))+ "%20"+encodeURIComponent(state.trim( ))+ "%20"+encodeURIComponent(country.trim( ))+ "%20"+encodeURIComponent(zipcode.trim( ))+"\"></iframe> // Display the given htmlnode on the SAP screen htmlnode(200, [5,85], [50,140], z_sold_to_address); The resulting screen is shown below:

269

WS/64 Developer Guide

270

WS/64 Developer Guide

usecss
The usecss command is used to modify the included CSS format in the WS Web Server. These modifications are usually for personalizing the WS platform to match a customer's corporate environment, but can be for a variety of purposes. Some possible uses might be to add background image or to specify an external location for a CSS file. In this section we will demonstrate how to use the usecss command.

Options
The usecss command does not take any options.

Examples
Adding a Background Image To add a background image to the CSS, the following syntax may be used: usecss("string"); The string in the preceding syntax would include the specifications for the background image. For example, if we wished to use the image file 'Synactive.jpg', we would need to add the following code to the config.sjs file in the C:\Program Files\Synactive Inc\GuiXTFuzion directory: usecss("body.urBdyStd {background-image: url('.demo_images/synactive.jpg'); No-repeat;}"); This code will result in a background image being added to the server. CSS files are also maintained in the server. Specifying an External CSS File It is also possible to specify an external file to use as the CSS file with GuiXT Web Server. The syntax is as follows: usecss("filename"); If a user wants to specify the external file 'test.css' for use as the CSS, it is necessary to add the following code to the config.sjs file: usecss("C:\\Program Files\\Synactive Inc\\GuiXTFuzion\\test.css"); GuiXT Web Server will now use the specified file as the source for the CSS.

271

WS/64 Developer Guide

usejs
The usejs command is utilized to include Javascript or a file within a script in WS Web Server. Usejs functions very similarly to the usecss command and is placed in the same config.sjs configuration file as well. The syntax is as follows: usejs("string");

Options
The usejs command does not take any options.

Example
Including a script
The string in the command could include a number of parameters or possibly a short script that would then be incorporated into the WS script. For example, if a user wanted to include code to print out 'Hello World', the following would need to be included in the config.sjs configuration file in the C:\Program Files\Synactive Inc\GuiXTFuzion\ directory. usejs("println('Hello, World')"); The body of the action to be performed would be included within the double-quotes. In this case, the included line is for a simple 'println' operation. However, this string could be more complex as well.

Including a file in WS
There are times when users may wish to call a separate Webscript function or even a complete script from an external file. To do this, the syntax would be as follows: usejs("filename"); For example, if a user wished to include a script or function that would be housed externally in the file C:\ExternalScripts\TestFunction.js, it would be necessary to include the following code in the config.sjs configuration file: usejs("TestFunction.js"); We do not need to include the true path - the code can find the relevant file as long as it is in the same directly. if the file is housed in a different directory, then it would be necessary to include the full path to the file, as in the following example: usejs("C:\ScriptFiles\TestFunction.js"); This file can contain any content from a single function to a complete script. Once called, the file will run, and then the remainder of the original code will continue from the point where the file left off.

272

WS/64 Developer Guide

6.0 WS System Variables


Within the WS platform environment are a number of system variables that can be used for a variety of tasks. These are supported in all released versions of WS and are as follows: _ashost................................................................................................................................................... 273 _client .................................................................................................................................................... 273 _database ............................................................................................................................................... 273 _dynpro ................................................................................................................................................. 274 _language .............................................................................................................................................. 274 _listfirstvisiblerow ................................................................................................................................ 274 _listlastvisiblerow ................................................................................................................................. 274 _liststring............................................................................................................................................... 274 _message ............................................................................................................................................... 275 _page.exists ........................................................................................................................................... 275 _program ............................................................................................................................................... 276 _title ...................................................................................................................................................... 276 _transaction ........................................................................................................................................... 276 _user ...................................................................................................................................................... 276 As previously stated, system variables can be used in a wide variety of situations, so in this section, we will explain how each of the system variables listed in the preceding table can be used in the WS environment. All variables are written in the following syntax: &V[_variableName] System variable names are reserved and cannot be used for any user-created variables. Doing so may cause problems.

_ashost
The _ashost variable specifies the actual server name of the given SAP server. Operations can be performed based on a particular system name. This is particularly useful when users are connecting to multiple SAP ERP systems. In the following example we will print out the server: println("Host>>" +_ashost);

_client
The _client variable can be used to find data on any user in the system. In our example, if we wished to find the current user, and then output that information to the console window, we could write the following code: println("Current user>>" + _client);

_database
The _database variable can be used to perform operations based on the database or to simply find which database is being used. To find the database and to output that information to the console, we would write the following: println("Database>>" +_database);

273

WS/64 Developer Guide

_dynpro
A DynPro is the actual SAP program name. Each SAP program is identified by a dynpro number. Examples of dynpro numbers are the following: 0101, 0100, etc. The dynpro is used with the language code and the program name to identify a given SAP screen. T he _dynpro variable is used to find which dynpro is currently being accessed or to perform operations based on a particular dynpro number. In our example, we will simply find out which dynpro we are accessing and output that information to the console: println("DynPro>>" +_dynpro);

_language
The _language variable is used to return the current language code of a given implementation. The available language codes are listed in the Help section. If users are operating in different languages, this variable is useful for specifying the different language files or different operations for different users based on language. To find the current language and output that information to the console, we would write the following: println("The language is>>" +_language);

_listfirstvisiblerow
The _listfirstvisiblerow system variable is used to specify the first row of a list screen that is visible to a user. In the following example, we will use this to obtain the first visible row for the 'Assigned Source of Supply to Requisitions' list screen contained in the ME56 transaction. The code in the RM06BL00.E0120.sjs script file would be as follows: println("First visible row is>> " + _listfirstvisiblerow);

_listlastvisiblerow
The _listlastvisiblerow system variable is used to specify the last row of a list screen that is visible to a user. In the following example, we will use this to obtain the last visible row for the 'Assigned Source of Supply to Requisitions' list screen contained in the ME56 transaction. The code in the RM06BL00.E0120.sjs script file would be as follows: println("Last visible row is>> " + _listlastvisiblerow);

_liststring
The _liststring system variable is used to obtain the cursor's current position on the list screen; not the full content of the row where cursor is. In the following example, we will use this to obtain the cursor's current position on the 'Assigned Source of Supply to Requisitions' list screen contained in the ME56 transaction. The code in the RM06BL00.E0120.sjs script file would be as follows: println("Current cursor position is>> " + _liststring);

274

WS/64 Developer Guide

_message
The _message variable is used to return various SAP system messages. Various levels of messages can be defined; the default is to return everything. Status messages can be output either to the SAP screen or to the console. To see current messages in the console window, use the following: println("Messages>>" +_message);

_page.exists
The _page.exists property is used to identify individual tabs in a transaction. For example, the SAPMV45A.E4001 screen in the VA01 transaction has a number of tabs, as shown below:

With _page.exists, operations can be performed based on which tab of a given page is being edited, as shown in the following example: if(_page.exists("Sales")) { set("F[Sold-to party]", "1460"); } It is also possible to use the page command to verify if a given tab or page is actually present as shown in the following examples if(_page.exists("Tasks")) if(_page.exists("Tasks.2")) Please note that the _page.exists command uses the field's GuiXTName, not the label.

275

WS/64 Developer Guide

_program
Every dynpro has a program name associated with it, as shown in the following examples: SAPMV45A, SALSLMTR_NAVIGATION, etc. The _program variable returns the program name for the current screen. To return the current program number to the console, the following code can be used: println("Program>>" +_program):

_title
This variable retrieves the screen title where the user currently resides. An example is shown below: println("Screen title is>>" + _title);

_transaction
The _transaction variable is used to identify individual SAP transactions. it differs from the '_page' variable in that it refers to the transaction ID, such as 'VA01' as opposed to the actual page, which could be something quite different. Operations can be performed based on the transaction ID, as shown in the following example: if(_transaction=="va01") { set("F[Order Type]", "OR"); }

_user
The _user variable specifies the current user. To find the user information and output it to Console, the following code can be used: println("User>>" +_user);

276

WS/64 Developer Guide

7.0 Appendices
This section will include frequently asked questions and known issues with the WS Platform. Topics covered are as follows: Appendix I: Feature/Interface Comparison Appendix II: Version History Appendix III: Relative Positioning Appendix IV: Combining Screens in WS Appendix V: Standard Javascript Functions Appendix VI: Custom Functions Appendix VII: Displaying Unicode in Console Appendix VIII: Icon Library

Appendix I: Feature/Interface Comparison


The following chart will list each feature in WS in alphabetical order and will specify in which interface each is supported. This is a convenient place to determine if a given command is supported in a Server product, for example, or if it only functions in SAP GUI. Each interface will be specified as 'Yes' or 'No' for each individual command. Please note that not all options for every command will be supported on all platforms, The chart is based on the 1.2.132.0 WS release and is as follows: WS Feature / Command appendfile applyguiscript box boxsize buttonsize call checkbox clearscreen closefile column columnheader columnorder columnsize columnwidth comment copytext del dropdownlist (combobox) enter SAP GUI Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes WebUI Yes No Yes Yes Yes Yes Yes Yes Yes No No No Yes Yes Yes Yes Yes No Yes GuiXT Server Yes No Yes Yes Yes Yes Yes Yes Yes No No No Yes Yes Yes Yes Yes No Yes Access Yes No Yes Yes Yes Yes Yes Yes Yes No No No Yes Yes Yes Yes Yes No Yes

277

WS/64 Developer Guide

fieldsize file gettableattribute getfieldattribute globaltextreplace goto - label htmlnode image inputfield leave localvaluehelp message noinput noscrollbar onmessage onscreen onUIEvents openfile pos pushbutton radiobutton readfile removefile return set setcursor sort start statusmessage table text textbox textreplace title usecss versionnumber view windowsize

Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes

Yes Yes Yes Yes Yes Yes Yes No Yes Yes No No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No Yes No No No Yes Yes Yes No Yes

Yes Yes Yes Yes Yes Yes No No Yes Yes No No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No Yes No No No Yes No Yes No Yes

Yes Yes Yes Yes Yes Yes No No Yes Yes No No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No No No No No Yes No Yes No No

278

WS/64 Developer Guide

Appendix II: Version History


The following chart lists the version of WS that supports each command or feature listed in this Developer Guide. If only one build is listed, then the specified command is supported on all products. If multiple products are listed, then the individual releases are the supported versions. In all cases, unless otherwise noted, all builds subsequent to the listed release will support the specified feature. For the purposes of this document, the earliest release supported is 1.1.100.0. Feature / Command appendfile applyguiscript box boxsize buttonsize call checkbox clearscreen closefile column columnheader columnorder columnsize columnwidth combobox / dropdownlist comment copytext del enter fieldsize file - alias getfieldattribute gettableattribute WS Supported 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.128.0 1.1.100.0 1.1.100.0 WS: 1.1.100.0; GuiXT Server: 3.3.304.0 WS: 1.1.100.0; GuiXT Server: 3.3.306.0 1.1.100.0 WS: 1.1.100.0; GuiXT Server: 3.3.292.0 1.2.136.0 1.1.124.0 1.2.130.0 1.1.100.0 1.1.100.0 1.2.132.0 1.1.123.0 1.1.100.0 WS: 1.1.100.0; GuiXT Server: 3.3.338.0

279

WS/64 Developer Guide

globaltextreplace goto-label image inputfield leave load localvaluehelp message nodropdownlist noinput noscrollbar onUIEvents openfile pos pushbutton radiobutton readfile removefile return set setcursor statusmessage switchto table text textbox tip title versionnumber view windowsize

WS: 1.2.136.0; GuiXT Server: 3.4.359.0 1.1.100.0 1.1.100.0 1.1.100.0 unknown WS: 1.1.100.0; GuiXT Server: 3.3.282.0 1.1.100.0 1.1.100.0 1.2.130.0 1.1.100.0 WS: 1.2.145.0 GuiXT Server: 3.4.367.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.122.0 1.1.100.0 1.1.100.0 1.1.100.0 1.2.146.0 1.1.100.0 1.1.100.0 1.2.130.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 280

WS/64 Developer Guide

wscommand wsmessage ws_log ws_WS ws_vap

1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 WS Web Server Commands

usecss usejs htmlnode rfcconnect

1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 WS System Variables Variable WS Supported 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0 1.1.100.0

_ashost _client _database _dynpro _language _listfirstvisiblerow _listlastvisiblerow _liststring _message _program _title _transaction _user _ashost _client

281

WS/64 Developer Guide

Appendix III: Relative Positioning


It is possible to use relative positioning to move a SAP screen element. This method is available with all types of screen elements. To position a screen element relative to another screen element, we will use the 'offset' option. The offset option must be used with the field option as in the following examples. Either native elements or GuiXT elements can be used as the element that serves as the base for the position and the syntax is as follows: {field:"[screen_element]", "offset":[rows, cols]}, "Label", {field:"[screen_element]", "offset":[rows,cols]}); The field option and the offset option must be used together to perform relative positioning. The rows and columns specified in the 'offset' brackets are by how many rows and columns the element will be offset. Negative signs may be used to offset above and to the left of the original screen element as in the following example: checkbox({"offset":[-1,40], field:"F[Sales Organization]"}, "Test"); The resulting element is shown below:

Any time that relative positioning is used, it will be used in the same place as the usual positioning information. So in the case of the checkbox above, the usual coordinates that mark the on-screen position would normally be in the same location in the code as the relative positioning, For example, a checkbox is usually written as: checkbox([x,y], "Label", {"options":value});

282

WS/64 Developer Guide

However, when relative positioning is used, the [x,y] coordinates are replaced by the relative positioning. The same checkbox using relative positioning would be as follows: checkbox({field:"[screen_element]", "offset":[x,y]}, "Label", {option":value});

Alternate Syntax
A second method of using relative positioning on screen elements can also be used. This syntax is as follows: inputfield("[screen_element]+[rows,cols]", "label", "[screen_element]+[rows,cols]", {"option":value}); In the following example, we will set the first screen element as shown in the following code: inputfield([4,5], "Base", [4,20], {"name":"inpfld_1", "size":16}); The second element will be offset by using a '+[rows, cols]' format as shown in the following example code: inputfield("F[Base]+[7,5]", "Inputfield Test 2", "F[Base]+[7,20]", {"name":"mrp","size":14}); The resulting screen will appear as shown below:

283

WS/64 Developer Guide

Examples
In the following examples, we will demonstrate how to use relative positioning with the following screen elements: Checkboxes Inputfields Pushbuttons Radiobuttons

Checkboxes
In the following example, we will create a new checkbox on the VA01 screen, positioned relatively to the Organizational Data groupbox. The code is as follows: checkbox({"offset":[1,40], field:"F[Sales Organization]"}, "Test"); The resulting screen is displayed below:

If we change the offset from [1,40] to [5,30], the checkbox will move accordingly as shown below:

284

WS/64 Developer Guide

Inputfields
In the following example, we will create a new screen element - in this case an inputfield called 'Base' that has an internal name of 'inpfld_1'. The code is as follows: inputfield([4,5], "Base", [4,20], {"name":"inpfld_1", "size":16}); We will then create a second inputfield that we will position based on the first inputfield's screen position. The code is as follows: inputfield({field:"F[Base]","offset":[2,5]},"Test", {field:"F[Base]","offset":[2,20]}); Because the new element is an inputfield, we need to ensure that both the label and the field are moved correctly, which is why there are two offset statements. This is not necessary for elements that are not inputfields. What we have done is specified that the new screen element will be offset two rows and five columns from the original element. The field itself will be offset by two rows and twenty columns. The resulting screen will appear as shown below:

285

WS/64 Developer Guide

Pushbuttons
In the following example, we will position a pushbutton relative to the Order Type field on the VA01 initial screen. To do this, we would first add the following code to the VA01 script file: pushbutton({"offset":[5,35], field:"F[Order Type]"}, "Relative Positioning Test", {"process":z_test}); The resulting pushbutton is drawn on the screen as shown below:

If we change the offset from [5,35] to [12,6], the pushbutton will move accordingly as shown in the following screen:

286

WS/64 Developer Guide

287

WS/64 Developer Guide

Appendix IV: Combining Screens in WS


In WS, it is possible to combine screens and create processes that include fields taken from a number of individual screens. These operations can only be performed if the user has a properly licensed version of the GuiXT WS engine installed. In this section we will discuss the process of combining multiple SAP screens and we will also provide a short tutorial based on the SAP MM01 transaction. In order to combine SAP screens, user will need to utilize functions, variables and event handlers, all of which will be covered in this document. In WS, the individual screen recordings are saved as functions, and are triggered with the onscreen command. Each individual screen must also have an Enter command, but it is important to note that only one enter command per screen may be employed.

MM01 Transaction
This example will demonstrate how to combine screens in a user-created transaction using the Designer developer tool. To create the material, please do the following: 1. Launch SAP GUI and type '/nmm01' into the transaction field as shown below:

2. Launch Designer and click the Record button to begin recording. 3. On the main Create Material (Initial Screen), enter the following data and then click Enter: Industry Sector: C Material Type: FERT 4. The Select Views popup screen will display. Click the 'Select All' button click the green arrow or press Enter. and then either

5. The Organizational Levels popup screen will display. Enter the following data and then click the Enter key: Plant: 1000 Stor.Location: 0001 6. The Create Material screen will display with a material number assigned. In the Basic data 1 tab, enter the following data: Highlighted field beside the material number: <Any text string> Base Unit of Measure: EA Material Group: 0001

288

WS/64 Developer Guide

7. Click the Purchasing tab and enter the following data: Purchasing Group: 001 Mfr. Part Number: <any value> 8. Click the context menu icon following data: MRP Type: ND MRP Controller: 000 . In the resulting context menu, select the MRP1 tab and enter the

9. Select the MRP2 tab from the context menu and enter the following data: Sched. Margin Key: 000 10. Select the MRP3 tab from the context menu and enter the following data. Please note that this value must be entered even if the same value is already present: Availability check: 01 11. Select the Plant/data Stor.1 tab from the context menu and enter the following data: Storage Bin: <any value> 12. Select the Plant/data Stor.2 tab and enter the following data: Profit center: 1000 13. Select the Accounting 1 tab from the context menu and enter the following data: Valuation class: 7920 Price control: S Price unit: 13 Standard price: 41 Moving price: 13 14. Click the Record button to stop recording and then select the Script tab in Designer to view the generated script. An example script based on a MM01 transaction is shown below: function function1(){ // Create Material (Initial Screen) onscreen 'SAPLMGMM.0060' set('F[Industry sector]', 'C'); set('F[Material Type]', 'FERT'); enter(); // Create Material (Initial Screen) onscreen 'SAPLMGMM.0070' enter('/20'); // Create Material (Initial Screen) onscreen 'SAPLMGMM.0070' enter(); // Create Material (Initial Screen) onscreen 'SAPLMGMM.0080' set('F[Plant]', '1000'); set('F[Stor. Location]', '0001'); 289

WS/64 Developer Guide

enter(); // Create Material 75930 (Finished product) onscreen 'SAPLMGMM.4004' set('F[MAKT-MAKTX]', 'Test Material 0001'); set('F[Base Unit of Measure]', 'EA'); set('F[Material Group]', '0001'); enter('=SP09'); // Create Material 75930 (Finished product) onscreen 'SAPLMGMM.4000' set('F[Purchasing Group]', '001'); set('F[Mfr Part Number]', 'test'); enter('=SP12'); // Create Material 75930 (Finished product) onscreen 'SAPLMGMM.4000' set('F[MRP group]', '001'); set('F[MRP Type]', 'ND'); enter('/n'); // SAP Easy Access onscreen 'SAPLSMTR_NAVIGATION.0100' enter('/nmm01'); // Create Material (Initial Screen) onscreen 'SAPLMGMM.0060' enter(); // Create Material (Initial Screen) onscreen 'SAPLMGMM.0070' enter('/20'); // Create Material (Initial Screen) onscreen 'SAPLMGMM.0070' enter(); // Create Material (Initial Screen) onscreen 'SAPLMGMM.0080' set('F[Plant]', '1000'); set('F[Stor. Location]', '0001'); enter(); // Create Material 75931 (Finished product) onscreen 'SAPLMGMM.4004' set('F[MAKT-MAKTX]', 'Test Material 0001'); set('F[Base Unit of Measure]', 'EA'); set('F[Material Group]', '0001'); enter('=SP09'); // Create Material 75931 (Finished product) 290

WS/64 Developer Guide

onscreen 'SAPLMGMM.4000' set('F[Purchasing Group]', '001'); set('F[Mfr Part Number]', 'test'); enter('=SP12'); // Create Material 75931 (Finished product) onscreen 'SAPLMGMM.4000' set('F[MRP Type]', 'ND'); set('F[MRP Controller]', '000'); enter('=SP13'); // Create Material 75931 (Finished product) onscreen 'SAPLMGMM.4000' set('F[SchedMargin key]', '000'); enter('=SP14'); // Create Material 75931 (Finished product) onscreen 'SAPLMGMM.4000' set('F[Availability check]', '01'); enter('=SP19'); // Create Material 75931 (Finished product) onscreen 'SAPLMGMM.4000' set('F[Storage Bin]', 'test'); enter('=SP20'); // Create Material 75931 (Finished product) onscreen 'SAPLMGMM.4000' set('F[Profit Center]', '1000'); enter('=SP24'); }

The script is created in the form of a single function that can be called from anywhere. Internally however, it is separated into screen blocks by using the Onscreen command to specify the actual screens where the actions will occur. Each screen block has an associated 'Enter' command - as previously noted there can be only a single 'Enter' for each screen.

291

WS/64 Developer Guide

Appendix V: Standard Javascript Functions


In WS, there are several standard Javascript functions that are available for use. These functions are as follows: Typeof Date functions

In this appendix, we will briefly describe and demonstrate each of the available functions.

Typeof
This function is used to obtain the type of screen control or variable that the user has created. An example is shown below: if (typeof(z_true) != "boolean") { println("<<<<<<<<<<Value of z_true>>>>>>>" + z_true); var z_true = true; }

Date functions
The following functions can be used to operate on dates. There is a date object in Javascript and it can be used to perform a variety of useful actions. The date object can also be converted to binary format if necessary. The date functions are as follows:

Creating a new date object:


To create a new date object, use the following syntax: var dobj = new Date();

Finding current day, month and year:


To find what day it is, use the following syntax: var oDay = dobj.getDay(); The same logic used to find a current day can be applied to the month and year as well. To find the current month, use the following syntax: var oMonth = dobj.getMonth(); To find the current year, use the syntax below: var oMonth = dobj.getFullYear();

292

WS/64 Developer Guide

Appendix VI: Custom Functions


This section contains user-created functions that can be used with the WSOffice DLL in order to access ActiveX objects and make calls to the local system. There are two main topics, which are as follows. ActiveXObject File Functions

293

WS/64 Developer Guide

ActiveXObject
The ActiveXObject adds support for the Microsoft COM objects. This object enables users to make calls to a user's local file system among other useful actions. We will not cover all possible uses of this object here. Please see the Microsoft COM Control documentation for more detailed explanation of how to use this object. An example is as follows: var xx = new ActiveXObject("Scripting.FileSystemObject"); The ActiveXObject requires that the wsoffice.dll must both be installed and also be loaded in the script in order for the command to function as designed. Therefore, in order to use this feature, it is important for developers to ensure that the following code is included in the script immediately before the new ActiveXObject variable is created. load("wsoffice");

Examples
In the following example, we are creating a pushbutton on an SAP screen. The pushbutton will call a function that contains an ActiveXObject. When the toolbar pushbutton is clicked, the function will proceed to make a call to the local file system that will result in a pre-specified file being moved from its original location to a new location. The screen containing the new toolbar pushbutton appears as shown in the following example:

The code used to create the screen in question is shown below: pushbutton([TOOLBAR], "Rename File ",{ "process":RenameFile}); function RenameFile(){ load("wsoffice"); 294

WS/64 Developer Guide

var objCopy, test; objCopy = new ActiveXObject("Scripting.FileSystemObject"); test = objCopy.GetFile("C:\\guixt\\Book2.xls"); test.Move("C:\\guixt\\Book2_rename.xls"); } In the preceding function, we have created a new ActiveXObject named 'objCopy', which now allows us to make calls to the file system through the WSOffice DLL. Methods of this new object are then utilized to get a specified file. A method of the new object is then utilized to move the file to a new location

295

WS/64 Developer Guide

WS Office Functions
The following custom functions are very useful for performing file and directory actions. However, they can only be used if the WSOffice.DLL is installed. This dll is used primarily to make calls to Visual Basic and thus enable Microsoft Office functionality to perform bulk data transfer from Excel worksheets or PDF forms to SAP. These custom functions are discussed and demonstrated in the following sections. File Functions replaceText selectDirectory sort startApplication

296

WS/64 Developer Guide

File Functions
File commands are used in WS Office to act upon external files. All of the custom functions listed in this section require the WSOffice.dll to be installed on the target system and should be centrally housed in the ELOGON or some other file. The ELOGON.sjs file is one that Synactive provides with WS Office and is read at login, after which any functions within this file are globally available. The ELOGON.sjs file must be stored in the script directory in order for it to be read. Regardless of where these functions are stored, the file in which they reside can be loaded using the previously explained 'load' command. The commands covered here are as follows: copyFile renameFile selectFile

copyFile
This is a user-created custom function that is used to copy a file from one location to a different location. A copy of the source file is created, named as specified by the user. If a file with the same name exists in the target directory, the older file will be over-written by the newer version. The syntax of this command is as follows: copyFile("C:\guixt\scripts\SAPMV45A.E0100.sjs", "C:\guixt\old_scripts\SAPMV45A.E0100.sjs"); The copyFile function is actually used as a method of the previously introduced ActiveXObject. So before calling the CopyFile function, we must crate a new object. The function actually uses a standard Javascript object method to copy the files from one location to another. This object is shown in the following example: function copyFile(){ var objCopy = new ActiveXObject("Scripting.FileSystemObject"); objCopy.CopyFile("C:\\GuiXT\\Scripts\\Book2.xls", "C:\\GuiXT\\salesdemo\\copy\\Book3.xls"); objCopy = null; } Files can be copied to and from any type of file repository supported by WS except SAP Web Repositories and HTTP/FTP shares. These are as follows: Local files (eg. C:\guist\scripts\SAPMV45A.E0100.sjs) Network Shares (eg. \\NETSHARE\\guixt\\scripts\\SAPMV45A.E0100.sjs)

297

WS/64 Developer Guide

renameFile
RenameFile is another user-created custom function that is used to rename a file. It uses a standard Javascript move operation to perform this function and unlike the copyFile command, it will not overwrite an existing file with the same name as that chosen for the new name. The syntax is as follows: renameFile("C:\guixt\scripts\Logo.PNG", "C:\guixt\scripts\Test.PNG"]); This standard Javascript move operation (MoveFile) is a method of the Copy object and is shown in the following example whering we are creating a custom function that then calls the MoveFile method: function renameFile(){ var objCopy = new ActiveXObject("Scripting.FileSystemObject"); objCopy.MoveFile("C:\\GuiXT\\Book2.xlsx","C:\\GuiXT\\Book_onur.xl sx"); objCopy = null; } In the following example, we create the file 'Book2.xlsx' in the C:\guixt directory as shown below.

We are also creating a pushbutton in a screen to perform the Renamefile operation. The screen is shown as follows:

298

WS/64 Developer Guide

The code is shown below: pushbutton([TOOLBAR] , "Rename File" ,"/nmm01",{"process":RenameFile}); The resulting file after being renamed is shown below:

299

WS/64 Developer Guide

selectFile
The user-created selectFile custom function will open a dialog box that enables users to specify the name of a file. When this function is used, it will invoke the standard Windows dialog box for file selection. The code that creates the dialog is stored in a function that is as follows: function selectFile(){ //This function is for selecting a file //SaveBox method-- String function. Displays the File Save As dialogue box. //filter and setting a title is not possible var dlg = new ActiveXObject('JSDlgBox.browser'); var ret = dlg.OpenBox(); println("-------Specified File--------" + ret + "--------"); dlg = void 0; return ret; } The function shown above is used to select a file. In the example we used the OpenBox method to open an existing file. However, the SaveBox method could be used instead if the user wishes to display the File Save As dialog instead of the Open File dialog. Depending on the system, it may or may not be possible to change the title on the dialog box. In our example, we have created a pushbutton and an inputfield. the user will enter the filename and then the process will open the given file. The screen appears as follows:

The code is as follows: pushbutton([5,17], "Select File", {"process":test_selectfile, "size":[1,30]}); inputfield([5, 49], {"name":"z_filename", "size":"50", "nolabel":true}); text[6,49], 'Select the file desired');

300

WS/64 Developer Guide

The process called is simply a small function that in turn calls the main custom function that we introduced earlier and which is housed in the ELOGON file. This process function that calls our custom selectFile function is as follows: function test_selectfile() { var filename = selectFile(); set("V[z_filename]", filename); }

301

WS/64 Developer Guide

replaceText
This operation creates a custom function that then uses Javascript search functions to find and replace strings in a text variable. The words searched for cannot have any spaces between the search strings and the comma delineating them. The search terms are also case-sensitive. The syntax is as follows: replaceText("find","replace"); The replaceText function is a custom function and the code is as follows: function replaceText(){ set("V[z_var]" , "&V[z_search]"); copytext({"fromtext":"z_textbox","tostring":"z_string"}); replace(z_var,z_string); copytext({"fromstring":"z_replace","totext":"z_textbox"}); } This custom function works by calling two other functions that will perform the specified actions - one that searches and one that replaces. The search function is as follows: function search(string,keyword){ if (string.indexOf(keyword) != -1){ // if keyWord is found, var z_slice_position = string.indexOf(keyword) + keyword.length + 1; var new_string = string.slice(z_slice_position); return(new_string.split(" ",1)); } } Once a term to be replaced is located, a second function is called to actually perform the replacement. This function is as follows: function replace(src,str) { var myArray = []; i =0;z_sresult = ""; myArray = src.split(','); for (i=0; i<myArray.length;i++){ println("--Arry value----" + myArray[i]); if(isBlank(myArray[i])) { message("Please enter find and replace values!"); goto end; } } if(search(str,myArray[0])) z_replace = str.replace(myArray[0],myArray[1]); while(isBlank(z_sresult)) { if(search(z_replace,myArray[0])) z_replace = z_replace.replace(myArray[0],myArray[1]); else z_sresult = "X"; } end: return(z_replace); }

302

WS/64 Developer Guide

In the following example, we will demonstrate how these are used. We will create a textbox on the MM01 screen along with a toolbar pushbutton to initiate the actions and a search box for users to search a particular piece of text. The code to create these screen elements is as follows: inputfield([2,1],"Search",[2,10],{"name":"z_search","size":20}); textbox([3,1],[10,50],{"name":"z_textbox"}); We will also create a pushbutton on the toolbar that calls the previously introduced replaceText function as a process to initiate the replacement action. The code is as follows: pushbutton([TOOLBAR],"Replace","/nmm01",{"process":replaceText}); The screen itself will appear as shown below:

Once a user enters text into the main textbox, he can search and replace any terms that are entered into the search field. An example of this is shown below. The user is searching for the term 'example', which will be replaced with 'tutorial'.

303

WS/64 Developer Guide

When the user clicks the toolbar pushbutton, the code will search for all occurrences of the term 'example' and replace it with 'tutorial'. The screen will now appear as follows:

304

WS/64 Developer Guide

selectDirectory
This custom function chooses a directory from which users can select a file to be opened. This is very useful when choosing an Excel or PDF from to open for bulk data transfer to SAP via WS Office. The selectDirectory custom function is shown as follows: function selectDirectory(){ var dirName = ""; dirvalue = readDirectory(0,"Please select a directory",0); set('V[z_directory]',dirvalue); } Within the selectDirectory custom function is a second custom function, the readDirectory function. This function is where the dialog box attributes are defined and this function must be called for a user to display a dialog box. The code is as shown below: function readDirectory(wHnd,strTitle,iOptions){ //This function is for selecting a directory //BIF_browseincludefiles //the use of this option enables the selection of file in select directory dialog box var aWshShell = new ActiveXObject("Shell.Application"); var objFolder = aWshShell.BrowseForFolder(wHnd, strTitle, iOptions); objFolder = objFolder.ParentFolder.ParseName(objFolder.Title).Path; println("-------Specified Directory--------" + objFolder + "-------"); aWshShell = void 0; return objFolder; } When a SAP user invokes the selectDirectory command, these custom functions are accessed and used. In our example, we have created a pushbutton and an input field on a SAP screen as shown below:

305

WS/64 Developer Guide

When the pushbutton is pressed by the user, the SelectDirectory command calls a dialog box in which the user can specify the directory to be opened. The dialog box is shown below:

The code is as follows: pushbutton([6,1], "Select Directory", "/0", {"process":selectDirectory}); inputfield([6,40], "Directory", [6,60], {"name":"z_directory", "size":"50"}); The code for the custom function is shown below: function selectDirectory() { var dirName = " "; dirvalue = readDirectory(0, "Please select a directory", 0); set('V[z_directory]', dirvalue); } The user will select a directory and that directory name will be populated into the field on the screen as shown below:

306

WS/64 Developer Guide

sort
The sort functionality is a custom function that is used either to sort the values for an array of variables or to sort the rows of a table of variables. These types of variables consist of single cell variables where at least one part of the variable name is a row or column index. The code is as follows: function sort(param){ var people = [];i=0; //get the values to the array, each time create the array again since we do not know what would the values be. do { set("V[t_firstname]" , "&V[z_firstname_&V[i]]"); set("V[t_lastname]" , "&V[z_lastname_&V[i]]"); set("V[t_telephone]" , "&V[z_telephone_&V[i]]"); set("V[t_address]" , "&V[z_address_&V[i]]"); people[i] = {"FirstName":t_firstname,"LastName":t_lastname,"Telephone":t_telephone ,"Address":t_address}; i++; set("V[z_temp]" , "&V[z_firstname_&V[i]]"); println("------Value of the field-------" + z_temp); } while (!isBlank(z_temp)); println("-----------People length--------" + people.length); //get the values to the array switch(param.l_sort) { case "l_firstname": people.sort(sortByFirstName);break; case "l_lastname": people.sort(sortByLastName);break; case "l_tel": people.sort(sortByTelephone);break; default: people.sort(sortByAddress); } //set the array values to the fields for (i=0; i < people.length; i++){ println("-----FirstName------" + people[i].FirstName); set("V[z_firstname_&V[i]]" , people[i].FirstName); set("V[z_lastname_&V[i]]" , people[i].LastName); set("V[z_telephone_&V[i]]" , people[i].Telephone); set("V[z_address_&V[i]]" , people[i].Address); } }

In the following example, we have created a table on the MM01 transaction and populated it with some data in an unsorted format as shown below:

307

WS/64 Developer Guide

When a user clicks on the pushbuttons above each column, the data will be sorted according to the column selected. For example, if the user wished to sort the data by first name, he or she would click the 'First Name' pushbutton. The transaction would change to the following:

When the user returns to the VA01 screen however, the data would then be sorted as shown below:

308

WS/64 Developer Guide

Each time a user presses a pushbutton, the result will be to take the user to the 'Create Standard Order' screen. But on returning, the data will be sorted according to the pushbutton the user pressed. Each pushbutton is tied to another custom function that in turn calls the custom Sort function and then modifies the results returned by the Sort function into the onscreen results seen by a user. The code is as follows: function isBlank(jvar){ return (jvar == null || jvar == "" || jvar == void 0); } for (a=firstChild; a!=null; a=a.nextSibling){ a.del(); } idx = 0; pos = 1; pushbutton([0,1] , "First Name" ,"/nva01", {"process":sort,"size":[1,20],"using":{"l_sort":"l_firstname"}}); pushbutton([0,22] , "Last Name" , "/nva01", {"process":sort,"size":[1,20],"using":{"l_sort":"l_lastname"}}); pushbutton([0,43] , "Telephone" , "/nva01", {"process":sort,"size":[1,15],"using":{"l_sort":"l_tel"}}); pushbutton([0,59] , "Address" , "/nva01", {"process":sort,"size":[1,30],"using":{"l_sort":"l_address"}}); while (idx < 10) { inputfield([pos,1] ,{"name":"z_firstname_&V[idx]","size":20,"maxlength":30,"nolabel":true });

309

WS/64 Developer Guide

inputfield([pos,22] , {"name":"z_lastname_&V[idx]","size":20,"maxlength":30,"nolabel":true}) ; inputfield([pos,43] , {"name":"z_telephone_&V[idx]","size":15,"maxlength":20,"nolabel":true} ); inputfield([pos,59] , {"name":"z_address_&V[idx]","size":30,"maxlength":50,"nolabel":true}); idx++;pos++; } function sortByFirstName(a,b) { var x = a.FirstName.toLowerCase(); var y = b.FirstName.toLowerCase(); return ((x < y) ? -1 : ((x > y) ? 1 } function sortByLastName(a,b) { var x = a.LastName.toLowerCase(); var y = b.LastName.toLowerCase(); return ((x < y) ? -1 : ((x > y) ? 1 } function sortByTelephone(a,b) { var x = a.Telephone.toLowerCase(); var y = b.Telephone.toLowerCase(); return ((x < y) ? -1 : ((x > y) ? 1 } function sortByAddress(a,b) { var x = a.Address.toLowerCase(); var y = b.Address.toLowerCase(); return ((x < y) ? -1 : ((x > y) ? 1 }

: 0));

: 0));

: 0));

: 0));

310

WS/64 Developer Guide

startApplication
This custom function starts a particular application. This is primarily used when writing scripts for WS Office, as WS Office makes calls to external applications during the bulk data transfer process. The syntax is as follows: startApplication(filename[0]); What actually happens is that user invokes a custom function to start an application. The custom function is as follows: function startApplication(strFile,strParamStr){ //This function is for starting an application with parameters if specified var aWshShell = new ActiveXObject("WScript.Shell"); if (strParamStr != null) strFile = strFile + " -" + strParamStr; aWshShell.run(strFile); } What we are actually doing is creating the custom object aWshShell and referencing the standard VBScript object which is WScript.Shell. We are then executing the Run method of that function to start an application. In the following example, we are specifying that a particular application will be started and a particular file will be opened. The SAP screen is shown below:

The code is as follows: pushbutton([5,1], "Start: Open Excel File", "/0", {"process":startAppExcel}); function startAppExcel(){ var dirName = ""; var fileName = ["Book2.xlsx"]; dirName = readDirectory(0,"Please select a directory",0); startApplication(dirName + "\\" + fileName[0]); } 311

WS/64 Developer Guide

Once the pushbutton is pressed, the following dialog will appear:

The SAP user can now choose the file to open. Start can be used to access any application of which the user knows the name. Examples include Web browsers and other Microsoft Office applications such as Word.

312

WS/64 Developer Guide

Appendix VII: Displaying Unicode in Console


If a user is working in a non-Latin based language such as Chinese, the Console output may display incorrectly in the default state as shown below:

To remedy this and display Unicode characters correctly, it will be necessary to change the default font in the Console to a Unicode-compliant font. In our example, we will make 'Lucida Console' the default font. To change the default font, please do the following: 1. Launch GuiXT WS. 2. Go to the Console window and click on the menu in the upper left corner as shown below:

313

WS/64 Developer Guide

3. The Properties window will display. Go to the 'Font' tab and select 'Lucida Console' in the Font section as shown in the following screenshot:

4. Click OK. 5. The Unicode characters will now display correctly as shown in the Trim example below:

. 314

WS/64 Developer Guide

Appendix VIII: Icon Library


The following icons are used in this document:

Important note

Warning

Additional Information

315

You might also like