Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dynamic reference

Former Member
0 Likes
840

Hi Experts,

I need to make my select statement completely DYNAMIC i.e. including names of fields and variables into which they are going to be stored and also the processing logic - in following way:

TABLES: PA0001.

DATA: BEGIN OF WA,

PERNR TYPE PERSNO,

END OF WA.

DATA: lv_f1(5) TYPE c.

PARAMETERS: p_pernr TYPE persno.

lv_f1 = 'PERNR'.

SELECT single (lv_f1) FROM pa0001 INTO WA-(LV_F1) WHERE pernr = p_pernr.

IF sy-subrc = 0.

WRITE:/ WA-(lv_f1).

ENDIF.

But the above code is whoing errors...... can you please suggest me how to correct the errors.....

Regards

Vasu

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
805

DATA: BEGIN OF wa,

pernr TYPE persno,

END OF wa.

DATA: lv_f1(5) TYPE c.

PARAMETERS: p_pernr TYPE persno.

DATA:lv_string TYPE string.

FIELD-SYMBOLS:<fs>.

lv_f1 = 'PERNR'.

CONCATENATE 'WA-' lv_f1 INTO lv_string.

assign (lv_string) to <fs>

SELECT SINGLE (lv_f1) INTO <fs> FROM pa0001 WHERE pernr = p_pernr.

IF sy-subrc = 0.

write wa-pernr.

skip 1. "or

write <fs>.

ENDIF.

7 REPLIES 7
Read only

Former Member
0 Likes
805

Ignore

Edited by: Vikranth.Reddy on Jun 16, 2010 2:34 PM

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
805

Earlier response deleted.

You cannot use dynamic tokens with INTO , SAP documentation says:

For the specification of target, there is no dynamic variant that corresponds to the other additions. Instead, you can work with dynamically created data objects (see the example for CREATE DATA).

Check this code snippet:

TYPES: BEGIN OF ty,
pernr TYPE persno,
END OF ty.

PARAMETERS: p_pernr TYPE persno.

DATA: dref TYPE REF TO data,
      lv_f1 TYPE fieldname.
FIELD-SYMBOLS: <wa> TYPE ANY,
               <val> TYPE ANY .

CREATE DATA dref TYPE ty.
ASSIGN dref->* TO <wa>.

lv_f1 = 'PERNR'. 

SELECT SINGLE (lv_f1) FROM pa0001
INTO <wa>  "-->Change this
WHERE pernr = p_pernr.
IF sy-subrc = 0.
  ASSIGN COMPONENT lv_f1 OF STRUCTURE <wa> TO <val>.
  IF sy-subrc = 0.
    WRITE / <val>.
  ENDIF.
ENDIF.

Edited by: Suhas Saha on Jun 16, 2010 2:48 PM

Read only

Former Member
0 Likes
805

select single wa-pernr ?

Read only

Former Member
0 Likes
805

Duplicate removed

Edited by: Vikranth.Reddy on Jun 16, 2010 2:44 PM

Read only

Former Member
0 Likes
805

Duplicate removed

Edited by: Vikranth.Reddy on Jun 16, 2010 2:44 PM

Read only

Former Member
0 Likes
805

Duplicate removed

Edited by: Vikranth.Reddy on Jun 16, 2010 2:44 PM

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
806

DATA: BEGIN OF wa,

pernr TYPE persno,

END OF wa.

DATA: lv_f1(5) TYPE c.

PARAMETERS: p_pernr TYPE persno.

DATA:lv_string TYPE string.

FIELD-SYMBOLS:<fs>.

lv_f1 = 'PERNR'.

CONCATENATE 'WA-' lv_f1 INTO lv_string.

assign (lv_string) to <fs>

SELECT SINGLE (lv_f1) INTO <fs> FROM pa0001 WHERE pernr = p_pernr.

IF sy-subrc = 0.

write wa-pernr.

skip 1. "or

write <fs>.

ENDIF.