First issue (empty books):

  • books is a local variable, existing in a current frame stack, as soon as you leave the method it disappears. Well, in your case you're not using it, so it's empty
  • ^books is a global variable, so it's stored in a database and you're using it

Second issue (12@Library.Book in value). 12@Library.Book is an OREF. As it's essentially a pointer it cannot be stored in a persistent way.

What do you want to achieve with your code?

Learning.InterSystems.com has hundrers of online courses. Check multimodel development with ObjectScript.