Former Member

Regarding one formula

Hi,

I have written one program , in which one place i get month number like 6 for june and 7 for july, and then i have to convert this in quarter number.

Basically we have divided year in 4 quarter.

So I have written this formula:

lv_temp6 = ( lv_temp6 - 1 ) / 3 + 1.

Where lv_temp6 = month value like 6 for june and 7 for july.

But when i execute this formula for june month means 6 number, it gives 3 value, but it should be 2. When i debugged code, then it was found that

lv_temp6 =(6-1)/3+1.

= 5/3 +1

= 1.667 +1.

= 2+1 = 3

I have declared lv_temp6 as a int.

So please tell me how can we get 2 instead of 3. Also this should be correct for another value also.

Thanks

Devesh Babu

10|10000 characters needed characters exceeded

Related questions

• Posted on Jul 06, 2012 at 04:06 AM

Hi,

Your analysis is correct - the problem is because of INT. Hardcoding is one option - but if you want the algorithmic (dunno if that is the right word) solution, use CEIL, and change the argument to a float or packed no.

For instance,

DATA: lv_temp_p type p decimals 3.

lv_temp_p = the_month.

lv_temp = CEIL( lv_temp_p / 3 ).

Regards,

Suhas

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 05, 2012 at 10:43 AM

Hi,

my thought is, Is it possible to hard code by using case statement and

If lv_temp = 01 or 02 or 03 assign the quarter number lv_temp6 =1

like wise

If lv_temp = 04 or 05 or 06 assign the quarter number lv_temp6 =2

If lv_temp = 07 or 08 or 09 assign the quarter number lv_temp6 =3

If lv_temp = 10 or 11 or 12 assign the quarter number lv_temp6 =4

Just a thought.

Regards,

Archana

10|10000 characters needed characters exceeded
• Posted on Jul 05, 2012 at 11:09 AM

Hi

I would prefer the below code. If you still want to use your code, you will again endup with a IF-ELSE statement.

IF lv-temp GE '1' AND lv_temp LE '3'.

lv_temp = 1.

ELSEIF lv-temp GE '4' AND lv_temp LE '6'.

lv_temp = 2.

ELSEIF lv-temp GE '7' AND lv_temp LE '9'.

lv_temp = 3.

ELSEIF lv-temp GE '10' AND lv_temp LE '12'.

lv_temp = 4.

ENDIF.

Regards

Murthy