简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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