I have decided to open a new section in my blog: Time and again, I stumble over SAP related problems and issues that consume quiet a large amount of my (precious) time doing debugging and bug fixing. Sometimes the SCN is a helpful source of information, sometimes it is not. For the issues that I had to fix without finding helpful resources in SCN or on the internet in general, I have created the SAP category in my blog, where I will write short posts on the original problem and the solutions that I have discovered.
The problem that I spent half of my morning on, had to do with SAP Smartforms. It is – generally – possible to create a text object containing the contents of a standard text element. In its most simple form, the text element is given through a static tuple: text name, text object, text ID, and language.
It is also possible, to determine the text name dynamically in ABAP coding, e. g. in the Initialization routine, and use a variable as element property. If you want to do this, you have to change the property to dynamic (see red box in the picture below) and put the variable name between &.
Now, if you have correctly defined and set your variable, it should work as expected. It should!
For me, it didn’t work. Instead the text name was always empty. After some debugging, I found that the value got lost during a move operation/routine that is executed before the form is really generated.
perform %move using %textkey-name ‘&GV_TEXTID&’.
Further research showed that this routine checks the dictionary object and the variable length. If the value used in the smart form coding is longer than the dictionary element type for the text name field, the value is – not truncated but – set to SPACE. Don’t ask me why the SAP developer chose to go that way; it was surely giving me some headaches 😦
Hence, the solution would be to use global variables that have exactly the same type and field length as the text element property you want to set dynamically!