2007 Jun 18 6:21 AM
Hi all,
Here I need to transfer tab delimeted file from application server to my internal table.
Here I am using FM for searching for the file in the specified directory.
But how to convert that tab delimeted file into internal table without any length mismatchings.
waithing for reply,
thanks and regards,
jeeva
2007 Jun 18 6:24 AM
Hi,
Check this code..
DATA: WA(100).
OPEN DATASET '/tmp/test.txt' FOR INPUT IN TEXT MODE.
if sy-subrc <> 0.
message e208(00) with 'Error in opening file'.
endif.
DO.
READ DATASET '/tmp/test.txt' INTO WA.
if sy-subrc <> 0. EXIT. ENDIF.
* Split the record based on tab..
SPLIT WA AT cl_abap_char_utilities=>horizontal_tab
INTO ITAB-FIELD1 ITAB-FIELD2.
APPEND ITAB.
ENDDO.
Thanks
Naren
Hi all,
Here I need to transfer tab delimeted file from application server to my internal table.
Here I am using FM for searching for the file in the specified directory.
But how to convert that tab delimeted file into internal table without any length mismatchings.
waithing for reply,
thanks and regards,
jeeva
2007 Jun 18 6:24 AM
Hi
You can use FM GUI_UPLOAD with file type 'ASC' to upload your tsab delimited data into internal table.
Define the internal table in such a way that the fields can accomodate the data from the file.
Sorry, forgot that the file is on application server.
Discard this solution.
Use Open dataset command....
Regards
Raj
Message was edited by:
Rajasekhar Dinavahi
2007 Jun 18 6:24 AM
Hi,
Check this code..
DATA: WA(100).
OPEN DATASET '/tmp/test.txt' FOR INPUT IN TEXT MODE.
if sy-subrc <> 0.
message e208(00) with 'Error in opening file'.
endif.
DO.
READ DATASET '/tmp/test.txt' INTO WA.
if sy-subrc <> 0. EXIT. ENDIF.
* Split the record based on tab..
SPLIT WA AT cl_abap_char_utilities=>horizontal_tab
INTO ITAB-FIELD1 ITAB-FIELD2.
APPEND ITAB.
ENDDO.
Thanks
Naren
2007 Jun 18 8:21 AM
Hello Prakash
Here is a slight improvement to Narendran's coding:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_FILE_SYSTEM_MANAGER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_file_system_manager.
TYPE-POOLS: truxs.
DATA:
gt_t001 TYPE STANDARD TABLE OF t001,
gt_text_data TYPE truxs_t_text_data,
gd_record LIKE LINE OF gt_text_data. " NOTE: max. 4096 chars !!!
" NOTE: sample .txt file with company code data (T001)
PARAMETERS:
p_path TYPE char512 DEFAULT 'X:usrsaptranstmpt001_data.txt'.
START-OF-SELECTION.
" (1) Create sample file on application server
SELECT * FROM t001 INTO TABLE gt_t001.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
* I_LINE_HEADER =
* I_FILENAME =
* I_APPL_KEEP = ' '
TABLES
i_tab_sap_data = gt_t001
CHANGING
i_tab_converted_data = gt_text_data " TAB-delimited
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" (2) Save data onto application server
OPEN DATASET p_path FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
LOOP AT gt_text_data INTO gd_record.
TRANSFER gd_record TO p_path.
ENDLOOP.
CLOSE DATASET p_path.
" (3) Read file from application server
OPEN DATASET p_path FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
CHECK ( syst-subrc = 0 ).
CLEAR: gd_record.
REFRESH: gt_text_data.
DO.
READ DATASET p_path INTO gd_record.
IF ( syst-subrc NE 0 ).
EXIT.
ENDIF.
APPEND gd_record TO gt_text_data.
ENDDO.
CLOSE DATASET p_path.
" (4) Convert TAB-delimited format to SAP data
REFRESH: gt_t001.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR =
cl_abap_char_utilities=>horizontal_tab
* I_LINE_HEADER =
i_tab_raw_data = gt_text_data
* I_FILENAME =
TABLES
i_tab_converted_data = gt_t001
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'T001'
TABLES
t_outtab = gt_t001
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
END-OF-SELECTION.Regards
Uwe