Skip to Content

How to copy data from the clipboard

Estimated Reading Time: 1 Minutes

If an isCOBOL program needs to use the current data from the clipboard, and that isCOBOL program has an active screen, it is simple to do using the action-paste action of an entry-field.
The basic code to place the data from the Clipboard into an entry-field and then get it from the entry-field to a variable is as follows:

       initialize ws-clipboard
       modify  ef-clipboard value  spaces
       modify  ef-clipboard action action-paste 
       inquire ef-clipboard value  ws-clipboard
       .

The variable ws-clipboard would be defined as:

       01 ws-clipboard pic x any length.

And the ef-clipboard entry-field would be defined with the property visible 0 to be invisible.
The screen might look like this.

For example, if you copy text (ctrl-c) from a file you are editing in notepad and then you press the push-button on the screen, the clipboard data will be written to ws-clipboard using the code above.
Then you can display to a message box (or use for any needed business logic in a real program).

You can download the complete sample program attached below that demonstrates this functionality.

Compile it with this command line:

   iscc  -sp="%iscobol%sampleisdef" copyfromclipboard.cbl

Run it with this command line:

   iscrun COPYFROMCLIPBOARD
How to copy data from the clipboard
  • Attached Files
  • copyfromclipboard.cbl (2.21 KB) 8