Hi Nelson,
It can be done but probably not as simply as a for next loop. There's a CATS function that will concatenate to dynamic arrays and return a new dynamic array with the results. It's not that simple though if you want to concatenate a new delimiter. Here's an example that does it two ways. Take a look and see which one you think is easier to understand and maintain.
ARRAY = 'A1':@VM:'A2':@VM:'A3':@VM:'A4'
ARRAY<2> = 'B1':@VM:'B2':@VM:'B3':@VM:'B4'
LN = DCOUNT(ARRAY<1>, @VM)
* PUT THEM TOGETHER WITH A FOR NEXT LOOP
LOOP.RESULT = ''
FOR LINE.NO = 1 TO LN
LOOP.RESULT<1,LINE.NO> = ARRAY<1,LINE.NO>:'-':ARRAY<2,LINE.NO>
NEXT
PRINT LOOP.RESULT
* DO THE SAME THING WITH THE CATS FUNCTION
* CATS CONACTENATES THE VALUES FROM ONE ARRAY TO ANOTHER ARRAY AND RETURNS THE RESULTING ARRAY
* IN ORDER TO USE IT, WE NEED TO HAVE A CORRECTLY SIZED ARRAY OF THE DELMITERS SO THAT WE
* CAN CONACTENATE IT WITH THE SECOND ARRAY
DELIMS = STR('-':@VM, LN)
* WE'RE ALWAYS GOING TO END UP WITH AN EXTRA ELEMENT AT THE END SO WE NEED TO STRIP THAT OFF
DELIMS = FIELD(DELIMS, @VM, 1, LN)
* NOW WE CAN BUILD A NEW ARRAY BY CONCACTENATING OUR DELIMITERS WITH ARRAY<2>
DELIM.ARRAY = CATS(DELIMS, ARRAY<2>)
* FINALLY WE CAN BUILD THE NEW ARRAY WITH ARRAY<1> AND DELIM.ARRAY
RESULT = CATS(ARRAY<1>, DELIM.ARRAY)
PRINT RESULT
STOP
If you're trying to get the best performance, CATS is faster. To loop through each of those sections 999,999 times took the first method 2,510 milliseconds. The second took 960 milliseconds. For most real world cases it's better to go with understandable.
------------------------------
Joe Goldthwaite
Consultant
Phoenix AZ US
------------------------------
Original Message:
Sent: 11-06-2024 14:12
From: Nelson Schroth
Subject: Is there a UniVerse BASIC command like Excel TRANSPOSE?
I have a statistics program that builds an array with <1,POS>= sku and <2,POS>=qty. The output would often have 8-9k SKUs.
When I dump it out to a sequential file, I want to output the data as a sinlge row for each sku in the format of SKU:<delimiter>:QTY
I know I can do this programatically using a for...next loop, but wondered if ther was a quicker/built-in way to do this?
Nelson
------------------------------
Nelson Schroth
president
C3CompleteShop LLC
Harrison OH US
------------------------------