Académique Documents
Professionnel Documents
Culture Documents
)
When I began learning the concept of field symbols , it looked quite scary with all the brackets and new syntax.
But now after using it almost on a regular basis I actually am kind of tempted to use it maximum to where I can.
Field symbols are better performance wise but I am not going down that lane. I am here explaining how to
be using it practically and effectively. In simple words , a field symbol refers or points (pointers known as in C
language) to something. That something can be a table , a field or even nothing. When I say nothing I mean
that the structure of a field symbol can be determined dynamically.
For our purpose let us consider MARA table as the referring table and MATNR field as the referring field.
Definition :
field-symbols: <fs_tab> type standard table,
<fs_wa> type mara.
Here we have defined a table <fs_tab> containing no structure and <fs_wa> with structure MARA.
Assign :
Note for field symbols just defining does not mean that we can start using it after definition. We have to assign
a structure to that field symbol. i.e we have to tell the program that not <fs_tab>will be referring to table MARA.
Now we have an internal table itab_mara defined.
Data : itab_mara like mara occurs 0 with header line.
All we have to do is before using <fs_tab> we have to write
Data : itab_mara like mara occurs 0 with header line.
You can now use <fs_tab> and whatever changes you make to <fs_tab> reflects to itab_mara.
Loop at <fs_tab> assigning <fs_wa>.
<fs_wa>-matnr = NEW CHANGE MATERIAL.
Endloop.
Now this automatically refer to <fs_tab> which will automatically modify itab_mara[].
i_structure_name = p_tab
changing
ct_fieldcat
= itab_fcat.
loop at itab_fcat into fcat.
clear: fcat-domname, fcat-ref_table.
modify itab_fcat index sy-tabix from fcat.
endloop.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = itab_fcat
importing
ep_table
= fs_data.
assign fs_data->* to <fs_tab>.
create data dyn_line like line of <fs_tab>.
assign dyn_line->* to <fs_wa>.
******* Assign
select * from (p_tab) up to 10 rows into corresponding fields of table <fs_tab>.
loop at <fs_tab> assigning <fs_wa>.
assign component 'MATNR' of structure <fs_wa> to <fs_matnr>.
<fs_matnr> = 'NEW CHANGE'.
endloop.
Here we use assign component as we do not know which fields are there in <fs_wa> before runtime.