on 07-18-2011 2:06 PM
Hi,
I need to access to work area fields but I dont know all the name of the fields in advance, cause I'm offering the possibility to the user to add fields in the application in the future.
wa_my-VARIABLE will definitely not work
I would like to know if its possible ?
Thanks !
ls_struc_fld should be an existing structure....
ls_fieldname is of type string....
i am just wondering that the user should add his filed in the exisitng structure at the dictionary level...
<fs_STR> will be type any....
and then you can use the below code.
MOVE ls_struc_fld-fieldname TO ls_fieldname.
ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_STR> TO <fs_val>.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I will have a table in the ABAP dictionnary to make it more automatic than several structures
ZEXCELFIELDS
with different components : fieldname, optional(WDY_BOOLEAN), order (of appearance) etc...
I wanted to SELECT the fieldname with WHERE conditions
and than access my working area
wa-fieldname
This is more what I want to do.
Thanks you for your help !!!
Edited by: Benjamin Art on Jul 18, 2011 3:57 PM
Made research and it seems that Field symbol are the only one solution to dynamically chose wich fieldname I want
I created a structure with 6-7 WDY_BOOLEAN (ZSTRUCT)
DATA : ls_fieldname TYPE STRING
lv_sruct TYPE ZSTUCT
FIELD-SYMBOLS <fs_STR> TYPE ANY
FIELD-SYMBOLS <fs_val> TYPE ANY ???
MOVE zstruct-fieldname TO ls_fieldname.
ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_STR> TO <fs_val>.
zstruct-fieldname ??? I dont have this fieldname name :s
Whats the difference between <fs_STR> and <fs_val> and which one I use after, to do wa-<fs> ?
how to navigate in the field symbol ? (first field, second field...)
I have a list of fieldnames in string, It is possible to do wa-my_fieldnames with field symbols ? if yes How ? Thanks !
Thanks, im not used to program with field symbols
Kr,
BA
Edited by: Benjamin Art on Jul 19, 2011 5:20 PM
Hello BA,
this is possible but you need to work with the memory area of the attributes. have a look at the following report code
types:
begin of ty_struct,
var1 type string,
var2 type string,
end of ty_struct.
data ls_target type ty_struct.
data ls_source type ty_struct.
field-symbols <fs_source> type any. "data source
field-symbols <fv_source> type any. "to hold source variable data
field-symbols <fv_target> type any. "to hold target variable data
"populating some data into <FS_SOURCE>
ls_source-var1 = 'Variable 1'.
ls_source-var2 = 'Variable 2'.
assign ls_source to <fs_source>.
"asigning the memory area of <FS_SROUCE>-VAR1 to <FV_SOURCE>
assign component 'VAR1' of structure <fs_source> to <fv_source>.
"asigning the memory area of LS_TARGET-VAR1 to <FV_TARGET>
assign component 'VAR1' of structure ls_target to <fv_target>.
"moving the data from <FV_SOURCE> to <FV_TARGET>. Since the <FV_TARGET points to LS_TARGET-VAR1,
"the data will be moved to LS_TARGET-VAR1
<fv_target> = <fv_source>.
assign component 'VAR2' of structure <fs_source> to <fv_source>.
assign component 'VAR2' of structure ls_target to <fv_target>.
<fv_target> = <fv_source>.
write: ls_target-var1, ' - ' , ls_target-var2.
clear: ls_target.
data lt_fieldnames type table of string.
data lv_fieldname type string.
lv_fieldname = 'VAR1'.
append lv_fieldname to lt_fieldnames.
lv_fieldname = 'VAR2'.
append lv_fieldname to lt_fieldnames.
loop at lt_fieldnames into lv_fieldname.
assign component lv_fieldname of structure <fs_source> to <fv_source>.
assign component lv_fieldname of structure ls_target to <fv_target>.
<fv_target> = <fv_source>.
endloop.
write: / ls_target-var1, ' - ' , ls_target-var2.
BR, Saravanan
Hello Benjamin,
you mentioned that you have the list of all the fieldnames. If so then you can use the following code
"LT_FIELDNAMES contains the list of all the fieldnames in the structure
loop at lt_fieldnames into lv_fieldname.
assign component lv_fieldname of structure <fs_source> to <fv_source>.
assign component lv_fieldname of structure ls_target to <fv_target>.
<fv_target> = <fv_source>.
endloop.
if you dont know the list of fieldnames in the struture then you can use the function module DDIF_FIELDINFO_GET to get the list of fields in a structure. you can refer the documentation of this FM to know about how to use this.
BR,
Saravanan
Ok thanks
I have wrote this test code
And how I populate data in my tables ?
REPORT ZZ_00_FIELDSNAME.
TABLES: DFIES,
X030L.
DATA: BEGIN OF INTTAB OCCURS 100.
INCLUDE STRUCTURE DFIES.
DATA : END OF INTTAB.
DATA : lv_cpt TYPE I.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'ZOPTFIELDS'
LANGU = SY-LANGU
TABLES
DFIES_TAB = INTTAB
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE:/ 'Field name not found'.
ENDIF.
lv_cpt = 0.
DATA lt_fieldnames TYPE TABLE OF string.
DATA lv_fieldname TYPE string.
data ls_target type zoptfields.
data ls_source type zoptfields.
field-symbols <fs_source> type any. "data source
field-symbols <fv_source> type any. "to hold source variable data
field-symbols <fv_target> type any. "to hold target variable data
"populating some data into <FS_SOURCE>
"ls_source-var1 = 'Variable 1'.
"ls_source-var2 = 'Variable 2'.
assign ls_source to <fs_source>.
LOOP AT INTTAB.
IF lv_cpt > 2.
lv_fieldname = INTTAB-FIELDNAME.
APPEND lv_fieldname TO lt_fieldnames.
ENDIF.
lv_cpt = lv_cpt + 1 .
ENDLOOP.
LOOP AT lt_fieldnames INTO lv_fieldname.
ASSIGN COMPONENT lv_fieldname OF STRUCTURE <fs_source> TO <fv_source>.
ASSIGN COMPONENT lv_fieldname OF STRUCTURE ls_target TO <fv_target>.
<fv_target> = <fv_source>.
ENDLOOP.
"WRITE: / ls_target-var1, ' - ' , ls_target-var2.
Kr,
BA
Hello Benjamin,
are you getting all the fieldnames in lt_fieldnames? because I didnt quite get the condition part in the loop to populate the fieldnames.
LS_SOURCE is the structure which should have input data. and after the value assignment loop, the LS_TARGET will have the output data.
now if your input data is table (say LT_SOURCE) and if you want to construct LT_TARGET (output table) then code goes like this
loop at lt_source into ls_source.
assign ls_source to <fs_source>.
LOOP AT lt_fieldnames INTO lv_fieldname.
ASSIGN COMPONENT lv_fieldname OF STRUCTURE <fs_source> TO <fv_source>.
ASSIGN COMPONENT lv_fieldname OF STRUCTURE ls_target TO <fv_target>.
<fv_target> = <fv_source>.
ENDLOOP.
append ls_target to lt_target.
endloop.
BR, Saravanan
Edited by: Saraa_n on Jul 20, 2011 11:59 AM
Hi,
I just don't need the 2 first one (mandt and a id).
I don't have the data in the table, just used the table ZOPTFIELDS to have the fieldnames (all type of WDY_boolean here).
I have to assign data while executing
That was my code before parametrisation of fields
Here I remember in a table which fields have been checked or not (checkboxgroup)
DATA :
lo_el_optionalfields TYPE REF TO if_wd_context_element,
lt_el_optionalfields TYPE wdr_context_element_set,
lt_c_optionalfields TYPE STANDARD TABLE OF zoptfields,
wa_optfields LIKE LINE OF lt_c_optionalfields.
READ TABLE lt_el_optionalfields INTO lo_el_optionalfields INDEX 1.
wa_optfields-from = lo_el_optionalfields->is_selected( ).
READ TABLE lt_el_optionalfields INTO lo_el_optionalfields INDEX 2.
wa_optfields-admin = lo_el_optionalfields->is_selected( ).
READ TABLE lt_el_optionalfields INTO lo_el_optionalfields INDEX 3.
wa_optfields-tm = lo_el_optionalfields->is_selected( ).
READ TABLE lt_el_optionalfields INTO lo_el_optionalfields INDEX 4.
wa_optfields-tickets = lo_el_optionalfields->is_selected( ).
READ TABLE lt_el_optionalfields INTO lo_el_optionalfields INDEX 5.
wa_optfields-pool = lo_el_optionalfields->is_selected( ).
READ TABLE lt_el_optionalfields INTO lo_el_optionalfields INDEX 6.
wa_optfields-type = lo_el_optionalfields->is_selected( ).
READ TABLE lt_el_optionalfields INTO lo_el_optionalfields INDEX 7.
wa_optfields-ref = lo_el_optionalfields->is_selected( ).
INSERT wa_optfields INTO TABLE lt_c_optionalfields.
And now I dont know if there is more after ref.
Thats not the only part of code that I have to adjust.
Kr,
BA
Edited by: Benjamin Art on Jul 20, 2011 12:10 PM
Please check whether this solves your problem.
data :
lo_el_optionalfields type ref to if_wd_context_element,
lt_el_optionalfields type wdr_context_element_set,
lt_c_optionalfields type standard table of zoptfields,
wa_optfields like line of lt_c_optionalfields,
lv_bool type wdy_boolean,
lv_index type i.
lv_index = 3. "to skip MANDT and ID
loop at lt_el_optionalfields into lo_el_optionalfields.
lv_bool = lo_el_optionalfields->is_selected( ).
"Assigning value based on the index
assign component lv_index of structure wa_optfields to <fv_target>.
<fv_target> = lv_bool.
lv_index = lv_index + 1.
endloop.
append wa_optfields to lt_c_optionalfields.
"if you want to insert it into DDIC table zoptfields then replace the append statement with INSERT statment
this will work only if the order of elements in lt_el_optionalfields is in sync with attributes order in zoptfields. if the order is not sync then i doubt whether this can achieved.
BR, Saravanan
User | Count |
---|---|
87 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.