Search code examples
abapsap-query

Existing column considered non-existent during Select


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.

Solution

  • 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…?