Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Probably it should be a TYPE ANY

Max

7 REPLIES 7

Former Member
0 Kudos

Hi

Probably it should be a TYPE ANY

Max

0 Kudos

I will try it.

Sandra_Rossi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

0 Kudos

Hi

I'm not sure because I can use an old abap release, so I don't all new commands, but as Sandra Rossi said:

PERFORM ZMAPPINGS=>(<lwa_map>-mapping_method) USING <lv_from> p_wa_record CHANGING <lv_to>.


is a "strange" line


I mean a method is called as it was a FORM



I suppose you haven't any sintax error because you have a dynamic calling, the name of the routine is stored in ZMAPPINGS=>(<lwa_map>-mapping_method), but at rutime the system expects a FORM instead of a METHOD, so you have that dump, try to change that line:


CALL METHOD

ZMAPPINGS=>(<lwa_map>-mapping_method) USING <lv_from> p_wa_record CHANGING <lv_to>.

Max


0 Kudos

Thank you for pointing this out to me.

I will change this.

Former Member
0 Kudos

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