Solved

Combine table data into one line

  • 30 August 2022
  • 2 replies
  • 71 views

Badge

Hi everbody,

I want to generate an integer parameter that contain whole data from the table in one line, where the values for the same row are sparated by “,” and values of each rows are separated by “|”.

Wish the final result looks like that:

“1, 2 | 3, 4 | 5, 5 | 6, 7 | 8, 9 | 12, 0”

Table:

Location\XY Lan Long

Place1

1 2

Place 2

3 4
Place 3 5 5
Place 4 6 7
Place 5 8 9
Place 6 12 0

 

The data is located in the parameter(cityID, XY). Where CityID corresponds to list of cities, and XY has two possible values “Lan” and “Long”.

Thank you for your help :)

Cheers,

icon

Best answer by Chris Kuip 31 August 2022, 07:26

View original

2 replies

Userlevel 5
Badge +7

Hello,

The function fnc_strFromMat converts a matrix to a string according to the format you specified.  It is used as follows:

sp_line := fnc_strFromMat( ip_dat(i_place, i_col) );

After execution this statement, the value of sp_line:

    sp_line := "1, 2 | 3, 4 | 5, 5 | 6, 7 | 8, 9 | 12, 0" ;

The function fnc_strFromMat is implemented as follows:

Implementation of function fnc_strFromMat​​​

Some remarks based on the above code:

  • Lines 11-20: These lines describe the input argument p_mat, making it two dimensional. The sets s_rows, and s_cols are passed by reference.
  • Line 21-23: A helper string parameter.
  • Line 5-8: A string for each element in the matrix, including its separation from next.
    If there is a next element in the row, then its separation from next is ", ”
    If there is a next row, then its separation from next is " | ”

Please find the complete example in the attachment.

 

Hope this helps,

 

Chris

Badge

Thank you so much Chris!

 

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator