<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: how do I develop a multithreading application within PowerBuilder classic? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-do-i-develop-a-multithreading-application-within-powerbuilder-classic/qaa-p/380473#M33299</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;#1: The name must be unique for registered objects in the application. If you try to register a second object with the same name the function SharedObjectRegister should return SharedObjectExistsError!&lt;/P&gt;&lt;P&gt;You may use a shared or global variable instead of instance variable as thread counter.&lt;/P&gt;&lt;P&gt;#2: You can't use the transaction object from main thread (SQLCA) in a shared object. You need a separate database connection for each shared object if you want to access the database.&lt;/P&gt;&lt;P&gt;One parameter of function of_checkvalid of your shared object is a datawindow control. I think the shared object cannot access this object from main thread. You may pass only nonvisualobjects. If you want to check data from a datawindow you may pass it as blob (see function GetFullState / SetFullState).&lt;/P&gt;&lt;P&gt;To return a result from shared object to main thread you need a (nonvisual) callback object with a function you can call from the shared object.&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jan 2017 11:59:39 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2017-01-17T11:59:39Z</dc:date>
    <item>
      <title>how do I develop a multithreading application within PowerBuilder classic?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-develop-a-multithreading-application-within-powerbuilder-classic/qaq-p/380472</link>
      <description>&lt;P&gt;hi guys&lt;/P&gt;&lt;P&gt;     there was a legacy program need to maintain,then I tried to check a batch number of product that if supplies was less than all sells,I believe it's a good experience for   &lt;/P&gt;&lt;P&gt;colleagues that after scaned the barcode of that batch number  application then checked the supplies and sells aysnchrously.althought I have searched Google,however Powerbuilder is less infomation I could found  about multithreading,it's not a clear instrution in Powerbuilder help as well.&lt;/P&gt;&lt;P&gt;I'm not sure two questions about multithreading within powerbuilder&lt;/P&gt;&lt;P&gt;#1 if the exception is going to occur when SharedObjectRegister the same name when open two windows like following? &lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;P&gt;window w_1&lt;BR /&gt;opensheet(w_1,"w_inv",w_main,0,Original! )&lt;/P&gt;&lt;P&gt;// then in two same w_inv windows exectue SharedObjectRegister with same name in a //same time,is it going to ocurr the exception?&lt;/P&gt;&lt;P&gt;SharedObjectRegister ('nov_checkvalidobject', ls_var)&lt;/P&gt;&lt;P&gt;#2 some pages said that main thread and sub thread are independent,does it mean that if need to execute SQL select syntax,I can't use sqlca transaction which has connected to a database in main thread?&lt;/P&gt;&lt;P&gt;please take a look at my code,please give me suggestion that I have done wrong or should be aware.thanks in advance&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//w_inv instance variable:&lt;/P&gt;&lt;P&gt;//long ll_multithreadcount&lt;BR /&gt;//string is_sbmodel&lt;BR /&gt;//nov_checkvalidobject tarea_No[ ]&lt;/P&gt;&lt;P&gt;//this is wf_multithread_cal&lt;/P&gt;&lt;P&gt;//long as_row&lt;/P&gt;&lt;P&gt;string ls_var&lt;BR /&gt;ErrorReturn ler_error&lt;BR /&gt;long ll_threadcurrent&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ll_threadcurrent=ll_multithreadcount&lt;BR /&gt;ls_var = 'objeto_' +string(ll_threadcurrent)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if is_new='0' then&lt;BR /&gt;   cb_add_main.enabled=false&lt;BR /&gt;   &lt;BR /&gt;elseif is_new='1' then&lt;BR /&gt;   cb_delete_main.enabled=false&lt;BR /&gt;   cb_delete_sub.enabled=false&lt;BR /&gt;end if&lt;BR /&gt;&lt;BR /&gt;ler_error = SharedObjectRegister ('nov_checkvalidobject', ls_var)&lt;BR /&gt;&lt;BR /&gt;choose case ler_error&lt;BR /&gt;       case SharedObjectExistsError!&lt;BR /&gt;         &lt;/P&gt;&lt;P&gt;messagebox("Error","The instance name is already used",stopsign!)&lt;/P&gt;&lt;P&gt;if is_new='0' then&lt;BR /&gt;   cb_add_main.enabled=true&lt;BR /&gt;   &lt;BR /&gt;elseif is_new='1' then&lt;BR /&gt;   cb_delete_main.enabled=true&lt;BR /&gt;   cb_delete_sub.enabled=true&lt;BR /&gt;end if&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;         return -1&lt;BR /&gt;       case SharedObjectCreateInstanceError! &lt;BR /&gt;         &lt;/P&gt;&lt;P&gt;messagebox("Error","The object could not be created",stopsign!)&lt;/P&gt;&lt;P&gt;if is_new='0' then&lt;BR /&gt;   cb_add_main.enabled=true&lt;BR /&gt;   &lt;BR /&gt;elseif is_new='1' then&lt;BR /&gt;   cb_delete_main.enabled=true&lt;BR /&gt;   cb_delete_sub.enabled=true&lt;BR /&gt;end if&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;         return -1&lt;BR /&gt;         &lt;BR /&gt;       case SharedObjectCreatePBSessionError! &lt;BR /&gt;         &lt;/P&gt;&lt;P&gt;messagebox("Error","The object in the session could not be created",stopsign!)  &lt;/P&gt;&lt;P&gt;if is_new='0' then&lt;BR /&gt;   cb_add_main.enabled=true&lt;BR /&gt;   &lt;BR /&gt;elseif is_new='1' then&lt;BR /&gt;   cb_delete_main.enabled=true&lt;BR /&gt;   cb_delete_sub.enabled=true&lt;BR /&gt;end if&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;         return -1&lt;BR /&gt;     end choose&lt;BR /&gt;&lt;BR /&gt;      &lt;BR /&gt;     ler_error = SharedObjectGet (ls_var,  tarea_No[ll_threadcurrent])&lt;BR /&gt;     choose case ler_error&lt;BR /&gt;       case SharedObjectCreateInstanceError! &lt;BR /&gt;         &lt;/P&gt;&lt;P&gt;messagebox("Error","The local reference to the shared object could not be created",stopsign!)&lt;/P&gt;&lt;P&gt;if is_new='0' then&lt;BR /&gt;   cb_add_main.enabled=true&lt;BR /&gt;   &lt;BR /&gt;elseif is_new='1' then&lt;BR /&gt;   cb_delete_main.enabled=true&lt;BR /&gt;   cb_delete_sub.enabled=true&lt;BR /&gt;end if&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;         return -1&lt;BR /&gt;       case SharedObjectNotExistsError!  &lt;BR /&gt;         &lt;/P&gt;&lt;P&gt;messagebox("Error","The instance name is not registered ",stopsign!)&lt;/P&gt;&lt;P&gt;if is_new='0' then&lt;BR /&gt;   cb_add_main.enabled=true&lt;BR /&gt;   &lt;BR /&gt;elseif is_new='1' then&lt;BR /&gt;   cb_delete_main.enabled=true&lt;BR /&gt;   cb_delete_sub.enabled=true&lt;BR /&gt;end if&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;         return -1&lt;BR /&gt;     end choose&lt;BR /&gt;&lt;BR /&gt;tarea_No[ll_threadcurrent].POST of_checkvalid(dw_2,as_row)&lt;BR /&gt; &lt;BR /&gt;SharedobjectUnregister(ls_var)&lt;BR /&gt;&lt;BR /&gt;ll_multithreadcount++&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;if is_new='0' then&lt;BR /&gt;   cb_add_main.enabled=true&lt;BR /&gt;   &lt;BR /&gt;elseif is_new='1' then&lt;BR /&gt;   cb_delete_main.enabled=true&lt;BR /&gt;   cb_delete_sub.enabled=true&lt;BR /&gt;end if&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;return 0&lt;/P&gt;&lt;P&gt;//nov_checkvalidobject: there is a function in nov_checkvalidobjec which is of_checkvalid&lt;/P&gt;&lt;P&gt;// there is 2 parameters in it&lt;/P&gt;&lt;P&gt;//paramter #1 datawindow as_dw&lt;/P&gt;&lt;P&gt;//paramter #2 long as_therow&lt;/P&gt;&lt;P&gt;//of_checkvalid function code:&lt;/P&gt;&lt;P&gt;decimal ld_invnum,ld_depnum&lt;BR /&gt;string ls_prodno,ls_batchno,ls_prodadd&lt;BR /&gt;&lt;BR /&gt;if as_therow&amp;lt;0 or as_therow&amp;gt;as_dw.rowcount() then return -1&lt;BR /&gt;&lt;BR /&gt;ls_prodno=as_dw.getitemstring(as_therow,"prod_no")&lt;BR /&gt;ls_batchno=as_dw.getitemstring(as_therow,"batch_no")&lt;BR /&gt;ls_prodadd=as_dw.getitemstring(as_therow,"prod_add")&lt;BR /&gt;&lt;BR /&gt;if isnull(ls_prodno) or trim(ls_prodno)="" or isnull(ls_batchno) or trim(ls_batchno)=""  or isnull(ls_prodadd) or trim(ls_prodadd)="" then return -2&lt;BR /&gt; //check the number of all sells&lt;BR /&gt; select isnull(sum(inv_num),0) into :ld_invnum from inv_sub where prod_no=:ls_prodno and batch_no=:ls_batchno and prod_add=:ls_prodadd;&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;//check the number of all suppliers&lt;/P&gt;&lt;P&gt;select isnull(sum(dep_num),0) into :ld_depnum from dep_sub where prod_no=:ls_prodno and batch_no=:ls_batchno and prod_add=:ls_prodadd;&lt;BR /&gt; &lt;BR /&gt; if ld_invnum&amp;gt;ld_depnum then &lt;BR /&gt;   as_dw.setitem(as_therow,"if_is_valid","failed")&lt;BR /&gt;   return -3&lt;BR /&gt;end if&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;as_dw.setitem(as_therow,"if_is_valid","pass")&lt;BR /&gt;return 0&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 09:34:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-develop-a-multithreading-application-within-powerbuilder-classic/qaq-p/380472</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-01-17T09:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: how do I develop a multithreading application within PowerBuilder classic?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-develop-a-multithreading-application-within-powerbuilder-classic/qaa-p/380473#M33299</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;#1: The name must be unique for registered objects in the application. If you try to register a second object with the same name the function SharedObjectRegister should return SharedObjectExistsError!&lt;/P&gt;&lt;P&gt;You may use a shared or global variable instead of instance variable as thread counter.&lt;/P&gt;&lt;P&gt;#2: You can't use the transaction object from main thread (SQLCA) in a shared object. You need a separate database connection for each shared object if you want to access the database.&lt;/P&gt;&lt;P&gt;One parameter of function of_checkvalid of your shared object is a datawindow control. I think the shared object cannot access this object from main thread. You may pass only nonvisualobjects. If you want to check data from a datawindow you may pass it as blob (see function GetFullState / SetFullState).&lt;/P&gt;&lt;P&gt;To return a result from shared object to main thread you need a (nonvisual) callback object with a function you can call from the shared object.&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 11:59:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-develop-a-multithreading-application-within-powerbuilder-classic/qaa-p/380473#M33299</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-01-17T11:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: how do I develop a multithreading application within PowerBuilder classic?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-develop-a-multithreading-application-within-powerbuilder-classic/qaa-p/380474#M33300</link>
      <description>&lt;P&gt;Each background thread has its own set of global variables which includes sqlca. The background thread will have to connect to the database before performing any SQL statements.&lt;/P&gt;&lt;P&gt;When calling SharedObjectRegister, the instancename must be unique. You can create a global variable or shared variable within the window that you increment before each call and use it in the name like this:&lt;/P&gt;&lt;P&gt;gi_instance ++&lt;/P&gt;&lt;P&gt;ls_instance = "instance" + String(gi_instance)&lt;/P&gt;&lt;P&gt;SharedObjectRegister("objectname",ls_instance)&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 13:49:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-develop-a-multithreading-application-within-powerbuilder-classic/qaa-p/380474#M33300</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-01-17T13:49:21Z</dc:date>
    </item>
  </channel>
</rss>

