cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP CQL - Join a JS array with Database (like For All Entries in ABAP)

bbalci
Contributor

Hi , I'm coding something on SAP CAP on NodeJS , I've a question about a CQL query :

imagine I have a JS array with 2 fields, something like below :

const t_header = [
{bukrs: "1000", belnr: "00001"},
{bukrs: "2000", belnr: "00001"},
{bukrs: "2000", belnr: "00002"}
]

I need to query another db (items) table corresponding to the entries in JS array above,
So I've taken out "bukrs" field as a separate array and "belnr" field as another separate array and then used them with "in" operator as below :

const t_bukrs = t_header.map(line => line.BUKRS);
const t_belnr = t_header.map(line => line.BELNR);

const t_item =
await SELECT.from(BSEG).where({BUKRS: { in: t_bukrs}, BELNR: { in: t_belnr}});

But it's resulting some unwanted entries,
for example I don't need an entry with fields : bukrs: "1000" and belnr: "00002" in above example.

How can I properly code it ?
( P.S. it's just same thing what "FOR ALL ENTRIES" statement does in classical ABAP )
Thanks
Bulent Balci

View Entire Topic
KM11
Participant
0 Kudos

Hi bulent-balci

One way is you can create a dynamic select query looping through all records using 'and' (where bukrs = '1111' and belnr = '123456789' Or where bukrs = '2111' and belnr = '223456789' .)

Do post if you find a better way, will be great to know.

Thanks

Kanika