Application Development and Automation 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: 
Read only

why not initial not work

former_member625844
Participant
2,024

I use below code to loop an itab but the if condition can't exlude anything.

LOOP AT gt_data INTO DATA(gs_data).
     IF gs_data-rfarea is not initial.
          ...
      endif.
endloop.

But if I changed the code to

LOOP AT gt_data INTO DATA(gs_data).
     IF gs_data-rfarea <> ''.
          ...
      endif.
endloop.

And it worked. So what's the reason? Is this because the SQL which select data into itab?

Below is the SQL.

SELECT
        faglflext~rbukrs,
        faglflext~rfarea,
        faglflext~rcntr,
        cskt~ltext,
        faglflext~racct,
        skat~txt50,
        faglflext~hsl01,faglflext~hsl02,faglflext~hsl03,faglflext~hsl04,faglflext~hsl05,faglflext~hsl06,faglflext~hsl07,faglflext~hsl08,faglflext~hsl09,
    faglflext~hsl10,faglflext~hsl11,faglflext~hsl12,faglflext~hsl13,faglflext~hsl14,faglflext~hsl15,faglflext~hsl16
  INTO TABLE @DATA(gt_data)
  FROM faglflext
  LEFT JOIN skat       ON faglflext~racct = skat~saknr
  LEFT JOIN cskt ON faglflext~rcntr = cskt~kostl AND cskt~datbi = '99991231'
 WHERE faglflext~rbukrs IN @company1
   AND faglflext~ryear = @pyear
   AND faglflext~rcntr IN @costc
   AND faglflext~racct IN @acct
   AND FAGLFLEXT~rfarea in @CostP.
1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
1,616

Your code

SELECT
        faglflext~rbukrs,
        faglflext~rfarea,
        ...
  INTO TABLE @DATA(gt_data)
  FROM faglflext
  ...
LOOP AT gt_data INTO DATA(gs_data).

It means that RFAREA in GT_DATA is of type FAGLFLEXT-RFAREA, so it's CHAR 16.

Conclusion: it means that:

     IF gs_data-rfarea is not initial.

is strictly identical to:

     IF gs_data-rfarea <> ' '.

and the error is in your analysis or presentation of error.

3 REPLIES 3
Read only

former_member1716
Active Contributor
1,616

loki_luo15,

Instead of IS NOT INITIAL, try IF NOT NULL. Check how the program behaves then we can understand how the data is stored.

Also your code is not right as explained below:

     IF gs_data-rfarea <> ''.   --> Not Rite
          ...
      endif.


***Try this 
     IF gs_data-rfarea <> space.
          ...
      endif.

Regards!

Read only

1,616

All of these literals/constants are strictly identical in ABAP:

''
' '
space

NB 1: '' is not an empty character literal because the minimum for a literal of type C is one character, so it means one space.

NB 2: I'm not talking about the back quote (`) here, which is used for literals of type STRING, it has a different meaning and behavior.

Read only

Sandra_Rossi
Active Contributor
1,617

Your code

SELECT
        faglflext~rbukrs,
        faglflext~rfarea,
        ...
  INTO TABLE @DATA(gt_data)
  FROM faglflext
  ...
LOOP AT gt_data INTO DATA(gs_data).

It means that RFAREA in GT_DATA is of type FAGLFLEXT-RFAREA, so it's CHAR 16.

Conclusion: it means that:

     IF gs_data-rfarea is not initial.

is strictly identical to:

     IF gs_data-rfarea <> ' '.

and the error is in your analysis or presentation of error.