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

How dynamically upload CSV file to customer table

com_2018
Participant
0 Likes
1,163

Hi,

How dynamically upload CSV file to customer table?

Import parameters:

1 Table name

2 Comma separate data (by function 'UPLOAD')

Could you gvie any ieda?

Reward points for you help.

Thanks and regards,

collysun

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
882

Create an internal table itab with your fields in the file and then use GUI_UPLOAD to upload your CSV file to the internal table.


TABLES: ztable.
DATA filename TYPE string.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      =  filename
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
  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.

INSERT ZTABLE FROM TABLE ITAB.

Hi,

How dynamically upload CSV file to customer table?

Import parameters:

1 Table name

2 Comma separate data (by function 'UPLOAD')

Could you gvie any ieda?

Reward points for you help.

Thanks and regards,

collysun

5 REPLIES 5
Read only

Former Member
0 Likes
883

Create an internal table itab with your fields in the file and then use GUI_UPLOAD to upload your CSV file to the internal table.


TABLES: ztable.
DATA filename TYPE string.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      =  filename
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
  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.

INSERT ZTABLE FROM TABLE ITAB.

Read only

0 Likes
882

Hi,

I want to dynamically upload.

Read only

0 Likes
882

Do you mean that you want the filename to be dynamically specified?

PARAMETERS : file(128).

DATA filename TYPE string.

filename = file.

Now do GUI_UPLOAD.

Read only

0 Likes
882

Hi,

I want to that add-on table is dynamical.

Read only

0 Likes
882

You can create dynamic internal table structures using field-symbols like this.

TABLES: z538emp.
FIELD-SYMBOLS <fs> STRUCTURE z538emp DEFAULT z538emp.
"Define the structure of field symbol dynamically"
"Then assign it to your internal table"
DATA itab LIKE <fs> OCCURS 0.
DATA filename TYPE string.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      =  filename
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
  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.