SAPGUI Edit “Bad Length” error message when setting a value

SAPGUI Edit "Bad Length" error message when setting a value

When you try to set a value in a SAPGUI Edit object, QTP throws an error message about the length of the string you are providing.

Seems the issue is reproducible for specific versions of the SAP Server and caused by SAP.

SAP Server provides to QTP the Max Length value based on the default value on the SAP EditBox, this way if the default value has a maxlength of 4 characters, this will be the value that QTP will use in the validation when you are setting a new value in the SAP EditBox.

For example if by default you have the value: “.xls” it will provide to QTP the max length value = 4. This way, when QTP is trying to use the Set method, the internal validation of QTP fails because the value provided its mayor than the MaxLength got from the SAP Server and this way you get the popup message.

The Workaround to prevent this problem is to assign the text using the SAP Object Directly, this way you bypass the QTP verification of the string length and you won’t get the error message:

SAPGuiSession("…").SAPGuiWindow("…").SAPGuiEdit("…").Object.Text "abcdefg.xls"

One thought on “SAPGUI Edit “Bad Length” error message when setting a value

  1. How to deal with the same scenario where input value is getting fetched from Excel sheet instead of hard-coding it with Set or Object.Text?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s