05-20-2022 5:14 PM
HI I have question about my code...
i would like if one of my condition is true, i would it write the message with the variable is true
Thanks
IF P_LONG = 0 OR P_LARG = 0 OR P_HAUT = 0.
WRITE 'You can't put a 0'.
ELSE.
WRITE 'VALID'.
ENDIF.
05-20-2022 5:14 PM
Thank you for visiting SAP Community to get answers to your questions.
Since you're asking a question here for the first time, I'd like to recommend you with the following steps so you can get the most out of your community membership:
I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.
I hope you find this advice useful, and we're happy to have you as part of SAP Community!
All the best,
-Alex
05-20-2022 5:24 PM
What your code does, is what you read: if one of the three is zero then "you can't put a 0", else "valid".
Could you explain your question please?
05-20-2022 6:05 PM
Have a little read about boolean logic, as you're making a common error by people who don't understand it.
Maybe AND would be your friend.
05-20-2022 9:42 PM
I as the user to enter numerical data to make a calulation, and i don't want him to be able to put 0 in on of the field, and i would like to return error message to him in indicating the field or fiels where where he field in 0
05-21-2022 10:48 AM
Or maybe you don't understand the concept of Types. Did you define P_LONG, P_LARG and P_HAUT with a numeric type? If not, probably your code won't work well.
05-22-2022 7:24 PM
sorry Sarah, i haven’t post the Declaration part, i did it, declare it.
Data : P_LONG type i,
P_LARGE type i,
P_HAUT type i.
05-22-2022 8:07 PM
So, yes, it's numeric type.
So, your code is correct, it corresponds to what you want to do.
05-23-2022 12:27 AM
Yes but i want the message error gave me the name of the field and the field that has the '0'.
IF P_LONG = 0 OR P_LARG = 0 OR P_HAUT = 0.
WRITE P_LONG ' can't HAVE a 0'.
ELSE.
WRITE 'VALID'.
ENDIF.
The message i have is
' 0 You can't put 0'
I have declare the name of the field in "Text Elements"
05-23-2022 6:31 AM
So you have to test separatly each field :
IF p_long eq 0.
write |P_LONG can't have a 0|.
ELSE.
IF p_larg eq 0.
write |P_LONG can't have a 0|.
ELSE.
IF p_haut eq 0.
write |P_LONG can't have a 0|.
ENDIF.
ENDIF.
ENDIF.
05-23-2022 6:35 AM
or you could create a table of variables
something like (not tested).
DATA(ma_jolie_table) = VALUE ...( ( fieldname = 'P_LONG' ) (fieldname = 'P_LARG' ....).
LOOP AT ma_jolie_table
INTO DATA(ls_ma_jolie_ligne).
ASSIGN (ls_ma_jolie_ligne-fieldname) to field-symbol(<field>).
CHECK <field> IS ASSIGN.
IF <field> eq 0.
write /1 |{ ls_ma_jolie_table-fieldname } can't have a 0|.
ENDIF.
ENDLOOP.
05-23-2022 7:22 AM
OK. Your question was not clear. You'd better give example of what you expect, like if user enters 0 in P_LONG, how to write:
P_LONG can't have a 0