cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP CTE comparing columns of same row condition is not working

lcs00
Explorer
0 Kudos
414
  • SAP Managed Tags

 

"sample scenario
WITH +raw_data AS (
  SELECT sold_to_id, bill_to_id
   FROM Z_table
  )

  SELECT *
   FROM +raw_data as A
   WHERE A~sold_to_id <> A~bill_to_id
   INTO TABLE (LT_KUNNR).

 

hi guys, does anyone knows why the statement above will give me sy-subrc = 4 but it returns me result if I use conventional SELECT?

 

Accepted Solutions (0)

Answers (1)

Answers (1)

lcs00
Explorer
0 Kudos

I have found the answer with chatgpt..it was due to my columns contain NULL values

 

3. Null Values

If either column1 or column2 contains NULL values, the comparison will not return TRUE because any comparison with NULL returns NULL. To handle NULL values, use IS NULL or COALESCE:

 

 
WITH cte_name AS (
    SELECT column1, column2    FROM table_name)
SELECT *
FROM cte_nameWHERE COALESCE(column1, '') = COALESCE(column2, '');