Normal Topic Need Help Understanding 2 Dimensional Arrays (Read 1487 times)
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Need Help Understanding 2 Dimensional Arrays
Jan 3rd, 2018 at 5:40pm
Print Post Print Post  
Hey folks,

I have a mass update that creates an export file, and on each record looks up a corresponding status code -- it does this 34,000 times, so understandably it hogs server resources and slows down other clients.

The status codes it looks up are only 50 different status code numbers -- so it occurs to me I could create a 2 dimensional array and access it ... however, I've never done such a thing before.

Would anyone with experience in this tell me how I could use one GLOBAL command to load the 2-dimensional array, and how I could then refer to it to look up information?

Thanks kindly ...
  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Need Help Understanding 2 Dimensional Arrays
Reply #1 - Jan 5th, 2018 at 2:39pm
Print Post Print Post  
Hi Blair,

Are your status codes number consecutively from 1 to 50 or are they non-sequential like 101, 444, 1056, 4020?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Need Help Understanding 2 Dimensional Arrays
Reply #2 - Jan 9th, 2018 at 10:44pm
Print Post Print Post  
They are non sequential, in groups ranging from 1001 to 9999 .  There are about 90 status codes ...
  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Need Help Understanding 2 Dimensional Arrays
Reply #3 - Jan 10th, 2018 at 4:43pm
Print Post Print Post  
Okay, then you'll need something like the following:

In Global Code
Code
Select All
Stat gsStatusCodes as Array[100, 2] of String
Stat gsCodeCount as Int
Stat gsMax as Int = 100

Subroutine PopulateStatusCodeArray()
Var vList as String
Var vLine as String
Var vCode as String

	gsCodeCount = 0
	vList = @XLookupSourceListAll("Data\StatusCodes.db", "/=", "Statuses!StatusCode", "StatusCode;StatusDesc")
	If vList <> "" Then
	{
		While vList <> ""
		{
			gsCodeCount = gsCodeCount + 1
			If gsCodeCount <= gsMax Then
			{
				vLine = Split(vList, @Newline())
				vCode = Split(vLine, ";")
				gsStatusCodes[gsCodeCount, 1] = vCode
				gsStatusCodes[gsCodeCount, 2] = vLine
			}
			Else
			{
				Writeln("Error! More than " + gsMax + " status codes!")
			}
		}
	}

End Subroutine

Function FindStatusDesc(vCode as Int) as String
Var vDesc as String
Var vLoop as Int
Var vFound as Int

	vLoop = 1
	vFound = 0
	While((vLoop <= gsMax) and (vFound = 0))
	{

		If gsStatusCodes[vLoop, 1] = vCode Then
		{
			vDesc = gsStatusCodes[vLoop, 2]
			vFound = 1
		}
		vLoop = vLoop + 1
	}
	If vFound = 0 Then
	{
		Writeln("Unable to locate a Status code of " + vCode)
	}

	Return(vDesc)
End Function

PopulateStatusCodeArray() 



And then in where you need to find the Description, just call it like such
Code
Select All
Writeln(FindStatusDesc(9001)) 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Need Help Understanding 2 Dimensional Arrays
Reply #4 - Jan 10th, 2018 at 9:26pm
Print Post Print Post  
Thanks ... I will give that a try!
  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Need Help Understanding 2 Dimensional Arrays
Reply #5 - Jan 10th, 2018 at 9:30pm
Print Post Print Post  
You'll obviously need to tweak the XLookupSourceListAll() call to fit your application but if you run into any issues, you know where I am.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged