Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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


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.
  it_mara TYPE TABLE OF mara,
  it2_mara TYPE TABLE OF mara,
  wa_mara LIKE mara.

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

  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: / '.' .

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.

2nd example

REPORT  z_temp_02 .

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

  <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>.

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



Former Member
Not what you were looking for? View more on this topic or Ask a question