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

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

问题描述

有没有办法用动态计算的长度来声明 char 变量(或者可能是字符串)?此编码阐明了我想要的:

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 с.

不要使用 CREATE DATA 和/或字段符号提出解决方案:我已经尝试过它们,但它们不适用于我的情况.此类声明的目的是添加前导零和/或将其他逻辑应用于此字符串.因此字符串要严格地声明!

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!

有什么建议吗?

推荐答案

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

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.

编辑 1:完全可以将 SHIFT、OVERLAY 和 TRANSLATE 与 STRING 变量一起使用,至少在最近的版本中是这样.

EDIT 1: It's perfectly possible to use SHIFT, OVERLAY and TRANSLATE with STRING variables, at least in reasonably recent releases.

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

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天全站免登陆