postgresql: procedure to return the number of occurrences of given year and service
Assuming the tb_orders table has an id, would you not be able to do something like the following?
RETURN (SELECT COUNT(tbo.id)
          FROM tb_orders tbo
         WHERE YEAR(tbo.created_dt) = year AND tbo.order_code = order_code);

In your DECLARE you are overwriting the year value, and I'm not at all sure what n_service is supposed to do. If all you want is a count, then COUNT() is all you need. Mind you, using YEAR() in the WHERE clause is not great, but it's sufficient for the sake of this example.

Note: The syntax may be a bit off. I'm a bit rusty with stored procedures in PostgreSQL.