{"id":728,"date":"2011-03-03T20:00:38","date_gmt":"2011-03-04T01:00:38","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=728"},"modified":"2021-03-10T20:00:00","modified_gmt":"2021-03-11T01:00:00","slug":"powerbuilder-setting-column-value-without-looping-through-all-rows","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-setting-column-value-without-looping-through-all-rows\/","title":{"rendered":"PowerBuilder &#8211; Setting column value without looping through all rows."},"content":{"rendered":"<p>A question came up on the TekTips website about setting a column in all the rows in a datawindow to the same value without looping through. In this case the writer was loading data from over one hundred Excel files and wanted to track the filename of where the data came from. At first I thought you could simply put an expression to modify the data in a column but you cannot. Then I thought you could set up a computed column and modify the expression but you cannot do a rowscopy from a computed column. Then I came up with the following.<\/p>\n<p>Since the data is being imported via the importfile method, I needed to set the initial value of a column to the filename within the &#8216;working&#8217; or &#8216;temp&#8217; datawindow which the data is initially loaded into. After defining the external datawindow with the number of data columns equal to my import files, I added a row to the column definitions in the table section. This object I called &#8220;d_excelloadtemp&#8221;.<\/p>\n<pre name=\"code\" class=\"VB\"> column=(type=char(255) updatewhereclause=yes name=file_name dbname=&quot;file_name&quot; )<\/pre>\n<p>In my case this was the fifth line in that section. This is important since when defining the column for the modify, you need to give it an ID value which is the same as the order in which it appears in the table section, in this case 5.<\/p>\n<p>The permanent datawindow object has all five columns defined with the &#8216;file_name&#8217; column being the same as the added one in the &#8216;temp&#8217; datawindow object. In fact, I pulled its visual definition syntax, which is used in the &#8216;create column&#8217; modify statement, from the source of this datawindow (called &#8220;d_excelload&#8221;).<\/p>\n<p>The code is in the clicked event of the load button.<\/p>\n<pre name=\"code\" class=\"VB\">integer li_rc\nlong ll_rc\nstring ls_filename, ls_msg, ls_modify\n\/\/ first file to process\nls_filename = &#039;c:\\temp\\inventoryA.csv&#039;\n\n\/\/ the modify is taken from the datawindow object source.  Remember to put a tilde in front\n\/\/ of any double quotes.\nls_modify = &quot;create column(band=detail id=5 alignment=~&quot;0~&quot; tabsequence=50 border=~&quot;0~&quot; color=~&quot;33554432~&quot; x=~&quot;1184~&quot; y=~&quot;8~&quot; height=~&quot;64~&quot; width=~&quot;489~&quot; html.valueishtml=~&quot;0~&quot;  name=file_name visible=~&quot;1~&quot; edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=no  font.face=~&quot;Tahoma~&quot; font.height=~&quot;-10~&quot; font.weight=~&quot;400~&quot;  font.family=~&quot;2~&quot; font.pitch=~&quot;2~&quot; font.charset=~&quot;0~&quot; background.mode=~&quot;1~&quot; background.color=~&quot;536870912~&quot; background.transparency=~&quot;0~&quot; background.gradient.color=~&quot;8421504~&quot; background.gradient.transparency=~&quot;0~&quot; background.gradient.angle=~&quot;0~&quot; background.brushmode=~&quot;0~&quot; background.gradient.repetition.mode=~&quot;0~&quot; background.gradient.repetition.count=~&quot;0~&quot; background.gradient.repetition.length=~&quot;100~&quot; background.gradient.focus=~&quot;0~&quot; background.gradient.scale=~&quot;100~&quot; background.gradient.spread=~&quot;100~&quot; tooltip.backcolor=~&quot;134217752~&quot; tooltip.delay.initial=~&quot;0~&quot; tooltip.delay.visible=~&quot;32000~&quot; tooltip.enabled=~&quot;0~&quot; tooltip.hasclosebutton=~&quot;0~&quot; tooltip.icon=~&quot;0~&quot; tooltip.isbubble=~&quot;0~&quot; tooltip.maxwidth=~&quot;0~&quot; tooltip.textcolor=~&quot;134217751~&quot; tooltip.transparency=~&quot;0~&quot; transparency=~&quot;0~&quot; )&quot;\n\nls_msg = dw_2.modify(ls_modify)\n\n\/\/ Below is where we load two files.  If you plan on processing many, put this in a loop\n\/\/ set the initial value of the new column\nls_modify = &quot;file_name.initial=&#039;&quot; + ls_filename + &quot;&#039;&quot;\nls_msg = dw_2.modify(ls_modify)\n\/\/ import rows\nll_rc = dw_2.importfile(ls_filename)\n\/\/ copy the data to the permanent datawindow\nli_rc = dw_2.rowscopy( 1, 9999, Primary!, dw_1, 9999, Primary!)\n\ndw_2.reset()\n\/\/ next file\nls_filename = &#039;c:\\temp\\inventoryB.csv&#039;\n\/\/ modify the value of the dynamic column\nls_modify = &quot;file_name.initial=&#039;&quot; + ls_filename + &quot;&#039;&quot;\nls_msg = dw_2.modify(ls_modify)\n\nll_rc = dw_2.importfile(ls_filename)\n\/\/ copy again to the permanent datawindow\nli_rc = dw_2.rowscopy( 1, 9999, Primary!, dw_1, 9999, Primary!)<\/pre>\n<p>Sample screen<br \/>\n<a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2011\/03\/Excelload.png\"><img loading=\"lazy\" class=\"aligncenter wp-image-730 size-full\" title=\"Excelload\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2011\/03\/Excelload.png\" alt=\"\" width=\"593\" height=\"450\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2011\/03\/Excelload.png 593w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2011\/03\/Excelload-300x227.png 300w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2011\/03\/Excelload-150x113.png 150w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/><\/a><\/p>\n<p>Export files can be found <a href=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2011\/03\/excellload.zip\">excellload<\/a>. This is in PB11.5.1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A question came up on the TekTips website about setting a column in all the rows in a datawindow to the same value without looping through. In this case the writer was loading data from over one hundred Excel files and wanted to track the filename of where the data came from. At first I&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[21,12,16],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/728"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=728"}],"version-history":[{"count":6,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/728\/revisions"}],"predecessor-version":[{"id":1936,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/728\/revisions\/1936"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}