-1

I want to display the content of Mara table.

types : begin of str_mara,
          matnr type mara-matnr,
          ernam type mara-ernam,
        end of str_mara.

data it_mara type table of str_mara .

select matnr ernam from mara into TABLE it_mara .

loop at it_mara into str_mara.
  write:/ str_mara-matnr , str_mara-ernam.
endloop.
3
  • 3
    That's all the difference between a variable and a type... Dec 18, 2018 at 20:15
  • 2
    Are you absolutely sure you want to select all the entries from MARA table into an internal table without using any critera?
    – Jagger
    Dec 18, 2018 at 20:28
  • Exactly same question asked on SCN Dec 19, 2018 at 13:16

3 Answers 3

4

Well, there is no variable named str_mara. There is just a type named str_mara.

Just loop using a field symbol as it should be done anyway.

LOOP AT it_mara ASSIGNING FIELD-SYMBOL(<str_mara>).
   WRITE: /, <str_mara>-matnr, <str_mara>-ernam.
ENDLOOP.
2

Type is just a static definition, no memory is allocated, therefore cannot be used on its own.

You can either create a variable with that type or use a inline declaration to create a variable like that.

  • option 1: data ls_mara type str_mara.

  • option 2: loop at lt_mara into data(ls_mara).

Or go with Umar's answer :)

BTW, be sure to check your where condition on the access to mara table.

-1

You can also use inline declaration to display content of mara table with fewer line of ABAP code.

SELECT matnr, ernam FROM mara INTO TABLE @DATA(lt_mara) .
LOOP AT lt_mara ASSIGNING FIELD-SYMBOL(<fs_mara>).
   WRITE: /, <fs_mara>-matnr, <fs_mara>-ernam.
ENDLOOP.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.