Application Development 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: 

work area using field symbol

Former Member
0 Kudos
1,583

Hi gurus,

I have two internal table with different structure . i am going to use this table

on the based of if else.

so at one time i am going to use only one internal table.similarly i want to define my workarea also on the base of if else. is it possible to defined workarea dynamically.

i have defined field symbol <FS> like

IF <Con1>

assign internaltable1 to <fs>.

ELSE.

assign internaltable2 to <fs>.

ENDIF.

simillary i want to defined workarea but it gives me error.

thanks,

Neo

5 REPLIES 5

Former Member
0 Kudos
260

Check the below code :

REPORT zsharad_test1.

data : i_mara like mara occurs 0 with header line.

data : i_makt like makt occurs 0 with header line.

PERFORM get_data TABLES i_mara.

PERFORM get_data TABLES i_makt.

FORM get_data TABLES p_tab_data.

FIELD-SYMBOLS: <wa> TYPE ANY.

LOOP AT p_tab_data ASSIGNING <wa>.

ENDLOOP.

endform.

Thanks

Seshu

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
260

Example.




REPORT zrich_001.

type-pools: abap.

TYPES: BEGIN OF ttab1,
       f1 TYPE c,
       f2 TYPE c,
       f3 TYPE c,
       END OF ttab1.

TYPES: BEGIN OF ttab2,
       f4 TYPE i,
       f5 TYPE i,
       f6 TYPE i,
       END OF ttab2.

DATA: itab1 TYPE TABLE OF ttab1.
DATA: wa1 LIKE LINE OF itab1.
DATA: itab2 TYPE TABLE OF ttab2.
DATA: wa2 LIKE LINE OF itab2.

FIELD-SYMBOLS: <fs_tab> TYPE table,
               <fs_wa>.

IF abap_true = 'X'.
  ASSIGN itab1[] TO <fs_tab>.
  ASSIGN wa1 TO <fs_wa>.
ELSE.
  ASSIGN itab2[] TO <fs_tab>.
  ASSIGN wa2 TO <fs_wa>.
ENDIF.

Regards,

RIch Heilman

Former Member
0 Kudos
260

Hi RIch Heilman ,

Thanks for your useful reply .

i did same way as you suggest . but now when i use this <WA> at that time it gives me error like

The data object<WA> has no structure and there fore no component like

' Component name'.

this is the sample code.

LOOP at <fs> assigning <wa>.

<wa>-component1 = 'A'.

endloop.

Thanks,

Neo

0 Kudos
260

Hi,

You have to declare the field symbol like this:

field-symbols:

<fs_itab> like...the itab that you want to assign to the field symbol.

Regards,

Roberto.

Former Member
0 Kudos
260

Hi gurus,

this is the sample code i am trying to run.

you can also test this code .

******************************************************

TYPES: BEGIN OF ttab1,

f1 TYPE c,

f2 TYPE c,

f3 TYPE c,

END OF ttab1.

TYPES: BEGIN OF ttab2,

f4 TYPE i,

f5 TYPE i,

f6 TYPE i,

END OF ttab2.

data: abap_true type c.

DATA: itab1 TYPE TABLE OF ttab1.

DATA: wa1 LIKE LINE OF itab1.

DATA: itab2 TYPE TABLE OF ttab2.

DATA: wa2 LIKE LINE OF itab2.

FIELD-SYMBOLS: <fs_tab> TYPE table,

<fs_wa>.

IF abap_true = 'X'.

ASSIGN itab1[] TO <fs_tab>.

ASSIGN wa1 TO <fs_wa>.

ELSE.

ASSIGN itab2[] TO <fs_tab>.

ASSIGN wa2 TO <fs_wa>.

ENDIF.

LOOP at <fs_tab> assigning <fs_wa>.

<fs_wa>-f1 = '1'.

endloop.

****************************************************************

it gives me error like

The data object <fs_wa> has no structure and there for no component called

'f1'.

please guide me where i am wrong.

thanks,

Neo