PDA

Ver la Versión Completa : Subir archivo separado por Comas


jjeffer
15/07/11, 01:01:52
Hola,

Estoy creando un programa que me permita subir un archivo separado por comas, estoy utilizando esta función GUI_UPLOAD pero no funciona :confused: , solo sirve cuando el archivo esta separado por TAB, espero que puedan ayudarme.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_filename
filetype = 'ASC'
has_field_separator = ' ' "Tambien utilizo ','.
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* replacement = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = p_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 ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Gracias, :)

mysmb2
15/07/11, 12:25:55
hola, esa funcion solo admite separadores con TAB, vas a tener que levantar el archivo en una tabla interna de una linea y luego a esa linea hacerle SPLIT de la forma
SPLIT linea AT ',' INTO tabla-campo1 tabla-campo2..etc.

saludos.

jjeffer
15/07/11, 15:35:08
Muchas gracias Sebastian, tu respuesta me sirvió de mucha ayuda.

Coloco el codigo por si a alguien le sucede lo mismo que a mi :D

"Declaro la TI con solo un campo tipo STRING
DATA: BEGIN OF ti_texto OCCURS 0,
line TYPE string,
END OF ti_texto.

"Declaro la variable que contiene el nombre del archivo
DATA l_filename TYPE string.


l_filename = 'c:\prueba.txt'.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_filename
filetype = 'ASC'
has_field_separator = ','
TABLES
data_tab = ti_texto
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.

"wt_itabct es la tabla donde voy a insertar los registros
LOOP AT ti_texto.
SPLIT ti_texto-line AT ',' INTO wt_itabct-zzidprssrv
wt_itabct-zzfchrem
wt_itabct-zzcodarch
wt_itabct-zztotreg.
APPEND wt_itabct.
ENDLOOP.