0

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Merve Gül
  • 1,377
  • 6
  • 23
  • 40
  • Here's the page in the SAP Library explaining LOOP AT: http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/frameset.htm – Danny T. Jun 12 '12 at 14:12
  • 1
    Also, please do not use non-english words in your code, bilgileri and kaydi make your code harder to maintain for whoever will someday maintain your code. – tomdemuyt Jun 12 '12 at 14:56

2 Answers2

4

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.
Danny T.
  • 1,130
  • 10
  • 23
1

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

Mtu
  • 643
  • 10
  • 18