‎2010 Nov 04 10:44 AM
Hi,
Is there any method by which I can create variable names dynamically.
My requirement is to assign each of the values in the select option of the screen (p_stat) to separate variables.
Code is as shown below:
LOOP AT p_stat.
CLEAR: field, l_field.
l_field = sy-tabix.
CONCATENATE 'lv_text' l_field INTO field.
ASSIGN (field) TO <fs>.
<fs> = p_stat-low.
GET REFERENCE OF <fs> INTO wa_query-value_low.
APPEND wa_query TO gt_query.
ENDLOOP.
For the first loop pass, the value of p_stat has to be assigned to lv_text1, 2nd loop pass value to lv_text2 etc......
I was able to do so using field symbol. But here I have to then declare the variables like lv_text1, lv_text2 etc separately which will only be known (ie, the no: of variables to declare) only at the runtime.
Is there any solution.
Thanks & Regards,
Soumya.
‎2010 Nov 04 11:10 AM
‎2010 Nov 04 11:11 AM
Hi Suhas,
Decalartions are as follows:
DATA : gt_query TYPE mdm_query_table,
wa_query TYPE mdm_query.
Regards,
Soumya.
‎2010 Nov 04 11:36 AM
Hello,
I don't find these DDIC elements in my system. Are these specific to MDM?
Anyway why don't you create an internal table of REF TO DATA & store the data references(via GET REFERENCE) as lines of the internal table.
Check the example provided in this SAP online documentation for further details:[http://help.sap.com/abapdocu_70/en/ABAPGET_REFERENCE.htm]
BR,
Suhas
‎2010 Nov 04 11:36 AM
Hi,
I do not know exactly what you want to do. If it helps you can create dinamyc tables with method cl_alv_table_create=>create_dynamic_table. I show you an example below.
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1> type table.
FIELD-SYMBOLS: <dat1> type data.
DATA: es_dfies LIKE LINE OF et_dfies.
CALL FUNCTION 'TR_NAMETAB_GET'
EXPORTING
IV_TABNAME = 'VIMFLAGTAB'
IV_GET_LENGTHS_IN_CHARMODE = 'X'
IV_GET_TEXTS = ' '
IMPORTING
ET_DFIES = et_dfies.
ES_HEADER =
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN <fs_data>->* TO <fs_1>.
SELECT *
FROM (from_clause)
APPENDING TABLE <fs_1>
WHERE (where_clause).
LOOP AT <fs_1> ASSIGNING <dat1>.
DO.
READ TABLE ET_DFIES INTO es_dfies INDEX sy-index.
ASSIGN COMPONENT es_dfies-fieldname OF STRUCTURE <dat1> TO <data>.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
‎2010 Nov 04 11:36 AM
Hello you can try like this. Make changes as necessary . Just in se11 search for data element * XX * and use the required one.
DATA:li_index(2) TYPE n,
wf_str TYPE REF TO data.
FIELD-SYMBOLS:<fs> TYPE ANY.
DATA:lf_element TYPE REF TO cl_abap_elemdescr,
i_tot_comp TYPE cl_abap_structdescr=>component_table,
la_comp LIKE LINE OF i_tot_comp ,
lf_new_type TYPE REF TO cl_abap_structdescr.
DO 10 TIMES.
CLEAR i_tot_comp[].
li_index = sy-index.
lf_element ?= cl_abap_elemdescr=>describe_by_name( 'CNTXX_KK' ).
CONCATENATE 'CNT' li_index '_KK' INTO la_comp-name.
la_comp-type =
cl_abap_elemdescr=>get_i( ).
APPEND la_comp TO i_tot_comp.
TRY.
lf_new_type = cl_abap_structdescr=>create( i_tot_comp ).
CATCH cx_sy_struct_creation . "#EC NO_HANDLER
ENDTRY.
CREATE DATA wf_str TYPE HANDLE lf_new_type.
ASSIGN wf_str->* TO <fs>.
ENDDO.