Question

I am trying to add a new record to my internal table and this code is giving me an error, but I am doing exactly the same thing as in my SAP book. What am I doing wrong?

TYPES : BEGIN OF personel_bilgileri,
  Ad TYPE c LENGTH 20,
  Soyad TYPE c LENGTH 20,
  Telefon_no Type n LENGTH 12,
  END OF personel_bilgileri.

TYPES personel_bilgi_tablo_tipi TYPE STANDARD TABLE OF
personel_bilgileri WITH NON-UNIQUE KEY ad soyad.

DATA : personel_bilgi_kaydi TYPE personel_bilgileri,
       personel_bilgi_tablosu TYPE personel_bilgi_tablo_tipi.

personel_bilgi_kaydi-ad = 'Murat'.
personel_bilgi_kaydi-soyad = 'Sahin'.
personel_bilgi_kaydi-telefon_no = '5556677'.

APPEND personel_bilgi_kaydi TO personel_bilgileri.

personel_bilgi_kaydi-ad  = 'Ayse'.
personel_bilgi_kaydi-soyad = 'Bil'.
personel_bilgi_kaydi-telefon_no = '5556611'.

APPEND personel_bilgi_kaydi TO personel_bilgileri.

personel_bilgi_kaydi-ad = 'Mehmet'.
personel_bilgi_kaydi-soyad = 'Kalan'.
personel_bilgi_kaydi-telefon_no = '5556622'.

APPEND personel_bilgi_kaydi TO personel_bilgileri.

Actually, I don't know which adding record method I should use. I mean there is too many ways to do this operation. Which method will be the true one?

I am getting this error:

The field Personel_bilgileri is unknown, but there are following fields similar names...

Moreover, I can do this with LOOP AT, but I didn't understand the usage of LOOP AT. What does it do?

Was it helpful?

Solution

In your code sample, you first defined PERSONEL_BILGILERI as a TYPE, then PERSONEL_BILGI_TABLO_TIPI as a internal table TYPE of PERSONEL_BILGILERI.

Up to that point, no variables are declared yet. Only data types.

Then:

  • PERSONEL_BILGI_KAYDI is defined of type PERSONEL_BILGILERI. This is a structure that you use as a work area (which is fine).
  • PERSONEL_BILGI_TABLOSU is defined of type PERSONEL_BILGI_TABLO_TIPI. So PERSONEL_BILGI_TABLOSU is your internal table.

When you APPEND your work area, you have to append to an internal table, not a data type. try with PERSONEL_BILGI_TABLOSU instead of your type PERSONEL_BILGI:

APPEND personel_bilgi_kaydi TO personel_bilgileri_tablosu.

OTHER TIPS

You need to APPEND your WA(workarea, personel_bilgi_kaydi) in to your table (personel_bilgi_tablosu). You cant append the WA to the defined type.

So it should look like this:

APPEND personel_bilgi_kaydi TO personel_bilgi_tablosu.

Also you can use this code to show them on the page.

    LOOP AT personel_bilgi_tablosu into personel_bilgi_kaydi.

       write: / 'İSİM: ' ,personel_bilgi_kaydi-ad,
             'SOYİSİM: ',personel_bilgi_kaydi-soyad,
              'TEL NO: ', personel_bilgi_kaydi-telefon_no.

    ENDLOOP.

You can use other methods to show your table on the page, such as REUSE_ALV_GRID_DISPLAY. You can get more information about that in scn.sap.com

Hope it was helpful.

Kolay gelsin.

Talha

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top