banner



29. Which Data Directive Creates A 10-byte Packed Bcd Variable?

To write the commencement blog took me some time though there are few topics in my mind which I recollect I should blog. To write a blog with the correct contents and presenting in a way which is very helpful for others is a claiming and hats off to al the bloggers for their efforts. I take been a constant follower of scn blogs and many such blogs has helped me a lot. So this is my first humble endeavour to share something which I feel would aid anyone who come beyond similar issue.

The topic is about packed number. Recently I came beyond an upshot with ane of our customers where they having issues storing big amount value to a packed decimal field. It was throwing overflow exception . To solve this issue I tried searching to become to know how packed decimals behave I couldn't get enough details anywhere nigh the exact behavior of packed decimals and i had spend some time to write a exam programme to understand the right behavior of packed decimals.

Customer was having  a custom domain of data type dec length  16 and decimal 9 .Based on the diverse documentations on packed number our assumption was that nosotros have created a packed number with maximum length possible which is length 16 .

image - Copy.jpg

The amount value we were trying to store is 100000000.00. 9 digits before the decimal and 2 digits after the decimal .We were getting an overflow exception .I could encounter from the amount value if i reduce the number of digits before the decimal by i the overflow exception doesn't happen ( 8 digits before the decimal and 9 digits after the decimal ) . This made me wonder what's the length all nearly and how information technology works in case of packed decimal . I spend some time debugging the event.

Beneath is how it appeared in the debugger .

/wp-content/uploads/2016/05/debugger1_964589.jpg

What I sympathize is  though I have declared my domain is of length 16 and dec 9 ,internally system converts into a packed decimal of length 9 and

dec nine .P(9) DECIMAL ix.Now I had to understand what's this length stands for ,what does it mean past length nine  in case of packed decimal.

Predefined Numeric Types is explained hither ABAP Keyword Documentation

Based on  definitions well-nigh packed decimal length 9 ways 9 bytes and  two digits forms 1 byte so the actual length is 18 digits which includes one space for +/- sign. So in this case a domain  declared with the  length xvi and decimal 9 is converted past the organization as a packed decimal of length 9 and decimal nine which ways a full of xviii digits including ix decimal and 8 digits before the decimal and one space for the sign . At present I understood the reason why the amount 100000000.00 was not accepted by the variable ,instead 10000000.00 was accustomed .

Overview of All Predefined Dictionary Types is explained hither ABAP Keyword Documentation

Below is the examination program to sympathize more near packed decimals.

REPORT ZTEST_PROGRAM

*Data Declarations

information lv_char(l) value '9.999999999'.

data: lv_p TYPE p LENGTH 16 DECIMALS 9.

data: lv_num type i value one.

information: lv_dec type i value 9.

write:/ 'Keeping Decimal identify constant equally nine'.

Do 25 TIMES.

lv_num = lv_num + 1.

CONCATENATE 'nine' lv_char  into lv_char.

Effort .

  lv_p  = lv_char.

Take hold of CX_SY_CONVERSION_OVERFLOW .

write:/'overflow'.

  ENDTRY.

CHECK lv_p is Not INITIAL.

  write:/ lv_p, lv_num ,'Numbers and', lv_dec,' Decimals'.

ENDDO.

uline.

write:/ 'Keeping Decimal place constant as 9 in the state of affairs'.

Articulate: lv_num,lv_dec,lv_p,lv_char.

lv_char = 'ix.999999999'.

lv_num = 1. lv_dec = nine.

Practice 10 TIMES.

  lv_num = lv_num + 1.

CONCATENATE 'nine' lv_char  into lv_char.

Effort .

  lv_p2  = lv_char.

CATCH CX_SY_CONVERSION_OVERFLOW .

  write:/'overflow'.

ENDTRY.

Bank check lv_p2 is Non INITIAL.

  write:/ lv_p2, lv_num ,'Numbers and', lv_dec,' Decimals'.

ENDDO.

uline.

write:/ 'Keeping Decimal identify constant as 3'.

CLEAR: lv_num,lv_dec,lv_p,lv_char.

data: lv_p1 TYPE p LENGTH ix DECIMALS iii.

lv_char = 'nine.999'.

lv_num = 1.

lv_dec = 3.

Exercise twenty TIMES. lv_num = lv_num + i.

CONCATENATE '9' lv_char  into lv_char.

TRY .

   lv_p1  = lv_char.

CATCH CX_SY_CONVERSION_OVERFLOW .

  write:/'overflow'.

ENDTRY.

  C HECK lv_p1 is NOT INITIAL.

  write:/ lv_p1, lv_num ,'Numbers and', lv_dec,' Decimals'.

ENDDO.

If we have to keep the length fixed for the  domain( alleged length 16 decimal 9 ) , reduce the decimal points to hold more digits earlier the decimal .Below is a screenshot to show when the overflow will occur for the used domain reducing the decimal is reduced to 3 digits. Below is the output from the in a higher place lawmaking . This shows 14 Numbers are possible before decimal and 3 numbers afterward decimal.

/wp-content/uploads/2016/05/decimal_964591.png

And then what we have to empathize is the length divers in the domain is not the actual length of the packed decimal. if I declare a domain of length 20 and decimal ix ,in debugger I could see the organization converts it to a packed decimal of length xi and decimal 9.The maximum allowed length of packed decimal is 16 which is 16 bytes .

Then to empathise maximum value possible, I accept increased the local packed decimal variable to 16 and was able to meet maximum number possible keeping decimals as 9 was huge number – in the help documentation – a formula is provided likewise. For easy understanding below screen shot is given.

packed decimal max.png

So above code as well support my understanding of 16*2 =  32 numbers possible in which 1 will exist taken past +/- sign – which will exist 22+9 = 31.

Hope this blog was useful.

You lot can also read more than nigh predefined numeric blazon in in help.sap.com

29. Which Data Directive Creates A 10-byte Packed Bcd Variable?,

Source: https://blogs.sap.com/2016/05/31/packed-decimal-simplified/

Posted by: wisegion1993.blogspot.com

0 Response to "29. Which Data Directive Creates A 10-byte Packed Bcd Variable?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel