{"id":39,"date":"2013-11-17T22:38:26","date_gmt":"2013-11-18T03:38:26","guid":{"rendered":"http:\/\/www.integrityautomatedsystems.com\/blog\/?p=39"},"modified":"2023-03-31T22:38:28","modified_gmt":"2023-03-31T22:38:28","slug":"saving-statedata-without-defining-a-bunch-of-temporary-variables","status":"publish","type":"post","link":"http:\/\/integrityautomatedsystems.com\/index.php\/2013\/11\/saving-statedata-without-defining-a-bunch-of-temporary-variables\/","title":{"rendered":"Saving state\/data without defining a bunch of temporary variables"},"content":{"rendered":"<p><a href=\"http:\/\/www.integrityautomatedsystems.com\/blog\/wp-content\/uploads\/2013\/11\/2013-11-14-00_42_02-LANSA-Editor-AJBTEST-Form_-test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-41\" src=\"http:\/\/www.integrityautomatedsystems.com\/blog\/wp-content\/uploads\/2013\/11\/2013-11-14-00_42_02-LANSA-Editor-AJBTEST-Form_-test.png\" alt=\"2013-11-14 00_42_02-LANSA Editor - AJBTEST ( Form_ ) - test\" width=\"854\" height=\"382\" srcset=\"http:\/\/integrityautomatedsystems.com\/wp-content\/uploads\/2013\/11\/2013-11-14-00_42_02-LANSA-Editor-AJBTEST-Form_-test.png 854w, http:\/\/integrityautomatedsystems.com\/wp-content\/uploads\/2013\/11\/2013-11-14-00_42_02-LANSA-Editor-AJBTEST-Form_-test-300x134.png 300w, http:\/\/integrityautomatedsystems.com\/wp-content\/uploads\/2013\/11\/2013-11-14-00_42_02-LANSA-Editor-AJBTEST-Form_-test-604x270.png 604w\" sizes=\"auto, (max-width: 854px) 100vw, 854px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Variable Scope<\/h3>\n<p>In RDMLX (The LANSA language), variables have a global scope.  This means that it&#8217;s really easy at times to accidentally clobber a field which you are using, by using the field for more than one purpose.  It can be argued that all fields should only be used for one purpose in a program, but there are scenarios where this can happen.  E.g.  You may be using a field to represent the selected value in a drop down list, and you may also be using the same field to populate the value when building the list.<\/p>\n<p>Global variables have historically been a cause of subtle bugs.  A couple of options exist to try and alleviate this problem.  Any code that would be better with a local variable scope can always be externalized into a reusable component (The first option).  This will also go a long way to minimize coupling.  However, if you do not want to re-architect your program, but still need to prevent your variable from becoming contaminated, you could always backup your variables at a convenient location and restore it later when you need the saved values back (the second option).<\/p>\n<h3>Use a List<\/h3>\n<p>If the save and restore have to handle more than a few variables, it becomes cumbersome if you are just using temporary variables to store the data.<\/p>\n<p>The solution shown in the image above defines a working list with one record.  Then when you want to backup the data, you merely do an ADD_ENTRY to_list(#LISTNAME).  And voila, you have saved the current state of these fields.  Once you are ready to restore the state of the fields, you can do a GET_ENTRY number(1) from_list(#LISTNAME) and you variables have been restored.<\/p>\n<p>This techniques tends to reduce the need for work fields, and can reduce the coding required to accomplish the same task.<br \/>\nLess work fields and less code = less bugs.<\/p>\n<p>Andy<\/p>\n<p><a title=\"Andy Bain\" href=\"http:\/\/www.linkedin.com\/in\/johnandybain\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/+AndyBain\" target=\"_blank\" rel=\"noopener\">https:\/\/plus.google.com\/+AndyBain<\/a><br \/>\n<a href=\"https:\/\/twitter.com\/jandybain\" target=\"_blank\" rel=\"noopener\">@jandybain<\/a><\/p>\n<p><script src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\" async=\"\"><\/script><!-- Horizontal Ads --> <ins class=\"adsbygoogle\" style=\"display: inline-block; width: 728px; height: 90px;\" data-ad-client=\"ca-pub-5372623468524052\" data-ad-slot=\"8082103234\"><\/ins><script>\/\/ <![CDATA[\n(adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n\/\/ ]]><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Variable Scope In RDMLX (The LANSA language), variables have a global scope. This means that it&#8217;s really easy at times to accidentally clobber a field which you are using, by using the field for more than one purpose. It can be argued that all fields should only be used for one purpose in a &hellip; <a href=\"http:\/\/integrityautomatedsystems.com\/index.php\/2013\/11\/saving-statedata-without-defining-a-bunch-of-temporary-variables\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Saving state\/data without defining a bunch of temporary variables<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":11,"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":234,"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions\/234"}],"wp:attachment":[{"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/integrityautomatedsystems.com\/index.php\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}