简体   繁体   English

通过字段符号更改 IDoc 段 SDATA?

[英]Changing IDoc segment SDATA via field-symbols?

My scenario is that I am getting an IDOC segment's data into a field symbol and change some fields based on some validations.我的情况是,我将 IDOC 段的数据放入字段符号中,并根据某些验证更改某些字段。

My code:我的代码:

READ TABLE idoc_data ASSIGNING FIELD-SYMBOL(<idocdata>) with key = 'E1EDK01'
IF sy-subrc = 0.

    lcl_struc ?= cl_abap_typedescr=>describe_by_name( 'E1EDK01' ).
    CREATE DATA dref TYPE HANDLE lcl_struc.
    ASSIGN dref->* TO FIELD-SYMBOL(<sdata>).

    IF <sdata> IS ASSIGNED.
      <sdata> = <idocdata>-sdata. 
      ....
      <idocdata>-sdata = <sdata>.
    ENDIF. 
ENDIF. 

Though the above snippet works fine, the continuity of field symbols is broken and now I have to pass back the changed data.虽然上面的代码片段工作正常,但字段符号的连续性被破坏了,现在我必须传回更改后的数据。 How do I use ASSIGN and let the field symbols take care of the changes rather than an explicit statement?如何使用ASSIGN并让字段符号处理更改而不是显式声明?

Something similar to below snippet though this won't work since <IDOC_DATA>-SDATA and <SDATA> aren't compatible.类似于下面的代码片段,尽管这不起作用,因为<IDOC_DATA>-SDATA<SDATA>不兼容。

READ TABLE idoc_data ASSIGNING FIELD-SYMBOL(<idocdata>) with key = 'E1EDK01'
IF sy-subrc = 0.
    FIELD-SYMBOLS: <sdata> TYPE E1EDK01.
    ASSIGN <idocdata>-sdata TO <sdata>.
    ....
ENDIF.

My expectation is that when I change the data in <SDATA>-FIELD1 , I want the changes to flow into <IDOCDATA>-SDATA without using <idocdata>-sdata = <sdata> .我的期望是,当我更改<SDATA>-FIELD1的数据时,我希望更改流入<IDOCDATA>-SDATA而不使用<idocdata>-sdata = <sdata>

As @Sandra mentioned above, the incompatibility of field-symbols can be resolved by using CASTING while assigning them.正如@Sandra 上面提到的,字段符号的不兼容可以通过在分配它们时使用CASTING来解决。 This would make the second snippet work.这将使第二个片段起作用。

...
IF sy-subrc = 0.
   FIELD-SYMBOLS: <sdata> TYPE E1EDK01.
   ASSIGN <idocdata>-sdata TO <sdata> CASTING.
   ...
ENDIF.

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

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