Vous êtes sur la page 1sur 3

Field Symbols (how to use practically??

)
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.

All we have to do is before using <fs_tab> we have to write


Assign : itab_mara[] to <fs_tab>.

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[].

Generated by Jive on 2014-10-06+02:00


1

Field Symbols (how to use practically??)

field-symbols: <fs_tab> type standard table,


<fs_wa> type mara.
data : itab_mara like mara occurs 0 with header line.
select * from mara up to 10 rows into table itab_mara.
assign : itab_mara[] to <fs_tab>.
loop at <fs_tab> assigning <fs_wa>.
<fs_wa>-matnr = 'NEW CHANGE MATERIAL'.
endloop.
New Scenario :
1. Now in the above case you have internal table itab_mara ready. Suppose you dont have
internal table itab_mara then what?
You will need to assign <fs_tab> and <fs_wa> dynamically and also apply a select query dynamically.
Consider the same case for table MARA and field MATNR.
Defining the field symbol is same and also the looping part is same. The only change is where and how you
assign the field symbols.
Consider the following scenario. You have a program with parameter field TABLE NAME. as soon as the user
enters a table name he will get 10 rows selected from that table and modify the a field.
parameters : p_tab type dd03l-tabname.
field-symbols: <fs_tab> type standard table,
<fs_wa> type any,
<fs_matnr> type matnr.
data: fs_data type ref to data,
dyn_line type ref to data.
data : itab_fcat type lvc_t_fcat.
data : fcat like line of itab_fcat.
start-of-selection.
******* Assign
call function 'LVC_FIELDCATALOG_MERGE'
exporting

Generated by Jive on 2014-10-06+02:00


2

Field Symbols (how to use practically??)

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.

Generated by Jive on 2014-10-06+02:00


3

Vous aimerez peut-être aussi