Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Stefan-Schnell
Active Contributor
1,596
Background Light is a server application, it is an ABAP to COM bridge and a replacement for the CL_GUI_FRONTEND_SERVICES class. It allows to use COM libraries and OS functions with ABAP background processes and without the SAP GUI for Windows.

In a normal ABAP program you can use COM calls and OS functions very easily. But, if you execute the same program as background process, COM calls and OS functions does not work. It is not possible to use COM calls and OS functions in ABAP background processes, because there is no communication between the application and the presentation server in this case.

Also you can not use COM calls with SAP GUI for Java, because it supports no COM calls. But with Background Light it is also possible. Background Light is an SAP server program and offers these possibilities. It is a bridge from your ABAP program to any COM library. After the registering of Background Light in the SAP system of your choice - via transaction SM59 - and the start of the server program on your presentation server you can use COM calls and OS functions in fore- and background processes with the same code and on each platform.

Here an older example how to send an e-mail via Outlook:
"-Begin-----------------------------------------------------------------
Report zBLightExample.

"-Variables-----------------------------------------------------------
Data:
BLight Type Ref To zBackgroundLight,
Outlook Type Integer,
hResult Type Integer,
olMsg Type Integer
.

"-Main--------------------------------------------------------------
Create Object BLight.
Check BLight->BackgroundLightExists( ) = 1.

BLight->CreateObject(
Exporting
progid = 'Outlook.Application'
Importing
oleobj = Outlook
hresult = hResult
).
Check Outlook <> 0 And hResult = BLight->S_OK.

BLight->GetPropertyObject(
Exporting
oleobj = Outlook
command = 'CreateItem(0)'
Importing
object = olMsg
hresult = hResult
).
If olMsg <> 0.

BLight->SetProperty(
Exporting
oleobj = olMsg
command = 'To=''my.name@stschnell.de'''
Importing
hresult = hResult
).
BLight->SetProperty(
Exporting
oleobj = olMsg
command = 'Subject=''Test'''
Importing
hresult = hResult
).
BLight->SetProperty(
Exporting
oleobj = olMsg
command = 'Body=''This is a test'''
Importing
hresult = hResult
).
BLight->CallMethod(
Exporting
oleobj = olMsg
command = 'Display'
Importing
hresult = hResult
).
BLight->CallMethod(
Exporting
oleobj = olMsg
command = 'send'
Importing
hresult = hResult
).
BLight->CallMethod(
Exporting
oleobj = olMsg
command = 'Quit'
Importing
hresult = hResult
).
Call Method BLight->FreeObject
Exporting OLEObj = olMsg.
EndIf.

Call Method BLight->FreeObject
Exporting OLEObj = Outlook.

"-End-------------------------------------------------------------------

Beyond these functionality offers Background Light an enrichment of methods to handle COM libraries. Also open Background Light the gate wide, to use all COM libraries without any customizing of the security options of the SAP Logon program. And it offers with his functional Add-Ons the mighty possibility to use Windows Management Instrumentation (WMI).

Here an example how to read information from the BIOS:
"-Begin-----------------------------------------------------------------
Program zBLightExample.

"-DataTypes-----------------------------------------------------------
Types BackgroundLight Type Ref To zBackgroundLight.

"-Variables-----------------------------------------------------------
Data:
BLight Type BackgroundLight,
hResult Type Integer,
WMI Type Integer,
oEnum Type Integer,
oNext Type Integer,
ExecQuery Type String,
BIOSManufacturer Type String,
BIOSName Type String,
BIOSVersion Type String,
Text Type String,
Button Type i
.

"-Main----------------------------------------------------------------
Create Object BLight.
Check BLight->BackgroundLightExists( ) = 1.

Call Method BLight->GetObject
Exporting ProgID = 'winmgmts:\\.\root\CIMV2'
Importing OLEObj = WMI hResult = hResult.

Check WMI <> 0 And hResult = BLight->S_OK.

ExecQuery = 'ExecQuery(''Select * from Win32_BIOS''' &&
', ''WQL'', 48)'.

Call Method BLight->CreateEnumeration
Exporting OLEObj = WMI Command = ExecQuery
Importing EnumObj = oEnum hResult = hResult.

If oEnum <> 0 And hResult = BLight->S_OK.

Call Method BLight->GetNextEnumerationObject
Exporting EnumObj = oEnum
Importing NextObject = oNext hResult = hResult.

While oNext <> 0.

Call Method BLight->GetPropertyString
Exporting OLEObj = oNext Command = 'Manufacturer'
Importing String = BIOSManufacturer hResult = hResult.

Call Method BLight->GetPropertyString
Exporting OLEObj = oNext Command = 'Name'
Importing String = BIOSName hResult = hResult.

Call Method BLight->GetPropertyString
Exporting OLEObj = oNext Command = 'Version'
Importing String = BIOSVersion hResult = hResult.

Text = `Manufacturer: ` && BIOSManufacturer &&
CL_ABAP_CHAR_UTILITIES=>CR_LF &&
`Name: ` && BIOSName &&
CL_ABAP_CHAR_UTILITIES=>CR_LF &&
`Version: ` && BIOSVersion.

Call Method BLight->MsgBox
Exporting
Text = Text
Caption = 'Information about BIOS'
Style = BLight->MB_OKOnly
Importing
Button = Button.

Call Method BLight->FreeEnumeration
Exporting EnumObj = oNext.

Call Method BLight->GetNextEnumerationObject
Exporting EnumObj = oEnum
Importing NextObject = oNext hResult = hResult.

EndWhile.

Call Method BLight->FreeEnumeration
Exporting EnumObj = oEnum.

EndIf.

Call Method BLight->FreeObject
Exporting OLEObj = WMI.

"-End-------------------------------------------------------------------

 

Background Light offers an easy interface to start and stop the server thread and to control the incoming calls.


 

Hint: If you use Background Light with a tiny trick, you can ensure that the COM calls are for the correct user on their presentation server - use as destination the sy-uname variable.

2017/12/29 - New version of SAP NetWeaver RFC library is available

  • Background Light works fine with the new version of SAP NetWeaver RFC libary 7.50


2017/03/12 - A new version of Background Light is available

2015/06/05 - A new version of Background Light is available

  • Background Light is not longer only as 32-bit version available, it is now also as 64-bit version available - you can find some reasons here.


 

You can download Background Light here.
Labels in this area