Skip to Content
author's profile photo Former Member
Former Member

How to define attributes in methods given as Field Symbols dynamically casted

Hi,

i have assigned a string to a field-symbol via a casting type (line 16/17) and then i am refering to one of the fields in the field-symbol (line 22/24).

Later I try to call a method with this field which is again assigned to a field-symbol (line 29).

What type do I have to declare in the definition of the called method for the attribute lv_to (line 44/45/46) ?

For ease of understanding see the source code:

FORM data_mapping  USING    p_wa_record TYPE t_record
                           p_l_spos TYPE i
                  CHANGING p_wa_record_data.

  DATA: l_new_data TYPE c LENGTH 750.


  FIELD-SYMBOLS :  <data> TYPE any.
  FIELD-SYMBOLS :  <l_target> TYPE any.

  CASE p_wa_record-sa.
    WHEN '01'.
* Tabelle ZMO_CON_VT01
      ASSIGN p_wa_record_data TO <data> CASTING TYPE zcon_vt01_s01_host.
      ASSIGN l_new_data TO <l_target> CASTING TYPE zcon_vt01_s01.
    WHEN '02'.
* Tabelle ZMO_CON_VT02
*      ...
  ENDCASE.

  LOOP AT lt_mapping ASSIGNING FIELD-SYMBOL(<lwa_map>) WHERE sa = p_wa_record-sa.
    ASSIGN COMPONENT <lwa_map>-from_field OF STRUCTURE<data>  TO FIELD-SYMBOL(<lv_from>).
    CHECK sy-subrc = 0.
    ASSIGN COMPONENT <lwa_map>-to_field OF STRUCTURE <l_target> TO FIELD-SYMBOL(<lv_to>).
    CHECK sy-subrc = 0.
    IF <lwa_map>-mapping_method IS INITIAL.
       <lv_to> = <lv_from>.
    ELSE.
      PERFORM ZMAPPINGS=>(<lwa_map>-mapping_method) USING <lv_from> p_wa_record CHANGING <lv_to>.
    ENDIF.
  ENDLOOP.
  p_wa_record_data = l_new_data.
ENDFORM.

*&---------------------------------------------------------------------*
*&       Class ZMAPPINGS
*&---------------------------------------------------------------------*
*       Mappings
*----------------------------------------------------------------------*
CLASS zmappings DEFINITION.

  PUBLIC SECTION.

    METHODS map_gv_sgber_sc IMPORTING lv_from TYPE string p_wa_record TYPE t_record CHANGING lv_to TYPE ?? .
    METHODS map_gv_sgbsta_sc IMPORTING lv_from TYPE string p_wa_record TYPE t_record CHANGING lv_to TYPE ??.
    METHODS map_vorsorge_sc IMPORTING lv_from TYPE string p_wa_record TYPE t_record CHANGING lv_to TYPE ??.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

Thank you!

BR Mike

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 07, 2016 at 09:19 AM

    Hi

    Probably it should be a TYPE ANY

    Max

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2016 at 02:31 PM

    Line 29 = PERFORM !!?? or CALL METHOD ... EXPORTING lv_from = <lv_from> ...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 08, 2016 at 09:25 AM

    It will be hard to award the right answer because this code does have more than one error.

    It seems that the use of "type any" helped.

    But it line 29 the method name cannot be found and the program dumps.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 09, 2016 at 08:33 AM

    The solution was to move the Class out of the Report into the Klasslibrary of the Package.

    And use the the concrete type when defining the Methods.

    When calling i don't care because the mapping knows exactly which Method to use.

    So the final code looks like that:

    CALL METHOD zmappings=>(<lwa_map>-mapping_method) EXPORTING lv_from = <lv_from> p_wa_record = p_wa_record RECEIVING lv_to = <lv_to>.


    which calls similar definitions as the following:

    class-methods MAP_GV_SGBER_SC
    importing
    value(LV_FROM) type ANY
    !P_WA_RECORD type ZCON2_T_RECORD
    returning
    value(LV_TO) type CHAR01 .

    So thank you all for you help.

    And now I really have a problem to award the right answer (mine is definetly not in the election).

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.