cancel
Showing results for 
Search instead for 
Did you mean: 

INSERT FROM SELECT - The expression that contains "WAERS" can get null values since it contains...

Sandra_Rossi
Active Contributor
0 Kudos
211

Hello,

I've got this ABAP syntax check warning for all key fields of ZTABLE (WAERS, etc.) of below ABAP code:

The expression that contains "WAERS" can get null values since it contains fields that were not created with "Initial Values" in the dictionary.

Syntax check internal message code: INSERT 211.

ABAP code (there's a list of columns and a WHERE clause with IN and = followed by ABAP variables, no SQL expression):

INSERT ztable FROM ( SELECT waers, ... FROM zcview ).

WAERS is the first key field of ZTABLE. ZTABLE has a client key field in the very first position.

ZCVIEW is a CDS entity view with this code (only inner join, no left outer join):

define view entity ZCVIEW
  as select from bkpf
  inner join ...
{
  key bkpf.waers,
  ...
  sum( ... ) as sum_...,
  ...
  cast(' ' as belnr_d) as extbelnr,
  ...
}
where ... // conditions against constants
group by ... // all fields before the sum fields

The description says to use ##NULL_VALUES to remove the warning. This works fine.

I'd like to know the reason why there is this warning.

I see in the ABAP documentation INSERT dbtab, source - Alternative 3 ( SELECT subquery_clauses ... ):

Null values to be inserted can be produced in the following cases:

  • As results of outer joins in the FORM clause of the subquery.
  • As results of SQL expressions in the SELECT list of the subquery.
  • If a field read by the subquery already contains a null value.

A catchable exception of exception class CX_SY_OPEN_SQL_DB is raised in the case of columns that are key fields of the DDIC database table or DDIC view to be filled. If it is known statically that null values can be inserted into key fields, a syntax check warning that can be hidden by the pragma null_values is produced.

Is there a way to avoid the warning without using ##NULL_VALUES?

Why exactly is the warning sent with INSERT ztable FROM ( SELECT ... )?

Thank you.

Sandra

ABAP release: 7.58.

EDIT April 9th, 2025: I have updated a little bit the question because it didn't make sense as I had used the example of BKPF-BUKRS which is NOT NULL in BKPF, so I replaced with WAERS,

Accepted Solutions (1)

Accepted Solutions (1)

Sandra_Rossi
Active Contributor

The warning is because of:

  1. the source column BKPF-WAERS is not defined with the words NOT NULL, hence theoretically some values could be NULL (but actually it can't be NULL because the lines are inserted and updated only via ABAP statement INSERT, UPDATE, MODIFY which can't set NULL in database tables),
  2. the target column ZTABLE-WAERS is defined with NOT NULL,
  3. so, theroretically, it might lead to an exception at runtime if BKPF-WAERS is null.

Hence, COALESCE is a good solution to avoid the exception to define a value instead of the NULL value:

INSERT ztable FROM ( SELECT coalesce( bkpf~waers , ' ' ), ... FROM zcview ).

 

Answers (2)

Answers (2)

Sandra_Rossi
Active Contributor

It's possible to use the SQL function COALESCE to convert NULL into a value, and the warning doesn't show up anymore, e.g.

INSERT ztable FROM ( SELECT coalesce( bkpf~waers , ' ' ), ... FROM zcview ).

But is it good to use COALESCE for just a warning...

sap_cohort
Active Contributor
0 Kudos

It's probably a generic warning requiring a pragma is all.  No way around probably. 
As a test I would remove "BUKRS" to see if you get a warning about the next field after "BUKRS"

Sandra_Rossi
Active Contributor
Yes, warning for all key fields.