This is the business scenario: an SD invoice is created. Every price conditions is fetched from order (delivery) into VBRK document. Invoice is registered in FI (SD invoice not modifiable). Time (months) pass. User create / modify / delete conditions (also the ones gone into above invoice). And also, users chenge customer (of the above invoice) position in customer hierarchy with VHD1N (this means that all hierarchical price conditions are lost for invoices created after hierearchy update). What I need was to simuate again the invoice price conditions so that conditions belonging to invoice are evaluated with new values user set (after accounting), and other conditions (hierarchical, valid at invoice date) remains.
I tried to create/simulate new invoice with date of the old, with BAPI above mentioned, but functions give me no conditions in output (I saw that tables name in interface had "_in" trailer and I thought it were only in input, but also could have been because I tried to create invoice without reference to order and so conditions were not copied). So I thought to simulate a new order with date = invoice date and read conditions (in someway) from order simulation. There's a problem: simulation bapi read customer hierarchy at sy-datum. there is an oss note saying this is the normal working of the system (also in VA01 setting document/price date) (I ask myself why... there is validity in KNVH - customer hierarchy table..). I don't know if I miss something in my tests, but this was the situation I was trying to resolve on sdn when I wrote the post.
My last idea has been this: Sap standard provides functionality I was looking for, in agreement handling (KONA and so on...), so I read the program that executes this task and I found where "old" invoice were re-evaluated. The above code it's (quite) what Sap standard do and works perfectly: evaluates again conditions updated (after invoice accounting) and apply hierarchical conditions valid at invoice date (and not today).