Skip to Content

Problem with IF statement in SAP Script

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.



SSSS2.jpg (877.5 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Jul 14, 2016 at 07:57 PM

    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:




    But for the strings it's:




    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 13, 2016 at 06:57 AM

    Hi Hubert,

    What type of fields are LV_HLTST_LEN and LV_PSP_LEN? If they are numeric fields, maybe you should remove the quotes in the if/elseif conditions:

    /: IF &LV_HLTST_LEN& LE 3

    H1 ,,&LV_HLTST&


    H2 ,,&LV_HLTST&


    H3 ,,&LV_HLTST&

    /: ELSE

    H4 ,,&LV_HLTST&

    /: ENDIF

    Kind regards,


    Add a comment
    10|10000 characters needed characters exceeded

    • Hi again Rudy,

      thanks for your continous support.

      I checked the form with [Form] -> [Check] -> [Definition]. Result was both times (with and without period sign at end of IF, ELSEIF and ENDIF statement): "No errors found in form ZMM_ABRUF_LEFER"

      According to this, the evaluation of the logical expressions did not change with period signs.

      &LV_HLTST& is only printed once, with size of the paragraph selected by log.exp. (H1 in case of LV_HLTST_LEN = 16 😔 )

      Best regards,


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.