Skip to Content
0
Former Member
Jun 18, 2015 at 10:24 AM

Upload flat file having pipeline symbol

22 Views

PARAMETERS: p_file TYPE rlgrap-filename.

*****Define Itab of your Z-Table and Work Area of That*********

**Data: Itab like table of ztmm_comp,

** wa like line of Itab.

TYPES: BEGIN OF ttab,

rec(1000) TYPE c,

END OF ttab.

TYPES: BEGIN OF zs_tmm_comp,

fld1 TYPE ztmm_comp-company,

fld2 TYPE ztmm_comp-company_code,

fld3 TYPE ztmm_comp-city,

END OF zs_tmm_comp.

DATA: itab TYPE TABLE OF ttab WITH HEADER LINE.

DATA: it_datatab TYPE TABLE OF zs_tmm_comp WITH HEADER LINE.

DATA: wa TYPE zs_tmm_comp.

DATA path TYPE string.

path = p_file.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

* filename = 'c:\file1.txt'

filename = path

has_field_separator = 'X'

TABLES

data_tab = it_datatab

EXCEPTIONS

OTHERS = 1.

LOOP AT itab.

CLEAR it_datatab.

SPLIT itab-rec AT '|' INTO it_datatab-fld1

it_datatab-fld2

it_datatab-fld3.

APPEND it_datatab.

ENDLOOP.

LOOP AT it_datatab INTO wa.

MODIFY ztmm_comp FROM wa.

* modify ztmm_comp FROM it_datatab.

IF sy-subrc = 0.

MESSAGE s000(000) WITH 'The data has been saved'.

ENDIF.

ENDLOOP.