Fanuc Subprogram (Local Subroutine)

Fanuc Subprogram (Local Subroutine)

Category : Fanuc

On or Offsite CNC Training
Tel: David 07834 858 407

Fanuc Subprogram (Local Subroutine)

If you have ever used local subroutines on Heidenhain or Yasnac. Then you will know how convenient it is to save all your programs in one go. No need to remember to save all those shitty little external sub programs.

What’s He On About?

If you are now saying “what the fuck is he on about”. Here is an explanation.

A local subroutine or subprogram is where you stuff all your subprograms at the end of your main program.

So on a Fanuc control if you were making this part below.

Drill spot drill then tap.

Fanuc Subprogram

Programme would look like this.

Fanuc Subprogram


Thing is the code is just repeated three times. I have nice round numbers in here like X40. and Y20. so it’s easy to notice mistakes. But if it was X40.392 for example you wouldn’t spot a slight mistake.

So if you call a subprogram it looks like this.

Fanuc Subprogram

And then your Subprogram is like this.

Fanuc Subprogram

Fanuc Subprogram

The M98 P500 calls the external Fanuc Subprogram. Read this if you don’t know about sub programmes.

Saves you having to repeatedly write shit loads of code.

So that’s why we use a Fanuc Subprogram. But……

You have to look after these bloody things and they seem to be able to just get lost on their own.

You find them at the back of the fridge sometimes along with a piece of mouldy old cheese. At least you can make a meal of the cheese.

Fanuc Subprogram No More Lost Programs

So this is how it looks with a Local Subroutine.

All you need to do is replace P with Q. So mind your P’s and Q’s as they say.

The Q corresponds to any N number. So you could have loads of these stacked up at the end of your programme and you only need to save it once. All this shit will go with it and you don’t need to worry about it ever again.

Haas To The Rescue

Of course Mr Haas sorted this out years ago with M97, this calls a local sub. M98 calls an external program. It’s on all Haas machines and you definitely do need to fuck with any parameters.

Just A word Of Caution.

There are PARAMETERS involved. Arrrrrrrrrrrh……..the dreaded PARAMETERS

To call a subroutine on your Fanuc control. You first need to make sure that Bit 0 of parameter 06005 is set to 1

Fanuc Subprogram

This should make it work. If it doesn’t then maybe you should call the Samaritans.

It’s only on the newer controls by the way.

Sub programs on a Siemens control.

Thanks For Reading My Articles We Love you all .

If you have been affected by any of the issues in this post or need CNC Counselling then contact me.

If you want to learn to program CNC Milling Machines






Jeff Long

April 7, 2021 at 9:22 pm

Thank you very much for this information. I figured there had to be a way. Its just such a nice feature to have. You get used to using it on the Haas. Would have been great to have that 30 years ago on the fanucs.


    April 8, 2021 at 9:40 am

    It’s not on all Fanuc controls but if it’s there then why not use it. Thanks for your comment.


April 11, 2021 at 6:24 pm

One question, Is possible use both sub program call (M98 with P and M98 with Q)?


    April 21, 2021 at 4:35 pm


C-li Thibault

January 12, 2023 at 9:56 am


Merci beaucoup pour cette aide. En revanche une fois fini mon M98 Q1001 L16.
Au M99 (dans le sous programme local) il remonte au debut du programme O1..

Quelqu’un aurait-il une solutions pour qui continue le programme ?

Merci d’avance pour vos retour.


    January 18, 2023 at 2:04 pm

    Pouvez-vous envoyer une copie de votre programme s’il vous plaît

Log out of this account

Leave a Reply

WP to LinkedIn Auto Publish Powered By :