0
votes

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
are you running your request on the right schemaHamza
What do you mean by "schema"? I am quite new to SAP. I am working on BOT environment currently (if that's relevant).Bartosz_76
You say "section" concerning TABLES and DATA but I guess you mean "ABAP Keyword". According to your code, it seems that your infoset is querying the table LIKP primarily, in that case your code should not do a syntax error about likp-kunnr (but it's an error to have knb1-kunnr at the left of =, it should be either knb1~kunnr or kunnr). Please clarify which table(s) your infoset is querying primarily. Note that the codes of two Additional Fields share the same global scope, you cannot declare the same type or variable twice.Sandra Rossi
I think that the table that is quered primarly is VTTK... I am trying to add LIKP or KNB1 to queried tables too (because the whole idea is to have WHERE knb1~kunnr = likp-kunnr), but it won't let me. I am trying to add "additional table" next to "additional fields", but when I am specyfing that KNB1 should have WHERE KUNNR = LIKP-KUNNR, it throws an error that it's "not declared" anywhere in the code and I am lost. If I try to declare it, it throws an error... because "it's already declared."Bartosz_76
You must give an order to each of your codes, that you can see in the Extras tab. Declare your variables in the right order, and only once.Sandra Rossi

2 Answers

2
votes
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).

0
votes

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