‎2010 Nov 03 2:35 PM
Hi,
I am having an issue in converting the non char data like decimal into character. Here is my code In the output I see '#' signs where I am supoose to get certain amount values in the decimal format. I require it because I need to download the data into a file. Any thoughts? Rest of the code looks fine. Thanks in advance,
VG
field-symbols: <fs_table> type standard table,
<fs_wa>,
<fs_string>.
CREATE DATA v_dref Type table of (v_tabname).
assign v_dref->* TO <fs_table>.
select * from (v_tabname) into table <fs_table>.
loop at <fs_table> assigning <fs_wa>.
assign component sy-index of structure <fs_wa> to <fs_string> casting type c.
if sy-subrc = 0.
write:/ <fs_string>.
else.
write: <fs_string>.
endif.
endloop.
output: 10000100000001019999123120090101 ############0001
‎2010 Nov 03 4:52 PM
Hi vinu,
here is the working code.
For every field in the table I create a character field of the defined length. The just move the contents to it and do a WRITE.
FORM tabout .
DATA:
lv_len TYPE sy-linsz,
lr_data TYPE REF TO data.
FIELD-SYMBOLS:
<fs_table> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY,
<fs_string> TYPE ANY,
<any> TYPE ANY.
CREATE DATA lr_data TYPE TABLE OF (p_table).
ASSIGN lr_data->* TO <fs_table>.
SELECT * FROM (p_table) INTO TABLE <fs_table> UP TO 20 ROWS.
LOOP AT <fs_table> ASSIGNING <fs_wa>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <any>.
IF sy-subrc = 0.
DESCRIBE FIELD <any> LENGTH lv_len IN BYTE MODE.
CREATE DATA lr_data TYPE c LENGTH lv_len.
ASSIGN lr_data->* TO <fs_string>.
<fs_string> = <any>.
IF sy-index = 1.
WRITE:/ <fs_string>.
ELSE.
WRITE: <fs_string>.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. " TABOUTRegards,
Clemens
‎2010 Nov 03 3:01 PM
HI,
What do you mean decimal format? 3,453 ? Or float 3,210+E2 ..
Anyway you should try to use TYPE NUMC INSTEAD OF C for Numerical Char...
Or try this For the conversion (passing values throughout field-symbols)
DATA : V_FLOAT TYPE F VALUE '2456.5678912',
V_CHAR(25),
P10_4(10) TYPE P DECIMALS 8.
CALL FUNCTION 'CEVA_CONVERT_FLOAT_TO_CHAR'
EXPORTING
FLOAT_IMP = V_FLOAT
FORMAT_IMP = P10_4
ROUND_IMP = ' '
IMPORTING
CHAR_EXP = V_CHAR.
Hope to help, bye
‎2010 Nov 03 3:22 PM
Hi,
Thanks for the response. I tried Numeric type 'N' too. It gave the same results. Yes it is decimal not float. I cannot use the FM because I am reading all the table layout dynamically. At the run time, I do not know which field has a dceimal format? Since I am using field symbols. I am stuck here. Any thoughts or leads shall be helpful?
VG
‎2010 Nov 03 3:37 PM
Is this your actual code ????
loop at <fs_table> assigning <fs_wa>.
assign component sy-index of
structure <fs_wa> to <fs_string>. "sy-index or sy-tabix ??
if sy-subrc = 0.
write:/ <fs_string>.
endif.
endloop.
‎2010 Nov 03 3:40 PM
Hi
...Can't you determine type using DESCRIBE FIELD <W_FIELD> TYPE c_type? and moving in this way?
Probably it works....
‎2010 Nov 03 4:52 PM
Hi vinu,
here is the working code.
For every field in the table I create a character field of the defined length. The just move the contents to it and do a WRITE.
FORM tabout .
DATA:
lv_len TYPE sy-linsz,
lr_data TYPE REF TO data.
FIELD-SYMBOLS:
<fs_table> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY,
<fs_string> TYPE ANY,
<any> TYPE ANY.
CREATE DATA lr_data TYPE TABLE OF (p_table).
ASSIGN lr_data->* TO <fs_table>.
SELECT * FROM (p_table) INTO TABLE <fs_table> UP TO 20 ROWS.
LOOP AT <fs_table> ASSIGNING <fs_wa>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <any>.
IF sy-subrc = 0.
DESCRIBE FIELD <any> LENGTH lv_len IN BYTE MODE.
CREATE DATA lr_data TYPE c LENGTH lv_len.
ASSIGN lr_data->* TO <fs_string>.
<fs_string> = <any>.
IF sy-index = 1.
WRITE:/ <fs_string>.
ELSE.
WRITE: <fs_string>.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. " TABOUTRegards,
Clemens
‎2010 Nov 03 5:21 PM
Hi Clemens,
I tried your code, getting an error . at
It is the same incompatible issue failing to convert the decimal data into character.
<fs_string> = <fs_any>. UC_OBJECTS_NOT_CONVERTIBLE
Please advise.
Thanks,
VG
‎2010 Nov 03 5:32 PM
Hi Vinu,
Are you sure you used exactly my code?
I tried with database table EKBE which definitely has decimal values, got output like
110 4500000017 00010 00 1 2009 5000000039 0001 E 101 20091130 0.001 0.001 0.01 1.20 EU4What is your table?
Regards,
Clemens
‎2010 Nov 03 5:45 PM
@-Clemens - I tried your code , some problems with decimals values , adds a * in front.
@Vinu - Just some rough modification to the code written by Clemens
PARAMETERS:p_table TYPE tabname.
DATA:wf_maximum TYPE i,
wf_total_fields TYPE i,
wi_count TYPE i,
wf_ltype TYPE c,
wf_length TYPE i,
wi_index TYPE i.
DATA:i_comp TYPE cl_abap_structdescr=>component_table,
wa_comp LIKE LINE OF i_comp,
wa_fields TYPE abap_compdescr.
DATA:lr_data TYPE REF TO data,
lr_line TYPE REF TO data,
wf_data_str TYPE REF TO data,
wf_type_struct TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS:<fs_table> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY,
<fs_line> TYPE ANY,
<fs_field_s> TYPE ANY.
CREATE DATA lr_data TYPE TABLE OF (p_table).
ASSIGN lr_data->* TO <fs_table>.
CREATE DATA lr_line LIKE LINE OF <fs_table>.
ASSIGN lr_line->* TO <fs_line>.
SELECT * FROM (p_table) INTO TABLE <fs_table> UP TO 20 ROWS.
CLEAR:wf_ltype,wi_count.
DESCRIBE FIELD <fs_line> TYPE wf_ltype
COMPONENTS wi_count.
LOOP AT <fs_table> ASSIGNING <fs_wa>.
AT FIRST.
wf_maximum = 0.
wf_total_fields = wi_count.
WHILE wi_count GT 0.
wi_index = sy-index.
ASSIGN COMPONENT wi_index OF STRUCTURE <fs_wa> TO <fs_field_s>.
IF sy-subrc EQ 0.
DESCRIBE FIELD <fs_field_s> TYPE wf_ltype
OUTPUT-LENGTH wf_length.
IF wf_maximum LT wf_length.
wf_maximum = wf_length.
ENDIF.
ENDIF.
wi_count = wi_count - 1.
ENDWHILE.
CLEAR:wa_comp,i_comp[].
wa_comp-name = 'FIELD'(005).
wa_comp-type ?= cl_abap_elemdescr=>get_c( wf_maximum ).
APPEND wa_comp TO i_comp.
TRY.
wf_type_struct =
cl_abap_structdescr=>create( p_components = i_comp ).
CATCH cx_sy_struct_creation.
ENDTRY.
CREATE DATA: wf_data_str TYPE HANDLE wf_type_struct.
ASSIGN:wf_data_str->* TO <fs_line>.
ENDAT.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <fs_line>.
IF sy-subrc = 0.
WRITE <fs_line>.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
‎2010 Nov 03 6:20 PM
Hi Keshav,
what I do is create a character field with internal length of the respective structure field and move the structures field content to the character field. This will not use any built-in output conversion.
You do a lot of mumbojumbo but nothing more than a simple write on each field. This will use all conversion exits.
I do not get the conversion error, c ode not complexified but simplified:
FORM tabout .
DATA:
lv_string type string,
lr_data TYPE REF TO data.
FIELD-SYMBOLS:
<fs_table> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY,
<fs_string> TYPE ANY,
<any> TYPE ANY.
CREATE DATA lr_data TYPE TABLE OF (p_table).
ASSIGN lr_data->* TO <fs_table>.
SELECT * FROM (p_table) INTO TABLE <fs_table> UP TO 20 ROWS.
LOOP AT <fs_table> ASSIGNING <fs_wa>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <any>.
IF sy-subrc = 0.
lv_string = <any>.
IF sy-index = 1.
WRITE: lv_string .
ELSE.
WRITE lv_string .
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. " TABOUT
So again the question: Where does what kind of error occur with this code.
Regard,
Clemens
‎2010 Nov 03 6:24 PM
Hi Clemens,
That works like a charm .
As said you previous code had a problem .
<fs_string> = <any>. "while moving a large value it adds a * to it .
‎2010 Nov 03 6:34 PM
Thanks a lot guys. I need to get the data in one line something like this...because I need to download the data into a text file Any thoughts?
output: 10000100000001019999123120090101 ############0001
Thanks once again,
VG
‎2010 Nov 03 6:41 PM
Yes, Keshav,
I tried to give a determined fixed length to the output. This will not work with numerical type P or F data: P means we have Packed decimals, 2 decimals per byte (of defined length) plus half a byte for the sign. F is stored as pure binary, don't know the details.
Finally I decided just to move to string (implicit conversion should work for all simple types, that means all field types available in the used database.
But now we will not have constant line lengths. We could use the defined output length as a constant and (theoretical) maximum. But this may lead top confusion if some kind of (weird) output conversion will make the output (and the defined output length) shorter than the field's content.
In most cases we will waste space; most fields have more output length than internal length.
Anyway, nice thread to see how simple or how complex some tasks may be.
Regards,
Clemens
‎2010 Nov 03 7:19 PM
Hi Clemens,
We could use the defined output length as a constant and (theoretical) maximum. But this may lead top confusion if some kind of (weird) output conversion will make the output (and the defined output length) shorter than the field's content.
In most cases we will waste space; most fields have more output length than internal length.
thanks for your concerns.
keshav
‎2010 Nov 03 7:21 PM
Hi,
Thanks a lot guys. My purpose is half done. I need to donwload the data into a text file. Hence I am trying to convert the data into character. It is not happening. how to do it?
I tried something like this...
data:v_char(2550) type c.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <fs_line>.
IF sy-subrc = 0.
condense v_char.
concatenate v_char <fs_line> into v_char.
WRITE:/ <fs_line>.
Thanks in advance,
VG
‎2010 Nov 03 8:28 PM
thanks for the help. I have rewarded the points accordingly.
VG