Dear Marshal,
a heartly welcome from me, too, and thanks for the interesting question. Since I am not an expert I will link @meike here. But I have done some research. Also, maybe this answer on Wefugees will help you:
https://***.wefugees.de/813614/quite-ausbildung-start-master-degree-bachelor-degree-base?show=813614#q813614
In this brochure from BAMF from 2016 I have the following information:
"Die Erteilung eines Aufenthaltstitels sowie die damit einhergehenden Rechte und Auflagen sind an den jeweiligen Aufenthaltszweck gebunden. Ändert sich der Aufenthaltszweck, muss geprüft werden, ob der Aufenthaltstitel weiter Bestand hat und verlängert werden kann oder ob ein anderer Aufenthaltstitel in Frage kommt und ob die Rechte und Auflagen in Bezug auf den neuen Aufenthaltszweck geändert werden müssen." (BAMF 2016, P.6)
"In case of a chage of residence changes, it must be checked or if a different residence title is still valid and can be extended and another residence title is possible and the rights and conditions must be changed in relation to the new purpose of residence." (BAMF 2016, P.6)
In general, we (Wefugees) cannot make a generally valid statement about your individual situation. I have found a guidance here if a so-called " Spurenwechsel, change of track" is generally possible.
https://***.einwanderer.net/fileadmin/downloads/tabellen_und_uebersichten/Tabelle_Spurwechsel_2020.pdf
I can see from this table that the change from §16a Ausbildung to §16b studies is still possible before graduation.
--> We can recommend that you contact the Foreigners' Registration Office (Ausländerbehörde) in advance to discuss your options. In case of a change, you should first apply for the study program before you cancel your Ausbildung.
With warm regards
Saskia
Quelle:
Bundesamt für Migration und Flüchtlinge (2016): Wechsel zwischen Aufenthaltstiteln und Aufenthaltszwecken in Deutschland. Fokusstudie der deutschen nationalen Kontaktstelle für das Europäische Migrationsnetzwerk (EMN), online unter: https://***.bamf.de/SharedDocs/Anlagen/DE/EMN/Studien/wp67-emn-wechsel-aufenthaltstiteln-aufenthaltszwecken.pdf?__blob=publicationFile&v=19, (letzter Zugriff: 12.10.22)