can we use field symbol inside sql statement as work area
hi friends
i had a doubt wether this can be done or not
for eg;
DATA : BEGIN OF st_data,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF st_data.
FIELD-SYMBOLS : <p_data> LIKE st_data.
SELECT SINGLE vbeln posnr INTO <p_data> FROM vbap.
write : / <p_data>-vbeln.
write : <p_data>-posnr.
pls help me someone knows this
thnks
iVER.
Dear, yes u can use a field-symbols as a work area in your program.
AlThough your program will not work, it will dump your program.
once you use a filed-symbols in your program u have to assign a
structure to the field-symbols.
E.x,
TABLES: VBAP.
DATA : BEGIN OF ST_DATA,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ST_DATA.
FIELD-SYMBOLS : <P_DATA> LIKE ST_DATA.
ASSIGN ST_DATA TO <P_DATA>.
SELECT SINGLE VBELN POSNR FROM VBAP INTO <P_DATA>.
WRITE : / <P_DATA>-VBELN.
WRITE : <P_DATA>-POSNR.
then it will give the output as u want.
Prajesh shah.
Check this code may be of some use to u. Here the select list, selected data table and where clause all are dynamic.
PERFORM F_GET_DATA IN PROGRAM YCOMMON_PERFORM
USING &KNA1&
USING &W_KUNNR&
CHANGING &W_KUNNR&
CHANGING &W_LAND1&
CHANGING &W_NAME1&
FORM f_get_data TABLES i_inval STRUCTURE itcsy
i_outval STRUCTURE itcsy.
DATA : w_field(10).
DATA : i_field LIKE TABLE OF w_field.
DATA : w_condition(50),
i_condition LIKE TABLE OF w_condition,
w_where TYPE i,
w_outvalue TYPE i.
DATA : w_table TYPE tabname.
DATA : i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat.
DATA : d_ref TYPE REF TO data.
FIELD-SYMBOLS : <f_table> TYPE table,
<f_wa> TYPE ANY,
<f_field> TYPE ANY.
* sy-cprog = 'YCOMMON_PERFORM'.
* read table i_inval index 1.
DESCRIBE TABLE i_inval LINES w_where.
DESCRIBE TABLE i_outval LINES w_outvalue.
w_where = w_where - 1. "to eliminate the table record.
LOOP AT i_inval.
IF sy-tabix EQ 1.
w_table = i_inval-name. "get the table name.
"name of the table must be declared
"as it is.. eg KNA1
ELSE.
w_field = i_inval-name+2. "the field name to be
"declared as w_xxx.
IF w_where EQ 1.
CONCATENATE w_field ' EQ ''' i_inval-value ''''
INTO w_condition.
ELSE.
CONCATENATE w_field ' EQ ''' i_inval-value ''' AND'
INTO w_condition.
ENDIF.
w_where = w_where - 1.
APPEND w_condition TO i_condition.
ENDIF.
ENDLOOP.
LOOP AT i_outval.
MOVE i_outval-name+2 TO w_field. "the field name to be declared
"as W_XXXX.
APPEND w_field TO i_field.
ls_alv_cat-fieldname = w_field.
ls_alv_cat-ref_table = w_table.
ls_alv_cat-ref_field = w_field.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING it_fieldcatalog = i_alv_cat
IMPORTING ep_table = d_ref .
ASSIGN d_ref->* TO <f_table>.
SELECT (i_field) FROM (w_table)
INTO CORRESPONDING FIELDS OF TABLE
<f_table> WHERE (i_condition).
LOOP AT <f_table> ASSIGNING <f_wa>.
EXIT.
ENDLOOP.
DO w_outvalue TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE <f_wa> TO <f_field>.
READ TABLE i_outval INDEX sy-index.
MOVE <f_field> TO i_outval-value.
MODIFY i_outval INDEX sy-index.
ENDDO.
ENDFORM.