Using the Copytext Command
Copytext is used in GuiXT to copy text between screens, text files and variables. In this tip we will discuss how to use this command. The basic syntax is as follows:
copytext from...="v1" to...="v2"
The 'from...' location specifies where the text will be moved from and the 'to...' location designates the location the text will be move to. In the above syntax, we are moving text from one variable to a second variable. However, the copytext command is not restricted only to variables. Copytext can also be used to copy text between screens, files, strings or a template. Text can also be placed in the Windows Clipboard for later use in a screen, a variable or a file. The following To and From locations are supported:
From locations:
- -fromClipboard: Copies text from the Clipboard to a specified location.
- fromScreen=: Copies text from the specified screen in SAP. The copying action will occur only when the given screen is actually displayed in SAP or at the point in the InputScript where the ensuing 'Enter' command is encountered.
- fromString=: Copies text from the designated string.
- fromTemplate=: Copies text from a designated template, replacing the variables with the given text.
- fromText=: Copies form a specified text variable.
To locations:
- -toClipboard: Copies text to the Windows Clipboard.
- toFile=: Copies text to a specified file.
- toScreen=: Copies text to the specified field on the current screen.
- toSharedText: Copies text to a specified piece of shared text.
- toString=: Copies text to a given string.
- toText=: Copies to another text variable.
Using Windows Clipboard
To place text on the Windows Clipboard for later use, the syntax is as follows:
copytext fromText="v1" -toClipboard
In this example, the text will be copied from the variable 'v1' to the Windows clipboard. As long as nothing is copied to the Clipboard to over-write this text, the text can be used later in any supported location. To place the text into a particular screen, the following syntax would be used:
copytext toScreen=""X[LongText]" fromClipboard
Copying Between Variables
It is useful to copy text between variables, especially when a user might wish to modify a piece of text. The syntax is as follows:
copytext fromText="v1" toText="v2"
This will move the content of text variable 'v1' to the variable 'v2'. ONce a piece of text is modified, it can be moved back into 'v1'.
Copying To or From a Screen
When a given SAP screen is being displayed, text can be copied into a designated field on that screen. The syntax is as follows:
copytext fromText="v1" toScreen="F[Materials]"
In this example, we are copying the content of text variable 'v1' to the field 'Materials' on the current screen. It is also possible to do the reverse - to copy the content of a given field on the current screen - to a text variable as in the following example:
copytext fromScreen="F[Materials]" toText="v1"
Example
In the following example, we will use the copytext command to copy some long text from the IW31 transaction main screen (SAPLCOIH.E0100) to the IW31 Central Header screen (SAPLCOIH.E3000). To do this, we will add a custom field to the IW31 main screen, as shown below:
The code to do this is as follows:
pushbutton (17,36) "CopyText" "process=IW31_copytext.txt"
text (11,0) "GuiXT TextBox:"
del G[Reference]
textbox (12,15) (15,70) "name=G_sampletext"
This code adds a text box where a user can enter long text. The pushbutton calls the associated Input Script file 'copytext.txt' which contains the actual copytext function, as shown below:
// Defaulting some data on the initial screen
Set F[Order Type] "PM01"
Set F[Plng Plant] "1000"
Set F[Bus. Area] "1000"
Enter //Enter will hit enter on the screen to navigate to sceondary screen
// Create Maintenance Order : Central Header
Screen SAPLCOIH.3000
Set F[Mn.wk.ctr] "am-110" //Defaulting the value for the work center
Enter
// Create Maintenance Order : Central Header
Screen SAPLCOIH.3000
if P[Show long text window] //Check for the condition if the long text is not open
Enter "=LTHE" // Show long text window, open the long text window
endif
Enter
// Now that the long text window is open, we will use the copy text command
// Create Maintenance Order : Central Header
Screen SAPLCOIH.3000
Copytext fromText="g_sampletext" toScreen="X[LTEXT]"
Enter
The following screen results from the code above: