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: 

Query about GUI_UPLOAD

Former Member
0 Kudos

Hi All,

I am really sorry but this is a basic question and i need help immediately.

In my local file i have ';' as field seperator. How should I get the data properly. A little example would be fine and appreciated.

Thanks,

Jignesh

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi jignesh,

1. Exactly for this purpose,

i have developed an <b>independent FORM</b>

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

<b>(no matter what the separator)

(it can work with any kind of separator)</b>

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

regards,

amit m.

6 REPLIES 6

Former Member
0 Kudos

Hai Jignesh

Check the following Code

tables : mara.

data : begin of it_mara occurs 0,

matnr like mara-matnr,

mbrsh like mara-mbrsh,

mtart like mara-mtart,

maktx like makt-maktx,

meins like mara-meins,

end of it_mara.

start-of-selection.

perform upload_data.

&----


*& Form upload_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload_data .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'c:\mat_bdc.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = it_mara.

IF SY-SUBRC = 0.

SORT IT_MARA BY MATNR.

ENDIF.

ENDFORM. " upload_data

flat file structure is

PRANIT_011;C;COUP;This is Testing material;kg

PRANIT_012;C;COUP;This is Testing material;kg

PRANIT_013;C;COUP;This is Testing material;kg

PRANIT_014;C;COUP;This is Testing material;kg

PRANIT_015;C;COUP;This is Testing material;kg

Thanks & regards

Sreenivasulu P

Message was edited by: Sreenivasulu Ponnadi

0 Kudos

This is my code :::::::

*&---------------------------------------------------------------------*
*& Report  ZCONTACTLIST                                                *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZCONTACTLIST                            .

PARAMETERS: p_infile  LIKE rlgrap-filename
                        OBLIGATORY DEFAULT  '/usr/sap/'..

*DATA: ld_file LIKE rlgrap-filename.
DATA: gd_file type string.

*Internal table to store upload data
TYPES: BEGIN OF t_record,
    name1 LIKE pa0002-vorna,
    name2 LIKE pa0002-name2,
    age   TYPE i,
    END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
      wa_record TYPE t_record.

*Internal table to upload data into
DATA: BEGIN OF it_datatab OCCURS 0,
  row(500) TYPE c,
 END OF it_datatab.

*Text version of data table
TYPES: BEGIN OF t_uploadtxt,
  name1(10) TYPE c,
  name2(15) TYPE c,
  age(5)  TYPE c,
 END OF t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.


*String value to data in initially.
DATA: wa_string(255) TYPE c.

************************************************************************

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            def_filename     = p_infile
            mask             = ',*.txt.'
            mode             = 'O'
            title            = 'Upload File'(078)
       IMPORTING
            filename         = p_infile
       EXCEPTIONS
            inv_winsys       = 1
            no_batch         = 2
            selection_cancel = 3
            selection_error  = 4
            OTHERS           = 5.


************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
  gd_file = p_infile.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = gd_file
      FILETYPE                = 'ASC'
*      has_field_separator     = 'X'  "file is tab delimited
    TABLES
      data_tab                = it_record
    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 NE 0.
      write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
      skip.
    endif.

************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.

* Display report data
LOOP AT it_record INTO wa_record.
  WRITE:/     sy-vline,
         (10) wa_record-name1, sy-vline,
         (10) wa_record-name2, sy-vline,
         (10) wa_record-age, sy-vline.
ENDLOOP.

This is my flat file ::::::::

Jignesh;Patel;22

Durgesh;Tiwari;24

Gautam;Deshlahra;26

Its giving error code 8 ::: bad_data_format from GUI_UPLOAD..

Former Member
0 Kudos

Hi jignesh,

1. Exactly for this purpose,

i have developed an <b>independent FORM</b>

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

<b>(no matter what the separator)

(it can work with any kind of separator)</b>

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

regards,

amit m.

0 Kudos

in CALL FUNCTION 'GUI_UPLOAD' there is in exporting option of

has_field_separator just make it 'X'.

has_field_separator = 'X'

0 Kudos

Hi Amit...

During step1 only its giving error that bad data format !!!

My Flat file contains data like this::::

Jignesh;Patel;22

Durgesh;Tiwari;24

Gautam;Deshlahra;26

Hey Amit... THanks Mate !!!! Solved the problem !!!

Message was edited by: Jignesh Patel

hymavathi_oruganti
Active Contributor
0 Kudos

in the text file, replace all occurances of ',' with space , then u can use gui_upload normally.