Learning a piece for jazz improvisation
First, learn the melody. Sing it, get it inside your mind's ear. Play it on the fiddle, on the piano, guitar, anything, but learn the tune so that you internalise it totally, and can play it without the dots. Whistle it while walking down the street. Play it slowly. Play it fast, staccato, swung, not swung. Leave rests. Transpose it. Do all kinds of things with it, but do not add to it, yet. The point is to get you totally familiar with the melody, and for you to understand its intervallic structure.
Next, get the chord sequence and play the roots of the chords. While you are doing that, imagine the melody in your head, or sing it along with your root-playing. Listen for how the tune fits with the bass line. Then play roots and fifths, still singing or imagining the tune. Next spell out the chords in their entirety, arpeggiating them to the seventh, but now listen for how the harmony moves. Rather than imagining the melody, listen for the notes that change from one chord to the next. For example, if the change is from G major to G minor, note that, from triad to the next, the B is flattened to Bb. This will fix the movement of the harmony, and focus your attention on any modulation, or key changes that happen.
Note how long the chords stay in one key: for example, if you have a bar with E min 7 then a bar with A min 7 & D7, and a third bar of G maj 6, you have three bars in G major. That means you can play a G major scale over all three bars
If the fourth bar went to F min & Bb 7, taking you to Eb Maj in the fifth bar, you would have to play from Eb major in those two bars. Note which tones change, and which tones stay the same. G and D are the same in G major and Eb major. So is C. But F# becomes F, and A, E and B are all flattened to give you Ab, Eb and Bb. When you change key, these are the notes you look out for - the ones that change. The ones that gain or lose accidentals - sharps and flats.
So, this is the procedure - learn the tune, learn the bass, fill in the harmonies, note the modulations. That is how you learn the tune.
In my teaching, I show how to explore this structural knowledge to create beautiful and interesting improvisations.