COBOL问题-初学者的问题,请指导
我想实现下面的
图片 X(5) 字符串包含 A1992 并递增到 A9999 ,在达到 A9999 后, A 应替换为 B ,其他字符应重新初始化为 0000 即 B0000 ,这应该发生直到Z9999,有可能吗?
或者如果你能告诉我如何增加 A 到 Z 就足够了
I want to acheive the below
a string of pic X(5) contains A1992 and is incremented to A9999 , after it reaches A9999 , the A should be replaced by B and the other characters should be reinitialized to 0000 ie B0000 , this should happen until Z9999 , is it possible somehow ?
or if you could show me how to increment A till Z that would be suffice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要对此进行一些手动字符操作。有几个部分,首先,您需要处理数字部分的简单加法,然后您需要处理其翻转以增加 alpha 部分。
与此类似的数据结构可能会有所帮助:
这将与简单的执行循环一起使用,如下所示:
这是您可以做到的一种方法。
请注意,上面的代码采用了一些快捷方式(又名卑鄙的黑客)——比如将一个填充单元放入 Odometer-Char 数组中,这样我就不必对其进行范围检查。除了示例和想法之外,您不会想将其用于任何其他用途。
You will need to do some manual character manipulation on this one. There are several parts, first, you need to handle the simple addition of the numeric portion, then you need to handle the rollover of that to increment the alpha portion.
Data structures similar to this might be helpful:
This would be used with a simple perform loop like so:
That is one way you could do it.
Please note, the code above took some shortcuts (aka skanky hacks) -- like putting a pad cell in the Odometer-Char array so I don't have to range check it. You wouldn't want to use this for anything but examples and ideas.
我可能会使用嵌套的执行循环来做到这一点。
储存:
程序:
I'd probably do this with a nested perform loop.
Storage:
Procedure:
只是无法控制自己...这个怎么样...
这将打印从
A1992
开始到Z9999
的所有“数字”。基本上窃取了 Marcus_33 的代码并稍微修改了一下。如果您愿意,请投票给他的答案,而不是我的答案
Just can't help myself... How about this...
This will print all the "numbers" beginning with
A1992
through toZ9999
.Basically stole Marcus_33's code and twiked it a tiny bit more. If you feel so inclined please upvote his answer, not mine
对于混淆的 COBOL 爱好者,这是我能想到的最短(可移植)版本(假设具有内部函数的编译器):
在 OpenVMS/COBOL 上测试。我将值缩短为 X(3),因为观看跑步很无聊。非可移植版本(如果您了解平台的 Endianness)是重新定义前缀为
S9(4) COMP
并直接递增低位。但这个解决方案不会更短......For lovers of obfuscated COBOL, here's the shortest (portable) version I can think of (assuming a compiler with Intrinsic Functions):
Tested on OpenVMS/COBOL. I shorten the value to X(3) since it's boring to watch run. A non-portable version (if you are aware of the Endianness of your platform) is to redefined the prefix as a
S9(4) COMP
and increment the low-order bits directly. But that solution wouldn't be any shorter...