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

ABAP Program enhancement

Former Member
0 Likes
706

Hi Experts,

As i am not familiar with data types please update me...

I am using the below logic to calculacte years & months between 2 dates and save the result in YY.MM format.

The FM i am using will give years & months between 2 given dates.

My requirment is to save result in YY.MM format.

The code is working correctly...i need a minor enhancement to code

Currently if years are 8 and months are 8 the out put will be 8.08 but i want it in YY.MM format which is 08.08

I want to add a leading 0 if years <10

Please update

DATA: years TYPE tfmatage,

months TYPE tfmatage.

DATA: l_res TYPE p decimals 2 .

IF NOT SOURCE_FIELDS-/bic/zdob IS INITIAL.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

EXPORTING

I_DATE_FROM = SOURCE_FIELDS-/bic/zdob

I_DATE_TO = sy-datum

I_FLG_SEPARATE = 'X'

IMPORTING

  • E_DAYS =

E_MONTHS = months

E_YEARS = years.

l_res = years + months / 100.

WRITE l_res TO RESULT.

ENDIF.

WRITE / RESULT.

6 REPLIES 6
Read only

RaymondGiuseppi
Active Contributor
0 Likes
674

Add a USING EDIT MASK '__.__' to your WRITE statement.

Regards

Read only

0 Likes
674

Could you please update me in detail as i am not familiar with ABAP

Thanks

Read only

Former Member
0 Likes
674

here months is 2 character long. do one thing if month is less than 10 . Concatenae '0' month+0(1) into another of same month variable.

Read only

former_member435013
Active Participant
0 Likes
674

Hi,

you could do like this:

REPORT zhabitest4.

PARAMETER:

p_datum LIKE sy-datum.

DATA:

result(20).

DATA: years TYPE tfmatage,

months TYPE tfmatage,

y_num(4) TYPE n,

m_num(2) TYPE n.

DATA: l_res TYPE p DECIMALS 2 .

IF NOT p_datum IS INITIAL.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

EXPORTING

i_date_from = p_datum

i_date_to = sy-datum

i_flg_separate = 'X'

IMPORTING

  • e_days =

e_months = months

e_years = years.

  • l_res = years + months / 100.

  • WRITE l_res TO result.

y_num = years.

m_num = months.

CONCATENATE y_num+2(2) '.' m_num INTO result.

ENDIF.

WRITE / result.

regards

Walter Habich

Read only

0 Likes
674

Hi Walter,

Thanks for the update...

Its working as required YY.MM format.

i guess we are using any L_RES

Could you please briefly explain me what the code is doing

Thanks

Read only

former_member435013
Active Participant
0 Likes
674

Hi,

using edit mask for days < 9 results in missing zero after point.

Regards

Walter Habich