This can be done fairly easily: either as Tim Kuehn or Tom Bascom suggest or:
Allocate sufficiently large memory region to hold the data:
def var mp as memptr no-undo.
set-size(mp) = 1024. /* pre-calculated size depending on the data, in bytes */
/* copy contents of temp-table into mp */
run procedureInC (mp). /* run external procedure */
set-size(mp) = 0. /* free up the memory */
There are three major things that need to be filled in:
- Deciding how data should be structured within the memory region, this includes agreement on how 4GL data types will be represented (i.e. representation and length of strings, decimals, dates etc) and good understanding how your particular C compiler lays out structs in memory.
- Once there is an agreement on the first point 4GL guys can roll out a function that given a temp-table handle will calculate the required size of the memory region based on record size calculated using point 1 and number of records.
- Next 4GL guys can roll out a procedure copying temp-table into the memory region following the rules agreed in point 1 (look at PUT-BYTE, PUT-STRING etc in Progress Manual).
There is one more thing to remember, since the memory region is going to be allocated by Progress runtime and then freed straight after the call to your C function, you'd need to copy the content as it won't be any longer available once you return.
- Tim's solution is the simplest to implement from 4GL point of view, but you'd need to parse XML in C and it will use significantly more memory than the other two solutions.
- Tom's solution is a compromise. The data is sent in binary form, however it requires a bit more effort and skill on 4GL side. You'd need to roll out an API, manage state and the data is going to be transferred in a number of successive calls.
- The solution I described is what you have asked for. It allows to pass the data with minimum overhead all in one go. However, it's going to be configuration dependent - the layout of structs generated by your C compiler matters.
The other problem is that third solution requires someone on 4GL side who understand how data is represented on the machine level so you could have a meaningful conversation about various string representations and encodings, endianness, padding, representation of Progress decimals in C without loss of precision, representation of dates and so on. Clearly since 4GL people asked you to investigate the solution they might not be conversant in all these topics and hence you're better off with simplifying the task for them as much as possible and doing most of the work for them.
Another way is to hire a suitable consultant on 4GL side to do and thoroughly document this piece of work for you.
Yet another way is to keep asking smaller questions here on Stackoverflow whilst doing the bulk of the investigation and programming work yourself - we'll be happy to help. Good luck.