|
| 1 | +CREATE COMPUTE MODULE Transformation_Compute |
| 2 | + CREATE FUNCTION Main() RETURNS BOOLEAN |
| 3 | + BEGIN |
| 4 | + CALL CopyMessageHeaders(); |
| 5 | + -- CALL CopyEntireMessage(); |
| 6 | + |
| 7 | + CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNSC'; |
| 8 | + -- create references placeholders (the values will be changed later) |
| 9 | + DECLARE invoice REFERENCE TO InputRoot.XMLNSC.SaleEnvelope.SaleList.Invoice; |
| 10 | + DECLARE statement REFERENCE TO OutputRoot.XMLNSC.SaleEnvelope.SaleList; |
| 11 | + DECLARE article REFERENCE TO OutputRoot.XMLNSC.SaleEnvelope.SaleList; |
| 12 | + DECLARE amount REFERENCE TO OutputRoot.XMLNSC.SaleEnvelope.SaleList; |
| 13 | + DECLARE total DECIMAL 0; |
| 14 | + |
| 15 | + -- while invoice has next element |
| 16 | + WHILE LASTMOVE(invoice) DO |
| 17 | + -- create the new message |
| 18 | + CREATE LASTCHILD OF OutputRoot.XMLNSC.SaleEnvelope.SaleList AS statement Type XMLNSC.Folder Name 'Statement'; |
| 19 | + SET statement.(XMLNSC.Attribute)Type = 'Monthly'; |
| 20 | + SET statement.(XMLNSC.Attribute)Style = 'Full'; |
| 21 | + |
| 22 | + SET statement.Customer.(XMLNSC.Field)Initials = invoice.Initial[1] || invoice.Initial[2]; |
| 23 | + SET statement.Customer.(XMLNSC.Field)Name = invoice.Surname; |
| 24 | + SET statement.Customer.(XMLNSC.Field)Balance = invoice.Balance; |
| 25 | + |
| 26 | + SET total = 0; |
| 27 | + DECLARE items REFERENCE TO invoice.Item; |
| 28 | + -- while items has next element |
| 29 | + WHILE LASTMOVE(items) DO |
| 30 | + -- create new Article |
| 31 | + CREATE LASTCHILD OF statement.Purchases AS article Type XMLNSC.Folder Name 'Article'; |
| 32 | + SET article.(XMLNSC.Field)Desc = items.Description; |
| 33 | + SET article.(XMLNSC.Field)Cost = CAST(items.Price AS DECIMAL) * 1.6; |
| 34 | + SET article.(XMLNSC.Field)Qty = items.Quantity; |
| 35 | + |
| 36 | + SET total = (CAST(items.Price AS DECIMAL) * 1.6) * CAST(items.Quantity AS INTEGER); |
| 37 | + -- go to the next item |
| 38 | + MOVE items NEXTSIBLING NAME 'Item'; |
| 39 | + END WHILE; |
| 40 | + |
| 41 | + SET statement.(XMLNSC.Field)Amount = total; |
| 42 | + SET statement.Amount.(XMLNSC.Attribute)Currency = invoice.Currency; |
| 43 | + |
| 44 | + -- go to the next invoice |
| 45 | + MOVE invoice NEXTSIBLING NAME 'Invoice'; |
| 46 | + END WHILE; |
| 47 | + |
| 48 | + RETURN TRUE; |
| 49 | + END; |
| 50 | + |
| 51 | + CREATE PROCEDURE CopyMessageHeaders() BEGIN |
| 52 | + DECLARE I INTEGER 1; |
| 53 | + DECLARE J INTEGER; |
| 54 | + SET J = CARDINALITY(InputRoot.*[]); |
| 55 | + WHILE I < J DO |
| 56 | + SET OutputRoot.*[I] = InputRoot.*[I]; |
| 57 | + SET I = I + 1; |
| 58 | + END WHILE; |
| 59 | + END; |
| 60 | + |
| 61 | + CREATE PROCEDURE CopyEntireMessage() BEGIN |
| 62 | + SET OutputRoot = InputRoot; |
| 63 | + END; |
| 64 | +END MODULE; |
0 commit comments