Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

insert records to data base table from char format into decimal fields

Former Member
0 Likes
1,225

Hi,

I need to insert records into a custom table from an internal table that has all the data in the character format. Few fields in the custom table are in decimal format. It is giving an Unciode not convertible error. How to fix this...

I am using field symbols..

tables: ZA.

field symbols: <fs_table> type any.

I tried declaring <fs_table> type standard table it threw me an error.

i_wsmerg is an internal table with the same fields but data all in character format.

the data is in

loop at i_wsmerg.

assign i_wsmerg to <fs_table> CASTING TYPE ZA.

modify ZA from <fs_table>.

commit work.

endloop.

any thoughts how to fix this?

thanks,

VG

9 REPLIES 9
Read only

Former Member
0 Likes
1,115

Internal table should have same format as database table. If not, you should move records from one workarea to other with proper format before update database table.

DATA:
  it_za TYPE STANDARD TABLE OF za,
  wa_za LIKE LINES OF it_za.

LOOP AT i_wsmerg.
* Move fields from i_wsmerg to wa_za.  Do tranformations if you need.
  wa_za = it_wsmerg.
  APPEND wa_za TO it_za.
ENDLOOP.

MODIFY za FROM TABLE it_za.
COMMIT WORK.

Hope it helps.

Read only

0 Likes
1,115

Can I insert the record at one go by using some thing like CASTING operation. I got an error 'Conversion over flow' while reading the data from the work area(character) into the internal table (decimal) format.

The number of records are high, I was trying to achieve this using field symbols, but the CASTINGoperation to convert the character to decimal did not work.

Any thoughts?

Thanks,

VG

Read only

Former Member
0 Likes
1,115

Hi,

You can avoid field symbols in this case.

data: ls_za type za.

loop at i_wsmerg.

write: i_wsmerg-field1 to ls_za-field1,

i_wsmerg-field2 to ls_za-field2,

i_wsmerg-fieldn to ls_za-fieldn.

modify ZA from ls_za.

commit work.

endloop.

This may help you.

Goodluck.

Read only

deepak_dhamat
Active Contributor
0 Likes
1,115

hi ,

if you have fields in character format and want to push that data in decimal fields

that is in my sql right .

then do this

data : quantity(13) type c value '1300.00',

DATA : qty(13) TYPE n .

DATA qty1 TYPE p DECIMALS 3 .

qty = quantity .

qty1 = qty .

Regards

Deepak.

Read only

0 Likes
1,115

Hi,

Thanks for the response. Both did not work.

VG

Read only

Former Member
0 Likes
1,115

I usually do a little differently....I handle fields at the index level within each row.

While I have a field symbol of type any, I also have some generic variables like lv_p(15) type p decimals 2, lv_i type i, etc.

Once the <field-symbol> for a field is assigned, the set the LV_ variable equal to <field-symbol>. compute into other variables if conversion is required, then assign <field-symbol> = the lv_ variable last used.... with casting type whatever. The original <field-symbol> pointer now points to the data in the correct format.... You can then proceed with putting the data pointed to into the right column in your structure....

This has always worked for me when using the assign component sy-index of structure <name> to <field-symbol> approach, utilized inside an internal table loop.

Read only

0 Likes
1,115

Hi,

Thanks for the response. I might have to change the logic here. it worked when I read the character data into a variable of type p . but the problem is..

if I have avalue var1 = '00176'. and I read the data into decimal variable it reads '176.00' but I want '1.76'.

similarly, I have another var2 = '0123478' if I read the data into decimal variable it has to read '01234.78'

I have five fields withing the internal table to change their values to decimal. Is there an FM for this that would speed up the process?

Any thoughts? Please advise.

VG

Read only

0 Likes
1,115

Divide the variable by 100 after putting value into it.... like

lv_var1 = lv_var1 / 100.

No real benefit from calling FM....I use the same local variable over and over again, so long as same data type....just assign back to <fs> and then put into right column in your structure, before putting the next value to be converted into the variable. Or if you're processing a work area at a time...use 5 fields as it would appear you're doing.

Read only

0 Likes
1,115

This message was moderated.