cancel
Showing results for 
Search instead for 
Did you mean: 

get element data throu Parameter or variable

Former Member
0 Kudos

I Try to optimize my methods and put them from my view to the component Controller.

In my View MAIN i got a Context Node BLUBB with some data in it.

i write a method SAVE_DATA to save all the Data ob BLUBB.


     DATA lo_nd_BLUBB    TYPE REF TO if_wd_context_node.
     DATA lo_el_BLUBB     TYPE REF TO if_wd_context_element.
     DATA ls_BLUBB            TYPE wd_this->element_BLUBB.

     lo_nd_BLUBB = wd_context->get_child_node( name = wd_this->wdctx_BLUBB ).
     lo_el_BLUBB = lo_nd_BLUBB->get_element( ).
     IF lo_el_BLUBB IS INITIAL.
     ENDIF.

*   get all declared attributes
     lo_el_BLUBB->get_static_attributes( IMPORTING static_attributes = ls_BLUBB ).
*
**speichern
update BLUBB from ls_BLUBB.

This Coding workes fine in my View MAIN.

But now i what to have a Method SAVE_DATA in my Component Controller to use this more often in other Views etc.

I Created a Method SAVE_DATE in my CC with the Import Parameter (the Context Node BLUBB is mapped in den CC already)

TABLE Type String


*Übergebene Context node wird lokal übergeben.
data: xy_node type string.
xy_node =TABLE.

     DATA lo_nd_DATA TYPE REF TO if_wd_context_node.
     DATA lo_el_DATA TYPE REF TO if_wd_context_element.

     DATA ls_DATA    TYPE wd_this->element_BLUBB.

*    lo_nd_zberufuverf = wd_context->get_child_node( name = wd_this->wdctx_BLUBB ).
     lo_nd_DATA = wd_context->get_child_node( name = xy_node ).
     lo_el_DATA = lo_nd_DATA->get_element( ).
     IF lo_el_DATA IS INITIAL.
     ENDIF.

*   get all declared attributes
     lo_el_DATA->get_static_attributes( IMPORTING static_attributes = ls_DATA ).


CASE TABELLE.
   WHEN 'BLUBB'.
     update ZBLUBB from ls_DATA.
ENDCASE.

In my View MAIN i start the Method with


wd_comp_controller->data_save( 'BLUBB' ).

The Coding on line 8 is my Problem.


     DATA ls_DATA    TYPE wd_this->element_BLUBB.


This coding works for now..but when i whant to use an other context element...for example BLAH my Element wont do it.

So how can i change this definition so "BLUBB" is my Parameter or my Varaiable???

Something like this wont work, but i hope u understand what i mean


DATA ls_DATA TYPE wd_this->element_TABLE

Can u Please Help me.

Kind Regards

Tobi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi again,

thanks for your good examples.

But wenn i whanted to save my data i get always this Type conflikt.

I think my problme ist the fieldsymbol

in Your Example <lt_statt_attr> once with TYPE STANDARD TABE and once with TYPE ANY.

In both ways i always get a Type Conflict wenn i want to Move my DATA.

Here Comes the code

DATA: xy_node TYPE string.
   xy_node = node_name.

   DATA lo_nd_data         TYPE REF TO if_wd_context_node.
   DATA lo_el_data         TYPE REF TO if_wd_context_element.
   DATA lo_nd_info         TYPE REF TO if_wd_context_node_info.
   DATA lo_nd_struct_descr TYPE REF TO cl_abap_structdescr.
   DATA lv_type_name       TYPE string.
   DATA lo_stat_data       TYPE REF TO data.
   DATA lv_index           TYPE i.

   FIELD-SYMBOLS: <fs_data_table> TYPE STANDARD TABLE,
                  <fs_data> TYPE any.


*    lo_nd_zberufuverf = wd_context->get_child_node( name = wd_this->wdctx_zberufuverf ).
* read Node
   lo_nd_data = wd_context->get_child_node( name = xy_node ).
   IF lo_nd_data IS BOUND.
