Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Different length Records in flat file??

Hi all,

I have a flat file which has to be uploaded into database, this file has records like 21000 and some records in the file are bigger in length due to which the data is not coming into internal table properly

Thanks & Regards

Jerry

replied

Hi Jerry.

IF your are using GUI_UPLOAD try this

TYPES: BEGIN OF t_itab, field1 TYPE ..., . . fieldn TYPE ..., END OF t_itab. DATA: your_file TYPE string. DATA: your_itab TYPE STANDARD TABLE OF t_itab INITIAL SIZE 0. your_file = 'C:\x\x.txt'. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = your_file filetype = 'ASC' has_field_separator = 'X' TABLES data_tab = your_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.

Otherwise try this.

TYPES: BEGIN OF t_itab, field1 TYPE ..., . . fieldn TYPE ..., END OF t_itab. DATA: c_tab(2) TYPE c, g_string TYPE string, your_file TYPE string. DATA: your_itab TYPE STANDARD TABLE OF t_itab INITIAL SIZE 0, xitab TYPE t_itab OCCURS 0 WITH HEADER LINE. c_tab = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB. your_file = '/x/x.txt'. OPEN DATASET your_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF sy-subrc EQ 0. DO. READ DATASET your_file INTO g_string. IF sy-subrc NE 0. EXIT. ENDIF. SPLIT g_string AT c_tab INTO TABLE xitab. APPEND LINES OF xitab TO your_itab. ENDDO. ENDIF. CLOSE DATASET your_file.

Hope this help you.

Luis

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question