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

Elapse days - calculation

Former Member
0 Likes
1,162

I have Month and year field. Values Year(2009) and Month(4)

I want below logic to calculate -

MTD qty % = (qty * elapse days) / no of days in month

so from the above, I want to know,

1. How can we get the no of days from the above 2 objects (year and month).

2. Elapse days are the days that are over from current date to Ist day of that month.

eg: current date - 04.03.2009 , 1st day of the month - 04.01.2009,

elapse days = 2. (you need to consider all days in the month, not only working days)

so my questions is how can we get, # of days n a month from above 2 fields and elapse days based on the above condition.

please provide your suggestions.

Thanks,

Pra

I have Month and year field. Values Year(2009) and Month(4)

I want below logic to calculate -

MTD qty % = (qty * elapse days) / no of days in month

so from the above, I want to know,

1. How can we get the no of days from the above 2 objects (year and month).

2. Elapse days are the days that are over from current date to Ist day of that month.

eg: current date - 04.03.2009 , 1st day of the month - 04.01.2009,

elapse days = 2. (you need to consider all days in the month, not only working days)

so my questions is how can we get, # of days n a month from above 2 fields and elapse days based on the above condition.

please provide your suggestions.

Thanks,

Pra

6 REPLIES 6
Read only

anuj_srivastava
Active Participant
0 Likes
1,070

Hi ,

u can use this function module to find the no of days in that particular month.

HR_E_NUM_OF_DAYS_OF_MONTH .

For calculating the elapsed days u can put the simple arithmetic logic.

Elapsed day = sy-datum - 01/month/year.

While doing the arithmetic calculation the date should be of type datum.

Regards,

Anuj

Read only

0 Likes
1,070

Hi,

I want to use only Month and Year to get the no of days in the month.

Please provide me how to convert date(01 - constant), month, year into datum format.

thanks

Read only

0 Likes
1,070

Hi ,

If u will give the specific month as input to the FM it will return u the no of days in that specific month.

Regarding changing the date into datum format you need to write it into this format for month (04) and year ( 2009) as 20090401.

This can be achived using a simple concatenate statement.

Concatenate year month constant into date .

now you can do arithmetic operation with it.

Regards,

Anuj

Read only

former_member156446
Active Contributor
0 Likes
1,070

check this code which I wrote for you:

REPORT  zj_test LINE-SIZE 162.

TABLES: tfacs.
DATA: lv_num TYPE i, lv_string TYPE char40.

DATA: BEGIN OF itab.
        INCLUDE STRUCTURE tfacs.
DATA: END OF itab.

SELECT SINGLE *
  FROM tfacs
  INTO itab
  WHERE ident = 'US'
  AND  jahr = '2009'.

lv_string = itab-mon02. "for feb

lv_num = STRLEN( lv_string ).

WRITE: lv_num.

Read only

Former Member
0 Likes
1,070

Hello,

I think the sample program below does what you ask: it finds the days in the month (bit of an overkill to use function modules for that) and then computes the QTD.

Note that the internal string representation of a data variable is always YYYYMMDD, regardless of the "externalized" form (e.g. yyyy/mm/dd or dd.mm.yyyy), so this code will work regardless of your custom date format.

Regards,

Mark

REPORT  zqty_to_date.
PARAMETERS:
  p_date     TYPE dats,
  p_qty      TYPE i.

DATA:
  days      TYPE i,
  n_year    TYPE numc4,
  n_month   TYPE numc2,
  n_day     TYPE numc2,
  qtd(6)    TYPE p DECIMALS 1.


START-OF-SELECTION.
  n_year = p_date+0(4).
  n_month = p_date+4(2).
  n_day = p_date+6(2).

  PERFORM days_in_month USING n_year n_month CHANGING days.
  qtd = ( p_qty * ( n_day - 1 ) ) / days.
  WRITE: / 'Days in month:', days,
         / 'Qty  to date :', qtd.

*&---------------------------------------------------------------------*
*&      Form  days_in_month
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM days_in_month USING year month CHANGING days.
  DATA: ymod4   TYPE i,
        ymod100 TYPE i,
        ymod400 TYPE i.
  CASE month.
    WHEN 4 OR 6 OR 9 OR 11.
      days = 30.
    WHEN 2.
      ymod4 = year MOD 4.
      ymod100 = year MOD 100.
      ymod400 = year MOD 400.
      IF ( ymod4 = 0 AND ymod100 > 0 ) OR ( ymod100 = 0 AND ymod400 = 0 ).
        days = 29.
      ELSE.
        days = 28.
      ENDIF.
    WHEN OTHERS.
      days = 31.
  ENDCASE.
ENDFORM.                    "days_in_month

Read only

Former Member
0 Likes
1,070

solved