Heidenhain TNC 640: Tables & System Data
Almost everything interesting on a TNC 640 lives in a table: tool data, magazine pockets, presets, datums, compensation values, and any custom data you care to store. This reference maps the table landscape, then covers the four ways an NC program reads and writes it — FN 26/27/28 for freely definable tables, TABDATA for the active tool/compensation tables, SQL statements for everything at speed, and FN 18: SYSREAD for live system data — plus FN 16: F-PRINT for getting results out as formatted reports. Verified against the TNC 640 manuals (Klartext 34059x-11, Setup 34059x-18); numbers differ on other Heidenhain series.
The Table Landscape
Machine-wide tables live in TNC:\table\. Table and column names must start with a letter and must not contain arithmetic operators (SQL chokes on them).
| Table | File | What it holds |
|---|---|---|
| Tool table | TOOL.T (extension .T) | Up to 32 767 tools; the active table must be TNC:\table\TOOL.T. Other .T files are archives/test-run tables |
| Pocket table | TOOL_P.TCH (extension .TCH) | Tool-changer magazine assignment; name/path/content adaptable by the machine builder |
| Preset table | PRESET.PR (extension .PR) | Workpiece presets incl. basic rotations; row 0 is always the last manually set preset |
| Datum tables | *.D | Datum shifts, activated with SEL TABLE / TRANS DATUM TABLE (or Cycle 7) |
| Point tables | *.PNT | Machining positions for SEL PATTERN / CYCL CALL PAT |
| Touch-probe table | *.TP | Probe data: DIST, SET_UP, F, FMAX, TRACK, CAL_OF1/2, CAL_ANG |
| Freely definable tables | *.TAB | Your own columns/formats — the FN 26/27/28 and SQL playground |
| Compensation tables | *.tco / *.wco | Corrections in the tool coordinate system (alternative to DL/DR/DR2 in TOOL CALL) / shifts in the working-plane coordinate system |
| Pallet tables | *.P | Pallet management / Batch Process Manager |
| Turning tools / 3D comp | *.TRN / *.3DTC | Turning tool data (option 50); 3D tool-radius compensation values (TNC:\system\3D-ToolComp, referenced by the DR2TABLE column) |
TOOL.T — the columns worth knowing
| Column | Meaning |
|---|---|
| Geometry & identification | |
T / NAME | Tool number (indexed tools: 5.1, 5.2 … for stepped drills etc.) / name, max. 32 characters, capitals |
L / R / R2 | Length (absolute, from the tool reference point), radius, corner radius R2 for toroid/ball cutters |
DL / DR / DR2 | Delta (oversize/wear) values added to L, R, R2 |
LCUTS / LU / RN / ANGLE | Tooth length, usable length, neck radius, max. plunge angle — consumed by cycles and collision monitoring |
T-ANGLE / PITCH / RCUTS / R_TIP | Point angle (Cycle 240), thread pitch (Cycles 206/207/208), front-face insert width (251/252/OCM), tip radius |
| Tool life & changing | |
TL / RT | Tool locked / replacement-tool number |
TIME1 / TIME2 / CUR_TIME / OVRTIME | Max tool life / max life at TOOL CALL (triggers replacement) / current age (control-maintained) / permitted overrun |
TYP / DOC / PLC / PTYP / NMAX / LIFTOFF | Tool type, comment, PLC status, pocket-table type, spindle-speed limit, M148 lift-off permission |
| Automatic tool measurement (TT cycles) | |
CUT | Number of teeth (max. 99 in the tool-table dialog; 20 for measurement/cutting-data use) |
LTOL / RTOL / R2TOL | Wear tolerances for L / R / R2 — exceeded → tool locked (status L) |
LBREAK / RBREAK | Breakage tolerances for L / R |
DIRECT / R-OFFS / L-OFFS | Cutting direction when measuring rotating; radial offset for length measurement; axial offset for radius measurement |
Pocket table key columns: P pocket number, T tool number, RSV reservation (box magazines), ST special tool, F fixed pocket, L locked pocket, DOC comment from TOOL.T, PLC, PTYP, and LOCKED_ABOVE/BELOW/LEFT/RIGHT for box magazines. Preset table: PRESET.PR is editable only in Manual Operation / El. Handwheel after pressing CHANGE PRESET; new rows can only be appended at the end; write-protection per row is available. Touch-probe cycles 400–405, 408–419 and 14xx can write to it directly (see the probing article). Never delete line 0 of TOOL.T — the manual warns this permanently destroys the table structure.
FN 26 / 27 / 28 — Freely Definable Tables
Create a .TAB file in the file manager (the control offers stored templates; save your own under TNC:\system\proto), then shape it with the structure editor. Column types include TEXT, DEC, INT, LENGTH (converted in inch programs), FEED, FLOAT, BOOL, TSTAMP, UPTEXT, PATHNAME. Text-type columns can only be read or written via QS parameters — even if a cell happens to contain a number.
| Function | Syntax | Notes |
|---|---|---|
FN 26: TABOPEN | FN 26: TABOPEN TNC:\DIR1\TAB1.TAB | Only one table open per NC program at a time; a new FN 26 closes the previous one; must be a .TAB file |
FN 27: TABWRITE | FN 27: TABWRITE 5/"RADIUS,DEPTH,D" = Q5 | Writes row 5; multiple columns take values from successive Q numbers (here Q5, Q6, Q7). Executes only in Program Run Single Block / Full Sequence; writing a locked or missing cell raises an error |
FN 28: TABREAD | FN 28: TABREAD Q10 = 6/"X,Y,D" | Reads row 6 into Q10, Q11, Q12 (successive parameters of the same type); use a QS target for text columns: FN 28: TABREAD QS1 = 6/"DOC" |
53 Q5 = 3.75
54 Q6 = -5
55 Q7 = 7.5
56 FN 27: TABWRITE 5/"RADIUS,DEPTH,D" = Q5 ; writes Q5/Q6/Q7 into row 5
56 FN 28: TABREAD Q10 = 6/"X,Y,D" ; row 6 -> Q10, Q11, Q12
57 FN 28: TABREAD QS1 = 6/"DOC" ; text column -> QS1
Row count of the open table is readable with FN 18: SYSREAD ... ID56 NR4 — handy for loops that walk a table.
TABDATA — Direct Access to the Active Tables
The TABDATA functions (SPEC FCT → PROGRAM FUNCTIONS → TABDATA) hit the currently active tables without an FN 26 open/close dance: the tool table *.t (read-only) and the compensation tables *.tco and *.wco (read and write). Values convert automatically between mm and inch to match your program — unlike FN 18, which is always metric. Write access works only during program run; writes during simulation or block scan have no effect.
| Function | Example |
|---|---|
TABDATA READ | TABDATA READ Q1 = CORR-TCS COLUMN "DR" KEY "5" — row 5, column DR into Q1 (Q, QL, QR, or QS depending on column type) |
TABDATA WRITE | TABDATA WRITE CORR-TCS COLUMN "DR" KEY "3" = Q1 — e.g. push a probe-measured correction into the table |
TABDATA ADD | TABDATA ADD CORR-TCS COLUMN "DR" KEY "3" = Q1 — increment an existing value (repeat measurements) |
Compensation tables must be activated first with SEL CORR-TABLE TCS "TNC:\table\corr.tco", and a row is applied with FUNCTION CORRDATA TCS + row number (reset via FUNCTION CORRDATA RESET). An active .tco row overwrites DL/DR/DR2 from the TOOL CALL block; .wco acts as a shift in the working-plane coordinate system. Changed values take effect only when the compensation is activated again.
SQL Statements
For table work beyond single cells, the control exposes an SQL-like transaction interface — and HEIDENHAIN explicitly recommends SQL over FN 26–28 for speed. Programming SQL commands requires code number 555343. All SQL reads/writes are in metric units regardless of table or program settings — convert before positioning with a read value in an inch program. Every transaction, even read-only, must be concluded with COMMIT or ROLLBACK to release locks.
| Command | Purpose |
|---|---|
SQL BIND | Bind a Q/QS parameter to a table column (before FETCH/UPDATE/INSERT); empty BIND releases it |
SQL EXECUTE + SELECT | Open a transaction on chosen columns/rows; returns a HANDLE to the result set (0 = failed) |
SQL FETCH | Transfer a result-set row into the bound parameters |
SQL UPDATE / SQL INSERT | Change an existing row / append a new row |
SQL COMMIT / SQL ROLLBACK | Save / discard, and conclude the transaction |
SQL SELECT | Read a single value without opening a transaction |
11 SQL BIND Q881 "Tab_Example.Position_Nr"
12 SQL BIND Q882 "Tab_Example.Measure_X"
13 SQL BIND Q883 "Tab_Example.Measure_Y"
14 SQL BIND Q884 "Tab_Example.Measure_Z"
...
91 SQL BIND Q881 ; remove bindings when done
FN 18: SYSREAD — System Data
System data are addressed by group ID, number NR, and optional index IDX. Values always come back metric, regardless of the program’s unit (use TABDATA READ instead if you want automatic conversion from the tool table). Reads that must reflect real time should be preceded by FN 20: WAIT FOR SYNC, which halts the look-ahead:
32 FN 20: WAIT FOR SYNC
33 FN 18: SYSREAD Q1 = ID270 NR1 IDX1 ; current X position, input system
55 FN 18: SYSREAD Q25 = ID210 NR4 IDX3 ; active scaling factor, Z axis
The full list fills 40 pages of the Klartext manual (chapter 17); these are the groups a machinist macro actually touches:
| ID | Group | Highlights (NR / IDX) |
|---|---|---|
| Program & machine state | ||
ID10 | Program information | NR3 active machining cycle; NR6 last touch-probe cycle; NR110/111 does file/directory named in QS(IDX) exist |
ID20 | Machine status | NR1 active tool number; NR2 prepared tool; NR3 active tool axis (0=X 1=Y 2=Z); NR4 programmed spindle speed; NR5 spindle condition (M3/M4/M5); NR8 coolant on/off; NR9 active feed rate |
ID992 | Execution status | NR10/11 block scan active/info; NR14 number of the last FN 14 error; NR16 real execution (1) vs simulation (0) |
ID590 | Free machine status | NR2 IDX1–30 free values, cleared at program selection; NR3 IDX1–30 persistent through power failure |
| Positions & transformations | ||
ID270/ID271 | Current position | NR1, IDX 1–9 (X…W): nominal position in the input system, without / with handwheel offsets |
ID240/ID241 | REF position | NR1: nominal position in the machine REF system |
ID210 | Coordinate transformations | NR1 manual basic rotation; NR2 programmed rotation; NR3 mirror axes (bit-coded); NR4 scaling per axis (IDX); NR6/NR7 tilted plane active in run / manual modes |
ID220 | Datum shift | NR2 active datum shift per axis; NR3 difference reference point vs preset |
ID230 | Traverse range | NR2/NR3 negative/positive software limit switches; NR5 limits on/off |
| Tools | ||
ID50 | Tool table | IDX = tool number: NR1 L, NR2 R, NR3 R2, NR4 DL, NR5 DR, NR7 TL locked, NR8 RT, NR9–11 TIME1/TIME2/CUR.TIME, NR13 LCUTS, NR14 ANGLE, NR15 CUT, NR16/17 LTOL/RTOL, NR19/20 R-OFFS/L-OFFS, NR21/22 LBREAK/RBREAK, NR28 NMAX, NR32 TANGLE, NR34 LIFTOFF |
ID51 | Pocket table | IDX = pocket: NR1 tool number, NR2 special tool, NR3 fixed pocket, NR4 locked, NR5 PLC status |
ID52 | Tool pocket lookup | IDX = tool number: NR1 pocket number, NR2 magazine number |
ID60 | TOOL CALL values | NR1 T number, NR2 tool axis, NR3 S, NR4/5/7 DL/DR/DR2, NR8 tool index, NR9 active feed rate |
ID990 | Misc probe/tool | NR4 stylus deflected (0/1); NR8 momentary spindle angle; NR10 tool number from tool name in QS(IDX) — the trick for compensating named/indexed tools |
| Tables, presets, probes | ||
ID56 | File information | NR1 rows in tool table; NR2 rows in active datum table; NR4 rows in table opened by FN 26 |
ID500 | Datum table | Row + column: read values from the active datum table |
ID507/ID508 | Preset table | Row + IDX 1–6 basic transformation (X, Y, Z, SPA, SPB, SPC) / IDX 1–9 axis offsets |
ID530 | Active preset | NR1: number of the active row in the active preset table |
ID350 | Touch probe (TS) | NR50 probe type + table row; NR51 effective length; NR52 effective ball radius; NR53 center offset; NR55 feed rates |
ID30 | Cycle parameters | NR1 set-up clearance, NR2 depth, NR3 plunging depth … NR49 HSC mode / NR50 tolerance of Cycle 32 |
String-valued system data go through SYSSTR instead (ID10010 program paths, ID10025 channel name, ID10060 tool name from TOOL CALL, ID10321 date/time in 16 formats, ID10350/10353 probe types, ID10630 NC software version). Machine parameters are read with CFGREAD — see the Klartext & Q-Parameters article.
FN 16: F-PRINT — Formatted Output
FN 16 turns Q-parameter contents into measurement reports, pop-up messages, or printer output. Two pieces: a mask file (extension .A, created in the text editor) that defines the layout, and the FN 16: F-PRINT call naming mask and target. Mask syntax:
| Element | Meaning |
|---|---|
| Format characters | |
"text %9.3F", Q31; | Quoted format string, comma, source parameter, semicolon block end. 9.3F = 9 characters total, 3 decimals, floating |
%S / %RS | QS string, formatted / taken verbatim (use %RS for paths so specials aren’t parsed) |
%D or %I | Integer |
+ / - | Right- / left-aligned value |
* / %" / %% / \n | Comment line / literal quote / literal percent / line break |
| Keywords | |
CALL_PATH | Path of the calling NC program |
M_CLOSE / M_APPEND / M_APPEND_MAX / M_TRUNCATE | Close file / append on re-output / append up to a KB limit / overwrite on re-output |
M_EMPTY_HIDE / M_EMPTY_SHOW | Suppress / restore blank lines for undefined QS parameters |
HOUR MIN SEC DAY MONTH STR_MONTH YEAR2 YEAR4 | Real-time-clock fields |
L_ENGLISH, L_GERMAN, … L_ALL | Emit the following line only in that conversational language |
; Mask file TNC:\MASKE\MASKE1.A
"MEASURING LOG OF IMPELLER CENTER OF GRAVITY";
"DATUM: %02d.%02d.%04d",DAY,MONTH,YEAR4;
"TIME: %02d:%02d:%02d",HOUR,MIN,SEC;
"X1 = %9.3F", Q31;
"Y1 = %9.3F", Q32;
"Z1 = %9.3F", Q33;
L_ENGLISH;
"Remember the tool length";
; In the NC program:
96 FN 16: F-PRINT TNC:\MASKE\MASKE1.A/ TNC:\PROT1.TXT
Output targets: a file on the control (max. 20 KB; the log-file extension picks the type — .TXT, .A, .XLS, .HTML), SCREEN: for a pop-up window (close with CE, or programmatically with target SCLR:), an external path (e.g. PC325:\LOG\PRO1.TXT), or Printer:\. Repeated output to the same file appends unless the mask says M_TRUNCATE. Both mask and log paths may come from QS parameters (:'QS1' syntax), and relative paths work. Default output directories are set under MOD code 123 → fn16DefaultPath / fn16DefaultPathSim.
PLC Transfer: FN 19 / FN 29 / FN 37
For completeness: FN 19: PLC hands two numeric values/Q parameters to the PLC, FN 29: PLC hands over up to eight, and FN 37: EXPORT exposes local QL/QS parameters from your own OEM-style cycles to the calling program. All three carry the same manual warning: PLC access is password-protected OEM territory — use only in consultation with HEIDENHAIN or your machine builder. The everyday alternative for pushing data off the machine is FN 38: SEND (log/StateMonitor output, no PLC involvement): FN 38: SEND /"Q-Parameter Q1: %f Q23: %f" / +Q1 / +Q23.
References
- HEIDENHAIN, TNC 640 Klartext Programming User’s Manual, NC software 34059x-11, 01/2021, ID 892903-29 (FN functions, TABDATA, SQL, system data chapter 17).
- HEIDENHAIN, TNC 640 Setup, Testing and Running NC Programs User’s Manual, NC software 34059x-18, 10/2023, ID 1261174-25 (tool/pocket/preset tables, file types).
Have a question or want to contribute?
Contact us with corrections, additions, or topics you'd like covered.
Get in Touch