Existing column considered non-existent during Select

234 Views Asked by At

I need to select a field from knb1 where kunnr from knb1 is equal to kunnr in likp and assign it to field KART_KLIENT1. For a reason I can't warp my head around, it says that neither table knb1 nor likp have a column kunnr... Which both of them do.

I don't know where to look for a problem, both knb1 and likp are predefined database tables in SAP and kunnr column is there by default.

I am working in SQ02, adding the code to one of the fields.

  • If I add knb1 and lipk to TABLES section, there's an error saying they are already defined.
  • Trying to define kunnr in DATA section (TYPE or LIKE) doesn't change anything.
  • Using '~' instead of '-' in WHERE part of the SELECT doesn't change anything.

Thank you for your time.

TYPES: BEGIN OF ty_knb,
  tlfns TYPE knb1,
  END OF ty_knb.

DATA: wa_knb TYPE ty_knb.

SELECT SINGLE TLFNS
  INTO wa_knb
  FROM knb1
  WHERE knb1-kunnr = likp-kunnr.

KART_KLIENT1 = wa_knb-tlfns.
2

There are 2 best solutions below

0
On BEST ANSWER

So all of a sudden I stumbled upon a solution. Within the entire query the code for many fields is put inside a few of them and I had to move from one to another... I am not sure why exactly my solution works since I am new to ABAP, but my guess is, that it had to have something to do with the ordering of the fields. I am not certain though, as previously, I was moving the entire code from that field to another one, where the majority of the code is located in order to have all the table declarations in a single place. So it's either an inner thing of SAP I don't know about yet or there was some sort of a relation between different sections of the code that required my code to be written in that exact field with its exact place in the ordering…?

5
On
TYPES: BEGIN OF ty_knb,
  tlfns TYPE knb1,
END OF ty_knb.

This creates a structure type with one field tlfns, but the type of that column is not one field but actually a whole line of the database table knb1. Or in other words, you create a structure nested within a structure, also known as a "deep structure". I doubt that this is what you want to do. It seems to me that what you actually want to do is to have a structure with a field named tlfns which is the same type as the column named tlfns of the database table knb1.

In that case, you would write it like that:

tlfns TYPE knb1-tlfns,

Regarding your select statement, try this:

WHERE kunnr = likp-kunnr.

You only need to state the table in a WHEREcondition if it's ambiguous (for example when you JOIN multiple tables). But in that case you would write it like this:

WHERE knb1~kunnr = likp-kunnr.

(assuming likp is another structure with a field kunnr containing a valid customer number).