2015 May 22 7:33 AM
Hi gurus,
I am calculating overdue days with the help of following loop
if wa_data-pay_term = c01.
overdue_days = overdue_days - 0.
ELSEIF wa_data-pay_term = c02.
overdue_days = overdue_days - 7.
ELSEIF wa_data-pay_term = c03.
overdue_days = overdue_days - 14.
ELSEIF wa_data-pay_term = c04.
overdue_days = overdue_days - 30.
ELSEIF wa_data-pay_term = c05.
overdue_days = overdue_days - 45.
ELSEIF wa_data-pay_term = c06.
overdue_days = overdue_days - 60.
ELSE.
overdue_days = overdue_days - 90.
ENDIF.
But the loop is not working correctly. If wa_data-payterm = c04. it should subtract 40 instead it is subtracting 90. Please help me where i have gone wrong.
2015 May 22 7:43 AM
A CASE statement might be a more elegant way to code this as in
CASE wa_data-pay_term/
WHEN c01.
overdue_days = etc...
In ABAP 740 the SWITCH statement can make this even more compact, as you don't have to keep mentioning "overdue_days" in every branch.
Also, you should not use meaningless constants like C06. It should have name a name like C_RISKY_CUSTOMER so the code is easier to read.
Going even further, this should be a customising table (or BRF+ rule) in case the rules ever change e.g. a new customer group is added, or the value for Group 6 changes from 60 to 55 or something.
That way when (not if, when) the business rules change you don't have to change your program - this is known as the "open-closed" principle.
However, going back to your original question the only way I
F WA_DATA-PAYTERM = C04
could evaluate to false if is you have a spelling mistake in your definition of the constant C04.
Cheersy Cheers
Paul
2015 May 22 7:38 AM
Hi ,
First check in debugging mode what exactly value is coming in wa_data-pay_term
As per my understanding your code is correct.
Debug is the only thing.
Regards
Raj
2015 May 22 7:39 AM
Hi,
Debugging would be the best way to get the problem that is occurring. Check the value of wa_data-pay_term and value of C_04 during debugging and see if they match.
Hope this helps,
~Athreya
2015 May 22 7:42 AM
Hi Sathy,
You can use CASE statement for the above logic.
DATA: lv_date type i.
CASE lv_value.
when 'c01'.
lv_date = 0.
when 'c02'.
lv_date = 7.
when 'c03'.
lv_date = 14.
when 'c04'.
lv_date = 30.
.....
WHEN Other.
lv_date = 90.
ENSCASE.
overdue_days = overdue_days - lv_date.
Hope you are clear with logic.
Regards.
Praveer.
2015 May 22 7:43 AM
A CASE statement might be a more elegant way to code this as in
CASE wa_data-pay_term/
WHEN c01.
overdue_days = etc...
In ABAP 740 the SWITCH statement can make this even more compact, as you don't have to keep mentioning "overdue_days" in every branch.
Also, you should not use meaningless constants like C06. It should have name a name like C_RISKY_CUSTOMER so the code is easier to read.
Going even further, this should be a customising table (or BRF+ rule) in case the rules ever change e.g. a new customer group is added, or the value for Group 6 changes from 60 to 55 or something.
That way when (not if, when) the business rules change you don't have to change your program - this is known as the "open-closed" principle.
However, going back to your original question the only way I
F WA_DATA-PAYTERM = C04
could evaluate to false if is you have a spelling mistake in your definition of the constant C04.
Cheersy Cheers
Paul
2015 May 22 7:46 AM
Hi,
I have the feeling that you can use CASE here.
Your code will look much better and easier to debug.
http://help.sap.com/abapdocu_740/en/abapcase.htm
Regards .
2015 May 22 7:47 AM
Hi Sathyamurthy,
The code which you have written is correct but just check once in debugging what is happening and you can find the issue clearly.
Note: Instead of nested IF..ELSEIF you can move to CASE it increase performance of the program as well as it makes good readability to others.
Regards,
Chakradhar.