I created and then compiled a routine using the %Routine library
s routine = ##class(%Routine).%New(fileName_"."_extension)
d routine.Write(parsedRule)
//s status = routine.Save()
s status = routine.SaveStream(,.refresh)
if ($$$ISERR(status)) throw status
Now the routine compiles successfully and as a result it is saved on the database.
I can now use from anywhere:
set r = ##class(%Routine).%New("myGeneratedCode.mac")w r.SizeGet()

.png)