Application Development and Automation 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: 
Read only

Dynamic SQL - Long query

Former Member
0 Likes
782

Hi there,

I need to build a query at run time. The problem is I have two long JOIN conditions, as follows:


LEFT JOIN mbew ON mbew~matnr = mara~matnr AND mbew~bwkey = mseg~werks AND mbew~bwtar = mseg~bwtar
LEFT JOIN zmm_mseg_ext AS ext ON ext~mblnr = mkpf~mblnr AND ext~mjahr = mkpf~mjahr AND ext~zeile = mseg~zeile

I am using a table of EDPLINE structure but it has only 72 characters per line. Above joins are around 100 chars each. Trying to extend the line to 100 characters or use string as line type does not help. Either way I get

CX_SY_DYNAMIC_OSQL_SYNTAX exception.

I have also tried to split the statements into multiple lines i.e.:


[line1] LEFT JOIN mbew ON mbew~matnr = mara~matnr 
[line2]  AND mbew~bwkey = mseg~werks AND mbew~bwtar = mseg~bwtar

Still no go. How can I solve the issue ?

Thanks in advance,

Bart

1 ACCEPTED SOLUTION
Read only

andreas_mann3
Active Contributor
0 Likes
713

please post your complete coding with respect to select and join

A.

6 REPLIES 6
Read only

andreas_mann3
Active Contributor
0 Likes
714

please post your complete coding with respect to select and join

A.

Read only

0 Likes
713

SELECT goes more less like this:


SELECT
      mkpf~mjahr mkpf~mblnr
      mseg~zeile mseg~lifnr mseg~wempf mseg~kunnr
      mseg~werks mseg~lgort
      mara~matnr mara~matkl
      marc~steuc
      ekko~ekorg ekko~ekgrp
      mbew~eklas
      t023t~wgbez
      lfa1~vbund AS spdos
      kna1~vbund AS spkli
FROM 
mkpf JOIN mseg ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr
JOIN mara ON mseg~matnr = mara~matnr
JOIN marc ON mseg~matnr = marc~matnr AND mseg~werks = marc~werks
LEFT JOIN t023t ON t023t~matkl = mara~matkl AND t023t~spras = 'L'
LEFT JOIN zmm_mseg_ext AS ext ON ext~mblnr = mkpf~mblnr AND ext~mjahr = mkpf~mjahr AND ext~zeile = mseg~zeile
LEFT JOIN ekko ON ekko~ebeln = mseg~ebeln
LEFT JOIN mbew ON mbew~matnr = mara~matnr AND mbew~bwkey = mseg~werks AND mbew~bwtar = mseg~bwtar
LEFT JOIN lfa1 ON mseg~lifnr = lfa1~lifnr
LEFT JOIN kna1 ON mseg~kunnr = kna1~kunnr
WHERE
mkpf~budat IN o_budat
AND mseg~matnr IN o_matnr
AND marc~steuc IN o_steuc
AND mara~matkl IN o_matkl
AND mseg~lifnr IN o_lifnr
AND mseg~wempf IN o_wempf
AND mseg~kunnr IN o_kunnr
INTO CORRESPONDING FIELDS OF wa_entry.

Read only

0 Likes
713

No problem to put all of this into string variables.

Read only

0 Likes
713

Hello,

Hehe, yes, I was just trying to edit my post, but You responded and I couldn't do it anymore

It was a mistake in my query, It's true, string is sufficient to store the query, case closed.

Thanks,

Bart

Read only

rainer_hbenthal
Active Contributor
0 Likes
713

You can use string variables to put the whole code in it. Its not necessary to split the SQL in lines. Mos DBMS limit the SQL to 32lbyte, that will for sure fit into a string variable.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
713

Hello Bart,

There is definitely something wrong with the dynamic SELECT stmt you are creating. As suggested by Rainer try declaring the entire thing as TYPE STRING & proceed.

Anyways FYI you can refer to this SAP documentation on the different exceptions in Open SQL: [http://help.sap.com/abapdocu_70/en/ABENOPENSQL_EXCEPTIONS.htm|http://help.sap.com/abapdocu_70/en/ABENOPENSQL_EXCEPTIONS.htm]

BR,

Suhas