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: 

is both value initial is considered equal?

former_member625844
Participant
0 Kudos

I wrote below code tocheck changes in zplp1.

SELECT COUNT(*) FROM mbew WHERE matnr = wmbew-matnr AND bwkey = wmbew-bwkey
      AND zplp1 = wmbew-zplp1 AND zpld1 = wmbew-zpld1
      AND zplp2 = wmbew-zplp2 AND zpld2 = wmbew-zpld2.
IF sy-subrc <> 0.
        MESSAGE e006(zfico).
ENDIF.

And if the values of zplp1/p2/d1/d2 are initial it doesn't work. To solve this I think I can first query the orignial values from db and compare to new one like below.

 SELECT single *  FROM mbew WHERE matnr = wmbew-matnr AND bwkey = wmbew-bwkey
  into @data(mbew_o)    .
IF sy-subrc = 0.
       if ((mbew_o-zplp1 = wmbew-zplp1 ) or (mbew_o-zplp1 is initial and wmbew-zplp1 is initial)).
           else . 
                MESSAGE e006(zfico).
           ENDIF.
ENDIF.

Is there a simpler way to do it? Thx.

4 REPLIES 4

former_member1716
Active Contributor

loki_luo15,

Your Question does not have all the necessary details to get an answer:

1) What is WMBEW here?

2) What is your expectation here?

3) Your select statement has AND operator and Conditional Statement has OR operator.

Can you explain your question better?

Regards!

Sandra_Rossi
Active Contributor

I guess you didn't check the option "not null" of the Z columns, so all existing rows have Z columns with value "null" and the comparison fails because ABAP "initial" <> database "null".

If you check the option "not null", there will be a table adjustment to set initial values where values were previously null.

former_member625844
Participant
0 Kudos

@sandra.rossi.Thx. So if I want to check zplp1 changed or zplp1 is null I should write like below, is it?

where ( zplp1 = wmbew-zplp1 or zplp1 is initial )

Sandra_Rossi
Active Contributor
0 Kudos

What I recommend is that you set the option "not null", otherwise people will often make errors. I would consider not setting the option "not null" as being "error prone".

If not, your program will look like a mess. In case a line has ZPLP1 equal to null, not initial (I don't know its type so I can't say space or zero or all zeroes...), you would use this complex code:

IF wmbew-zplp1 IS NOT INITIAL.
  SELECT ...
      WHERE ( zplp1 = wmbew-zplp1 ) ...
ELSE.
  SELECT ...
      WHERE ( zplp1 = wmbew-zplp1 OR zplp1 IS NULL ) ...
ENDIF.