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: 

Dynamic Where Clause for Key Field over 72 Characters

dean_hinson2
Active Contributor
0 Kudos

Hello,

A table previous built many years ago has a key of 66 characters. Yes, one field, ugh.

The examples I have seen for building dynamic where statements show the line being 72 characters. With the key field name and the condition, this would be longer that 72 characters.

Is there a way to solver this?

Regards, Dean.

8 REPLIES 8

hagit
Active Participant

Could you please share the example , which limits to 72 characters ?

dean_hinson2
Active Contributor

DominikTylczyn
Active Contributor
0 Kudos

SAP Help on sql_cond - (cond_syntax) doesn't say anything about 72 chars limit. The examples put dynamic WHERE into a string type variable, which is not limited to 72 chars.

dean_hinson2
Active Contributor
0 Kudos

Hello Dominik,

So then I can use a string and that would be suffice?

Regards, Dean.

hagit
Active Participant

Look at the comment (not the answer) in the link you sent.

the code in the comment is:

DATA : l_where TYPE string,
       i_marc TYPE STANDARD TABLE OF marc.

CONSTANTS: l_quote TYPE char1 VALUE ''''.

PARAMETERS : p_plant TYPE marc-werks.

CONCATENATE 'WERKS' space '=' space l_quote p_plant l_quote space
            'AND' space 'PERKZ' space '=' space l_quote 'M' l_quote
       INTO l_where RESPECTING BLANKS.

SELECT * FROM marc INTO TABLE i_marc WHERE (l_where).

As 3a9e4ce873a94034b33dc62b0ce600ee wrote "The example put dynamic WHERE into a string type variable, which is not limited to 72 chars."

dean_hinson2
Active Contributor

Hello Dominik,

I was looking at the other one. Sorry that I didn't see that particular section. Then I am good o go forward.

Thank you.

Regards, Dean.

Sandra_Rossi
Active Contributor
0 Kudos

which can be written:

DATA(l_where) = |WERKS = '{ p_plant }' AND PERKZ = 'M'|.

be aware of CL_ABAP_DYN_PRG class to avoid SQL Injection Attacks (see ABAP documentation).

Sandra_Rossi
Active Contributor
0 Kudos

dean.hinson2

to answer your question "so then I can use a string", as you can see in "SAP Help on sql_cond - (cond_syntax)
":
  • "The data object cond_syntax can be a character-like data object or a standard table with a character-like row type"

"character-like data object" means STRING or TYPE C or whatever, as can be found here.