File Upload with ws_upload

Current Release for article: 4.6b This article describes creating a workstation upload to SAP. The WS_UPLOAD function replaces the old GUI_UPLOAD. GUI_UPLOAD should no longer be used.

Upload a file from a workstation, or a "presentation server" as it is known in the SAP world, to an ABAP program is a relatively simple procedure requiring a call to the BAPI WS_UPLOAD. The BAPI processes the request and returns an internal table containing the uploaded file.

Let's begin by defining the itab that will hold the input file from the workstation..

data: begin of plant occurs 200,

MATNR(18),
WERKS(4),
VKORG(4),
VTWEG(2),

end of plant.

.Next, lets define the input file name and tell the program to prompt for input:

parameters: wsfile(132) lower case.

start-of-selection.

Alternates for the parameters option:
One of the problems with the way we have defined the parameters is that the dialog box that is presented by SAP starts deep within the SAP libraries on the presentation server. Another is that the fully qualified filename can not exceed the 132 character limit. Most people will want to use a file on C:, on a Windows platform. Here's how to tell the dialog box to start in C:

parameters: wsfile(132) default 'C:\input.txt'

Importing the raw pattern:

In the ABAP editor click the Pattern button.


In the interactive dialog (see image, right), enter the function name WS_UPLOAD. The pattern inserted is shown below.


CALL FUNCTION 'WS_UPLOAD'
* EXPORTING
* CODEPAGE = ' '
* FILENAME = ' '
* FILETYPE = 'ASC'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB =
* EXCEPTIONS
* CONVERSION_ERROR = 1
* FILE_OPEN_ERROR = 2
* FILE_READ_ERROR = 3
* INVALID_TYPE = 4
* NO_BATCH = 5
* UNKNOWN_ERROR = 6
* INVALID_TABLE_WIDTH = 7
* GUI_REFUSE_FILETRANSFER = 8
* CUSTOMER_ERROR = 9
* OTHERS = 10
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

What you need in to call the function:

CALL FUNCTION 'WS_UPLOAD'

EXPORTING
FILENAME =wsfile
FILETYPE = 'DAT'

TABLES
DATA_TAB = plant

EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.

IF SY-SUBRC <> 0.
WRITE: / 'Error Uploading', wsfile, SY-SUBRC.
STOP.
ENDIF.

The call is very simple. The filename is the name of the variable that holds the user selection for the file on the presentation server. Filetype is a little tricky. There are a number of different values available, including

  • 'ASC' (ASCII)
  • 'DAT' (Tab-delimited data)
  • 'IBM' (EBCDIC)
  • 'BIN' (binary)

Check the function module documentation for a complete list of values.

Datatab is the ITAB name created in the first step of this procedure. If the procedue completes normally, the upload information will be in this table.

Return to ABAP help


[Our portfolio] [A history of Computers and Networks]
[Perl help] [ABAP help] [MySQL help]
[TCP/IP troubleshooting] [HTML help] [Feedback] [Humor]
Advertise on Golden Ink's Georgia Network


In Association with Amazon.com