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: 

ORDER BY error in INNER JOIN

0 Kudos

I'm writing a select statement using inner join for 5 tables and need to order the output from one among them but i get an error saying ""VBRK" is invalid here (due to grammar). contains an invalid character or it is a keyword. (It might be possible to escape it using "!"). Or a space is missing or there is one space too many.". The following is the code

SELECT * INTO TABLE lt_dli_dlief_vbfa_vbrk_ekbe
FROM ad01dli
INNER JOIN ad01dlief
ON ad01dli~dlinr = ad01dlief~dlinr
INNER JOIN vbfa
ON vbfa~vbelv = ad01dlief~vbeln
"AND stufe = '00'
"AND vbtyp_v = 'L'
INNER JOIN vbrk
ON vbrk~vbeln = vbfa~vbeln
"AND rfbsk = 'C' "VBRK-VBELN = VBFA-VBELN AND VBRK-RFBSK = 'C'
LEFT OUTER JOIN ekbe "EKBE
ON ekbe~ebeln = ad01dli~zz_ebeln "EKBE-EBELN = AD01DLI-ZZ_EBELN
FOR ALL ENTRIES IN lt_ad01dli_ad01dlief
WHERE ad01dli~objnr = lt_ad01dli_ad01dlief-ad01dli-objnr "AD01DLI-OBJNR IN 5b4.AD01DLI-OBJNR
AND ad01dli~orig_objnr = lt_ad01dli_ad01dlief-ad01dli-orig_objnr "AD01DLI-ORIG_OBJNR IN 5b4.AD01DLI-ORIG_OBJNR
AND ad01dli~kstar = lt_ad01dli_ad01dlief-ad01dli-kstar "AD01DLI-KSTAR IN 5b4.AD01DLI-KSTAR
AND ad01dli~lstar = lt_ad01dli_ad01dlief-ad01dli-lstar "AD01DLI-LSTAR IN 5b4.AD01DLI-LSTAR
AND ad01dli~pernr = lt_ad01dli_ad01dlief-ad01dli-pernr "AD01DLI-PERNR = 5b4.AD01DLI-PERNR
AND ad01dli~zz_ebeln = lt_ad01dli_ad01dlief-ad01dli-zz_ebeln "AD01DLI-ZZ_EBELN = 5b4.AD01DLI-ZZ_EBELN
AND ad01dli~zhr_nonbillable = lt_ad01dli_ad01dlief-ad01dli-zhr_nonbillable "AD01DLI-ZHR_NONBILLABLE = 5b4.AD01DLI-ZHR_NONBILLABLE
AND ad01dli~zhr_remote = lt_ad01dli_ad01dlief-ad01dli-zhr_remote "AD01DLI-ZHR_REMOTE = 5b4.AD01DLI-ZHR_REMOTE
AND ad01dli~zzhr_awkey = lt_ad01dli_ad01dlief-ad01dli-zzhr_awkey "AD01DLI-ZZHR_AWKEY = 5b4.AD01DLI-ZZHR_AWKEY
AND ad01dli~profnr = lt_ad01dli_ad01dlief-ad01dli-profnr "AD01DLI-PROFNR = 5b4.AD01DLI-PROFNR
AND ad01dli~timestmp LT lt_ad01dli_ad01dlief-ad01dli-timestmp "AD01DLI-TIMESTMP < 5b4.AD01DLI-TIMESTMP
AND ad01dlief~vbeln <> lv_vgbel "AD01DLIEF-VBELN <> 3a.VBRP-VGBEL
AND vbfa~stufe = '00'
AND vbfa~vbtyp_v = 'L'
AND vbrk~rfbsk = 'C'
ORDER BY VBRK~BUDAT DESC VBRK-VBELN DESC.
What could be the possible error? Thanks in advance for any guidance.
4 REPLIES 4

VXLozano
Active Contributor
0 Kudos

I guess the problem is the asterisk. Try to put your field list (do you really need the fields of all five tables???) like

ad01dli~* ad01dlief~* vbfa~* vbrk~* ekbe~*

(not sure if "old" SQL will accept it, I'd try to move to the new one (using commas to separate fields and @ for values)

fedaros
Contributor

You have a ~ on first and a - on second:

ORDER BY VBRK~BUDAT DESC VBRK-VBELN DESC.

hdeveloper
Participant

Also BUDAT is not part of VBRK...

There are easy errors you have to review. I encourage you start from small and then you can start adding tables and fields. It's easier...

VXLozano
Active Contributor
0 Kudos

I did not noticed those two things... amazing XD