Why use subprograms
- Much shorter programs for repeated features or parts.
- Edits at the machine happen in one place.
- Less controller memory and faster transfer on older machines.
Syntax by controller
| Controller | Call | Return |
|---|---|---|
| FANUC / Haas | M98 P1001 (or M98 P1001 L4 for repeats) | M99 |
| FANUC macro | G65 P9810 X.. Y.. Z.. | M99 |
| SINUMERIK | Subprogram name (e.g. POCKET1) from .SPF | M17 / RET |
| Heidenhain | CALL LBL 1 | LBL 0 |
| Okuma OSP | CALL O1001 | RTS |
Example: same pocket on four fixtures
O1000 (MAIN)
T3 M06
G54 G00 X0. Y0. S9000 M03
G43 H03 Z25. M08
M98 P1001
G55 M98 P1001
G56 M98 P1001
G57 M98 P1001
M30
O1001 (POCKET - WORKS IN ANY OFFSET)
G00 X10. Y10.
G01 Z-3. F300.
(... pocket moves ...)
G00 Z25.
M99
Macro calls
Posts can call probing macros (for example Renishaw routines on many machines), tool breakage checks and custom shop macros with parameters taken from CAM, instead of expanding everything into plain G-code.
Things to watch
- Subprogram numbers must not clash with existing programs on the machine.
- Subprograms should be incremental- or offset-independent as intended.
- Some controllers need subprograms in separate files; others allow them in the same file.
Subprograms make NC code shorter; good posts make them automatic.
Subprogram and macro output
See our CNC post processor development service and canned cycle handling.