cancel
Showing results for 
Search instead for 
Did you mean: 

How to move the method from compoenent controller to assistance class method

former_member5006
Participant
0 Kudos

Hi,

    My scenario is  ..

In my compoenent i used lot of serviece calls for rfc's ,

so that for every rfc  there was one method  was created  in component controller (let say for 10 rfc's 10 methods are created with nodes and attributes).

How can i move these methods  from component controller to assistance class methods .,.. ?

It was created with node declarations and context , element declarations  as

data lo_nd_vbak type ref to if_wd_context_node.

wd_context , wd_this ,wd_comp_controller  and so on.

How can  i use these syntaxes in assistance class ? ....

when i copy these methods same  from component controller to assistance class  methods it was giving errors  with above declarations .. how can i remove of those .. ?

can u please  provide one document  or clear explanation please ,,

Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi Naveen,

You can move the service call business logic from component controller to an assistance class by making some adjustments like passing controller references, etc

You can achieve your requirement as below

  • let us say we have a method in component controller as below

method call_bapi_1.

data lo_node type ref to if_wd_context_node.

data lo_element type ref to if_wd_context_node.

data lt_items type wd_this->elements_ITEMS.

data ls_items like line of lt_items.

lo_node = wd_context->get_child_node( name = wd_this->wdctx_items ).

call function 'BAPI_1'

  exporting

  ITEMS = LT_ITEMS

  Receiving

  return = lt_return.

endmethod.

  • Now, we need to move whole method into assistance class,


    • Create a method BAPI_1 in assistance class and the parameters CO_CONTEXT, CO_THIS as changing parameters
    • Replace  wd_context with co_context & wd_this with co_this as required
    • We call an assistance method BAPI_1( ) as below

               wd_assist->bapi_1(

                    changing

                       co_context = wd_context

                       co_this = wd_this ).

Hope this helps you.

Regards,

Rama

former_member5006
Participant
0 Kudos

Hi Rama,

               Can  you please tell me how can i declare go_context and co_this in above class .

i am facing the exact problem here only ..Unable to declare compoenent controller attributes and view attributes  in assistance class.

let say one example ..

   DATA ls_c_is_address TYPE IF_COMPONENTCONTROLLER=>element_is_address.

..in this here i written same code in assistance class method i am getting error like IF_COMPONENTCONTROLLER is unknown 

how can i solve this ....

ramakrishnappa
Active Contributor
0 Kudos

Hi Naveen,

We cannot access the component attributes like WD_THIS->ELEMENT_is_address. Because, wd_this refers to the IF_COMPONENTCONTROLLER which generates at runtime by WD framework. But we can have reference of wd_context & wd_this in assistance class and with dynamic programming we can get the info from that reference.

Hope you are creating nodes with a static DDIC structure.Hence, the internal tables and internal structures will be created by using the DDIC type.

The method BAPI_1( ) in assistance class should have parameters as below

 

-------------------------------------

I would like to suggest you that, attach every node with a DDIC type and use that to create tables/structures in method.

"you can get DDIC type from node & create an internal table as below as below


DATA lo_node TYPE REF TO if_wd_context_node.
  DATA lo_type TYPE REF TO cl_abap_structdescr.
  DATA lv_type TYPE string.
  DATA LO_DATA TYPE REF TO DATA.
  FIELD-SYMBOLS <FS_DATA> TYPE ANY.

  lo_node = co_context->get_child_node( name       = 'ADDRESSES'
  ).

 
  lo_type ?=
  lo_node->get_node_info( )->get_static_attributes_type( ).

  lv_type = lo_type->get_relative_name( ).

  CREATE DATA LO_DATA TYPE TABLE OF (LV_TYPE).

  ASSIGN LO_DATA->* TO <FS_DATA>.

  lo_node->get_static_attributes_table(
    IMPORTING
      table = <FS_DATA>
  ).

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

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

Option2: you can read data from context nodes in WD component and pass all the data as parameters to an assistance class method which just calls the bapi and update the parameters back

Regards,

Rama

former_member222068
Active Participant
0 Kudos

Hi Naveen,

  I have shared you a link. That particular document will solve all the errors that you are getting. I have written complete web dynpro logic in the assistance class.

Thanks & Regards,

Sankar Gelivi

Answers (3)

Answers (3)

former_member222068
Active Participant
0 Kudos

Hi Naveen,

This document will give you how to improve performance of an application.

http://scn.sap.com/docs/DOC-50851

Thanks & Regards,

Sankar Gelivi


krishnadhuriya
Explorer
0 Kudos

Hi!

You can move your coding to assistance class method and you can pass parameters to that method by calling through wd_assist  in component controller .

if I correctly understand your question...

Former Member
0 Kudos

you can use Assistance class Attributes to store the data  while calling RFC in  Assistance class method and where you are calling this Assistance class method in View/Controller, can set at the Node/attribute. .

former_member5006
Participant
0 Kudos

Hi chandra Agarwal,

             

i didnt get u clearly ..

Through Service call i got all the methods, attributes and nodes..

can u elaborate clearly please ...