Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Why doesn't knb1-kunnr and likp-kunnr exist?

bmierzwi
Participant
0 Kudos

Hello,

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
5 REPLIES 5

Sandra_Rossi
Active Contributor

bmierzwi
Participant
0 Kudos

That is a link to my question and I am afraid it's not answered yet. :<

Nikhil_Rao_ABAP
Participant

Hello,

A couple of things that do not look quite right in the snippet you posted.

a) in the TYPES: BEGIN OF... declaration why is the TLFNS field typed like the whole KNB1 structure, should it be TLFNS TYPE KNB1-TLFNS or TLFNS TYPE TLFNS(i.e. the data element TLFNS)

b) in where clause why is it WHERE knb1-kunnr = likp-kunnr, should it simply not be WHERE kunnr = likp-kunnr( since the select statement has FROM knb1 )

c) KNB1 contains the customer information at the company code level. So shouldn't the where clause also have had a AND BUKRS = <some other field in the program/code containing the company code value>

Regards,

Nikhil

bmierzwi
Participant
0 Kudos

Thank you for the time and input, Nikhil.

I implemented the changes you suggested, including the BUKRS part (5000 here, I was made to know), but there is still no result. 😕

It feels like I already managed to exhaust all possible solutions and all I am left with is possibly something being wrong outside of the code.

The infoset is quering VTTK mainly and I thought that perhaps I should "Join" KNB1 and LIKP there… but they have no connection to VTTK. So I thought I might join VTTP to VTTK and then I can link LIKP to VTTP by vbeln and then I can link KNB1 to LIKP by kunnr… But there are other "additional fields" in this query already, they are using LIKP-KUNNR without it being added in the "Join" at all, so I am at a loss why isn't my select working.

Regards,
Bartosz

bmierzwi
Participant
0 Kudos

The issue's resolved. Turned out it was the matter of the ordering in the end. I can't provide the specifics, because I don't really understand why it works. I just moved the code from one section to another (previously I copied all existing code from the section to which I returned eventually in order to have all the code within a single field)… and it just started working. So I either just don't know something about SAP's inner workings or perhaps there is some sort of a veiled relations between different sections of the code that required my newly introduced code to be precisely in that very field (due to the ordering, I suppose).