* get info
     lo_nd_info = lo_nd_data->get_node_info( ).
     IF lo_nd_info IS BOUND.
* get type description
       lo_nd_struct_descr = lo_nd_info->get_static_attributes_type( ).
* check if type name is DDtype
       IF lo_nd_struct_descr IS BOUND AND lo_nd_struct_descr->is_ddic_type( ) EQ abap_true.
* relativ Name übergabe
         lv_type_name = lo_nd_struct_descr->get_relative_name( ).
****        IF lo_nd_info->is_multiple( ) EQ abap_true AND id_index = 0.

**********************************************************************
*DATA für TYPE TABLE OF
* create data object basierend
CREATE DATA lo_stat_data TYPE TABLE OF (lv_type_name).
ASSIGN lo_stat_data->* TO <fs_data_table>.

IF <fs_data_table> is ASSIGNED.
   lo_nd_data->get_static_attributes_table( IMPORTING   table = <fs_data_table> ).
ENDIF.


CASE node_name.
               WHEN 'ZBERUFUVERF'.
                 DATA datenxy TYPE zberufuverf.
*                MOVE-CORRESPONDING <fs_data> TO datenxy. " ohne table
                 MOVE-CORRESPONDING <fs_data_table> TO datenxy. " mit table
                 UPDATE zberufuverf FROM datenxy.


If i try to Move the <fs_data_table> TO datenxy i get the Syntax Error

<fs_data_table> is no structure or table with header line.

But i dont know how to define this field symbol like this


I tryed earlear to use <fs_data> (without) Table but when i try this i get a dump because of type mismatch in my MOVE-CORRESPONDING line.

Here is the Screenshot of my Context Node ZBERUFUVERF


ramakrishnappa
Active Contributor
0 Kudos

Hi Tobias,

Your code looks fine .. till CASE statement.

Please change your code as below


        CASE NODE_NAME.


          WHEN 'ZBERUFUVERF'.


            DATA lt_zdata TYPE TABLE OF ZBERUFUVERF.

            CLEAR lt_zdata.
            APPEND LINES OF <fs_data_table> TO lt_zdata.

            MODIFY ZBERUFUVERF FROM TABLE lt_zdata.


        ENDCASE.

It should work.

Let me know, if you need any further assistance.

Regards,

Rama

Former Member
0 Kudos

Edit:

in my Debugger i see that <fs_data_table> has my changes in it..so everthing is right.

but how did i get this data in my table ZBERUFUVERF ?

ramakrishnappa
Active Contributor
0 Kudos

Thats good.

Please change the code as suggested in previous reply.

Answers (5)

Answers (5)

Former Member
0 Kudos

mayby i got a improvemet for this coding.

the Key for this coding is to find out the name of the context node

******************************************************************************************

  lo_nd_data = wd_context->get_child_node( name = xy_node ).
   IF lo_nd_data IS BOUND.
* get info
     lo_nd_info = lo_nd_data->get_node_info( ).
     IF lo_nd_info IS BOUND.
* get type description
       lo_nd_struct_descr = lo_nd_info->get_static_attributes_type( ).
* check if type name is DDtype
       IF lo_nd_struct_descr IS BOUND AND lo_nd_struct_descr->is_ddic_type( ) EQ abap_true.
* relativ Name übergabe
         lv_type_name = lo_nd_struct_descr->get_relative_name( ).
****        IF lo_nd_info->is_multiple( ) EQ abap_true AND id_index = 0.

*********************************************************************
*DATA für TYPE TABLE OF
* create data object basierend
CREATE DATA lo_stat_data TYPE TABLE OF (lv_type_name).
******************************************************************************************


But because i now the name of the node (import parameter xy_node) i can just use this one line of code

CREATE DATA lo_stat_data TYPE TABLE OF (xy_node).


and i got the same effect.

ramakrishnappa
Active Contributor
0 Kudos

Hi Tobias,


Tobias Kübler wrote:

