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

Calculation regarding months

Former Member
0 Likes
556

Hi,

I have an itab.

It has fields vbeln posnr and edatu.

Now I have to go to vbep and find out the relevant edatu for the vbeln and posnr.

If edatu is with in this month(say june), I will display on the output as with in this month.

If edatu falls under next month (i.e above june 30 and less than aug 1), I will display on the output as under next month. (I mean here only for the next month, not with in next month).

Like this, I have to display the output for upto next 3 months. I can do data retrieval easily but could not figure out about these months exactly. Can you suggest a code here?

I appreciate.

Thanks.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
526

Here is an example program showing how you can setup your month buckets using ranges.



report zrich_0001.

ranges: r_datum1 for sy-datum,
        r_datum2 for sy-datum,
        r_datum3 for sy-datum.

data: tmp_datum type sy-datum.



tmp_datum = sy-datum.

clear r_datum1.
r_datum1-sign = 'I'.
r_datum1-option = 'BT'.
r_datum1-low+0(6) = tmp_datum+0(6).
r_datum1-low+6(2) = '01'.
call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = r_datum1-low
     importing
          last_day_of_month = r_datum1-high.
append r_datum1.

call function 'RE_ADD_MONTH_TO_DATE'
     exporting
          months  = 1
          olddate = r_datum1-low
     importing
          newdate = tmp_datum.



clear r_datum2.
r_datum2-sign = 'I'.
r_datum2-option = 'BT'.
r_datum2-low+0(6) = tmp_datum+0(6).
r_datum2-low+6(2) = '01'.
call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = r_datum2-low
     importing
          last_day_of_month = r_datum2-high.
append r_datum2.


call function 'RE_ADD_MONTH_TO_DATE'
     exporting
          months  = 1
          olddate = r_datum2-low
     importing
          newdate = tmp_datum.



clear r_datum3.
r_datum3-sign = 'I'.
r_datum3-option = 'BT'.
r_datum3-low+0(6) = tmp_datum+0(6).
r_datum3-low+6(2) = '01'.
call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = r_datum3-low
     importing
          last_day_of_month = r_datum3-high.
append r_datum3.


check sy-subrc  = 0.

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
527

Here is an example program showing how you can setup your month buckets using ranges.



report zrich_0001.

ranges: r_datum1 for sy-datum,
        r_datum2 for sy-datum,
        r_datum3 for sy-datum.

data: tmp_datum type sy-datum.



tmp_datum = sy-datum.

clear r_datum1.
r_datum1-sign = 'I'.
r_datum1-option = 'BT'.
r_datum1-low+0(6) = tmp_datum+0(6).
r_datum1-low+6(2) = '01'.
call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = r_datum1-low
     importing
          last_day_of_month = r_datum1-high.
append r_datum1.

call function 'RE_ADD_MONTH_TO_DATE'
     exporting
          months  = 1
          olddate = r_datum1-low
     importing
          newdate = tmp_datum.



clear r_datum2.
r_datum2-sign = 'I'.
r_datum2-option = 'BT'.
r_datum2-low+0(6) = tmp_datum+0(6).
r_datum2-low+6(2) = '01'.
call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = r_datum2-low
     importing
          last_day_of_month = r_datum2-high.
append r_datum2.


call function 'RE_ADD_MONTH_TO_DATE'
     exporting
          months  = 1
          olddate = r_datum2-low
     importing
          newdate = tmp_datum.



clear r_datum3.
r_datum3-sign = 'I'.
r_datum3-option = 'BT'.
r_datum3-low+0(6) = tmp_datum+0(6).
r_datum3-low+6(2) = '01'.
call function 'LAST_DAY_OF_MONTHS'
     exporting
          day_in            = r_datum3-low
     importing
          last_day_of_month = r_datum3-high.
append r_datum3.


check sy-subrc  = 0.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
526

Hi Nuren,

Try with the following code.

DATA V_DATE1 TYPE VBAK-EDATU.

DATA V_DATE2 TYPE VBEP-EDATU.

DATA V_MONTH1(2).

DATA V_MONTH2(2).

DATA V_DIFF_MONTHS TYPE I.

V_MONTH1 = V_DATE1+4(2).

V_MONTH2 = V_DATE2+4(2).

V_DIFF_MONTHS = V_MONTH2 - V_MONTH1.

<b>CASE V_DIFF_MONTHS.

WHEN '1'.

WRITE:/ 'NEXT MONTH'.

WHEN '2'.

WRITE:/ 'AFTER 2 MONTHS'.

WHEN '3'.

WRITE:/ 'AFTER 3 MONTHS'.

ENDCASE.</b>

Thanks,

Vinay

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
526

You can then check your EDATU against each bucket.

if ivbep-edatu in r_datum1.
   ...
Endif.

if ivbep-edatu in r_datum2.
   ...
Endif.


if ivbep-edatu in r_datum3.
   ...
Endif.

Regards,

Rich Heilman