<file_sep>Step 1  Download the  jacob DLL  from  below website

for  64 Bit "jacob-1.18-x64.dll"   
	 32 bit "jacob-1.18-x86.dll"
	 
https://sourceforge.net/projects/jacob-project/files/jacob-project




Copy the .DLL file to your C:\Windows\System32\ folder. (32 bit)
Copy the .DLL file to your C:\Windows\SysWOW64\ folder. (64 bit)

Step2 
Download the  Jacob.jar 
Copy to  both the below locations
C:\Program Files\Java\jdk1.8.0_141\lib 
C:\Program Files\Java\jdk1.8.0_141\bin


Refer the below  website reference for development 
https://blogs.sap.com/2017/04/12/how-to-combine-sap-gui-scripting-and-selenium-webdriver/

For 64bit  need to edit registry using following instructions 
https://erpinnews.com/how-to-make-sap-rot-wrapper-library-available-in-a-64-bit-environment

<file_sep>package com.Samples;

import java.io.IOException;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import com.library.generic.SAPGeneric;
import com.library.generic.SAPGuiClassName;

public class Login extends SAPGuiClassName {

	/*
	 * Declaring the ActiveXComponent Objects 
	 */
	ActiveXComponent SAPROTWr, GUIApp, Connection, Session, Obj,SAPGIRD;
	Dispatch ROTEntry;
	Variant Value, ScriptEngine;
	private Process p;	
	SAPGeneric sapGenric;
	/*
	 * Opens the SAP Session and returns the Active Session Object 
	 */
	@BeforeClass
	public void getSapSessionObject() throws InterruptedException{
		String cnt = "0";
		ComThread.InitSTA();
		
		//Opening the SAP Logon 
		try {
	        p = Runtime.getRuntime().exec("C:\\Program Files\\SAP\\FrontEnd\\SAPgui\\saplogon.exe");
	    } catch (IOException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
	    }
		Thread.sleep(5000);
		//-Set SapGuiAuto = GetObject("SAPGUI")---------------------------
		SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");

		ROTEntry = SAPROTWr.invoke("GetROTEntry", "SAPGUI").toDispatch();
		//-Set application = SapGuiAuto.GetScriptingEngine------------
		ScriptEngine = Dispatch.call(ROTEntry, "GetScriptingEngine");
		GUIApp = new ActiveXComponent(ScriptEngine.toDispatch());

		SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");
		//SAP Connection Name 
		Connection = new ActiveXComponent(
				GUIApp.invoke("OpenConnection","QR1 - Retail").toDispatch());
		
		//-Set session = connection.Children(0)-----------------------

		//Initialization for the SAPGeneric
		sapGenric  = new SAPGeneric(Connection);
		sapGenric.setSession(new ActiveXComponent(sapGenric.getSession().invoke("FindById", "wnd[0]").toDispatch()));
	}
	
	
	/*
	 * Logging to SAP GUI 
	 */
	@Test
	public void  LoginSAPGUI() throws InterruptedException
	{
		Thread.sleep(2000);
		sapGenric.SAPGUISetPasswordField("R<PASSWORD>", "username");
		sapGenric.SAPGUITextFieldSet("RSYST-BNAME", "password");
		sapGenric.SAPGUIEnter();
		
	}
	/*
	 * WorkBench exporting xml 
	 */
	public void exportStorePosTransactions(String storenumber, String dateOfTrans, String filelocation, String filename)
		    throws InterruptedException
		  {
		    Thread.sleep(5000L);
		    sapGenric.SAPGUIOKCodeFiled("okcd", "/n/posdw/xmlo");
		    sapGenric.SAPGUIEnter();
		    Thread.sleep(2000L);
		    sapGenric.SAPGUICTextFieldSendKeys("STORE", storenumber);
		    sapGenric.SAPGUICTextFieldSendKeys("DAY", dateOfTrans);
		    sapGenric.SAPGUIbtnClick("btn[8]");
		  }
     
}
