‎2012 Nov 14 12:05 PM
Hi,
How to dynamically name instances of a particular class.
For example: I have 4 screens 9000,9001,9002,9003.
data: lv_name type string.
field_symbols: <fs_objref> TYPE REF TO cl_gui_custom_container.
CREATE OBJECT GR_CUST_CONT_9000,
CREATE OBJECT GR_CUST_CONT_9001,
CREATE OBJECT GR_CUST_CONT_9002,
CREATE OBJECT GR_CUST_CONT_9003,
Instead of this, I need to assign a variable lv_name.
CONCATENATE 'GR_CUST_CONT_' lv_dynnr INTO lv_name.
assign lv_name TO <fs_objref>.
CREATE OBJECT <fs_objref>
Regards,
DPM
‎2012 Nov 15 10:00 AM
Hi DPM,
I think, instead of that it would be better to have internal table containing object references (object collection).. this internal table can have field 'Sceen ID' and "Reference to custom container (REF TO)'.
Then you can instaintiate the object per screen id and add it to the object collection.. while retriving, simply get the required object by referring screen id field from the internal table..
Best Regards,
Abhijit
‎2012 Nov 15 3:50 PM
Field names in an ABAP program are only there to make the programmer's life easier. If you find yourself building logic around the names of fields which you declare in your program, you're doing something wrong. Whatever relationship you're trying to define in the names of your fields, you should instead be defining in the values of a field.
In your specific situation, you shouldn't define the relationship between a screen number and it's custom container object by naming the custom container object from that screen number. Instead, as Abhijit said, you should create a table that relates a screen number (in one column) to the custom container object) in another column.
‎2012 Nov 19 2:47 AM
Howdy,
For what its worth, I don't think there's any problem using naming convention to achieve what seems to be a repetitive task.
So your code should work like this (change highlighted in bold)
CONCATENATE 'GR_CUST_CONT_' lv_dynnr INTO lv_name.
assign (lv_name) TO <fs_objref>.
CREATE OBJECT <fs_objref>
You may also want to consider encapsulating the Create object call in a method or subroutine and passing the object reference.
Cheers
Alex