Is there any way to declare char variable (or maybe string) with the length which is calculated dynamically? This coding clarifies what I want:
DATA: len TYPE i,
a TYPE i,
b TYPE i.
len = a + b.
DATA: var(len) TYPE с.
Do not propose solutions with CREATE DATA and/or field symbols: I’ve tried them but they are not applicable in my case.
The intention of such declaration is adding leading zeroes and/or apply other logic to this string. Therefore string is to be declared strictly!
Any proposals?
Under the restrictions you impose (without specifying any understandable reasons besides “trust me”), this isn’t possible.
It’s also completely pointless to even try this. Either you know the length at compile time or you don’t. If you need to treat the lenght as a variable, then there’s no point in trying to generate data types dynamically. Use a STRING and take care of the leading zeroes manually. It’s not that hard.
EDIT 1:
It’s perfectly possible to use SHIFT, OVERLAY and TRANSLATE with STRING variables, at least in reasonably recent releases.
EDIT 2:
If you need complex patterns, use regular expressions – report DEMO_REGEX_TOY and the ABAP documentation should provide you with enough information.