Creating User roles and profiles in SAP system

This can be done using – Legacy Systems Migration Workbench LSMW transaction. This workbench works like a sort of macro recorder and allows you to record the steps in a transaction and you can replay that record multiple times as per the requirement. This also allows you to replace the values you used in your recorded transaction with new values.

A more complex option would be to write ABAP code and this is more flexible to add different privileges to different roles.