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 Comma separated Text file.

Former Member
0 Kudos

Hi all ,

i would like to upload a comma seperated text file into an internal table using CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD but am not able to load correctly. Please let me know any aditional parameters should be pass to this FM.

data **********

060000012,1001,01052005,2.5,C123,0198345678912

08000001,1001,01052005,5.0,C123,016545678912

08000001,1002,02052005,2.5,C234,012345678912

*********

types : Begin of ty_itab,

pernr(10),

ABS_ATT_TYPE(4),

REC_CCTR(10),

work_order(12),

date(8),

hours(8).

types: end of ty_itab.

data : itab type standard table of ty_itab with header line .

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD

EXPORTING

FILENAME = 'C:\LOAD.TXT'

FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • DAT_MODE = SPACE

  • CODEPAGE = SPACE

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • READ_BY_LINE = 'X'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

CHANGING

DATA_TAB = itab[]

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

NOT_SUPPORTED_BY_GUI = 17

ERROR_NO_GUI = 18

others = 19

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

Thx

Palani

11 REPLIES 11

former_member188685
Active Contributor
0 Kudos
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = 'C:LOAD.TXT'
FILETYPE = 'ASC'
<b> HAS_FIELD_SEPARATOR = 'X'</b>
* HEADER_LENGTH = 0
* DAT_MODE = SPACE
* CODEPAGE = SPACE
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
CHANGING
DATA_TAB = itab[]
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
NOT_SUPPORTED_BY_GUI = 17
ERROR_NO_GUI = 18
others = 19
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

uncomment the bold one..

Former Member
0 Kudos

I have uncommented but still not workin . u can try to copy n exe with uncommenting that parameter. this prg which i have given.

Thx

Palani

0 Kudos

as you are telling that is comma delimited then save the file as comma delimited,

this can be done uisng excel , open the text fiel with excel and save it as .csv file. and try ...

or else i will tell another solution for it...

Data: begin of itab occurs 0,
      rec(1000) type c,
      end of itab.

Data: begin of itab2 occurs 0,
      matnr type mara-matnr
      werks type marc-werks
      quant(10) type c.
      end of itab2.
  file = 'C:test.txt'.
 
  call method cl_gui_frontend_services=>gui_upload
    exporting
      filename                = file
    filetype                = 'ASC'
     has_field_separator     = 'X'
    changing
      data_tab                = itab
  exceptions
    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.


Loop at itab.
 
clear itab2.
split itab-rec at ',' into itab2-matnr 
                           itab2-werks
                           itab2-quant.
append itab2.
 
endloop.

you can do using any of the one...

0 Kudos

don't forget to reward if your problem solves..

regards

vijay

former_member188685
Active Contributor
0 Kudos
report ZTEST .
 
data: file type string.
 
types: begin of ttab,
      matnr type mara-matnr,
      werks type marc-werks,
      end of ttab.
 
data: itab type table of ttab.
 
start-of-selection.
 
  file = 'C:test.csv'.
 
  call method cl_gui_frontend_services=>gui_upload
    exporting
      filename                = file
    filetype                = 'ASC'
     has_field_separator     = 'X'
    changing
      data_tab                = itab
  exceptions
    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.

[code]

Former Member
0 Kudos

HI

Is there any fm to upload directly.

Thx

Palani

0 Kudos
 file = 'C:test.csv'.
 
  call method cl_gui_frontend_services=>gui_upload
    exporting
      filename                = file
    filetype                = 'ASC'
     has_field_separator     = 'X'
    changing
      data_tab                = itab
  exceptions
    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.

if it is .csv file then specify the file name as text.csv and give has_field_separator = 'X'..

this should upload ...

regards

vijay

0 Kudos

Try to save the text file as comma delimited file using excel.(open with exccel, save as .csv file)

and use upload , specify has_fieldseparator = 'X'.

if it doesn't work then refer to the other logic which i mentioned..

regards

vijay

Former Member
0 Kudos

HI,

i don't have any idea whether we can read comma separeted text file.

but you can solve the problen by creating an internal table say itab1

with one field of type c and length around 130 or so.

first get all the text file contents into it.

and then loop by itab1

loop at itab1.

SPLIT itab1-field1 AT ',' INTO itab.

append itab.

clear itab.

endloop.

regards,

Manohar

Former Member
0 Kudos

Hi Palani

U can upload the data into another itab of single field.

and then split the fields into the corresponding fields of ty_itab.

Regards

Neelima.

Former Member
0 Kudos

Thanks problem resolved.