Whenever the user places the mouse cursor in an SAP field, the GUI Code Generator must identify the control corresponding to that field. While recording an SAP session, this information is automatically known. The controls originally created for the screen contain a control number, and the field’s repository name and screen label, if available. The Generator uses this information to mark a control as selected, or perform other operations.
At runtime, however (when the generated program runs), the recorded information may no longer be valid. The collection of controls created for the runtime screen may differ from the collection used at program generation. This would be true if:
For these reasons, the Generator must generate code that matches the assumed field with the controls that are actually generated at runtime. The code accesses these controls by repository name where possible, or by label name. Code for identifying the control (variableiCtrl ) might be generated as follows:
iCtrl = Sap.FindByField("P0006-LAND1", 0, SapMatch)
' Country key (index 26)
OKCheck iCtrl >= 0, "Error in setting output variable"
CountryKey = Sap.Controls(iCtrl).Value
TheOKCheck routine checks that iCtrl does in fact contain a valid value, meaning that it found a control with a name matching the repository name P0006-LAND1 .
If repository names and labels are not available, however, the Generator uses hard-coded control numbers to access controls:
CountryKey = Sap.Controls(26).Value
This kind of access is unreliable and should be avoided if possible. SAP recommends that you replace hard-coded control numbers with other code that navigates to the desired control.
For example, you might find a known control (identifiable by field name) and then navigates so many to the right, left, or down, from the landmark. For doing this, the following methods are useful: