hello zelodia i don't know exactly how things are for your machine, i don't have great experience with fanuc, but i can share a few things, hoping to help you

fastest performing codes are those with linear arhitecture, thus no conditions, no formulas, only coordinates + GM codes; a linear arhitecture requires less processing time from the controller

codes with non-linear arhitecture perform a bit slower, and require more processing time from the controller; depending on controller, there may be some functions available to speed up the processing time, so to have a non-linear code that perform almost as fast as a linear code

a code with soubroutines is a non-linear code, and each soubroutine represents a nesting level; in other words, each individual soubroutine is a linear code only at a specific nesting level

passing arguments to a soubroutine can be done using common and/or local variables; there may be also system variables, system local variables, reserved locals, extended adress chars, custom arrays, bytes arrays, file read/write, but this is less common ...

generally speaking, common variables have global behaviour, while local variables have only local behaviour :
.., a global variable can be used regardless of nesting level
... a local variable may be used :
...... only inside current nesting level
...... only inside current nesting level + deeper nesting levels, thus it may act as a "global" variable, starting from the nesting level where it was created; for example, if you use a program that calls soubroutine 1, and inside soubroutine 1 you create a local variable and also call another soubroutine, then that local variable may be available also inside the 2nd soubroutine, because it was created at a superior nesting level

such behaviours are very control specific, so you have to be sure about how your controller handles such situations

some controllers use more then a single set of local variables :
... set 1 ( eq #100-#200 ) may be volatile, thus it's content is no longer available after cnc reset and/or cnc power cycle ( on / off )
... set 2 ( eq #500-#600 ) may not be volatile, thus it's content is recorded, so not to lose it in case of reset and/or power cycle
... set 3 may be a limited set, designed for passing parameters to a soubroutine ( A #1 , B # 2, etc )

machines with dual spindles, may have each set specific to each spindle, for example, there may be set 1 for spindle 1, and another set 1 for spindle 2, thus, you may use #100 inside code for spindle 1, and another #100 inside code for spindle 2

some controllers use a 'nil / empty' state, so to show that a variable had not been initialized yet

it may be possible to check if a local variable had been initialized or not, allowing one to create soubroutines with overload content; this is a high-specific technique


it may seem a bit confusing, i don't know, i tried to explain it as simple as possible, but, once you master them, you may be able to create stable&versatile parametric soubroutines, that will help you deliver better codes / kindly