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 can't I extract data from KNB1 in my query?

bmierzwi
Participant
0 Kudos

Hello,

I asked a similar question before, but it included incorrectly written code and this derailed the narrative of my real problem.

I am modyfing a query in SQ02. This is my code:

TYPES: BEGIN OF tlf_knb,
tlfns TYPE knb1-tlfns,
END OF tlf_knb.

DATA: tlf_knb TYPE tlf_knb.

SELECT SINGLE tlfns
INTO tlf_knb
FROM knb1
WHERE kunnr = likp-kunnr
AND BUKRS = 5000. KART_KLIENT1 = tlf_knb-tlfns.

I need to take the phone number (tlfns) from KNB1 by linking it with LIKP by kunnr (customer number).

No errors are reported by SAP in this code. LIKP is not the main queried table, but it is used in the same fashion in the same field to get different data (it's a bit of a mess, the code for all fields is written in the same field) ALSO by (…)WHERE KUNNR = LIKP-KUNNR and it works as a charm.

So there are multiple lines of code querying LIKP and everything works except for my code that I pasted above.

The only thing that I added to the field that hasn't been there before is the table KNB1. It has the field KUNNR, it has values, it should be capable of joining with LIKP by this KUNNR no problem. That table is not added in the "Extras" section… but nor is any other table also used within this query and they all work correctly.

The thing is, while it reports no error, it just returns empty fields. The debugger doesn't show anything.

Tables are declared. As I mentioned, I am writing a very similar code to the code that already is there so this shouldn't be the issue of having anything declared incorrectly or put in a wrong place or the wrong order of declaration.

Also, I tried changing the data type of the column from knb1-tlfns to simple c and passed into it a string literal and it works perfectly. When I leave the data type of the field as C and try to put a tlfns there, it doesn't work again.

I attempted to convert the tlfns to C or I and pass it into the column like that (complete with changing the data type of the column to a respective type), but that also doesn't work. So, I reckon, my code doesn't even extract anything from KNB1 and tlf_knb is empty.

Here is what the code looks like after my attempts at converting the value to C or I:

TYPES: BEGIN OF tlf_knb,
 tlfns TYPE knb1-tlfns,
END OF tlf_knb.

DATA: tlf_knb TYPE tlf_knb,
 tlf_pars TYPE C.

SELECT SINGLE tlfns
 INTO tlf_knb
 FROM knb1
 WHERE kunnr = likp-kunnr
 AND BUKRS = 5000.
 
tlf_pars = tlf_knb-tlfns.

KART_KLIENT1 = tlf_pars.



Grateful for any answers.

1 ACCEPTED SOLUTION

bmierzwi
Participant

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 just had to move from one to another... I am not sure why it 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…?

6 REPLIES 6

Sandra_Rossi
Active Contributor

Please edit your question, select your code and press the "CODE" button to make it correctly colorized/indented, so that it's easier for us to analyze it. Thank you.

Nikhil_Rao_ABAP
Participant

Hello,

in an earlier post from the 19th, you said that you knew which company code - BUKRS, you wanted to get the KUNNR record for, and if memory serves right it was '5000'. so its possible you don't get the TLFNS because it simply gets it for some company code against whom the customer is extended but no TLFNS value is maintained. Can you make your where clause stricter by adding the company code condition also?

regards,

Nikhil

bmierzwi
Participant
0 Kudos

Hello Nikhil,

Thanks for the input, I am adding the BUKRS as well and, yes, your memory serves you well. 🙂 Unfortunately, adding it to the WHERE clause with AND keyword doesn't change anything. Still no values.

I also edited the question a bit -> when I put in a string literal (after changing the data type of the column to a simple c), then it works. But when I leave the data type of the column as c and try to pass in the tlfns, no results - if that gives any insight what my problem might be.

Regards,
Bartosz

Nikhil_Rao_ABAP
Participant

Hello Bartosz,

Can you still paste the most current version of the code snippet, please...

Cheers, Nik

bmierzwi
Participant
0 Kudos

Hello Nikhil,

I updated my question with the current version of the code.

Cheers,
Bartosz

bmierzwi
Participant

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 just had to move from one to another... I am not sure why it 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…?