How to close the document without closing Libreoffice? Python macro

How to close the document without closing Libreoffice? I tried these three ways, but they all close the document and libreoffice interface too.

Would it be possible to do this?

# coding: utf-8
from __future__ import unicode_literals
import uno

CTX = XSCRIPTCONTEXT.getComponentContext()
SM = CTX.ServiceManager

DESKTOP = XSCRIPTCONTEXT.getDesktop()
ODOC = XSCRIPTCONTEXT.getDocument()

def doc_close1(*args):
    ODOC.close(True)

def doc_close2(*args):
    ODOC.close(False)

def doc_close3(*args):
    ODOC.dispose()

See Sub DisposeDocument() in Misc module of standard library Tools

@mrkalvin: please don’t use UPPERCASE for everything, UPPERCASE should be used by Python-Convention only for Constants.
And O… -Prefixes also doesent make Sense.

I set XSCRIPTCONTEXT.getDocument() as a global constant on purpose. Is there a problem for this?

The letter O is because most of the Basic example code uses it to reference ‘oDoc = ThisComponent’

Thanks for the tips, I will follow your guidelines.

Following the tip that JohnSUN gave, the command used by the DisposeDocument() sub macro is this dispatcher:

.uno:CloseDoc

closes the document but not libreoffice

Thanks!