Track
/
ABAP
ABAP
/
Esercizi
/
Annidamento di ITAB
Annidamento di ITAB

Annidamento di ITAB

Facile

Istruzioni

Impara a combinare i dati di tre diverse tabelle interne in un'unica tabella interna di risultato, annidando i dati associati.

Alla classe verranno fornite tre tabelle interne che contengono tre set di dati completamente diversi: ARTISTS, ALBUMS e SONGS.

TYPES: BEGIN OF artists_type,
         artist_id   TYPE string,
         artist_name TYPE string,
       END OF artists_type.
TYPES: artists TYPE STANDARD TABLE OF artists_type WITH KEY artist_id.
TYPES: BEGIN OF albums_type,
         artist_id  TYPE string,
         album_id   TYPE string,
         album_name TYPE string,
       END OF albums_type.
TYPES: albums TYPE STANDARD TABLE OF albums_type WITH KEY artist_id album_id.
TYPES: BEGIN OF songs_type,
         artist_id TYPE string,
         album_id  TYPE string,
         song_id   TYPE string,
         song_name TYPE string,
       END OF songs_type.
TYPES: songs TYPE STANDARD TABLE OF songs_type WITH KEY artist_id album_id song_id.

I dati nella tabella ARTISTS sono mostrati di seguito.

ARTIST_ID ARTIST_NAME
1 Godsmack
2 Shinedown

I dati nella tabella ALBUMS sono mostrati di seguito.

ARTIST_ID ALBUM_ID ALBUM_NAME
1 1 Faceless
1 2 When Lengends Rise
2 1 The Sound of Madness
2 2 Planet Zero

I dati nella tabella SONGS sono mostrati di seguito.

ARTIST_ID ALBUM_ID SONG_ID SONG_NAME
1 1 1 Straight Out Of Line
1 1 2 Changes
1 2 1 Bullet Proof
1 2 2 Under Your Scars
2 1 1 Second Chance
2 1 2 Breaking Inside
2 2 1 Dysfunctional You
2 2 2 Daylight

Il tuo compito è restituire una tabella interna con record che combinano i valori di ciascuna tabella interna in modo strutturato, annidando la tabella interna SONGS in quella ALBUMS e, naturalmente, annidando la tabella interna ALBUMS in quella ARTISTS.

La tabella di ritorno prevista ha la seguente definizione:

TYPES: BEGIN OF song_nested_type,
         song_id   TYPE string,
         song_name TYPE string,
       END OF song_nested_type.
TYPES: BEGIN OF album_song_nested_type,
         album_id   TYPE string,
         album_name TYPE string,
         songs      TYPE STANDARD TABLE OF song_nested_type WITH KEY song_Id,
       END OF album_song_nested_type.
TYPES: BEGIN OF artist_album_nested_type,
         artist_id   TYPE string,
         artist_name TYPE string,
         albums      TYPE STANDARD TABLE OF album_song_nested_type WITH KEY album_id,
       END OF artist_album_nested_type.
TYPES: nested_data TYPE STANDARD TABLE OF artist_album_nested_type WITH KEY artist_id.

Bonus

Ci sono molti modi per portare a termine questo compito in ABAP. Quanto puoi essere efficiente nel completare il compito?

Modifica tramite GitHub Il link si apre in una nuova finestra o scheda
ABAP Exercism

Vuoi iniziare Annidamento di ITAB?

Iscriviti a Exercism per imparare e padroneggiare ABAP con 54 esercizi e il mentoring di persone reali, tutto gratis.