how to combine fields from different files

linus>cat data1

8119463 | 15000
8136789 | 50000
8152238 | 15000
8167890 | 15000
7155789 | 15000
8123334 | 30000
7166330 | 15000
8146683 | 15000
8152238    | 15000    
8167877    | 15000
7145389    | 15000
8178434    | 15000
7166222    | 50000
8167566    | 15000
8115410    | 45000
7100906    | 15000
7100893 | 30000
8104672    | 15000

linus>cat data2

8167877|CD9S|DOL1  
8136789|CD6S|DOL1
8152238|CD2S|DOL3
8104672|CD8S|DOL4
8152238|CD6S|DOL1
7155789|CD6S|DOL2
7100906|CD5S|DOL1
7166330|CDS|DOL7
8146683|PLUS|DOL4
8123334|PLUS|DOL3
7145389|PLUS|DOL9  
8178434|CD6S|DOL1
8167890|CD6S|DOL1
8167566|MAX1|DOL5
8119463|CD6S|DOL5
8115410|MAX9|DOL7
7100893|MAX+|DOL6
7166222|CD6S|DOL9

I need help on unix commands to combine the two tables together to form four fields and each row would be like below, then sum the total of field four for each unique field 3

OUTPUT FILE

8167877|DOL1|CD9S|15000
.....
.....

CD9S_total = xxxxxx
     CDS_total = xxxxxx
     DOL1_sum  = xxxxxx
     ....
     ....
nawk '
  BEGIN {
    FS=OFS="|"
  }
  FNR==NR {f1[$1+0]+=$2;next}
  { print $0,f1[$1+0]; tot[$2]+=f1[$1+0]}
  END {
    for (i in tot)
      printf("%s_total=%s\n", i, tot)
  }' data1 data2

Thanks a lot, it really works.