2009 Aug 06 2:38 AM
i am having a flat file in the appliaction server and it is 350 characters length stored for each line.
i mean like purchase order,matner,material text, kunnr,customer address etc, this all will be 365 chars including spaces.
I have decalred the file path like
file(150) type c.
so in file i store the physical path.
Now i used the statement to read the data into by itab , which has all the fields of applicaion server file .
Do
Read dataset file into waitab.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND waitab TO itab.
CLEAR waitab.
ENDDO.
1)My doubt is that
experts
i am simply using Read dataset file into waitab. and i did not mentioned the lenght of the file anywhere in the program? Will the system move all the 365 chars into waitab?
Or do i need to mention the lenght of the file?
2)Suppose my file is like this
1212222 2283838 2839293 383839283 38e439 3u39393 3839839 383993 2837383 38739378 3u873983
Now my itab will be
filed1(10),file2(7),field3(8),field4(7),filed5(8).
so in this case the first 10 chars of the file will be placed in field1,
next 7chars will be placed in field2, is it including spaces?
Here my file lenght is more than the itab, in this case what will happen?Beacuse my need is to have file first line into one record of itab , second line into another record , etc?
i am having a flat file in the appliaction server and it is 350 characters length stored for each line.
i mean like purchase order,matner,material text, kunnr,customer address etc, this all will be 365 chars including spaces.
I have decalred the file path like
file(150) type c.
so in file i store the physical path.
Now i used the statement to read the data into by itab , which has all the fields of applicaion server file .
Do
Read dataset file into waitab.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND waitab TO itab.
CLEAR waitab.
ENDDO.
1)My doubt is that
experts
i am simply using Read dataset file into waitab. and i did not mentioned the lenght of the file anywhere in the program? Will the system move all the 365 chars into waitab?
Or do i need to mention the lenght of the file?
2)Suppose my file is like this
1212222 2283838 2839293 383839283 38e439 3u39393 3839839 383993 2837383 38739378 3u873983
Now my itab will be
filed1(10),file2(7),field3(8),field4(7),filed5(8).
so in this case the first 10 chars of the file will be placed in field1,
next 7chars will be placed in field2, is it including spaces?
Here my file lenght is more than the itab, in this case what will happen?Beacuse my need is to have file first line into one record of itab , second line into another record , etc?
2009 Aug 06 3:39 AM
Hi,
<li>Try this way. This sample program is used to download TAB delimited file from application server.
<li>Let me know if you have any problem in doing.
Thanks
Venkat.O
REPORT ztest_program.
DATA: BEGIN OF it_t001 OCCURS 0,
bukrs TYPE t001-bukrs,
butxt TYPE t001-butxt,
ort01 TYPE t001-ort01,
land1 TYPE t001-land1,
waers TYPE t001-waers,
spras TYPE t001-spras,
ktopl TYPE t001-ktopl,
waabw TYPE t001-waabw,
END OF it_t001.
DATA: BEGIN OF it_app_file OCCURS 0,
data TYPE string,
END OF it_app_file.
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONSTANTS:hor_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
PARAMETERS : p_file(150) TYPE c.
START-OF-SELECTION.
"Open file for reading
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
DO.
READ DATASET p_file INTO it_app_file-data.
IF it_app_file IS INITIAL.
"If file ends or if does not have data
EXIT.
ELSE.
"Splitting TAB delimited data into into internal table
SPLIT it_app_file-data AT hor_tab INTO it_t001-bukrs
it_t001-butxt
it_t001-ort01
it_t001-land1
it_t001-waers
it_t001-spras
it_t001-ktopl
it_t001-waabw.
APPEND it_t001.
CLEAR it_t001.
ENDIF.
ENDDO.
ENDIF.
"close file
CLOSE DATASET p_file.
LOOP AT it_t001.
WRITE:/ it_t001-bukrs,
it_t001-butxt,
it_t001-ort01,
it_t001-land1,
it_t001-waers,
it_t001-spras,
it_t001-ktopl,
it_t001-waabw.
ENDLOOP.
2009 Aug 06 7:01 AM
2009 Aug 06 7:05 AM
Just follow the suggestion given by venkat.
Its looks fine for ur requirement.
U need to split file at delimiter and since ur field values are tab limited u need to use cl_abap_char_utilities=>horizantal_tab.
2009 Aug 06 8:29 AM
Hi,
Refer to the given code:
DATA: lv_app_server_file TYPE string.
lv_app_server_file = pa_afile.
To read file from Application server
OPEN DATASET lv_app_server_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET lv_app_server_file INTO wa_file_data.
IF sy-subrc = 0.
APPEND wa_file_data TO gi_file_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_app_server_file.
DATA: lv_file_separator TYPE c.
lv_file_separator = cl_abap_char_utilities=>horizontal_tab.
To upload file in other formats(CSV, Tab delimited etc)
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
i_field_seperator = lv_file_separator
i_tab_raw_data = gi_file_data
TABLES
i_tab_converted_data = gi_zhralcon_file
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.
Hope it helps.
Regards,
Rajesh Kumar
2009 Aug 07 3:13 AM
1)My doubt is that
experts
i am simply using Read dataset file into waitab. and i did not mentioned the lenght of the file anywhere in the program? Will the system move all the 365 chars into waitab?
Or do i need to mention the lenght of the file?
2)Suppose my file is like this
1212222 2283838 2839293 383839283 38e439 3u39393 3839839 383993 2837383 38739378 3u873983
Now my itab will be
filed1(10),file2(7),field3(8),field4(7),filed5(8).
so in this case the first 10 chars of the file will be placed in field1,
next 7chars will be placed in field2, is it including spaces?
Here my file lenght is more than the itab, in this case what will happen?Beacuse my need is to have file first line into one record of itab , second line into another record , etc?
2009 Aug 07 4:12 AM
no need to mention any length... it will pick the first line in the data set based on the linefeed and carriage return it will recognise that the line is ended and pick the first row of data the whole row...
better u declare you wa type string.... rather than wa(150) type c.
2009 Aug 07 6:06 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |