08-28-2009 12:02 PM
Dear ABAP developpers,
I have seen that a commonly used function on our current R3 (4.6c), SAP_CONVERT_TO_CSV_FORMAT, is marked as obsolete in ECC6. As we have plans for the upgrade to ECC6, I would like to know if anybody has an alternative for this function module?
kind regards,
Erik Groothof
10-13-2009 10:40 AM
part 3 final part.
when lc_float.
call function 'FLTP_CHAR_CONVERSION'
exporting
input = <lfs_field>
importing
flstr = lw_char.
assign lw_char to <lfs_field>.
when lc_hex.
assign component lw_struc_index
of structure <lfs_dref>
to <lfs_char> casting.
write <lfs_char> to lw_char.
assign lw_char to <lfs_field>.
endcase.
if <lfs_field> co lc_number.
condense <lfs_field> no-gaps.
else.
condense <lfs_field>.
endif.
case lw_first.
when abap_true.
lw_string = <lfs_field>.
when others.
concatenate lw_string
uw_separator
<lfs_field>
into lw_string.
endcase.
clear lw_first.
add 1 to lw_struc_index.
enddo.
append lw_string to rt_table_out.
clear: lw_string,
lw_first.
endloop.
endmethod.
08-28-2009 12:55 PM
Hi Erik,
Sap has not provide any alternative FM for this FM SAP_CONVERT_TO_CSV_FORMAT
till now.
See if you can do it by other way.
Regards,
Vijay
08-28-2009 1:01 PM
Hello Vijay,
Thanks for your reply but my basic question is if anybody has found an alternative way for using the functionality of this FM which is not available in ECC6.
If so, I can use his information as a workaround for not having this FM in ECC6.
regards,
Erik Groothof
08-28-2009 1:09 PM
Hi,
Well you can use GUI_DOWNLOAD. This can be considered as a standard download FM for any kind of file in ECC 6
Regards,
Vik
08-28-2009 1:15 PM
Dear Vik,
thanks for your anser but mabye you misunderstood my question.
The FM Gui_download is not the same as the FM SAP_CONVERT_TO_CSV_FORMAT.
The FM SAP_CONVERT_TO_CSV_FORMAT converts any internal table into a CSV formatted output table. This fucntion module is currently available in our SAP R3 4.7 system but will not be available in ECC6. I am looking for someone that has encountered the same problem and I am interested in his solution or workaround for this.
kind regards,
Erik Groothof
08-28-2009 1:39 PM
Hello Erik,
What would you be doing with a CSV formatted output table? I assumed you will be downloading the internal table as a CSV converted file, Which is the main function of SAP_CONVERT_TO_CSV_FORMAT. The same thing can be done using GUI_DOWNLOAD too by using the WRITE_FIELD_SEPARATOR parameter. Am not sure if this would help you but this is what i meant.
Regards,
Vik
08-28-2009 1:49 PM
Hello Vik,
Thanks for your reply.
good thinking but this is my problem: I need an internal table to be converted into CSV format and then pass this CSV internal table to an e-mail program. This e-mail program will add the CSV internal table as an attachment to the mail. This process is done in background and the GUI_DOWNLOAD needs to be executed on foreground.
kind regards,
Erik
08-28-2009 2:00 PM
Hello Erik ,
Well in that case am not sure if there is any alternate FM to convert a internal table to CSV formatted table.
Though this can be done manually , which can be considered as a workaround
data: begin of itab occurs 0,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of itab.
data: begin of iout occurs 0,
rec(1000) type c,
end of iout.
start-of-selection.
* Build the ITAB
itab-fld1 = 'A'.
itab-fld2 = 'B'.
itab-fld3 = 'C'.
append itab.
itab-fld1 = 'D'.
itab-fld2 = 'E'.
itab-fld3 = 'F'.
append itab.
itab-fld1 = 'G'.
itab-fld2 = 'H'.
itab-fld3 = 'I'.
append itab.
* Build the output internal table from ITAB Concatenate all fields into IOUT-REC
loop at itab.
concatenate itab-fld1 itab-fld2 itab-fld3 into iout-rec
separated by ','.
condense iout-rec no-gaps.
append iout.
endloop.
Now the internal table iout can be use as a attachment for sending the E-mail
Regards,
Vik
08-28-2009 2:18 PM
Hi Vik,
thanks again. This is usefull but the FM SAP_CONVERT_TO_CSV could handle any internal table and that makes it a generic solution.
With your sample I will need to know the exact structure of the table and need so create a solution for every implementation where I used this FM, where previously different internal tables were handled by the FM.
maybe I can create this logic using class cl_abap_typedescr and cl_abap_structdescr to determine dynamically the fields in an internal table and then process them with your solution.
but I was just hoping that all of this work would be ready and done in a class/method or FM like all of this work is already done in FM SAP_CONVERT_TO_CSV_FORMAT .
any way, thanks for your comments,
regards,
Erik
Edited by: Erik Groothof on Sep 9, 2009 3:09 PM
09-09-2009 2:47 PM
"Hi all",
for the ones that are interested in a similair function like SAP_CONVERT_TO_CSV_FORMAT I created the following methods:
due to limitation of 2500 characters, I posted this solution in multiple posts
in your program:
data:
ref_csv type ref to zcl_csv.
create object lref_csv.
lt_table_out = lref_csv->convert_to_csv( iw_seperator = zcl_contract_position=>c_csv_sep
it_tab_in = it_table_in ).
Create a class zcl_csv an put the following methods in it.
The parameters are defined as follows:
iw_separator type char1 (optional default value ';')
it_tab_in type table
it_tab_out type ztt_text4096 (a table type based on line type text4096)
method CONVERT_TO_CSV .
DATA:
lw_fields_table TYPE int2,
lref_typedescr TYPE REF TO cl_abap_typedescr,
lref_structdescr TYPE REF TO cl_abap_structdescr,
ls_structure TYPE REF TO data.
FIELD-SYMBOLS: <lfs_table> TYPE ANY TABLE,
<lfs_struct> TYPE ANY.
* Create a dynamic structure based on the passed table.
ASSIGN it_tab_in TO <lfs_table>.
CREATE DATA ls_structure LIKE LINE OF <lfs_table>.
ASSIGN ls_structure->* TO <lfs_struct>.
* describe the structure by data
lref_typedescr = cl_abap_typedescr=>describe_by_data( <lfs_struct> ) .
* Downcasting ! to get the fields of the structure
lref_structdescr ?= lref_typedescr.
* get the number of fields of the structure
DESCRIBE TABLE lref_structdescr->components LINES lw_fields_table.
* get the converted CSV file back
it_tab_out = me->convert_2_csv_table( ut_table_in = it_tab_in
uw_separator = iw_seperator
uw_fields = lw_fields_table
us_struct = <lfs_struct> ).
The parameters for this method can be found in the calling method CONVERT_TO_CSV (above)
endmethod.
Edited by: Erik Groothof on Oct 13, 2009 11:35 AM
Edited by: Erik Groothof on Oct 13, 2009 11:43 AM
Edited by: Erik Groothof on Dec 14, 2009 9:02 AM
10-13-2009 10:38 AM
part 2 of the methods
method CONVERT_2_CSV_TABLE .
* data type logic copied from fm SAP_CONVERT_TO_TEX_FORMAT (which is not available
* in ECC6 any more.)
constants:
lc_colon: type char1 value ':',
lc_integer TYPE char1 VALUE 's',
lc_packed type char1 value 'P',
lc_date type char1 value 'D',
lc_time type char1 value 'T',
lc_float type char1 value 'F',
lc_hex type char1 value 'X',
lc_number type char12 value '1234567890 '.
data:
lw_struc_index type int2,
lref_field type ref to data,
ls_struct type ref to data,
lw_first type char1,
ls_time type zss_time,
lw_char type char30,
lw_type type char1,
ls_char4096 type text4096,
lw_string type string.
field-symbols:
<lfs_field> type any,
<lfs_char> type c,
<lfs_dref> type any.
* create a reference to the same type of structure that is passed in this form
get reference of us_struct into ls_struct.
* assign this structure to be able to loop over the passed table
assign ls_struct->* to <lfs_dref>.
* loop at the table and convert every single field
loop at ut_table_in assigning <lfs_dref>.
lw_first = abap_true.
lw_struc_index = 1.
* for the number of fields in the table, process them
do uw_fields times.
assign component lw_struc_index
of structure <lfs_dref>
to <lfs_field>.
if sy-subrc is not initial.
exit.
endif.
describe field <lfs_field> type lw_type.
* some data types need special processing
case lw_type.
when lc_packed or lc_integer.
write <lfs_field> to lw_char.
assign lw_char to <lfs_field>.
when lc_time.
ls_time = <lfs_field>.
concatenate ls_time-hour
lc_colon
ls_time-min
lc_colon
ls_time-sec
into lw_char.
assign lw_char to <lfs_field>.
when lc_date.
call function 'CONVERT_DATE_TO_EXTERNAL'
exporting
date_internal = <lfs_field>
importing
date_external = lw_char.
assign lw_char to <lfs_field>.
10-13-2009 10:40 AM
part 3 final part.
when lc_float.
call function 'FLTP_CHAR_CONVERSION'
exporting
input = <lfs_field>
importing
flstr = lw_char.
assign lw_char to <lfs_field>.
when lc_hex.
assign component lw_struc_index
of structure <lfs_dref>
to <lfs_char> casting.
write <lfs_char> to lw_char.
assign lw_char to <lfs_field>.
endcase.
if <lfs_field> co lc_number.
condense <lfs_field> no-gaps.
else.
condense <lfs_field>.
endif.
case lw_first.
when abap_true.
lw_string = <lfs_field>.
when others.
concatenate lw_string
uw_separator
<lfs_field>
into lw_string.
endcase.
clear lw_first.
add 1 to lw_struc_index.
enddo.
append lw_string to rt_table_out.
clear: lw_string,
lw_first.
endloop.
endmethod.
12-07-2009 6:19 PM
Hi well done!
but could you please explain whats:
1. in the structure: zss_time
2. in the class: zcl_contract_position
3. what are the exact parameters for CONVERT_TO_CSV - I guess you forgot the seperator (?)
4. what are the exact parameters for CONVERT_2_CSV_TABLE
I tried it, but cant figure it out .
ty
Andreas
Edited by: Andreas Profitlich on Dec 7, 2009 7:46 PM
12-14-2009 8:25 AM
Hi Andreas
I was away for some holliday but here is my feedback on your remarks
zcl_contract_position=>c_csv_sep is just a reference to a constant value. It's the separator value and It contains the value ';'
ZSS_TIME is a structure with 3 fields
1) hour (num2)
2) min (num2)
3) sec (num2)
The param. for Convert_to_CSV are:
1) iw_separator - type char01 - default ';'
2) it_tab_in - type table -
3) it_tab_out - type ZTT_TEXT4096 ( this is a user define table type to data element TEXT4096 )
the param for Convert_2_csv_table
1) ut_table_in - type any table
2) uw_separator - type any
3) uw_fields - type int2
4) us_struct - type any
5) rt_table_out - type ZTT_TEXT4096 ( this is a user define table type to data element TEXT4096 )