简体   繁体   English

将字段符号传递给FORM

[英]Passing field-symbols into FORM

I need to assign data field (component of another field symbol) to field-symbol in a several places of code. 我需要在几个代码位中将数据字段(另一个字段符号的组件)分配给字段符号。 For the sake of reusability I decided to encapsulate this code in procedure, but I cannot understand how to pass field-symbols into this procedure. 为了可重用性,我决定将此代码封装在过程中,但我无法理解如何将字段符号传递给此过程。

LOOP bseg ASSIGNING <bseg>
...
PERFORM assigning USING <bseg>
                  CHANGING <wrbtr>.
...
ENDLOOP.

FORM assigning USING <bseg> TYPE bseg
               CHANGING <wrbtr> TYPE bseg-wrbtr
IF ...
  some logic here
  ASSIGN <bseg>-wrbtr TO <wrbtr>.
ELSE
  ASSIGN <bseg>-skfbt TO <wrbtr>.
ENDIF.

ENDFORM.

This code does not work. 此代码不起作用。

What should I do to change the field symbol reference too? 我该怎么做才能更改字段符号引用?

This is not possible, at least not the way you try to do it. 这是不可能的,至少不是你尝试这样做的方式。 Field symbols cannot be passed as the pointers they really are. 字段符号不能作为指针实际传递。 If you need something like that, you'll have to use real references. 如果你需要这样的东西,你将不得不使用真正的参考。

Not knowing anything about the rest of your code - it looks a bit weird. 对其余代码一无所知 - 看起来有点奇怪。 Why would you want to change data in BSEG fields directly? 为什么要直接更改BSEG字段中的数据? I can only assume that you're "abusing" fields to transport some custom value throughout the code, and that's usually a bad idea. 我只能假设你“滥用”字段在整个代码中传输一些自定义值,这通常是一个坏主意。 And if you need to do this, I'd rather do it this way: 如果你需要这样做,我宁愿这样做:

LOOP bseg ASSIGNING <bseg>.
   IF foo.
    l_my_wrbtr = <bseg>-wrbtr.
  ELSE.
    l_my_wrbtr = <bseg>-skfbt.
  ENDIF.

  " ... pro'lly thousands of lines I don't even want to see...

  IF foo.
    <bseg>-wrbtr = l_my_wrbtr.
  ELSE.
    <bseg>-skfbt = l_my_wrbtr.
  ENDIF.
ENDLOOP.    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM