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: 

[ABAP] IN A LOOP (Specified length can contain only numeric literals or constants.)

rachidroughi
Explorer
0 Kudos

Hello Guys,

sorry for the noob question, I forgot the correct syntax for this and didn't find anything in SCN.

- ERROR: Specified length can contain only numeric literals or constants

Any suggestion?

Best regards,

RR.

6 REPLIES 6

xiaosanyu
Participant
0 Kudos
where key(3) = 'XYZ'.

have a try.

0 Kudos

It should be dynamic... I mean, in a variable.

0 Kudos
where key CP 'XYZ*'.

Is this okay?

raymond_giuseppi
Active Contributor

try something like

* Build a dynamic wildcard field
lv_key_wildcard = lv_key_master(lv_key_length) && '*'.
* Use it in the where criteria
WHERE key CP lv_key_wildcard<br>

jasmin_gruschke
Product and Topic Expert
Product and Topic Expert

Hi Rachid,

as the compiler tells you "can only contain literals or constants". Other experts already answered, just to add that the documentation might make it clearer (https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenoffset_length.htm).

So you can either use a literal (see answer by Xiaosan Yu) or you might define a constant cv_key (instead of lv_key). Or depending on your specific requirement the wildcard alternative might be handy for you as well.

Best,
Jasmin

jack_graus2
Active Contributor
0 Kudos
DATA lv_key TYPE i.
LOOP AT lt_tree INTO DATA(ls_tree).
CHECK ls_tree(lv_key) = lv_key_master.
ENDLOOP.