{"id":31306,"date":"2025-09-30T10:16:01","date_gmt":"2025-09-30T10:16:01","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/sagex3\/?p=31306"},"modified":"2025-09-30T10:16:01","modified_gmt":"2025-09-30T10:16:01","slug":"arrays-in-sage-x3-4gl","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/sagex3\/2025\/09\/30\/arrays-in-sage-x3-4gl\/","title":{"rendered":"Arrays in Sage X3 4GL"},"content":{"rendered":"\n<p>Arrays in <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/development-services\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.greytrix.com\/sage-x3-erp\/development-services\/\" rel=\"noreferrer noopener\">Sage X3<\/a> 4GL provide a powerful and efficient way to store and manage multiple data elements under a single variable. They help streamline your code, improve readability, and reduce complexity when handling collections of related data.<\/p>\n\n\n\n<p>Sage X3 supports both single-dimensional and multi-dimensional arrays, with up to four dimensions allowed, giving developers flexibility to structure data as needed.<\/p>\n\n\n\n<p>In this blog, we&#8217;ll focus specifically on single-dimensional arrays\u2014covering how to declare them, assign values, check their size, and iterate through them using For loops.<\/p>\n\n\n\n<p><strong>New Stuff:<\/strong> <a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2025\/09\/30\/automating-rfq-request-for-quotation-creation-in-sage-x3\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2025\/09\/30\/automating-rfq-request-for-quotation-creation-in-sage-x3\/\" rel=\"noreferrer noopener\">Automating RFQ (Request for Quotation) Creation in Sage X3<\/a><\/p>\n\n\n\n<p><strong>Declaring Single-Dimensional Arrays<\/strong><\/p>\n\n\n\n<p>In Sage X3 4GL, there are two primary ways to declare a single-dimensional array:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Using the Number of Elements<\/strong><\/li>\n<\/ol>\n\n\n\n<p>You can define an array by specifying the total number of elements it should hold. The syntax differs slightly based on the data type.<\/p>\n\n\n\n<p>Examples:<br>Local Integer Num(5)         # Integer array with 5 elements<br>Local Char String(50)(5)     # Character array with 50 characters per element and 5 elements<\/p>\n\n\n\n<p>Notes:<br>For Integer, simply specify the number of elements in parentheses after the variable name.<br>For Char, first define the character size (e.g., 50), followed by the number of elements.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Using a Start\/End Index Range<\/strong><\/li>\n<\/ol>\n\n\n\n<p>You can also declare an array by defining a custom start and end index. This provides more control over how elements are indexed.<\/p>\n\n\n\n<p>Examples:<br>Local Integer Num(0..4)       # Array from index 0 to 4 (5 elements total)<br>Local Char String(50)(1..5)   # Array from index 1 to 5 (5 elements total)<\/p>\n\n\n\n<p><strong>Notes:<\/strong><br>This method lets you define both the start and end index explicitly.<br>If you specify only the start index, Sage X3 automatically sets the end index to the maximum allowed (32,767).<\/p>\n\n\n\n<p>Local Integer BigArray(1..)  # Starts at index 1, ends at 32,767<\/p>\n\n\n\n<p><strong>Checking Array Size with dim() Function<\/strong><\/p>\n\n\n\n<p>In Sage X3 4GL, you can determine the total number of elements in an array using the built-in dim() function. This is especially useful when working with loops or when the array size isn&#8217;t hardcoded.<br>Syntax:<br>dim(array_variable)<\/p>\n\n\n\n<p>Example:<br>Local Integer Numbers(0..3)<br>Infbox(num$(dim(Numbers)))  # Outputs: 4<\/p>\n\n\n\n<p><strong>Accessing and Concatenating Values<\/strong><\/p>\n\n\n\n<p>You can iterate through the array using a For loop along with the dim() function to retrieve or process each element.<\/p>\n\n\n\n<p>Example:<br>Local Char Word(50) : Word = \u201c\u201d<\/p>\n\n\n\n<p>For I = 1 To dim(Letters)<br>Word += Letters(I)<br>Next<\/p>\n\n\n\n<p><strong>Result:<\/strong><br>The final value of Word will be:<br>&#8220;ABCDE&#8221;<\/p>\n\n\n\n<p><strong>Tips:<\/strong><br>Always ensure your loop starts at the same index as your array&#8217;s defined start index (e.g., 1 in this example).<br>If your array starts at index 0, subtract 1 from the loop\u2019s upper limit to avoid an &#8220;index not found&#8221; error:<\/p>\n\n\n\n<p><strong>Example for array with index 0:<\/strong><br>Local Char Codes(1)(0..4) # Array starts at index 0<\/p>\n\n\n\n<p>Local Char Result(50) : Result = &#8220;&#8221;<\/p>\n\n\n\n<p>For I = 0 To dim(Codes) &#8211; 1<br>Result += Codes(I)<br>Next<\/p>\n\n\n[about_us_blog_common]\n","protected":false},"excerpt":{"rendered":"<p>Arrays in Sage X3 4GL provide a powerful and efficient way to store and manage multiple data elements under a single variable. They help streamline your code, improve readability, and reduce complexity when handling collections of related data. Sage X3 supports both single-dimensional and multi-dimensional arrays, with up to four dimensions allowed, giving developers flexibility\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2025\/09\/30\/arrays-in-sage-x3-4gl\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,13],"tags":[4438,4436,4434,4437,4433,4435],"class_list":["post-31306","post","type-post","status-publish","format-standard","hentry","category-sage-erp-x3","category-integration","tag-array-elements","tag-array-index","tag-arrays-in-sage-x3","tag-declaration-of-array","tag-dim-function","tag-single-dimension-array"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/31306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/comments?post=31306"}],"version-history":[{"count":4,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/31306\/revisions"}],"predecessor-version":[{"id":31310,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/31306\/revisions\/31310"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/media?parent=31306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/categories?post=31306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/tags?post=31306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}