cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between two dates in FOX formula

0 Kudos
1,276

Hi Experts,

I am a newbie here.

I am trying to find the difference between 2dates using FOX formulas, below is my code.

DATA VDATE TYPE ZVALUEDT.
DATA MDATE TYPE ZMATURITY.
DATA V_DATE TYPE D.
DATA M_DATE TYPE D.
DATA PER TYPE 0CALDAY.


FOREACH ZFD.
VDATE = ATRV( ZVALUEDT , ZFD).
MDATE = ATRV( ZMATURITY, ZFD).
V_DATE = VDATE.
M_DATE = MDATE.

PER = M_DATE - V_DATE .

{'/ERP/QUANTY',XXX,ZFD,MDATE,VDATE} = PER.

ENDFOR.

Not sure on the type of 'PER' variable here.. Is there any function to find the differences directly?

Thank you in advance.

Rajesh.

Accepted Solutions (0)

Answers (3)

Answers (3)

cornelia_lezoch
Active Contributor
0 Kudos

Hi Rajesh,

well, then you could define it in format D.

I am not sure what the value would be then and if this would then fit into your key figure...

regards

Cornelia

cornelia_lezoch
Active Contributor
0 Kudos

Hi Rajesh,

the difference between two dates can only be a number.

That´s why you can not feed it into per when per is type 0calday.

you need to define the result type I or F

data per type F.

kind regards

Cornelia

0 Kudos

Hi Cornelia,

I am getting below error after changing PER type to F.

Syntax error: Types of operands F and D do not agree

Message no. RSPLFOX057

Diagnosis

Types of operands must either be the same or compatible. Operands are compatible if they have the same data type. In addition, types I and F are compatible

Regards,

Rajesh.

cobaltaire
Participant
0 Kudos

Welcome Rajesh,

I think you should check for tutorials as it will help you better to understand the dynamic. I feel you are not explaining what is exactly your issue, you are specifically doing this operation M_DATE - V_DATE, if M_DATE (2020002) and V_DATE (2020001) you will obtain 0000001 and you are adding to {'/ERP/QUANTY',XXX,ZFD,MDATE,VDATE}. Do you have any error? Does code work?

My recomendation is that you can check this information in the menu of 'Operative' (selected one), 'Info' (Tutorials) and 'Verify HDB'.

Also, some easy way of checking, is printing messages with this kind of code:

MESSAGE I000(000) WITH 'TXT' MDATE VDATE PER.

You will see this text if you execute the function through the 'Sequence' it is involved in, with the option 'Execute step as trace'(picture), this option won't save the information in the cube and is a safe way to check the data you are generating.

Hope it helps and take your time for checking.

Kind regards

0 Kudos

Hi Lara,

Thank you for your reply.

I am getting below syntax error

"Syntax error: Types of operands F and 0CALDAY do not agree".

Understand /ERP/QUANTITY is type F, and PER type is defined as 0CALDAY; hence above error.

In my example, M_DATE is 20205101 (1st May 2020) and V_DATE is 2020601 (1st Jun 2020).

When i do subtraction, not sure on which type or variable should i declare for PER.

Regards,

Rajesh.

cobaltaire
Participant
0 Kudos

Change the type but I don't know if it will fix it as maybe you have to 'cast' the data, check in 'INFO' if new error appears:

DATA PER TYPE F.

0 Kudos

I tried changing types, but no luck.

When i change PER type F, getting error.(Types if operands F and D do not agree)

PER = M_DATE - V_DATE .

Any suggestions would be a great help!

Syntax error: Types of operands F and D do not agree

Message no. RSPLFOX057

Diagnosis

Types of operands must either be the same or compatible. Operands are compatible if they have the same data type. In addition, types I and F are compatible.

Rajesh,