With
ifyou can make script
commands dependent on conditions. For example, on the current GUI-Status
or on whether certain fields exist in the SAP screen.
Example
GuiXT
if Q[Status=ADD1] or Q[Status=UPD1]
Image (1,50) (10,90) "imgupd.gif"
else
Image (1,50) (10,90) "imgdis.gif"
endif
If the GUI Status is
ADD1
or UPD1,
the image file
"imgupd.gif"
will appear, otherwise
"imgdis.gif"will appear.
Conditions
What conditions
are available with
if
?
Firstly, you can look for the existence of screen elements by simply naming
the corresponding screen element in the
if
command. For example:
ifF[Amount]
means:
"if there is a field
Amount
on the screen".
if
I[Amount]
means: "if there
is an input field
Amount
on the screen".
ifP[Cancel]
means:
"if there is a
Cancel
pushbutton on the screen".
ifM[Change]means: "if
there is a menu item
Change".
ifM[Change=active]
means: "if there is a menu item
Change
which is active (not disabled)".
Secondly, you can inquire about certain status data:
ifQ[Status=xxxx]If the GUI-Status
is xxxx
ifQ[Language=x]
If the language key is x (1 character, E=English, D=German, F=French,
I=Italian,...)
ifQ[Database=xxx]if the system
(database server) id is xxx
ifQ[Transaction=xxxx]If the transaction
code is xxxx (N.B. only possible with SAP Rel.4 and upwards)
ifQ[ScreenVariant=xxxx]if an SAP
screen variant xxx is active (with a central GuiXT script)
ifQ[GuiXTVersion=yyyy
Qx x]if the GuiXT
Version is equal to yyyy Qx x. You can use <, = or >. See also
Tips & Tricks below.
if
Q[Popup]
if the
current screen is sent as a popup screen
if
Q[InactiveScreen]
if a
popup screen is sent on top of the current screen
if
Q[StopRequest]
if the
user has provoked a StopRequest in an InputScript (see
StatusMessage)
ifQ[Page=xxxx]if the current
page of a tabbed dialog is xxxxx (xxxxx is the text displayed on the
tab)
ifV[vname=value]if the variable
vname has the value (only possible with InputAssistant)
ifU[uname=value]if the using
parameter uname has the value (only possible with InputAssistant)
Thirdly you can inquire about
user options set in guixt.ini:
Option
opt1 Option opt2
withif
Q[Option=xxxx].
You can define up to 50 different
options in guixt.ini, each
Option
string containing up to 30 characters.
Is it
possible
to use nested
if else
endif?
Are logical
expressions permitted?
Yes, both
are possible. Example:
GuiXT
if not Q[Status=UPD1]
Image (1,50) (10,90) "imgdis.gif"
else
if (F[Company code] or F[Business area]) and not F[Order number]
Image (1,50) (10,90) "imgupd1.gif"
else
Image (1,50) (10,90) "imgupd2.gif"
PushButton (toolbar) "Cancel" "/OZC27"
endif
endif
You can use normal brackets,
"and",
"or"
and "not"
within logical expressions. Normal rules of logic apply for priority and
bracketing.
Option -strict
in variable comparison
When you
compare a variable with a value
ifV[vname=value]
the following rules are automatically
applied:
The comparison is
n o t case sensitive, i.e. "abXY" = "ABxy"
All values consisting
of zeros only are equal, and are also equal to the empty string: "0000"
= "0" = ""
Please use the option
-strict in order to compare the values without
applying these rules:
if V[vname=value]
-strict ... endif
Tips & Tricks
A field, e.g. F[Company
code], cannot be specified directly in an if statement, please use a
variable. Example:
Set V[buk]
"&F[Company code]" if V[buk=0001]
... endif
In order to compare two
variables V[x1] and V[x2], you have to use the value &V[x2] in
"if V[x1=value]":
if V[x1=&V[x2]]
... endif
"if Q[GuiXTVersion..."
is supported in GuiXT version 2002 Q4 3 and upwards. If you want
to ensure that in your script (probably the logon script) the installed
GuiXT version is at least 2002 Q4 5, you can use the following coding:
if Q[GuiXTVersion<2002 Q4 5]
Message "Please install new GuiXT versions \nFor questions contact S. Bauer
ext. 2649" Title="Update necessary"
endif
But in this case no message would appear in the versions prior to 2002
Q4 3, since the condition if Q[GuiXTVersion<....] didn't yet pertain,
and the indication "false" is returned. In order to cover such
cases as well, use "not ... >" with the previous GuiXT version id:
if not Q[GuiXTVersion>2002 Q4 4]
Message "Please install new GuiXT versions \nFor questions contact
S. Bauer ext. 2649" Title="Update necessary"
endif
You should not use
Screen
commands within
if ... endif,
since this makes the script hard to understand, and sometimes the behaviour
will be quite unexpected. Bad example: GuiXT
Screen S1
Set V[x] "a"
Enter
if V[x=b]
Screen S2
Enter "xx"
else
Screen S2
Enter "yy"
endif
Assume that we
have Screen S1 and then
Screen S2. Does GuiXT now process Enter
"xx" or Enter "yy"? In fact, in this example, Enter "xx" is executed,
since GuiXT looks for the next matching Screen command for Screen S2,
without considering open if statements of previous screen blocks.
Instead, please close all open "if" statements in each screen block:
GuiXT
Screen S1
Set V[x] "a"
Enter
Screen S2
if V[x=b]
Enter "xx"
else
Enter "yy"
endif
In some
cases it makes sense to use goto/label:
GuiXT
Screen S1
Set V[x] "a"
Enter
if V[x=b]
goto l_b
endif
Screen S2
Enter "xx"
goto l_continue
label l_b
Screen S2
Enter "yy"
label l_continue