0
votes

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

1
I am not sure what you mean with "the continuity of field symbols is broken". Can you explain that in a different way and elaborate on why it is a problem? - Philipp
I think that the second snippet would work if you used an untyped field-symbol (just FIELD-SYMBOLS <sdata>.). But now you have a field-symbol without a type which might cause other typing problems down the line. Depending on what "Logic goes here means, this might or might not be a problem which can or can't be easily solved. - Philipp
I think your 2nd example has the exact syntax error <IDOCDATA>-SDATA" and "<SDATA>" have incompatible types. It just needs CASTING: ASSIGN <idocdata>-sdata TO <sdata> CASTING. - Sandra Rossi
@SandraRossi always to the rescue. Yes, exactly what I was looking for. I never really understood the usecase of CAST. Is there anything I should be careful of using CAST in this scenario? - Ravi Rishie
In your scenario, CASTING should work without any issue because the structures of IDoc segments should contain only character-like fields (C, N, D, T). - Sandra Rossi

1 Answers

2
votes

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.