2010 Oct 06 11:41 PM
I use the open dataset for uploading CSV file in background but I get the values with "' and , characters.
What am I doing wrong? Can I get an example ?
Thanks,
Rebeka
2010 Oct 07 4:51 AM
Hi,
If I remember correctly, when using OPEN DATASET, the file name can not have spaces in the name. Try renaming your file removing spaces and retry.
For your code, you'll need to breakdown the CSV file by the delimiter.
This code makes an archive file while reading the main file.
OPEN DATASET filname IN TEXT MODE MESSAGE t_mesg.
IF sy-subrc NE 0.
MOVE 'X' TO t_error.
MESSAGE e100(z0) WITH 'Error reading file:' t_mesg.
EXIT.
ENDIF.
IF p_load = 'X'.
OPEN DATASET archfilname FOR OUTPUT IN TEXT MODE MESSAGE t_mesg.
IF sy-subrc NE 0.
MOVE 'X' TO t_error.
MESSAGE e100(z0) WITH 'Error opening achrive file:' t_mesg.
EXIT.
ENDIF.
ENDIF.
DO.
READ DATASET filname INTO my_rec.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF p_load = 'X'.
TRANSFER my_rec TO archfilname.
ENDIF.
SPLIT my_rec AT c_tab " Here my delimter was a tab change to ',' for comma
INTO in_rec-id
in_rec-fname
in_rec-lname
in_rec-addr
in_rec-apt
in_rec-city
in_rec-state
in_rec-zip
in_rec-branch
in_rec-phone1
in_rec-phone2
in_rec-phone3
in_rec-phone3_ext
in_rec-email
in_rec-hear
in_rec-prefcont
in_rec-ownland
in_rec-build
in_rec-ownhome
in_rec-get_promo
in_rec-cmt1
in_rec-subdate.
APPEND in_rec TO it_input.
ENDDO.
CLOSE DATASET filname.
IF p_load = 'X'.
CLOSE DATASET archfilname.
DELETE DATASET filname.
ENDIF.
ENDIF.
Refer This:
I use the open dataset for uploading CSV file in background but I get the values with "' and , characters.
What am I doing wrong? Can I get an example ?
Thanks,
Rebeka
2010 Oct 07 3:55 AM
Hi Rebeka,
While reading CSV file you have to SPLIT at , to get the values of each fields separately.
Regards,
Immanuel.
2010 Oct 07 4:48 AM
Hi Rebeka,
In the CSV file if a single field value contains ,(comma) as a character, then the CSV format puts " at the begining and at the end. You need to handle this by putting some logic. meand at the time of spliting the values u need to consider " for making it understand it is single field value.
Reagrds,
Amitava
2010 Oct 07 4:51 AM
Hi,
If I remember correctly, when using OPEN DATASET, the file name can not have spaces in the name. Try renaming your file removing spaces and retry.
For your code, you'll need to breakdown the CSV file by the delimiter.
This code makes an archive file while reading the main file.
OPEN DATASET filname IN TEXT MODE MESSAGE t_mesg.
IF sy-subrc NE 0.
MOVE 'X' TO t_error.
MESSAGE e100(z0) WITH 'Error reading file:' t_mesg.
EXIT.
ENDIF.
IF p_load = 'X'.
OPEN DATASET archfilname FOR OUTPUT IN TEXT MODE MESSAGE t_mesg.
IF sy-subrc NE 0.
MOVE 'X' TO t_error.
MESSAGE e100(z0) WITH 'Error opening achrive file:' t_mesg.
EXIT.
ENDIF.
ENDIF.
DO.
READ DATASET filname INTO my_rec.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF p_load = 'X'.
TRANSFER my_rec TO archfilname.
ENDIF.
SPLIT my_rec AT c_tab " Here my delimter was a tab change to ',' for comma
INTO in_rec-id
in_rec-fname
in_rec-lname
in_rec-addr
in_rec-apt
in_rec-city
in_rec-state
in_rec-zip
in_rec-branch
in_rec-phone1
in_rec-phone2
in_rec-phone3
in_rec-phone3_ext
in_rec-email
in_rec-hear
in_rec-prefcont
in_rec-ownland
in_rec-build
in_rec-ownhome
in_rec-get_promo
in_rec-cmt1
in_rec-subdate.
APPEND in_rec TO it_input.
ENDDO.
CLOSE DATASET filname.
IF p_load = 'X'.
CLOSE DATASET archfilname.
DELETE DATASET filname.
ENDIF.
ENDIF.
Refer This:
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |