Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Statement IF

d4xtian
Participant
0 Kudos

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.

11 REPLIES 11

AlexGourdet
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

Sandra_Rossi
Active Contributor
0 Kudos

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?

matt
Active Contributor
0 Kudos

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.

d4xtian
Participant
0 Kudos

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

Sandra_Rossi
Active Contributor
0 Kudos

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.

d4xtian
Participant
0 Kudos

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.

Sandra_Rossi
Active Contributor
0 Kudos

So, yes, it's numeric type.

So, your code is correct, it corresponds to what you want to do.

d4xtian
Participant
0 Kudos

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"

FredericGirod
Active Contributor

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.

FredericGirod
Active Contributor

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.

Sandra_Rossi
Active Contributor
0 Kudos

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