简体   繁体   中英

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.

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?

Something similar to below snippet though this won't work since <IDOC_DATA>-SDATA and <SDATA> aren't compatible.

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

As @Sandra mentioned above, the incompatibility of field-symbols can be resolved by using CASTING while assigning them. This would make the second snippet work.

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

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