# Assign a table inside a function

**URL:** <https://forum.kx.com/t/assign-a-table-inside-a-function/8800>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [May 9, 2014, 1:59am UTC](https://forum.kx.com/t/assign-a-table-inside-a-function/8800 "2014-05-09T01:59:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas\_agarwal1](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@vikas\_agarwal1](https://forum.kx.com/u/vikas_agarwal1)\
**Post date:** [May 9, 2014, 1:59am UTC](https://forum.kx.com/t/assign-a-table-inside-a-function/8800/1 "2014-05-09T01:59:00Z")

</div>

Hi,

I have a function that performs some calculation on a table and return the result. It all seems fine.

I have to write another function that will accept the output table name where we will write the same data rather than returning it to caller. Because it is a function, i am not able to use “value” function as inner table is not global.

Is there some way i can assign data to a table?

---

<div class="post-metadata">

**Author:** ![vikas\_agarwal1](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@vikas\_agarwal1](https://forum.kx.com/u/vikas_agarwal1)\
**Post date:** [May 9, 2014, 4:09am UTC](https://forum.kx.com/t/assign-a-table-inside-a-function/8800/2 "2014-05-09T04:09:00Z")

</div>

I think it is

tableName set data

where data can be any type

---

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [May 9, 2014, 4:17am UTC](https://forum.kx.com/t/assign-a-table-inside-a-function/8800/3 "2014-05-09T04:17:00Z")

</div>

Hi VIkas,\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

there are 2&nbsp; ways to do it:\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

setme1:{tmp:: 1 2 3 4 }\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

setme2:{`tmp2 set 1 2 3 4}\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

HTH,\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Kim\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

**Von:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com) [[mailto:personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)] **Im Auftrag von** Vikas Agarwal  
**Gesendet:** Freitag, 9. Mai 2014 11:10  
**An:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
**Betreff:** [personal kdb+] Re: Assign a table inside a function\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

I think it is\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

tableName set data\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

where data can be any type\<o:p\>\</o:p\>

---

<div class="post-metadata">

**Author:** ![vikas\_agarwal1](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@vikas\_agarwal1](https://forum.kx.com/u/vikas_agarwal1)\
**Post date:** [May 11, 2014, 7:41am UTC](https://forum.kx.com/t/assign-a-table-inside-a-function/8800/4 "2014-05-11T07:41:00Z")

</div>

Thanks Kim for reply. I think i was not clearer in my question.

suppose a variable tmp is having following value. and tmp will be a parameter to a function. I dont have to set tmp into a function. that can be easily done. But i have to set the value in tmp to something.

tmp:`vikas

;{x set (1 2 3 4)}[tmp]

now in the above code. vikas variable will be set to 1 2 3 4.

---

<div class="post-metadata">

**Author:** ![sohagan](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@sohagan](https://forum.kx.com/u/sohagan)\
**Post date:** [May 11, 2014, 9:42am UTC](https://forum.kx.com/t/assign-a-table-inside-a-function/8800/5 "2014-05-11T09:42:00Z")

</div>

Reference it by name:

q)tmp

`vikas

{x set (1 2 3 4)}[`tmp]

q)tmp

1 2 3 4

Thanks,

Sean

---

<div class="post-metadata">

**Author:** ![vikas\_agarwal1](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@vikas\_agarwal1](https://forum.kx.com/u/vikas_agarwal1)\
**Post date:** [May 11, 2014, 9:43pm UTC](https://forum.kx.com/t/assign-a-table-inside-a-function/8800/6 "2014-05-11T21:43:00Z")

</div>

Sean,&nbsp;

I did not want to set the tmp variable value. But i want to set the value inside temp to something.

so slight changes to your example:

q)tmp:`vikas

q)tmp

`vikas

q){x set (1 2 3 4)}[tmp]

`vikas

q)tmp

`vikas

q)vikas

1 2 3 4j

&nbsp;
