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

GUI_UPLOAD

Former Member
0 Likes
867

Hi,

I am using GUI_UPLOAD to upload file in an internal table.

The records are separated with |

For eg :

F200801/000035|0000|1|20071220|20071231|1230123456789|Free text|

These records are to be uploaded in internal table and then in Z table.

Pl. guide.

Rgds,

Priti

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
811

Hi,

have a look on the following code, and observe the flat file also

TABLES: kna1.

DATA: BEGIN OF itab1 OCCURS 0,

str(255),

END OF itab1.

DATA: itab2 TYPE kna1 OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = 'D:\ABAP EVE\ffile1.txt'

filetype = 'ASC'

TABLES

data_tab = itab1

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

no_authority = 10

OTHERS = 11.

IF sy-subrc <> 0.

WRITE:/ 'sorry'.

ELSE.

LOOP AT itab1.

SPLIT itab1-str AT ',' INTO itab2-kunnr itab2-name1.

APPEND itab2.

ENDLOOP.

IF sy-subrc = 0.

LOOP AT itab2.

WRITE:/ itab2-kunnr,itab2-name1.

INSERT INTO kna1 VALUES itab2.

ENDLOOP.

IF sy-subrc = 0.

WRITE:/ 'inserted'.

ELSE.

WRITE:/ 'not inserted'.

ENDIF.

ELSE.

WRITE:/ 'fail'.

ENDIF.

ENDIF.

Flat file:

10001,Sadney

10003,Yogesh

20005,Madan

<REMOVED BY MODERATOR>

Thanks,

Chandu

Edited by: Alvaro Tejada Galindo on Apr 25, 2008 5:44 PM

6 REPLIES 6
Read only

Former Member
0 Likes
811

Hi Priti,

what you can do is First create an Internal Table ITAB with the required fields and then call function GUI_UPLOAD as did below:

pay attention to this HAS_FIELD_SEPARATOR = '|'

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = 'FILEPATH'
*   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = '|'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  tables
    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
*   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.

and after this LOOP the ITAB and INSERT the records in the Database Table

Regards,

Sunil

Read only

0 Likes
811

Hi Sunil,

I had done already as you mentioned in the code.

But my itab is blank.The records are not appearing.

There is one file which contains header and item information.

Let me know how the itab has to be declared.

Rgds,

priti

Read only

0 Likes
811

check this code:

  call function 'GUI_UPLOAD'
    exporting
      filename                = vl_fname
      filetype                = 'ASC'
      has_field_separator     = ' '
    tables
      data_tab                = i_dwl  " <<<a flat structure table..
    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 e074(zv).
  endif.

  loop at i_dwl into w_dwl.
    if sy-tabix > 1.
      perform split_data using w_dwl 'X'.
    endif.
    clear w_dwl.
  endloop.
"<<<<<<<<<<<
form split_data  using  p_catsdata flag.

  split p_catsdata at '|' into  w_infile-bukrs w_infile-anln1
                                w_infile-anlkl w_infile-lnran
                                w_infile-bldat vl_erlbt
                                w_infile-anbtr w_infile-gdlgrp
                                w_infile-aktiv w_infile-sernr
                                w_infile-invnr w_infile-txt50
                                w_infile-ztext.
  w_infile-erlbt = vl_erlbt.
  clear: vl_erlbt.
append i_infile from w_infile.
clear: w_infile.

Read only

Former Member
0 Likes
811

put HAS_FIELD_SEPARATOR = '|'

Read only

Former Member
0 Likes
811

after that use

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = DV_FILE

FILETYPE = 'ASC'

APPEND = 'X'

WRITE_FIELD_SEPARATOR = 'X'

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = IT_FINAL

  • FIELDNAMES =

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 25, 2008 5:43 PM

Read only

Former Member
0 Likes
812

Hi,

have a look on the following code, and observe the flat file also

TABLES: kna1.

DATA: BEGIN OF itab1 OCCURS 0,

str(255),

END OF itab1.

DATA: itab2 TYPE kna1 OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = 'D:\ABAP EVE\ffile1.txt'

filetype = 'ASC'

TABLES

data_tab = itab1

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

no_authority = 10

OTHERS = 11.

IF sy-subrc <> 0.

WRITE:/ 'sorry'.

ELSE.

LOOP AT itab1.

SPLIT itab1-str AT ',' INTO itab2-kunnr itab2-name1.

APPEND itab2.

ENDLOOP.

IF sy-subrc = 0.

LOOP AT itab2.

WRITE:/ itab2-kunnr,itab2-name1.

INSERT INTO kna1 VALUES itab2.

ENDLOOP.

IF sy-subrc = 0.

WRITE:/ 'inserted'.

ELSE.

WRITE:/ 'not inserted'.

ENDIF.

ELSE.

WRITE:/ 'fail'.

ENDIF.

ENDIF.

Flat file:

10001,Sadney

10003,Yogesh

20005,Madan

<REMOVED BY MODERATOR>

Thanks,

Chandu

Edited by: Alvaro Tejada Galindo on Apr 25, 2008 5:44 PM