0

I want to set system variable MQSERVER for connecting to MQ using QTP. Each time this value is changed from QTP, I need to restart QTP to reflect changes.

E.g. in the system variables window, MQSERVER = ABCD

change the variable using

 Set objWSH = CreateObject("WScript.Shell")
 Set objSystemVariables = objWSH.Environment("SYSTEM") 
 objSystemVariables(MQVariableName) = MQVariableValue

The variable is set correctly but does not reflect in QTP code when connecting to websphere MQ.

Immediately when I restart QTP, the QTP reads the env variable correctly. Can you please let me know how I can use the below API method. I am getting type mismatch in QTP.

lnRetVal = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", 2, 1000, Null) 'Getting type mismatch here

Updating my original question with the code that connects to queue manager.

The very basic thing that I am trying to do is (which can't be done without restarting QTP)

1) Connect to a queue manager

2) Put the message

3) Connect to another queue manager

4) Read the output

Const MQOO_OUTPUT = 16
 Const MQOO_INPUT_AS_Q_DEF = 1
 Set MQS = CreateObject("MQAX200.MQSession")                          
 Set QM = MQS.AccessQueueManager(Environment.Value("MQName")) 'This will pass the queue name and  access the queue manager.
 Set MQQueue = QM.AccessQueue(strQueName, MQOO_INPUT_AS_Q_DEF Or MQOO_OUTPUT)
 Set PutOptions = MQS.AccessPutMessageOptions()
 PutOptions.Options = MQPMO_NO_SYNCPOINT
 Set PutMsg = MQS.AccessMessage() 
 PutMsg.CharacterSet = 1208
 PutMsg.MessageData = PutMsgStr 'the message text 
 PutMsg.ApplicationIdData = "INTF_0439B" 
 MQQueue.Put PutMsg, PutOptions 'write the message to queue.

Also, my websphere MQ version is 7.0.1.8

Mithilesh Indurkar
  • 481
  • 1
  • 5
  • 12
  • Is there any other way that I would not have to restart QTP to reflect the system environment variable changes. – Mithilesh Indurkar Jun 19 '17 at 11:17
  • What does the code look like that actually connects to MQ? It is possible you could just pass the connection details directly in the program vs having it rely on the MQSERVER env variable. – JoshMc Oct 13 '17 at 07:56
  • Well I really doubt if this can be done in QTP/VBScript. QTP does rely on the environment variable as far as I know. – Mithilesh Indurkar Oct 13 '17 at 11:42
  • Even if you doubt it why don't you post the line(s) of code that connects to MQ and let me see if I can help you with a method that would allow you to pass the details programatically. – JoshMc Oct 16 '17 at 06:14
  • Another option if you just need the ability to connect to more than one queue manager, you can do this via a CCDT (Client Channel Definition Table). The `MQSERVER` variable would be replaced with two variables `MQCHLLIB` (location of the CCDT file) and `MQCHLTAB` (the name of the CCDT file). The CCDT file itself can have one or more channels defined in it associated with a queue manager name. The app then just has to specify the queue manager name to connect to and MQ will look up the channel details via that file. – JoshMc Oct 16 '17 at 06:18
  • CCDT has additional benefits over `MQSERVER` in that you can set all possible client side settings, for example, `HBINT`, `SSLCIPH`, `SCYEXIT`, none of which are possible with `MQSERVER`. – JoshMc Oct 16 '17 at 06:19
  • While this may not answer your original question of how to get QTP to refresh the value of a environment variable with out restarting, it would provide a alternative to doing this with regard to IBM MQ connectivity details. If you can describe your use case I can write up a more detailed answer. If you could provide the version of IBM MQ client software you are using it will also help me provide the best answer as some things have changed in more recent versions of IBM MQ. – JoshMc Oct 16 '17 at 06:23
  • Thanks for this @JoshMc. I have updated my answer to reflect what you asked for. Please let me know if anything else is required. – Mithilesh Indurkar Oct 17 '17 at 07:48
  • You can use Channel table to accomplish this task. The channel table would be defined with two entries, the qmgr you put to and the qmgr you get from. In your code you can then just specify the Qmgr name as the key to look up the right connection details in the tab. MQv7.0 is out of support since Sep 2015, it would be recommended that you move to a more current version and a benefit of this is that they come with a client only version of runmqsc that allows you to create the channel table with only client supported tools. I'll write up a much more detailed answer soon. – JoshMc Oct 18 '17 at 00:27
  • Thanks @JoshMc, can you please guide me some more. Where can I find more info on this please ? – Mithilesh Indurkar Oct 26 '17 at 10:52

0 Answers0