‎2007 Sep 12 5:45 AM
Hi Experts,
How to upload .CSV file separated by ',' from Application server to an internal table.
Invoice No,Cust No,Item Type,Invoice Date,days,Discount Amount,Gross Amount,Sales Amount,Customer Order No.,Group,Pay Terms
546162,3233,1,9/4/2007,11,26.79,5358.75,5358.75,11264,HRS,11
546163,2645,1,9/4/2007,11,3.07,305.25,305.25,10781,C,11
Actually I read some already answered posts. But still I have some doubts.
Can anybody please send me the code.
Thanks in Advance.
‎2007 Sep 12 5:52 AM
DATA:
text1(30) TYPE c VALUE 'Beethoven',
text2(3) TYPE c,
file(30) TYPE c VALUE '/usr/test.dat'.
<b>To download file on application server</b>
OPEN DATASET file IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
TRANSFER text1 TO file.
CLOSE DATASET file.
<b>To read file from application server</b>
OPEN DATASET file IN TEXT MODE FOR INPUT ENCODING DEFAULT.
READ DATASET file INTO text1 MAXIMUM LENGTH 4.
READ DATASET file INTO text2.
CLOSE DATASET file.
WRITE: / text1, / text2.
‎2007 Sep 12 5:52 AM
DATA:
text1(30) TYPE c VALUE 'Beethoven',
text2(3) TYPE c,
file(30) TYPE c VALUE '/usr/test.dat'.
<b>To download file on application server</b>
OPEN DATASET file IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
TRANSFER text1 TO file.
CLOSE DATASET file.
<b>To read file from application server</b>
OPEN DATASET file IN TEXT MODE FOR INPUT ENCODING DEFAULT.
READ DATASET file INTO text1 MAXIMUM LENGTH 4.
READ DATASET file INTO text2.
CLOSE DATASET file.
WRITE: / text1, / text2.
‎2007 Sep 12 6:03 AM
Hi,
Define your internal table as
begin of it_tab occurs 0,
vbelnr
delimeter1,
kunnr,
delimeter2,
item type,
delimeter3
...
...
end of it_tab.
Then open the file using below statement.
OPEN DATASET file IN TEXT MODE FOR INPUT ENCODING DEFAULT.
do.
READ DATASET file INTO it_tab.
If sy-subrc = 0.
append it_tab.
else.
exit.
endif.
enddo.
CLOSE DATASET file.
Satya.
‎2007 Sep 12 6:18 AM
Hi Priya,
Check this code
Yhe logic used here is as follows,
Get all the data into an internal table in the simple format ie: a row with one field contains an entire line
After getting the data, we split each line of the table on every occurrence of the delimiter (comma in your case)
Here, I have named the fields as field01, field02 etc, you could use your own names according to your requirement
parameters: p_file(512).
DATA : BEGIN OF ITAB OCCURS 0,
COL1(1024) TYPE C,
END OF ITAB,
WA_ITAB LIKE LINE OF ITAB.
DATA: BEGIN OF ITAB_2 OCCURS 0,
FIELD01(256),
FIELD02(256),
FIELD03(256),
FIELD04(256),
FIELD05(256),
FIELD06(256),
FIELD07(256),
FIELD08(256),
FIELD09(256),
FIELD10(256),
FIELD11(256),
FIELD12(256),
FIELD13(256),
FIELD14(256),
FIELD15(256),
FIELD16(256),
END OF ITAB_2.
DATA: WA_2 LIKE LINE OF ITAB_2.
OPEN DATASET p_FILE FOR INPUT IN TEXT MODE ENCODING NON-UNICODE.
IF SY-SUBRC = 8.
WRITE:/ 'File' , p_FILE , 'cannot be opened'.
LV_LEAVEPGM = 'X'.
EXIT.
ENDIF.
WHILE SY-SUBRC <> 4.
READ DATASET p_FILE INTO WA_ITAB.
APPEND WA_ITAB TO ITAB.
ENDWHILE.
CLOSE DATASET p_FILE.
LOOP AT ITAB INTO WA_ITAB.
SPLIT WA_ITAB-COL1 AT ',' " where comma is ur demiliter
INTO WA_2-FIELD01 WA_2-FIELD02 WA_2-FIELD03 WA_2-FIELD04
WA_2-FIELD05 WA_2-FIELD06 WA_2-FIELD07 WA_2-FIELD08 WA_2-FIELD09
WA_2-FIELD10 WA_2-FIELD11 WA_2-FIELD12 WA_2-FIELD13 WA_2-FIELD14
WA_2-FIELD15 WA_2-FIELD16.
APPEND WA_2 TO ITAB_2.
CLEAR WA_2.
ENDLOOP.Message was edited by:
Kris Donald