В продолжение темы, единственный недостаток приведенного примера, это ИМХО не совсем удобная структура файла для загрузки, по этому немного модифицировал
На вход подаеться файл формата:
[код материала] <tab> [длинный текст]
report zmm_ozm_load_longtext.
tables: rlgrap.
parameters: p_file like rlgrap-filename default 'C:\1.cvs'.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
data: begin of lt_text occurs 1,
matnr like mara-matnr,
tdformat like tline-tdformat,
tdline like tline-tdline,
end of lt_text.
data: begin of lt_raw_text occurs 1,
matnr like mara-matnr,
longtext type string,
end of lt_raw_text.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
at selection-screen on value-request for p_file.
call function 'WS_FILENAME_GET'
exporting
def_filename = ''
def_path = 'C:\'
mask = ',*.cvs,*.*.'
mode = 'O'
title = 'Данные для загрузки'
importing
filename = p_file
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
start-of-selection.
perform read_text.
perform convert_text.
perform save_text.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form READ_TEXT
*&---------------------------------------------------------------------*
* Прочитать файл с даннами
*----------------------------------------------------------------------*
* <-- LT_TEXT - Данные загруженные для обработки
*----------------------------------------------------------------------*
form read_text.
data: l_filename type string,
l_filelength like sy-tabix.
l_filename = p_file.
call method cl_gui_frontend_services=>gui_upload
exporting
filename = l_filename
filetype = 'DAT'
importing
filelength = l_filelength
changing
data_tab = lt_raw_text[]
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 'Ошибка чтения файла с данными' type 'I'. exit. endif.
endform. " READ_TEXT
*&---------------------------------------------------------------------*
*& Form convert_text
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form convert_text.
data: l_line(3000) type c . " ????? уточнить длину
data: begin of lt_temp_lines occurs 10,
line(132) type c,
end of lt_temp_lines.
loop at lt_raw_text.
clear: lt_temp_lines[].
l_line = lt_raw_text-longtext.
call function 'RKD_WORD_WRAP'
exporting
textline = l_line
delimiter = ' '
outputlen = 132
* IMPORTING
* OUT_LINE1 =
* OUT_LINE2 =
* OUT_LINE3 =
tables
out_lines = lt_temp_lines
exceptions
outputlen_too_large = 1
others = 2.
loop at lt_temp_lines.
lt_text-matnr = lt_raw_text-matnr.
if sy-tabix = 1.
lt_text-tdformat = '/='.
else.
lt_text-tdformat = '/'.
endif.
lt_text-tdline = lt_temp_lines-line.
append lt_text.
endloop.
endloop.
endform. "convert_text
*&---------------------------------------------------------------------*
*& Form save_text
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form save_text.
data: l_count like sy-tabix,
ls_header like thead,
lt_lines like tline occurs 1 with header line.
sort lt_text by matnr.
"CLEAR: lt_lines[].
loop at lt_text.
on change of lt_text-matnr.
describe table lt_lines lines l_count.
if l_count > 0.
call function 'SAVE_TEXT'
exporting
header = ls_header
insert = 'I'
tables
lines = lt_lines
exceptions
id = 1
language = 2
name = 3
object = 4
others = 5.
endif.
ls_header-tdobject = 'MATERIAL'.
ls_header-tdname = lt_text-matnr.
ls_header-tdlinesize = '132'.
ls_header-tdid = 'GRUN'.
ls_header-tdspras = sy-langu.
clear: lt_lines[].
endon.
move-corresponding lt_text to lt_lines.
append lt_lines.
endloop.
describe table lt_lines lines l_count.
if sy-subrc = 0.
call function 'SAVE_TEXT'
exporting
header = ls_header
tables
lines = lt_lines
exceptions
id = 1
language = 2
name = 3
object = 4
others = 5.
endif.
call function 'COMMIT_TEXT'
importing
commit_count = l_count.
if l_count > 0. commit work. endif.
endform. " SAVE_TEXT