CopyText statement: As part of a larger script I have written a test script to read the Purchase Order text from the Material Master. The script reads Material Nos from a file, gets the long text and writes the data to another file.
The problem I have is that the long text retrieved for the first record is blank and the long text for the second record is that for the first record and so on. What could be the reason?

The problem here is that the InputScript script processing for a particular screen runs before the screen is actually built up by SAP GUI. There is no event "On screen display" which in fact would make sense in certain cases. Especially for the "CopyText fromScreen" statement, since it cannot be processed immediately but is postponed until SAP GUI has built up the screen.

This is why our documentation says "Please observe: The text is actually copied when the screen is displayed, or with the next "Enter" in an InputScript (asynchronous processing).".

Instead of

Screen SAPLMGMM.3050
  CopyText fromScreen=X[LONGTEXT_BESTELL] toText="iwtext"
  CopyText fromtext="iwtext" line=... tostring=...
  Enter "/NMM03"

Please use

Screen SAPLMGMM.3050
  CopyText fromScreen=X[LONGTEXT_BESTELL] toText="iwtext"
  Enter

Screen SAPLMGMM.300650
  CopyText fromtext="iwtext" line=... tostring=...
  Enter "/NMM03"