Application Development and Automation 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: 
Read only

load text file

Former Member
0 Likes
2,410

Hi,

i try to upload a text file from the server and what i get is just the first line in the table of string,

(data_tab) .

i want to get all the data in the file into one string or big variable how i can do that?

Regards

DATA: file_physical TYPE fileextern,
        physical_path TYPE pathintern,
        file_format TYPE fileformat,
        data_tab TYPE  standard table  of string   .

CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = l_file
      filetype                = 'ASC'
*    has_field_separator     = SPACE
*    header_length           = 0
*    read_by_line            = 'X'
*    dat_mode                = SPACE
*    codepage                = SPACE
*    ignore_cerr             = ABAP_TRUE
*    replacement             = '#'
*    virus_scan_profile      =
*  IMPORTING
*    filelength              =
*    header                  =
    CHANGING
      data_tab                = data_tab
    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.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,326

Hi,

Try passing the parameter READ_BY_LINE as 'X' and see.

regards,

Advait

20 REPLIES 20
Read only

Former Member
0 Likes
2,327

Hi,

Try passing the parameter READ_BY_LINE as 'X' and see.

regards,

Advait

Read only

0 Likes
2,326

Hi Advait ,

Thanks ,

i try it but what i get is table of string and just first line and he cut it,

i don't get all the data.

maybe there is other FM or Method that can do that?

my output have to be some string with all the data.

i new to this topic and need some help.

Thanks again and Best Regards

Read only

0 Likes
2,326

Does your file have many lines in it or just one line ?

regards,

Advait

Read only

0 Likes
2,326

Hi Advait,

my file is with 15 lines.

Regards

Read only

0 Likes
2,326

use this

gv_file TYPE string,

gc_filetype TYPE char3 VALUE 'ASC'.

gt_text_file your file structure

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = gv_file

filetype = gc_filetype

TABLES

data_tab = gt_text_file

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

Read only

0 Likes
2,326

Thats strange. Your code worked fine in my system. Make sure that the correct file is being picked up . Put a break point at CALL METHOD. See what value is being passed to the l_file.

regards,

Advait

Read only

0 Likes
2,326

Hi Advait ,

i put break point ,and to the l_file i move 'G:\das\rel1.txt' - the path,

and at the end of the method sy-subrc = 0.

but i get just 1 line in data_tab and this is not the all data in the first line of the file( it's cut ).

Any idea ?

Regards

Read only

0 Likes
2,326

I'm still not sure why this is happening. Try to use GUI_UPLOAD function instead, this is called within the method GUI_UPLOAD.

regards,

Advait

Read only

0 Likes
2,326

Hi Advait ,

thanks,

i try the fm and i get the same problem,

from your experience if i had in the text file 15 lines, i have to get in data_tab 15 lines to.

Regards

Read only

0 Likes
2,326

Hi,

Yes that is correct, you should get 15 lines if there are 15 line breaks in the file. There could be a problem in the file format as well. To make sure that is the case, what you can do is to create a dummy test file and test it. Example create a .txt file on your C drive with many lines and try to upload this file and see what result do you get.

regards,

Advait

Read only

0 Likes
2,326

Hi Advait,

Thanks,

i try other test file and i get it like u tell , i think that the format of the file is Johnson

but it end with .txt how i can check if it is o.k. file ?

there is a way to upload this format ?

Regards

Read only

0 Likes
2,326

change the decaration of data_tab then u will get all the lines of u r file into table data_tab

REPORT ZSRK_045 .

DATA : L_FILE TYPE STRING VALUE 'c:\fonelist2.txt'.

TYPES: BEGIN OF TP_DATA_TAB,

TEXT TYPE STRING,

END OF TP_DATA_TAB.

DATA : DATA_TAB TYPE STANDARD TABLE OF TP_DATA_TAB.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD

EXPORTING

FILENAME = L_FILE

FILETYPE = 'ASC'

CHANGING

DATA_TAB = DATA_TAB

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 NE 0.

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

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

ENDIF.

Read only

0 Likes
2,326

Hi sreekanth ,

Thanks,

there is a way to move the data from the table of string to one big string at the end of the Fm ?

Regards

Read only

0 Likes
2,326

Try to use 'BIN' instead of 'ASC'

Read only

Former Member
0 Likes
2,326

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = l_file

filetype = 'ASC'

has_field_separator = 'X'

  • header_length = 0

  • read_by_line = 'X'

  • dat_mode = SPACE

  • codepage = SPACE

  • ignore_cerr = ABAP_TRUE

  • replacement = '#'

  • virus_scan_profile =

  • IMPORTING

  • filelength =

  • header =

CHANGING

data_tab = data_tab

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.

Read only

0 Likes
2,326

Hi Sreekanth,

i change it and i face the same issue .

how i have to decalre data_tab?

Regards

Read only

Former Member
0 Likes
2,326

Hi Vijay

the data which you are getting into your internal table, loop on to it and concenate it into a string variable.

data: wa_tab type string,

lv_final type string.

loop at data_tab into wa_tab.

concatenate lv_final wa_tab into lv_final.

endloop.

Thanks

Vishal Kapoor

Read only

0 Likes
2,326

HI vishal ,

Thanks,

when i do concatenate and watch lv_final in the debugger i don't get all of the data ,

it cut the string ,

assume i have 6 lines in data_tab i get just 2 lines in lv_final.

u have idea way?

Regards

Read only

0 Likes
2,326

My file contains 100 lines of data (total 2016 characters) i have checked in debugging L_FINAL contains 2016 characters

DATA : L_FILE TYPE STRING VALUE 'c:\fonelist2.txt'.

TYPES: BEGIN OF TP_DATA_TAB,

TEXT TYPE STRING,

END OF TP_DATA_TAB.

DATA : DATA_TAB TYPE STANDARD TABLE OF TP_DATA_TAB.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD

EXPORTING

FILENAME = L_FILE

FILETYPE = 'ASC'

CHANGING

DATA_TAB = DATA_TAB

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 NE 0.

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

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

ENDIF.

DATA: WA_TAB LIKE LINE OF DATA_TAB,

L_TEMP TYPE STRING,

L_FINAL TYPE STRING.

LOOP AT DATA_TAB INTO WA_TAB.

L_TEMP = WA_TAB-TEXT.

CONCATENATE L_FINAL L_TEMP INTO L_FINAL.

ENDLOOP.

Read only

0 Likes
2,326

Hi sreekanth,

Thanks ,

but way when i see the debugger L_FINAL i don't see it until the end (of the data) i try to scroll the field to write and i don't see all the string way?

the problem is with the new debugger ?

Regards