ITAB Nesting Exercise Test Results

Hi,
I have done this exercise and run the test. It is showing a test failure, even though the expected result is shown to be the same as the actual. I think I have done the exercise correctly. Does anyone know what I can do?
Many thanks.

It would be helpful to see your code and the test output (not as an image). Codeblocks help a lot!

Hi Isaac,

I found a solution that does pass all the tests, but mine didn’t, and it looks pretty much the same to me. Here is my solution:

METHOD perform_nesting.

data: ls_nested type artist_album_nested_type,
ls_albums type album_song_nested_type,
ls_song_nest type song_nested_type,
song_tab TYPE STANDARD TABLE OF song_nested_type WITH KEY song_id.

loop at artists into data(ls_artists_line).
loop at albums into data(ls_album_line) where artist_id = ls_artists_line-artist_id.
ls_albums-album_id = ls_album_line-album_id.
ls_albums-album_name = ls_album_line-album_name.
loop at songs into data(ls_song) where album_id = ls_album_line-album_id
and artist_id = ls_artists_line-artist_id.
ls_song_nest-song_id = ls_song-song_id.
ls_song_nest-song_name = ls_song-song_name.
append ls_song_nest to ls_albums-songs.
endloop.
clear ls_song_nest.
clear ls_albums-songs.
append ls_albums to ls_nested-albums.
endloop.
free ls_albums-songs.
clear ls_albums.
ls_nested-artist_id = ls_artists_line-artist_id.
ls_nested-artist_name = ls_artists_line-artist_name.
append ls_nested to nested_data.
free ls_nested-albums.
clear ls_nested.
endloop.

ENDMETHOD.

Here is the test outcome:

Test Failure

Expected ‘artist_id: 1, artist_name: Godsmack, albums: [itab]’, got ‘artist_id: 1, artist_name: Godsmack, albums: [itab]’


Here is a solution that works and passes all tests:

METHOD perform_nesting.

data: ls_nested type artist_album_nested_type,
ls_albums type album_song_nested_type,
ls_song_nest type song_nested_type,
song_tab TYPE STANDARD TABLE OF song_nested_type WITH KEY song_id.

loop at artists into data(ls_artists_line).
loop at albums into data(ls_album_line) where artist_id = ls_artists_line-artist_id.
ls_albums-album_id = ls_album_line-album_id.
ls_albums-album_name = ls_album_line-album_name.
loop at songs into data(ls_song) where album_id = ls_album_line-album_id
and artist_id = ls_artists_line-artist_id.
ls_song_nest-song_id = ls_song-song_id.
ls_song_nest-song_name = ls_song-song_name.
append ls_song_nest to song_tab.
endloop.
clear ls_song_nest.
ls_albums-songs = song_tab.
clear song_tab.
append ls_albums to ls_nested-albums.
endloop.
free ls_albums-songs.
clear ls_albums.
ls_nested-artist_id = ls_artists_line-artist_id.
ls_nested-artist_name = ls_artists_line-artist_name.
append ls_nested to nested_data.
free ls_nested-albums.
clear ls_nested.
endloop.

ENDMETHOD.

The difference is simply that my solution is appending to the internal table ls_albums-songs directly. The second solution has a dedicated internal table called song_tab, which I find is unnecessary.

I suspect this may be an issue with the system that diagnoses the possible solutions, maybe?

Anyway, many thanks!

Regards,

John

hi, can you help opening an issue on GitHub - exercism/abap: Exercism exercises in ABAP. ?