Subroutines can be created in slib*.nc files (in the NAND1-1 folder) and in any control program.
When created in slib*.nc, these subroutines are loaded into memory when the controller is loaded and are there permanently.
When created in a control program, the subroutines must be written AFTER the main code. Any code that comes after the first M99 command, other than other subroutines, is not executed.
When created in the control program and in slib*.nc, each subroutine uses variables #1-#49 independently. That is, the assignment of these variables in one subroutine does not affect the same variable numbers in other subroutines and in the main code of the control program (if the subroutine is created in the control program).
From subroutines, other subroutines can be called.
If the control program file contains ONLY subroutines (does not contain the main code), the first subroutine number to be called is the one set in the #77 Macro program file main program No. setting.
If a subroutine number is set there that is not in the control program file with only subroutines, the file will not be executed.

The subprogram numbers are occupied:
In slib-g
O9053; O9081; O9082; O9073; O9083; O9074; O9084; O9028; O9029; O500; O501; O502; O503; O20000
In slib-m
O10000-O10002;   O10006; O10019; O10030; O10047;   O10050-O10091;    O10100-O10122;   O10129 O10130-O10133;   O10136; O10140; O10141;    O10150-O10181;    O10250-O10263;    O10270-O10281;  O10300-O10307

Creation: 
Oxxx (xxx subprogram number)
..
..
M99 (end of subprogram)
XYZABCIJKRHQDFS

Call: M98 (or G65) Rxxx Lxx XxxYxxZxxAxxBxxCxx IxxJxxKxxRxxHxxQxxDxxFxxSxx.
Pxxx - subprogram number (without the letter O).
Lxx - number of repetitions.
X-S parameters passed to the subprogram (to variables). They can be written in any sequence.
X#1 Y#2 Z#3 A#4 B#5 C#6 I#7 J#8 K#9 R#10 H#12 Q#14 D#15 F#16 S#17 
Also, a subroutine can be created in the UE executable, in slib-m.nc, in slib-g.nc
If the subroutine is created or changed in the firmware files, it is necessary to reboot the controller after saving the changes.

Translated with DeepL.com (free version)