But because i now the name of the node (import parameter xy_node) i can just use this one line of code

CREATE DATA lo_stat_data TYPE TABLE OF (xy_node).


and i got the same effect.

The below statement is working for you because your node name is same  as TABLE/Structure name

CREATE DATA lo_stat_data TYPE TABLE OF (xy_node)

......

at runtime :

CREATE DATA lo_stat_data TYPE TABLE OF (ZBERUFUVERF)

So, make sure that you have same name as table/structure name always.... otherwise it wont work

Regards,

Rama

Former Member
0 Kudos

yea but because i know the name (my import parameter) it is no problem here...

Former Member
0 Kudos

WOW Thank you verry mutch Rama,

with you Coding you saved my da

no it works fine...

Kind Regards

Tobias

ramakrishnappa
Active Contributor
0 Kudos

Okay..thats good... finally you are able to save you data

Former Member
0 Kudos

Hi Tobias,

Send context element reference(if_wd_context_element)  to the SAVE_METHOD from which ever view you are using along with Node name for your case statement.

then Try below code in SAVE_DATA

When 'BLUBB'.

ls_blubb = ls_element->get_static_attributes( ).

When 'BLAH'.

ls_blah = ls_element->get_static_attributes( ).

Regards

Ajay

ramakrishnappa
Active Contributor
0 Kudos

Hi Tobias,

Please change your code as below


METHOD save_data .


  DATA xy_node TYPE string.

  DATA lo_nd_data TYPE REF TO if_wd_context_node.
  DATA lo_el_data TYPE REF TO if_wd_context_element.

  DATA lr_data TYPE REF TO data.

  FIELD-SYMBOLS: <fs_data> TYPE any.

  xy_node = table.

 

   TRANSLATE xy_node TO UPPER CASE.

  lo_nd_data = wd_context->get_child_node( name = xy_node ).
 
  "if lead index is not set, use index = 1
  lo_el_data = lo_nd_data->get_element( INDEX = 1 ).


  "  get all declared attributes
  lr_data = lo_el_data->get_static_attributes_ref( ).

  "return if data ref is not bound
  IF lr_data IS NOT BOUND.
    RETURN.
  ENDIF.

  ASSIGN lr_data->* TO <fs_data>.

  " return if field symbol is not assigned
  IF <fs_data> IS NOT ASSIGNED.
    return.
  ENDIF.

  CASE xy_node.
    WHEN 'BLUBB'.
      data ls_zblubb TYPE ZBLUBB.
      MOVE-CORRESPONDING <fs_data> to ls_zblubb.

      update ZBLUBB FROM ls_zblubb.
    WHEN 'BLAH'.

    WHEN OTHERS.
  ENDCASE.


ENDMETHOD.

Please note that this works as work area.. for reading data of type table, you need to change the code accordingly.

Former Member
0 Kudos

Thank You for your Quick Answer.

I Try Your Coding above but i got this Error

Falscher Typ eines Operanden bei der Anweisung MOVE-CORRESPONDING.


So there is a Type Conflict beween

MOVE-CORRESPONDING <fs_data> to ls_zblubb.


I Try to change the type of the FIELD-SYMBOLS

FIELD-SYMBOLS: <fs_data> TYPE any TABLE.

But then i got a Syntax error

ASSIGN lr_data to <fs_data>.  is not Typ Compatibel


What can i do now?

I Think <fs_data> must be typed like a strcture...or a intern TAble

ramakrishnappa
Active Contributor
0 Kudos

Hi Tobias,

Please refer the below blog links

Custom getter & setter methods in Webdynpro ABAP - Part 1

Custom getter & setter methods in Webdynpro ABAP - Part 2

Try to create these methods and use .

Hope this meets your requirement.

Regards,

Rama

former_member222068
Active Participant
0 Kudos

Hi Tobias,

   Structure of the node and structure of the table should be same always. Check with the structures once.

Can you paste the screen shots of the context, method with parameters of the context.

Thanks & Regards,

Sankar Gelivi