I can not do any support of this macro until I look at the command line shapshot with full description of error
moreover my 46 line is a bit different then your. Have you modified the macro?
I am working on 12.1.SP4 version. I will not be checking it on lowest versions where units are absent.
I guess the error is in this variable [COLOR=#333333]!getSctnforBom[1].Dbref().Nwei.String('D2').Before('kg')[/COLOR] U should check the material(matref), if it is set then ask value..