‎2020 May 18 4:10 AM
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.
‎2020 May 18 7:29 AM
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.
‎2020 May 18 6:32 AM
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!
‎2020 May 18 9:27 AM
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.
‎2020 May 18 7:29 AM
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.