‎2007 Jul 19 5:45 AM
Hi experts....
I've to do a program to convert an internal table into CSV format dynamically thru a function module......
Could anyone help me on this.....if so,pls post in detail and will be appreciated if i can get any sample codes also.....
Its urgent....
thanks n regards
sankar
‎2007 Jul 19 6:16 AM
try with this code ......
and write statements accordingly .......
OPEN DATASET v_filename FOR OUTPUT IN TEXT MODE
ENCODING NON-UNICODE MESSAGE v_msg_txt.
IF sy-subrc = 0.
LOOP AT vit_itab2.
CLEAR : vit_itab2_wa , vit_itab3.
MOVE-CORRESPONDING vit_itab2 TO vit_itab2_wa.
CONCATENATE
vit_itab2_wa-vbeln
vit_itab2_wa-posnr
vit_itab2_wa-matnr
INTO vit_itab3 SEPARATED BY ','.
TRANSFER vit_itab3 TO v_filename.
ENDLOOP.
ENDIF.
CLOSE DATASET v_filename.
Prem
‎2007 Jul 19 5:50 AM
Hi
CSV means a text file, where the columns are separated by a character ";".
The best way to change a list to CSV is to create an internal table in the ABAP, with the structure of the required CSV.
You have to fill in this internal table.
Because you are running the program in background, you can't download the file, the best would be to store the file on the server in a separated directory.
1ST capture file from application server to internal table using open dataset and close data set.
Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma separated format then download this internal table using the Function Module GUI_DOWNLOAD.
EX-
Coding -
TYPE-POOLS: truxs.
TYPES:
BEGIN OF ty_Line,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF ty_Line.
TYPES: ty_Lines TYPE STANDARD TABLE of ty_Line WITH DEFAULT KEY.
DATA: itab TYPE ty_Lines.
DATA: itab1 TYPE truxs_t_text_data.
SELECT
vbeln
posnr
UP TO 10 ROWS
FROM vbap
INTO TABLE itab.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = itab
CHANGING
i_tab_converted_data = itab1
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 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\TEMP\test.txt'
TABLES
data_tab = itab1
EXCEPTIONS
OTHERS = 1.
Thanks,
Reward If Helpful.
‎2007 Jul 19 6:16 AM
try with this code ......
and write statements accordingly .......
OPEN DATASET v_filename FOR OUTPUT IN TEXT MODE
ENCODING NON-UNICODE MESSAGE v_msg_txt.
IF sy-subrc = 0.
LOOP AT vit_itab2.
CLEAR : vit_itab2_wa , vit_itab3.
MOVE-CORRESPONDING vit_itab2 TO vit_itab2_wa.
CONCATENATE
vit_itab2_wa-vbeln
vit_itab2_wa-posnr
vit_itab2_wa-matnr
INTO vit_itab3 SEPARATED BY ','.
TRANSFER vit_itab3 TO v_filename.
ENDLOOP.
ENDIF.
CLOSE DATASET v_filename.
Prem
‎2007 Jul 19 10:12 AM
Hi Prem,
I didnt get it clearly...could u post it elaborately......with full code.....so that i can go for it and will make change as per my convenient......
thanks
sankar
‎2007 Jul 19 10:15 AM
hi,,
isnt ur query answered yet.. please clarify what else is needed
regards
dinesh
‎2007 Jul 19 10:33 AM
Hi dinesh....
im not getting u what's ur question????...i've replied to prem for more help against his reply msg....and if ur doubt is on my question(1st)...then pls go thru it again and c the replies did by prem and one more guy....hope then u'll get it some solution or relax....
bye
sankar
‎2007 Jul 23 10:46 AM
HI DINESH.....
IM REALLY SORRY ABT THE THING I REPLIED...SINCE I WAS BLINDLY AT THE TIME AND DIDNT NOTICE UR NAME ABOVE AT THE MOMENT.....
HOPE U UNDERSTAND....
REGARDS
SANKAR