Former Member

# Calculate the values of respective days

Hi Experts,

Am a new beginner to ABAP development and facing some difficulties in my requirement.

I have a custom table where an amount value is saved for each day in my custom table. My requirement is to get to the values for each day and need to calculate all the values of working days in a week and have to show the total amount value for 5 days. I have seen some function modules to get the working days of the week, but how can I calculate the total value of those week. Please let me know, how can I do it.

10|10000 characters needed characters exceeded

### Related questions

Posted on Jan 01, 2014 at 06:11 PM

As you said you can calculate the no. of working days in week so just do a looping on that itab which have all working days on week and inside loop read the custom table with that date and do sum of all amount.

Itab_weeks output of fm which will give working days.

itab_cust data with custom table

loop itab_weeks into wa_weeks

read table itab_cust into wa_cust with key date = wa_weeks-date.

if sy-subrc = 0.

lv_sum = lv_sum + wa_cust-amount.

endif.

ennloop.

10|10000 characters needed characters exceeded
• Former Member
Posted on Jan 01, 2014 at 06:38 PM

Hi Dilip,

Refer below code.

types: BEGIN OF t_tab,

amt type i,

day type string,

end of t_tab.

data: i_tab TYPE STANDARD TABLE OF t_tab,

w_tab type t_tab,

total_amt type i.

w_tab-amt = 100.

w_tab-day = 'Monday'.

append w_tab to i_tab.

w_tab-amt = 100.

w_tab-day = 'Tuesday'.

append w_tab to i_tab.

w_tab-amt = 100.

w_tab-day = 'Wed'.

append w_tab to i_tab.

w_tab-amt = 100.

w_tab-day = 'Thu'.

append w_tab to i_tab.

w_tab-amt = 100.

w_tab-day = 'Fri'.

append w_tab to i_tab.

loop at i_tab into w_tab.

at last.

sum.

total_amt = w_tab-amt.

endat.

endloop.

10|10000 characters needed characters exceeded
• Posted on Jan 03, 2014 at 09:52 AM

Hi Dilip,

i think the date field is definitely available from your custom table here you can fetch the data

from those table providing suitable date and some other in where condition in select statement.

Data: ztable1 type ztable ( it is your custom table name ).
data: itab_ztable type ztable occurs 0 . ( Declaring Internal Table ).

data: tot_amt type p length 8 decimal 2.

select * from ztable into corresponding fields of table itab_ztable where date in date( your date ).

loop at itab_ztable into ztable1 .

tot_amt = tot_amt + ztable-amt .

endloop.

let me know still if you facing difficult to do.

regards,

Thangam.P

10|10000 characters needed characters exceeded
• Posted on Jan 02, 2014 at 04:04 AM

Hi Dilip Rao,

You can find the no of working day using below function module.

CALL FUNCTION 'DAY_ATTRIBUTES_GET'

EXPORTING

HOLIDAY_CALENDAR = ID

DATE_FROM = SY-DATUM

DATE_TO = LDAY

LANGUAGE = SY-LANGU

TABLES

DAY_ATTRIBUTES = I_DATA1

EXCEPTIONS

FACTORY_CALENDAR_NOT_FOUND = 1

HOLIDAY_CALENDAR_NOT_FOUND = 2

DATE_HAS_INVALID_FORMAT = 3

DATE_INCONSISTENCY = 4

OTHERS = 5.

To get the output in I_DATA1, you functional team must maintain the calendar ID.

Arivazhagan S

10|10000 characters needed characters exceeded
• Posted on Jan 03, 2014 at 07:17 PM

Could you please clarify what is the specific challenge you're facing? It seems that you already know an FM to find whether the date is a working day. Doing math operations in ABAP seems like a very basic task, even for a beginner. So what is the question exactly?