Application Development 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: 

how to calculate

Former Member
0 Kudos
174

Hi frens

I have a scenario in that

jan =10

feb = 25

mar = 35

apr = 55

may =66

ju =77

jul= 76

aug =80

...

...

..like these values will be there when i run my report on a particular month say(apr) and i need previous three months values(mar=35 feb=25 jan =10) when i run my report on aug i need last 3 months(jul jun may) .

when i run on jan 2009 i need(2008 dec nov oct vales)

how we can do it........

ps help me

thanks

Edited by: suma2285 on Apr 11, 2009 9:57 AM

7 REPLIES 7

Former Member
0 Kudos
152

Hi,

If you have these values in your internal table then add two more columns for Month number and year

2008 01 jan =10

2008 02 feb = 25

2008 03 mar = 35

2008 04 apr = 55

2008 05 may =66

2008 06 ju =77

2008 07 jul= 76

2008 08 aug =80

IF you running for the May 2008 then you get the month value 05 from the data sy-datum+4(2) and year 2008 from sy-datum(4).

L_month = sy-datum+4(2)

l_year = sy-datum(4).

Now ..

SORT ITAB by YEAR DESCENDING MONTH DESCENDING .
LOOP AT ITAB WHERE MONTH LT l_month and year LE l_year.
L_count = l_count + 1.
" Do your Processing...
If l_count EQ '3'.
EXIT.
ENDIF.
ENDLOOP.

0 Kudos
152

Hi frends

My problem was not solved I need to get the Previous three months values when i run my report on a particular month.

how these can be solved.

Thanks

0 Kudos
152

Hi, Suma.

Please Test the Code Bellow and Try to develop the logic like this hope will help you to solve out your problem.

DATA: BEGIN OF it_month OCCURS 12,
  no_of_month TYPE i,
  name_of_month(3),
  amount TYPE i,
  END OF it_month,
  no_of_month TYPE i,
  from TYPE i,
  to TYPE i.

PARAMETERS: month(3).

START-OF-SELECTION.
  it_month-no_of_month = 1.  it_month-name_of_month = 'Jan'. it_month-amount = 10. APPEND it_month.
  it_month-no_of_month = 2.  it_month-name_of_month = 'Feb'. it_month-amount = 20. APPEND it_month.
  it_month-no_of_month = 3.  it_month-name_of_month = 'Mar'. it_month-amount = 30. APPEND it_month.
  it_month-no_of_month = 4.  it_month-name_of_month = 'Apr'. it_month-amount = 40. APPEND it_month.
  it_month-no_of_month = 5.  it_month-name_of_month = 'May'. it_month-amount = 50. APPEND it_month.
  it_month-no_of_month = 6.  it_month-name_of_month = 'Jun'. it_month-amount = 60. APPEND it_month.
  it_month-no_of_month = 7.  it_month-name_of_month = 'Jul'. it_month-amount = 70. APPEND it_month.
  it_month-no_of_month = 8.  it_month-name_of_month = 'Agu'. it_month-amount = 80. APPEND it_month.
  it_month-no_of_month = 9.  it_month-name_of_month = 'Sep'. it_month-amount = 90. APPEND it_month.
  it_month-no_of_month = 10. it_month-name_of_month = 'Oct'. it_month-amount = 100. APPEND it_month.
  it_month-no_of_month = 11. it_month-name_of_month = 'Nov'. it_month-amount = 110. APPEND it_month.
  it_month-no_of_month = 12. it_month-name_of_month = 'Dec'. it_month-amount = 120. APPEND it_month.

  IF no_of_month LE 6.
    from = no_of_month + 1.
    to = from + 2.
    LOOP AT it_month FROM from TO to.
      WRITE: / it_month-name_of_month, it_month-amount.
    ENDLOOP.
  ELSEIF no_of_month GT 6.
    from = no_of_month - 1.
    to = from - 2.
    LOOP AT it_month FROM to TO from.
      WRITE: / it_month-name_of_month, it_month-amount.
    ENDLOOP.
  ENDIF.

AT SELECTION-SCREEN.

  TRANSLATE month TO LOWER CASE.

  CASE month.
    WHEN 'jan'.
      no_of_month = 1.
    WHEN 'feb'.
      no_of_month = 2.
    WHEN 'mar'.
      no_of_month = 3.
    WHEN 'apr'.
      no_of_month = 4.
    WHEN 'may'.
      no_of_month = 5.
    WHEN 'jun'.
      no_of_month = 6.
    WHEN 'jul'.
      no_of_month = 7.
    WHEN 'agu'.
      no_of_month = 8.
    WHEN 'sep'.
      no_of_month = 9.
    WHEN 'oct'.
      no_of_month = 10.
    WHEN 'nov'.
      no_of_month = 11.
    WHEN 'dec'.
      no_of_month = 12.
    WHEN OTHERS.
      MESSAGE: 'Month not Valid' TYPE 'E'.
  ENDCASE.

Please Reply if any Issue.

Best Regards,

Faisal

Former Member
0 Kudos
152

START-OF-SELECTION.

C = 0.

DO 4 TIMES.

C = C + 1.

CALL FUNCTION 'ISP_GET_MONTH_NAME'

EXPORTING

DATE = DATE-LOW

LANGUAGE = SY-LANGU

  • MONTH_NUMBER = A

IMPORTING

  • LANGU_BACK =

  • LONGTEXT =

SHORTTEXT = MON

EXCEPTIONS

CALENDAR_ID = 1

DATE_ERROR = 2

NOT_FOUND = 3

WRONG_INPUT = 4

OTHERS = 5

.

CONCATENATE MON DATE-LOW+2(2) INTO MONT SEPARATED BY '-'.

PERFORM RATE .

A = DATE-LOW+4(2) - 1.

B = DATE-LOW+0(4).

IF A = 0.

A = 12.

B = DATE-LOW+0(4) - 1.

ENDIF.

Hi...try this coding according to ur requirement----


CALL FUNCTION 'OIUREP_MONTH_FIRST_LAST'

EXPORTING

I_MONTH = A

I_YEAR = B

I_DATE = DATE-LOW

IMPORTING

E_FIRST_DAY = DATE1

E_LAST_DAY = DATE2

EXCEPTIONS

WRONG_DATE = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

DATE-LOW = DATE1.

DATE-HIGH = DATE2.

ENDDO.

Form Rate.

Endform.

Former Member
0 Kudos
152

You can create a database table and maintain it.

Your key in table would be the year and month.

While in report you can fetch the data from the table using your current date condition (using key).

Regards,

Lalit Mohan Gupta

Former Member
0 Kudos
152

Hi,

Considering that u r having theese values in an internal table......itab.

You can have the System date in a varialble...

from that get the month into an another variable.... var_month

Now sort the table itab----- decending.

loop that table itab

keep a count ie count =1.

and check the month field whether it is equal to the month u have in the variable (var_month).

is yes then store that count in var_count.

and exit from the loop.

now in another variable (var2_count)

ie var2_count = var_count - 3.

Now again loop that internal table

keep a count

if count = var2_count

write : that field of the table itab

end if.

if count = var2_count +1

write : that field of the table itab

end if.

if count = var2_count +2

write : that field of the table itab

endif.

endloop.

Hope this will help u.... try it out... I have jst given the logic... if something is not clear pls ask.

Thanks and regards

Suraj S Nair

Edited by: Suraj Nair on Apr 13, 2009 8:08 AM

Former Member
0 Kudos
152

hi,

Your problem is solved or not

Thanks

Suraj