In reply to Michael54:
Knowing the full context of how you plan to use these ranges would help in getting better answers. I probably would not have mentioned the alias construct if you indicated this was for class based code in your original post, since that only works for renaming nets.
Using macros is probably the most straightforward approach and works almost anywhere
`define FIRST_RANGE 28:24
`define SECOND_RANGE 17:12
expected_txn.raw_data[rgb_pos-:5] = data_range_bus[`FIRST_RANGE];
expected_txn.raw_data[rgb_pos+6-:6] = data_range_bus[`SECOND_RANGE];
Using packed structs and unions is the elegant/structured way of doing this, but it requires that you declare the target variable using these types, or make and assignments through a temporary variable.
See some examples here and here.