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: 

Create data dynamic issue

Former Member
0 Kudos
198

Hello

I'm creating field types dynamically using the following code

CREATE DATA lv_field_type TYPE (ls_abap_field_desc-type) LENGTH ls_prop-length.

But when I add the decimals like this :

CREATE DATA lv_field_type TYPE (ls_abap_field_desc-type) LENGTH ls_prop-length 
            DECIMALS ls_prop-dec.

i get the following error :

+You cannot use the "DECIMALS" addition with a dynamic type declaration. +

Use a static type declaration with the type "P" instead.

So I add the following line

CREATE DATA lv_field_type TYPE p LENGTH ls_prop-length  DECIMALS ls_prop-dec.

But the issue is that I'm not sure if type P is cover all the case's of decimal fields types.

Any idea how to overcome this issue?

Thanks,

Joy

Edited by: Joy Stpr on Aug 9, 2011 5:27 PM

1 ACCEPTED SOLUTION

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
152

Hello Joy,

Decimal field types you see in the ABAP dictionary for e.g., DEC, CURR, QUAN are derived from packed numbers.

For e.g., let us consider the data element WRBTR(CURR 13,2). So it is equivalent to TYPE p LENGTH (13+1)/2 = 7 DECIMALS 2.

The value range of TYPE p LENGTH 7 DECIMALS 2 is (9,999,999,999.99 to 9,999,999,999.99).

So we have 12 digits * 0.5 byte = 6 bytes + 0.5 byte for decimal p0int + 0.5 byte for sign(+/-) = 7 bytes. I hope you're clear

NB: In packed numbers 1 digit occupies 4 bits = 0.5 bytes.

I'll suggest you read the SAP documentation on Predefined Data Types for further info.

BR,

Suhas

PS: SAP does not recommend DEC, QUAN, CURR fields to have "even" lengths.

Edited by: Suhas Saha on Aug 9, 2011 9:56 PM

4 REPLIES 4

former_member209703
Active Contributor
0 Kudos
152

It depends on what your requirements are, but you have to keep in mind that the maximu length of P data type is 16 btyes.

It should be enough for basic calculations, distances, amounts and so forth...

If precision is required then you''l have to go for the F type.

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
153

Hello Joy,

Decimal field types you see in the ABAP dictionary for e.g., DEC, CURR, QUAN are derived from packed numbers.

For e.g., let us consider the data element WRBTR(CURR 13,2). So it is equivalent to TYPE p LENGTH (13+1)/2 = 7 DECIMALS 2.

The value range of TYPE p LENGTH 7 DECIMALS 2 is (9,999,999,999.99 to 9,999,999,999.99).

So we have 12 digits * 0.5 byte = 6 bytes + 0.5 byte for decimal p0int + 0.5 byte for sign(+/-) = 7 bytes. I hope you're clear

NB: In packed numbers 1 digit occupies 4 bits = 0.5 bytes.

I'll suggest you read the SAP documentation on Predefined Data Types for further info.

BR,

Suhas

PS: SAP does not recommend DEC, QUAN, CURR fields to have "even" lengths.

Edited by: Suhas Saha on Aug 9, 2011 9:56 PM

Former Member
0 Kudos
152

HI Suhas Saha,

Thanks for the Detailed answer!

I want to verify it ,does the fields with decimal can be just type P ? or there is another type for decimal ?

I ask it because when i try to create data for any other field with Dec i get error ....

Best Regards

Joy

Edited by: Joy Stpr on Aug 9, 2011 9:48 PM

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
152

> I want to verify it ,does the fields with decimal can be just type P ? or there is another type for decimal ?

> I ask it because when i try to create data for any other field with Dec i get error ....

As per SAP documentation i quote

For all other ABAP types and for the dynamic specification of name, the DECIMALS addition is not permitted.

Make it a habit to read the F1 documentation thoroughly, one can learn so much from it