2012 Jan 11 9:51 AM
Hi Experts,
I am new to OO programming and modifying a Webdynpro component to export a context data to a external class. As part of the requirement I want to export a data to external class and later on import the data from the class in another BADI during runtime. I am not sure how to implement this type of class but I assume it has something to do with constructor concept?
Can anyone help me as how to create and use such class?
2012 Jan 11 10:06 AM
Does all these process happens in a single execution & from where is the data to be exported ?
2012 Jan 11 10:36 AM
yes all happens in single execution. my idea is to export the data in WDDOBEFOREACTION method of the WDC.
the flow of the process is as given below
WDDOBEFOREACTION->BADI CALL->WDDOMODIFYVIEW.
the data will be exported in WDDOBEFOREACTION to class and imported in BADI call from the class.
2012 Jan 11 10:41 AM
If everything happens in a single flow why not use EXPORT TO / IMPORT FROM MEMORY
2012 Jan 11 10:44 AM
2012 Jan 11 10:51 AM
Hi,
You problem is a bit confusing. First of all i would recommend you to post this in Webdynpro forum. If you are talking about the standard classes then there is an option of enhancing the class using the new enhancement option by which you can get and set data. But I dont recommend this to a extent that there should be specific reason behind designing a class and including an customer enhancement may cause impact.
Kesav
2012 Jan 11 11:09 AM
my requirement is from the method WDDOBEFOREACTION of the WDC I want to export the context value to a Z class and later part of the execution in the BADI I want to retrive this exported data from the class.
2012 Jan 11 11:11 AM
Use the singleton pattern.
Create a class with attributes to hold the data you want to read in the BADI. Make a CONSTRUCTOR method, with appropriate importing parameters to populate the attributes. Make the constructor (instantiation) private. Create an attribute r_attr that is of TYPE REF your class.
Create a STATIC factory method that takes in your data (same importing parameters as the CONSTRUCTOR), and returns an instance of TYPE REF your class. In the factory method, if r_attr IS BOUND,m return r_attr. If it isn't, then CREATE r_attr, and then return it.
There are variations on this. You could have an static table of TYPE REF to your class, and have someway in the factory method of identifying which one you want.
matt
2012 Jan 11 5:41 PM
Hi matt,
Thanks for explaining the design. I am reading documentation in singleton pattern to understand it better. I have few questions on this but will get back after reading the documentation.
Btw you have mentioned that we can have a static table defined as TYPE REF to the class in the class attributes. I could not find in the class browser as how to implement this. I would be requiring to hold multiple lines of data in the class instance and hence this question.
2012 Jan 12 7:33 AM
Assume that an instance of your class has an attribute "name" of type string.
Define a table as a static: sth_instances type th_instance_ty.
Define the types under the type tab of class builder
TYPES: th_instance TYPE HASHED TABLE OF REF TO my_class WITH UNIQUE KEY table_line->name.
Alternatively, if your class doesn't have an identifying attribute, you could define a structure of:
TYPES: BEGIN OF s_instance_ty,
name TYPE string,
r_inst TYPE REF TO my_class,
END OF s_instance_ty.
TYPES: th_instance TYPE HASHED TABLE OF s_instance_ty WITH UNIQUE KEY name.
In the factory method, with an importing parameter of i_name type string, you read th_instance first, to see if an instance with the i_name exists already in sth_instances. If it does, you return the reference. If it doesn't you create it, and insert it into the table sth_instances.