on 2016 Jul 08 7:48 AM
Hi all,
in my SAP Script form two IF statments are evaluated in different ways. Please see the image below.
Both LV_PSP_LEN and LV_HLTST_LEN are calculated in one ABAP subroutine via PERFORM ... ENDPERFORM call.
Seems like the second comparison uses only the first digit of LV_HLTST_LEN.
I tried this values:
LV_HLTST_LEN = 3 => processor evaluates IF &LV_HLTST_LEN& LE '3' to true
LV_HLTST_LEN = 9 => processor evaluates ELSEIF &LV_HLTST_LEN& LE '9' to true
LV_HLTST_LEN = 16 => processor evaluates IF &LV_HLTST_LEN& LE '3' to true
LV_HLTST_LEN = 44 => processor evaluates ELSEIF &LV_HLTST_LEN& LE '9' to true
Please give me some hints to solve my problem.
Regards,
Hubert
Request clarification before answering.
In this case it's not the numbers that are getting compared but the alphanumeric strings. You can observe the same effect in Excel, for example, if you set Text type for the column. For the numbers the order would be:
3
9
44
But for the strings it's:
3
44
9
For the text type, the first character is compared first, then the next character and so forth.
The solution seems quite obvious though: since you only have few options in IF then instead of using a number (which does not work as expected) simply use some other indicator. E.g. 'A' would correspond to <= 3 case, then 'B' to 3-9 case, etc. Something like that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jelena,
I understand your arguments, but
1. why should SAPscript use numbers to compare in case of LV_PSP_LEN but alpha numeric values in case of LV_HLTST_LEN?
I want SAPscript to use numbers to compare with LV_HLTST_LEN! Where is the problem?
2. I thought already before of your suggestion to use indicators, but this could only be a workaround, no permanent solution.
Regards,
Hubert
Hi Hubert,
1) LV_PSP_LEN = 19. The IF-statement compares it with 17. As Jelena said, the characters are compared one-by-one:
1 LE 1 --> Yes
9 LE 7 --> No
Overall the outcome is no so that is why goes into the else part.
Kind regards,
Rudy.
@Jelana: thanks for your clarifying post. I haven't thought of that.
Hubert, your screenshot does not confirm that it "works" with another variable. It just works with this specific value because 17 is less than 19 no matter whether you use text or numeric order. You just got lucky there.
This helped me realized a possible solution though - just add zero ('03'), that should make the text order work as numeric.
| User | Count |
|---|---|
| 13 | |
| 8 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.