# Where should I assign the values of the transaction

**URL:** <https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268>\
**Category:** UVM\
**Tags:** UVM, uvm\_transaction, uvm\_sequence\
**Created:** [September 15, 2016, 1:21pm UTC](https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268 "2016-09-15T13:21:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saritr](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@saritr](https://verificationacademy.com/forums/u/saritr)\
**Post date:** [September 15, 2016, 1:21pm UTC](https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268/1 "2016-09-15T13:21:16Z")

</div>

Hi

i will start by explaining my requirement first . Using a UVM sequence my objective is to read data patterns from a file in hexadecimal format line by line and then feed/constrain the data field of my “trans” with data I read.

Each line can be in different lenght.

The stracture of the lines:  
len, cmd, addr, data, data, data, data, ……., \n

For example: “3,write,A0001000,00000000,00012000,A0000000,C0000000,00B00000 \n”

here is the code that i have written. I’m not sure if the assigmnent to the transaction should be here, or should I write a function in the transaction which will do it.

I attached the transaction code and the sequence code:

transaction

```verilog
typedef enum {READ = 0, WRITE = 1} direction_enum;
//----------------------------------------------------------------------
//Transaction
//----------------------------------------------------------------------
class axi_transaction extends uvm_sequence_item();
   bit id = 0; //const
   bit [31:0] addr;
   bit [2:0] size = 0'b100;//const
   direction_enum rw;
   bit [31:0] transfers [$];
   
   
   
   //factory registration
   `uvm_object_utils_begin(axi_transaction)
     
   `uvm_object_utils_end  

   //constructor
   function new(string name = "axi_transaction");
      super.new(name);
   endfunction: new

endclass: axi_transaction

```

sequence:  
//----------------------------------------------------------------------  
//Sequence  
//----------------------------------------------------------------------

```verilog
class axi_sequence extends uvm_sequence#(axi_transaction);
   `uvm_object_utils(axi_sequence)

     //new
     function new (string name = "axi_sequence");
	super.new(name);
     endfunction: new

   task body();
      int file_p, temp, len, success;
      int count;
      byte mode;
      string str;      
      logic [31:0] data;
      axi_transaction ax_trx;
      
      
      file_p = $fopen("commands_file.txt", "r");
      //in case file doesn't exist
      if (!file_p)
	begin
	   `uvm_error("ERROR:"," FILE OPENED FAILED");
	end
      //read file
      while (!$feof)
	begin
	   temp = $fgets(str, file_p);
	   ax_trx = axi_transaction::type_id::create(.name("ax_trx"), .contxt(get_full_name()));
	   start_item(ax_trx);
	   temp = $sscanf(str, "%d", len);
	   temp = $sscanf(str, "%c", mode);
	   case(mode)
	     "r": ax_trx.rw = READ;
	     "w": ax_trx.rw = WRITE;
	     default: success = 0;
	   endcase //case(mode)	     
	   temp = $sscanf(str,"%h", ax_trx.addr);
      	   for (int i = 0; i < len; i++) begin
	      temp = $sscanf(str,"%h", ax_trx.transfers[i]);
	   end
	   end
	   finish_item(ax_trx);
	   
      
   endtask: body

   endclass: axi_sequence

```

---

<div class="post-metadata">

**Author:** ![RonakShah](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/a9a28c/32.png) [@RonakShah](https://verificationacademy.com/forums/u/RonakShah)\
**Post date:** [September 16, 2016, 5:48am UTC](https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268/2 "2016-09-16T05:48:04Z")

</div>

Hi Saritr

We are also following same approach as you mention and have one basic sequence while read Text stimulus and convert it to transaction based stimulus.

I don’t see any issue in this approach.

So now question is which one is better approach

Is it good to model this in sequence Vs sequence\_item ?

---

<div class="post-metadata">

**Author:** ![saritr](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@saritr](https://verificationacademy.com/forums/u/saritr)\
**Post date:** [September 18, 2016, 8:12am UTC](https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268/3 "2016-09-18T08:12:48Z")

</div>

_In reply to [RonakShah](https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268/2):_

ok…so which one?:)

---

<div class="post-metadata">

**Author:** ![ilya](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/i/58f4c7/32.png) [@ilya](https://verificationacademy.com/forums/u/ilya)\
**Post date:** [September 20, 2016, 2:36am UTC](https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268/4 "2016-09-20T02:36:28Z")

</div>

_In reply to [saritr](https://verificationacademy.com/forums/t/where-should-i-assign-the-values-of-the-transaction/32268/3):_

we use the same approach if the vectors are from our customers. they dont know how to write the sequence.
