We can help. Together we learn....

Field symbol - Info

by Voice | Monday, April 27, 2009 in |

SAP recommends that you should only use field symbol when you can not achieve the same functionality by other means. 

Performance wise it is better to use field symbols but if not used properly, it can give a short dump. With conventional work area method, syntax checker is able to detect most of such errors incorporated in the code. But with field symbol it is unable to do so and hence unless and until you are very sure about the use, field symbols may back fire on you.

Below is one sample code which can help you in understanding the use of field symbols. Like a work are or table, field symbols can be declared by using a structure or it can be left unassigned and in this case it take the structure of the variable with which it is referred for the first time.

Field-symbols become indespensible when in your program there is a need to create a work area name or field name or internal table name dynamically. 

In this example, field symbols are used to call an internal table dynamically. You can extrapolate the same concept to work area and variables.

----------------------------------------------------------------------------------------------
PARAMETERS: p_1 TYPE tdobject.

DATA: i_stxh TYPE STANDARD TABLE OF stxh,
      w_stxh TYPE stxh.

SELECT * FROM stxh
INTO TABLE i_stxh
WHERE tdobject = p_1.

FIELD-SYMBOLS <i_t> TYPE ANY table.
FIELD-SYMBOLS <w_t> TYPE ANY.
data: name(10TYPE c.
data: name1(10TYPE c.

name = 'I_STXH'.
name1 = 'W_STXH'.
ASSIGN (name) TO <i_t>.
ASSIGN (name1) TO <w_t>.

IF sy-subrc = 0.

ENDIF.

LOOP AT <i_t> INTO <w_t>.

ENDLOOP.
 



--------------------------------------------------------------------------------------------------------------------------------------------------------
If you wish to assign content on one field symbol to other field symbol you can use,
assign <fs1> to <fs2>.

0 comments:

Categories