Skip to Content
avatar image
Former Member

Field Symbol- Work Area, assigning value without u0093loop at it assigning wa".

Hi,

Is there any way I can assign value to a <b>dynamic work area without using “loop at it assigning wa”.</b> In the first example error occurs at section ASSIGN COMPONENT.

There is no compilation error, but error “Field symbol has not yet been assigned” occurs at runtime.

The 2nd example works fine, but I want to do in a way other than looping.

For example like

wa_mara-matnr = '123'.

append wa_mara to it_mara.

Is there a way to do so?

REPORT  z_temp_01 .
*TABLES: mara.
DATA:
  it_mara TYPE TABLE OF mara,
  it2_mara TYPE TABLE OF mara,
  wa_mara LIKE mara.

FIELD-SYMBOLS:
  <fs_mara> TYPE table,
  <ld_column>   TYPE ANY,
  <fs1_wa_mara> LIKE LINE OF it_mara. " Workarea

DATA:
  ccolumnname(30) TYPE c.

ccolumnname = 'MATNR'.
UNASSIGN: <ld_column>.
*Problem section.
ASSIGN COMPONENT ccolumnname OF STRUCTURE <fs1_wa_mara>
TO <ld_column>.
<ld_column> =  '1234'.
IF ( <ld_column> IS ASSIGNED ).
  WRITE: / '.' .
ENDIF.

append <fs1_wa_mara> to it2_mara.
CLEAR <fs1_wa_mara>.

loop at it2_mara into wa_mara.
  write: / wa_mara-matnr.
clear wa_mara.
endloop.

2nd example

REPORT  z_temp_02 .

DATA:
  lit_mara TYPE TABLE OF mara,
  lit2_mara TYPE TABLE OF mara,
  lwa_mara LIKE mara.

FIELD-SYMBOLS:
  <fs_mara> TYPE table,
  <ld_column>   TYPE ANY,
  <fs_wa_mara> LIKE LINE OF lit_mara.

lwa_mara-matnr = '123'.
APPEND  lwa_mara TO lit_mara. "Insert 1 record in Internal table
ASSIGN lit_mara[] TO <fs_mara>.

*Assign data to dynamic work area.
* Is the loop at it assigning wa, necessary.
*Is there any other way to populate the work area.
LOOP AT lit_mara ASSIGNING <fs_wa_mara>.
  UNASSIGN: <ld_column>.
  ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_wa_mara> TO <ld_column>.
  <ld_column> = '1234'.
  append <fs_wa_mara> to lit2_mara.
  CLEAR <fs_wa_mara>.
ENDLOOP.

loop at lit2_mara into lwa_mara.
  write: / lwa_mara-matnr.
clear lwa_mara.
endloop.

Regards,

Vikas

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Sep 28, 2007 at 09:25 AM

    Try this:

      data:
        wa_ref type ref to data,
        it_mara type standard table of mara.
    
      field-symbols:
        <wa>          type any,
        <p_field>     type any.
    
      create data wa_ref like line of it_mara.
      assign wa_ref->* to <wa>.
    
      clear <wa>.
    
       assign component 'MATNR' of structure <wa> to <p_field>.
      <p_field> = 1234.
    
        insert <wa> into table it_mara.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 28, 2007 at 09:41 AM

    Hi Vikas,

    The problem is, u have declared a field-symbol work area, but u have not assigned anything to it, so it points to nothing. That's why u r getting dump in ur first example saying like 'Field Symbol not yet assigned'.

    So just add this line in ur first example and see :

    *Problem section.

    <i><b>ASSIGN wa_mara TO <fs1_wa_mara>.</b></i>

    ASSIGN COMPONENT ccolumnname OF STRUCTURE <fs1_wa_mara>

    TO <ld_column>.

    <ld_column> = '1234'.

    IF ( <ld_column> IS ASSIGNED ).

    WRITE: / '.' .

    ENDIF.

    -SatyaPriya

    Add comment
    10|10000 characters needed characters exceeded