Well the above approach works, but why not use the web3.js library which helps in doing the same. Just download web3.js using NPM (or anywhere else) and get the modules required for the task, by:
const_ = require('lodash');
const SolidityFunction = require('web3/lib/web3/function');
You can use the web3.js library along with your ABI to find the function definition, using the below code:
var ABI = JSON.parse(<your_ABI>);
var functionDef = new SolidityFunction('', _.find(ABI, { name: '<your_function_name>' }), '');
After this, you can call the method toPayload which will help you converting the values that you want to pass to your function into HEX Data.
var payloadData = functionDef.toPayload([<value_for_var_1>, <value_for_var_2>, <value_for_var_3>, <value_for_var_4>]).data;
payloadData can be used as Value for the DATA property. Example:
var rawTx = {
to: <to_address>,
data: payloadData,
value: '0x0',
from: <from_address>,
nonce: nonce,
gasLimit: gasLimit,
gasPrice: gasPrice
}
You can use this approach and forget about how many zeros to pad with. As the toPayload function handles everything.