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: 

Field Symbols

Former Member
0 Kudos

I have the following code:

loop at i_tab assigning <fs>.

at new <fs>-component1.

This does not compile-- Field symbol not assigned.

i_tab is an internal table with a header line and does have a component1.

This compiles.

loop at i_tab assigning <fs>.

at new i_tab-component.

Why doesn't the code with the Field Symbol compile?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

This is how the Field Symbol is typed.

data: <fs> like line of i_tab.

7 REPLIES 7

Former Member
0 Kudos

Hi

It depends on how u've defined the field-symbols <fs>.

If it's like:

FIELD-SYMBOLS: <fs> TYPE ANY.

The field-symbol is of generic type so it become like i_tab at runtime, in this case you can't compile the program.

Max

Former Member
0 Kudos

That is because the pointer <fs>-component1 is referencing only component1.

But AT NEW itab-component, not only refers to component1 but anything that is left to component1. So you end up addressing memory area outside the reference of the field symbol.

The AT NEW, AT LAST field1 statement with LOOP ... ENDLOOP always compares all the fields from left up to and including ield1

Former Member
0 Kudos

This is how the Field Symbol is typed.

data: <fs> like line of i_tab.

0 Kudos

Hi

Sorry your code is wrong u need to indicate the name of field in AT NEW statament, so:

DATA: BEGIN OF itab OCCURS 0,
       field,
       field2,
      END OF itab.


FIELD-SYMBOLS <wa> LIKE itab.

APPEND itab.
itab-field = 'A'. APPEND itab.
itab-field = 'B'. APPEND itab.
itab-field = 'C'. APPEND itab.
itab-field = 'C'. APPEND itab.
itab-field = 'A'. APPEND itab.
itab-field = 'E'. APPEND itab.
itab-field = 'E'. APPEND itab.

SORT itab BY field.

LOOP AT itab ASSIGNING <wa>.

  AT NEW field.
    write: / <wa>-field.
  ENDAT.

ENDLOOP.

Max

Former Member
0 Kudos

Try like this,

FIELD-SYMBOLS: <FS> TYPE ANY.

.

.

.

.

LOOP AT ITAB.

ASSIGN ITAB TO <FS> CASTING (Please check the syntax of this, as I don't have access to SAP).

**and now you can use <fs> as header of ITAB.

ENDLOOP.

Mubeen

Sm1tje
Active Contributor
0 Kudos

Like one of the replies more or less is saying is this. When doing a loop and using AT NEW, you would normally only have to use the field like this.

LOOP AT itab.

AT NEW field1.

ENDAT.

ENDLOOP.

So you don't need the itab-field1 to make this work.

Now you are using the ASSIGNING for a table with HEADER LINE (try to avoid this).

So it will work when you do this:

LOOP AT itab ASSIGNING <line>

AT NEW field1.

ENDAT.

ENDLOOP.

former_member194669
Active Contributor
0 Kudos

Have you tried something this way


report  zars no standard page heading
        line-size 170
        line-count 65(4).

data: begin of type_output occurs 0,
         matnr type matnr,
       end of type_output.
field-symbols : <wa> type any.

loop at type_output assigning <wa>.
  at new ('<wa>-matnr').   "<-----
  endat..
endloop.