If you’ve worked in Spain and want to take info re your contribution years with you, for purposes of applying for unemployment benefits in another EU country, then you need to apply for the portable document U1, with the Dirección Provincial of the State Employment Agency in the province where you last worked, preferably before you leave Spain as it can take quite a while for your application to be processed and it could delay your application for unemployment benefits if you only apply for it when you have become unemployed in the other EU country and need to present it to the authorities there, to accredit your contribution years from Spain.
More info, in Spanish.
You can also apply by phone, the option to use if you´re already abroad.
Scroll right down on THIS PAGE. Make sure to look up the ´fijo´ number for the provincial office you need, to avoid unnecessarily high costs.
Informative leaflet from the Employment Agency, also mentioning the option for the relevant authorities in other EU countries to request the contribution info from their Spanish counterpart.