cancel
Showing results for 
Search instead for 
Did you mean: 

What is the behavior of MAPPING FROM ENTITY USING CONTROL?

MichaelOnderka
Explorer
0 Kudos

Hello,

Im currenty trying to develop a unmanged RAP Service.

When implenting the change i want to extract only the changed fields from the imported entities

METHODS update FOR MODIFY
  IMPORTING entities FOR UPDATE signal.

Im creating my data with the current version from the database:

      DATA(ls_signal) = <signal>-signal->get_full( ).

Now i want to move the changed fields using the MAPPING FROM ENTITY USING CONTROL command.

LOOP AT entities ASSIGNING FIELD-SYMBOL(<entity>).
...
  DATA(ls_signal) = <signal>-signal->get_full( ).
  ls_signal = CORRESPONDING #( <entity> MAPPING FROM ENTITY USING CONTROL ).

Now ONLY the changed fields are in LS_SIGNAL.

Is this the correct bahavior?

Does CORRESPONING initilize the variable before transfering the fields?

9011609270
Explorer

Hi Michael,

did you already got an explanation or solution for this issue?

I face exactly the same problem. MAPPING FROM ENTITY USING CONTROL seems to initialize the target structure before moving the mapped attributes.

Thx, Jan

MichaelOnderka
Explorer

Hey Jan,


Ive Implemented my own solution for this problem. It replicates the functionality of mapping from entity but keeps the

old data. The map_to_tab needs to be defined for every structure you want to use this for. The control mapper should be universal. So far this is working but no 100% guarantee.

  
          map_to_tab(
              EXPORTING
              is_c = ls_signal_c          " New data
              where   = <entity>-%control " control
              CHANGING
               cs_t = ls_signal           " Data to be changed
            ).<br>

Implementation:

    METHODS map_to_tab
      IMPORTING is_c  TYPE /gibsfi/c_signal
                where TYPE any
      CHANGING  cs_t  TYPE /gib/sfi_signals 

  METHOD map_to_tab.

    DATA(c_full) = is_c.
    c_full = CORRESPONDING #( cs_t  MAPPING TO ENTITY ).

    zcl_rap_hlpr=>control_mapper(
      EXPORTING
        control = where
        from    = is_c
      CHANGING
        to      = c_full
    ).

    cs_t = CORRESPONDING #( c_full MAPPING FROM ENTITY ).
    cs_t-mandt       = sy-mandt.

  ENDMETHOD.

and

CLASS zcl_rap_hlpr DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    CLASS-METHODS:
      control_mapper
        IMPORTING
          control TYPE any
          from    TYPE any
        CHANGING
          to      TYPE any.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.


METHOD control_mapper.

    DATA(i) = 1.
    DATA lr_where TYPE REF TO cl_abap_structdescr.
    lr_where ?=   cl_abap_structdescr=>describe_by_data( control ).
    DATA(lt_comp) = lr_where->get_components( ).
    DO.
      ASSIGN COMPONENT i OF STRUCTURE control TO FIELD-SYMBOL(<where>).
      IF sy-subrc EQ 0.
        i = i + 1.
        IF <where> EQ '01'.
          READ TABLE lt_comp ASSIGNING FIELD-SYMBOL(<comp>) INDEX i - 1.
          IF sy-subrc EQ 0.
            ASSIGN COMPONENT <comp>-name OF STRUCTURE from  TO FIELD-SYMBOL(<from>).
            ASSIGN COMPONENT <comp>-name OF STRUCTURE to   TO FIELD-SYMBOL(<to>).
            <to> = <from>.
          ENDIF.
        ELSE.
          CONTINUE.
          i = i + 1.
        ENDIF.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.

  ENDMETHOD.
View Entire Topic
lloydfernandes
Advisor
Advisor

You could have used the BASE addition of the CORRESPONDING statement.

  ls_signal = CORRESPONDING #( BASE ( ls_signal ) <entity> MAPPING FROM ENTITY USING CONTROL ).