具有动态长度的字符变量 [英] Character variable with dynamic length

查看:100
本文介绍了具有动态长度的字符变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以声明具有动态计算长度的char变量(或字符串)?该编码阐明了我想要的内容:

 数据:len TYPE i,
a TYPE i,
b TYPE i 。
len = a + b。
数据:var(len)TYPEс。

不要提出带有CREATE DATA和/或字段符号的解决方案:我已经尝试过了,但是它们是不适用于我的情况。
这种声明的目的是添加前导零和/或对该字符串应用其他逻辑。因此必须严格声明字符串!



是否有提案?

解决方案方案

在您施加的限制下(除了信任我外,没有指定任何可理解的原因),这是不可能的。
即使尝试此操作也完全没有意义。您要么知道编译时的长度,要么不知道。如果您需要将长度视为变量,那么尝试动态生成数据类型毫无意义。使用STRING并手动处理前导零。

编辑1:
至少在合理的最新版本中,完全可以将SHIFT,OVERLAY和TRANSLATE与STRING变量一起使用。



编辑2:
如果您需要复杂的模式,请使用正则表达式-报告DEMO_REGEX_TOY和 ABAP文档应为您提供足够的信息。


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.

这篇关于具有动态长度的字符变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