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: 

Is it possible to create attribute in Z Class of type any

former_member184390
Participant
0 Kudos
262

Hi Friends,

I am working on a requirement to fine tune the code. for this i need to store the values retreived from a remote FM call in a global internal table. I am trying to check whether is it possible to create a global attribute of type any. This would help me to use the same internal table for down processing also. other wise i need to create several gloabl internal tables with the required structures.

any pointers on this would be very helpful.

Thanks,

udaya

1 ACCEPTED SOLUTION

Sm1tje
Active Contributor
0 Kudos
135

These generic types can only be used for field symbols and import / export parameters of methods and function modules. Here is a thought though: You can create some sort of container in which you can store all kinds of internal tables from your function module.

1. Create a global type in DDIC, or a local type in your class.

Code for local type:


TYPES: BEGIN OF ty_container,
         name        TYPE char30,
         container   TYPE REF TO data,
       END OF ty_container.

TYPES: tty_container TYPE SORTED TABLE OF ty_container WITH UNIQUE KEY name.

2. Create a private / protected attribute when using local type or any attribute you like when using a global type (set step 1).

3. Create a method (let's call it ADD_DATA) which imports the name of the structure the internal table from your FM is based on and the actual internal table. The import parameter for this internal table is typed TABLE (generic).

4. Coding in method:


  DATA: ls_itab TYPE ty_container.

  DATA: lv_data_ref       TYPE REF TO data.

  FIELD-SYMBOLS: <lt_value> TYPE table.

  CREATE DATA lv_data_ref LIKE ipt_itab.
  ASSIGN lv_data_ref->* TO <lt_value>.
  <lt_value> = ipt_itab[].

  ls_itab-name = itabname.
  ls_itab-container = lv_data_ref.
  INSERT ls_itab INTO TABLE gt_container.

Now the global attribute gt_container can hold any kind of internal table you add to it. It can be read using the NAME column field.

Hope this makes any sense to you, if not let me know.

BTW: Doesn't look like an ABAP Performance and Tuning issue (other forum).

5 REPLIES 5

Sm1tje
Active Contributor
0 Kudos
136

These generic types can only be used for field symbols and import / export parameters of methods and function modules. Here is a thought though: You can create some sort of container in which you can store all kinds of internal tables from your function module.

1. Create a global type in DDIC, or a local type in your class.

Code for local type:


TYPES: BEGIN OF ty_container,
         name        TYPE char30,
         container   TYPE REF TO data,
       END OF ty_container.

TYPES: tty_container TYPE SORTED TABLE OF ty_container WITH UNIQUE KEY name.

2. Create a private / protected attribute when using local type or any attribute you like when using a global type (set step 1).

3. Create a method (let's call it ADD_DATA) which imports the name of the structure the internal table from your FM is based on and the actual internal table. The import parameter for this internal table is typed TABLE (generic).

4. Coding in method:


  DATA: ls_itab TYPE ty_container.

  DATA: lv_data_ref       TYPE REF TO data.

  FIELD-SYMBOLS: <lt_value> TYPE table.

  CREATE DATA lv_data_ref LIKE ipt_itab.
  ASSIGN lv_data_ref->* TO <lt_value>.
  <lt_value> = ipt_itab[].

  ls_itab-name = itabname.
  ls_itab-container = lv_data_ref.
  INSERT ls_itab INTO TABLE gt_container.

Now the global attribute gt_container can hold any kind of internal table you add to it. It can be read using the NAME column field.

Hope this makes any sense to you, if not let me know.

BTW: Doesn't look like an ABAP Performance and Tuning issue (other forum).

0 Kudos
135

Thanks a lot Micky for your response. I tried to understand the explanation and tried a lot to interpret it. Sorry for requesting you again on how to take help from your response...

Let me phrase my requirement very detaily..

Currently we have a custom built customer cockpit screen in CRM having various blocks.

One for blocked sales order, latest return orders, sales orders, etc.whenever a customer calls up the support team, agent will take his customer id and go to cockpit screen to get a full view of the customer. to achieve this,there is a function module in ECC which accepts the customer number as input parameter and gives us the results for each block.

Issue: i search for a customer, and open the cockpit screen to see the detailis. Later i navigate to another screen to record the customer request. During this process, when i again come back to cockpit screen, the systme is making a new RFC call to ecc system to retrieve the information again for the already identified customer. now what i am trying to do is to avoid repeated RFC calls to ECC System. The proposal is like this, we create a custom class having internal tables that are declared static. This tables will be filled up with ECC data one time for a given customer and will make a new rfc call when the internal tables are blank or when the customer number changed.

For this, i need to declare as many internal tables(one for return order, salesorder, blocked sales order) with the respective associated structure in the class attributes.

What we are tyring here is: we will create as many internal tables and mention the type reference as any so that there is no need to create custom structures in CRM System for each itab.

is there any procedure by how i can declare internal tables in the class attributes of type any.

Sm1tje
Active Contributor
0 Kudos
135

No there isn't, like I said, these generic types can not be used for this (only for amangst others field-symbols). But what I did was offer you an alternative. And according to your detail explanation, I still think it should be possible to use it for your requirement.

So tell me what it is you do not understand from my previous post, and I'll try to explain. Maybe even give me some CRM structures from a return order, salesorder and/or blocked sales order. This might just make it more comprehensive.

0 Kudos
135

From your requirement, it looks like you need to use the Singleton Design Pattern. Have a look at this post:

http://help-abap.blogspot.com/2008/09/abap-object-design-patterns-singleton.html

For your requirement, you need to add the customer number as the importing parameter in the GET_OBJECT method. Use the Customer number in the method implementation, to figure out the if the customer got changed or not, if yes than create a new class.

Like:


class get_object.

  if zcl_customer=>o_customer is initial.
     create object zcl_customer=>o_customer   " Singleton OBject
        exporting
           iv_kunnr = iv_kunnr.   " IMporting parameter
  endif.
  if  zcl_customer=>o_customer->v_kunnr <> iv_kunnr.
     create object zcl_customer=>o_customer   " Singleton OBject
        exporting
           iv_kunnr = iv_kunnr.   " IMporting parameter
  endif.    

  ro_customer = zcl_customer=>o_customer.

endclass.

As Micky, suggested create the Table type with the TYPE REF TO DATA as the instance attribute in this class. So, you can fill up the this, with your retrieved result. So, when you need to select the data for different order type, you need to get the singleton object by calling the method GET_OBJECT of the class ZCL_CUSTOMER.

Like:


form get_orders.
  data: lo_customer type ref to zcl_customer.
  lo_customer = zcl_customer=>get_object( v_kunnr ).
  read table lo_customer->t_Data with itabtype = 'SO'.
  check sy-subrc <> 0.
*   Call the RFC here
*   Get the data and fill up the T_DATA
endform.

Regards,

Naimesh Patel

Former Member
0 Kudos
135

Moderator message - Moved to the correct forum

Rob