Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file separated by "|"

Former Member
0 Kudos

Hi,

I know I can use WS_UPLOAD to upload files but how can I tell the function that the separator is "|".

Do I need to use another FM?

Regards

1 ACCEPTED SOLUTION

former_member221770
Contributor
0 Kudos

Hi Jose,

First of all, don;t use WS_UPLOAD - it's obselete, instead use GUI_UPLOAD. I haven't seen a FM that lets you define your own field separators. What I have done in the past is use GUI_UPLOAD into a table with a char1000 field. Then I loop at this table and use the "SPLIT" command.

eg

split tbl_data-rec at '|' into.....

Works fine for me everytime.

Hope this helps.

Cheers,

Pat.

7 REPLIES 7

former_member221770
Contributor
0 Kudos

Hi Jose,

First of all, don;t use WS_UPLOAD - it's obselete, instead use GUI_UPLOAD. I haven't seen a FM that lets you define your own field separators. What I have done in the past is use GUI_UPLOAD into a table with a char1000 field. Then I loop at this table and use the "SPLIT" command.

eg

split tbl_data-rec at '|' into.....

Works fine for me everytime.

Hope this helps.

Cheers,

Pat.

0 Kudos

I think if you us ethe HAS_FIELD_SEPARATOR parmeter in the GUI_UPLOAD, you can avoid the loop.

Regards,

Suresh Datti

0 Kudos

Suresh,

According to the FM Documentation the HAS_FIELD_SEPARATOR parameter indicates whether the file is Tab Deliminated or not.

Pat.

Former Member
0 Kudos

Hi José,

I think you can't upload '|' separated files

by the FM: WS_UPLOAD.

But there is a similar FM :

KCD_CSV_FILE_TO_INTERN_CONVERT

which uploads any delimited file.

Specify the filename in : I_FILENAME

And the delimiter | in : I_SEPARATOR

You can test the FM in SE37.

But you can't do it the direct way.

See a program on this...

DATA: BEGIN OF itab OCCURS 0,
        vbeln LIKE vbak-vbeln,
        ernam LIKE vbak-ernam,
      END OF itab.

DATA itab2 LIKE TABLE OF <b>KCDE_CELLS</b> WITH HEADER LINE.

CALL FUNCTION <b>'KCD_CSV_FILE_TO_INTERN_CONVERT'</b>
  EXPORTING
    i_filename            = 'D:dataupl.txt'
    i_separator           = '|'
  tables
    e_intern              = itab2
* EXCEPTIONS
*   UPLOAD_CSV            = 1
*   UPLOAD_FILETYPE       = 2
*   OTHERS                = 3
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT itab2.
  SPLIT itab2-value AT '|' INTO itab-vbeln itab-ernam.
  APPEND itab.
  CLEAR itab.
ENDLOOP.

And the file: upl.txt

12345|text

12346|text2

12347|text3

Regards,

Wenceslaus.

0 Kudos

hi,

here is the sample code of the same ... hope this helps

DATA W_WSU_FILENAME02 TYPE STRING.

DATA W_WSU_FILETYPE02 TYPE CHAR10.

W_WSU_FILETYPE02 = 'ASC'.

READ TABLE ITAB_FILE1_TABLE INDEX 1 INTO W_WSU_FILENAME02.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = W_WSU_FILENAME02

FILETYPE = W_WSU_FILETYPE02

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = ITAB_INFILE

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Regards,

Santosh

former_member186077
Active Participant
0 Kudos

Hi ,

you can use the same FM ,

move the corresponding fields into respective itab using split ....

or

Use GUI_UPLOAD and specify the field seperator in HAS_FIELD_SEPARATOR parameter.

Thanks and Regards ,

Sriranjani Chimakurthy.

Former Member
0 Kudos

Hi jose,

1. Exactly for this purpose,

i have developed an independent FORM

where we give inputs

a) file name (eg. abcd.txt)

b) separator (eg | in your case)

c) internal table (eg. t001)

2. It will provide the data

in proper format

(no matter what the separator)

(it can work with any kind of separator)

3. just copy paste in new program.

REPORT abc.

*----


*----


change your table declaration and file name

*----


DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

PERFORM myupload TABLES t001 USING 'd:\t001.txt' '|'.

BREAK-POINT.

*----


in debug see t001

*----


  • INDEPENDENT FORM

*----


FORM myupload TABLES orgtab

USING filename separator.

*----


Data

DATA : BEGIN OF itab OCCURS 0,

myline(1000) TYPE c,

END OF itab.

DATA : extension(5) TYPE c.

DATA : name(100) TYPE c.

DATA : newfilename TYPE string.

*----


Step 1

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = filename

TABLES

data_tab = itab.

*----


Step 2

LOOP AT itab.

REPLACE ALL OCCURRENCES OF separator IN itab-myline WITH

cl_abap_char_utilities=>horizontal_tab.

MODIFY itab.

ENDLOOP.

*----


Step 3

DATA : path LIKE pcfile-path.

path = filename.

CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'

EXPORTING

complete_filename = path

  • CHECK_DOS_FORMAT =

IMPORTING

  • DRIVE =

extension = extension

name = name

  • NAME_WITH_EXT =

  • PATH =

EXCEPTIONS

invalid_drive = 1

invalid_extension = 2

invalid_name = 3

invalid_path = 4

OTHERS = 5

.

*----


Step 4

newfilename = filename.

REPLACE name IN newfilename WITH 'temp'.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = newfilename

TABLES

data_tab = itab

  • FIELDNAMES =

.

*----


Step 5

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = newfilename

has_field_separator = 'X'

TABLES

data_tab = orgtab.

ENDFORM. "myupload

3.

regards,

amit m.