### Calculate charges in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/5GettingDataInput/dml_gsg_c_0044.htm Calculates a 5% charge based on the total amount variable. ```DML %amount * 0.05 ``` -------------------------------- ### Referencing Custom Functions in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/9ExtendingDML/dml_gsg_c_0067.htm Demonstrates how to reference custom functions in DML using fully-qualified names, short names, or just the function name when in the correct context. Parameters are passed within parentheses. ```dml ... myentity.commonstuff\calendar.IsLeapYear(%year) ... ... commonstuff\calendar.IsLeapYear(%year) ... ... IsLeapYear(%year) ... ``` -------------------------------- ### Define and Use a SQL Custom Function in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Illustrates the process of defining and invoking a SQL custom function within DML. This allows DML scripts to execute SQL queries or stored procedures for data retrieval or manipulation. It requires proper database connectivity setup. ```SQL CREATE FUNCTION GetCustomerName (customerId INT) RETURNS VARCHAR(255) AS $$ BEGIN RETURN (SELECT name FROM customers WHERE id = customerId); END; $$ LANGUAGE plpgsql; ``` ```DML import "GetCustomerName" // ... other DML code ... // Call the custom SQL function output.customerName = GetCustomerName(input.customerId); ``` -------------------------------- ### Calculate grand total in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/5GettingDataInput/dml_gsg_c_0044.htm Computes the grand total by applying a 5% increase to the base amount. ```DML %amount * 1.05 ``` -------------------------------- ### Calculate partner fees using external rates Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/5GettingDataInput/dml_gsg_c_0044.htm Computes partner fees by multiplying the amount by 5% and a dynamic rate retrieved from an external XML document based on the supplier name. ```DML %amount * 0.05 * rates:\partner\name[where item = order:\Root\order\supplier\name]\..\rate ``` -------------------------------- ### Handling Data and Storing in Variables in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Covers how to handle data and store values in variables within DML. This includes assigning values to variables, which can then be used in subsequent transformations or logic. It's crucial for managing intermediate data during mapping. ```DML variable myValue = input.data; output.processedData = myValue * 2; ``` -------------------------------- ### Looping with a Fixed Number of Iterations in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Demonstrates how to use a loop that repeats a specific number of times in DML. This is useful for processing a known quantity of items or performing a repetitive task a set number of times. The 'for' loop structure is commonly used. ```DML for (i = 0; i < 5; i++) { output.items[i] = input.sourceItems[i]; } ``` -------------------------------- ### DML Expression Calculation Example Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/2BasicExpressions/dml_gsg_c_0019.htm Demonstrates how DML expressions are computed, showing both implicit value determination through the last statement and explicit assignment using the '$' character. ```dml %pi := 3.14; %area := %pi * %radius * %radius; %height * %area ``` ```dml $ := 4 ``` -------------------------------- ### Concatenate and Multiply Strings in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/4WorkingwithStrings/dml_gsg_c_0030.htm Demonstrates how to merge multiple string literals using the concatenation operator and how to repeat strings using the external multiplication operator. Multiplication operations are prioritized over addition in DML expressions. ```DML "leading" + "middle" + "tailing" 3 * "leading" + "middle" * 2 ``` -------------------------------- ### Conditional Logic with if-then-else in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Shows how to implement conditional logic using if-then-else statements in DML. This allows for different processing paths based on specified conditions, enabling dynamic data transformation. Boolean expressions are used to evaluate conditions. ```DML if (input.amount > 100) { output.discount = input.amount * 0.10; } else { output.discount = 0; } ``` -------------------------------- ### Basic Math Operators in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Introduces the fundamental arithmetic operators available in DML for performing mathematical calculations. This includes addition, subtraction, multiplication, and division. These operators are essential for numerical data processing. ```DML output.sum = input.a + input.b; output.difference = input.a - input.b; output.product = input.a * input.b; output.quotient = input.a / input.b; ``` -------------------------------- ### Selecting Occurrences with Path Cardinalities in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Explains how to select specific occurrences from a list or array using path cardinalities in DML. This allows for precise targeting of elements within complex data structures, especially when dealing with repeating nodes. Square brackets `[]` are used for indexing. ```DML output.firstItem = input.items[0]; output.lastItem = input.items[last]; ``` -------------------------------- ### DML Date Literal Examples Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/2BasicExpressions/dml_gsg_c_0015.htm Provides examples of DML date literals, showcasing different formats for specifying dates, times, and time zones. Dates are enclosed in single quotes and follow a strict format. ```dml '2000-12-31' '2001-01-00::01' '2006-12-25 12' '2006-12-25 12:10' '2006-12-24 23:59:.9999' '2006-07-04 12:00:-04' ``` -------------------------------- ### Generating Occurrences from Occurrences in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Illustrates how to create new repeating elements (occurrences) based on existing ones in DML. This is a powerful technique for restructuring data, transforming lists, and generating complex output structures from simpler inputs. The `generate` or similar instructions are used. ```DML generate output.newItems from input.sourceItems { output.newItems.name = input.sourceItems.description; } ``` -------------------------------- ### Month Shift Examples and Behavior Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/3NumbersOperators/dml_gsg_c_0026.htm Provides examples of month shifts, highlighting how they operate on the same day of the next month and handle month-end adjustments, including leap year considerations for February. ```DML '2003-01-13' +M 1 '2008-01-31' +M 3 '2008-01-31' +M 1 '2003-05-31' -M 3 '2008-01-31' +M 2 '2006-04-30' -M 1 ``` -------------------------------- ### Define and Use a Java Custom Function in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Demonstrates how to define and utilize a Java custom function within DML for extended mapping capabilities. This involves creating a Java class with the desired function and then calling it from the DML script. It's useful for complex logic or external library integration. ```Java public class MyCustomFunctions { public static String greet(String name) { return "Hello, " + name + "!"; } } ``` ```DML import "MyCustomFunctions.java" // ... other DML code ... // Call the custom Java function output.greeting = MyCustomFunctions.greet(input.name); ``` -------------------------------- ### Compute Invoice Amount with Multiple 'where' Clauses Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/5GettingDataInput/dml_gsg_c_0042.htm Filters discount occurrences based on customer name, start date, and end date to retrieve the applicable rate. ```DML \invoice\line[1]\quantity * \invoice\line[1]\price * in2:\discount[where item\name = \invoice\customer\name] [where item\beginning <= \invoice\date] [where item\ending >= \invoice\date]\rate[1] ``` -------------------------------- ### XML Order Request Example Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/1IntroducingDML/dml_gsg_c_0008.htm This XML snippet represents a sample order request from a web server, detailing customer and supplier information, along with line items for an order. It serves as a template for creating a corresponding Business Document in Axway Mapping Services. ```xml USD VISA 2007-03-10 James T. Johanson C-070310-150
White House 1600 Pennsylvania Avenue NW Washington 20500 DC 202-456-1111 202-456-2461
Bombay Club Restaurant S-150110
815 Connecticut Ave NW Washington 20006 DC 202-659-5012
calamari peri peri 2 7.5 masala crab cake 2 12 tandoori mixed grill 1 22 lamb biryani 1 14.95 naan 5 2.5 Chardonnay Shale Ridge 1 30
``` -------------------------------- ### Control loop execution with next Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/8HandlingMultipleOccurences/dml_gsg_c_0058.htm Shows how to use the 'next' instruction within a 'loop on' block to skip empty lines during processing. ```DML %address := ""; loop on \\address\lines { if (length(this) < 1) then next; %address := %address + this + "\n"; }; %address := %address + \\address\zip + " " + \\address\city; %address ``` -------------------------------- ### Calling Built-in Functions in DML Expressions Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/9ExtendingDML/dml_gsg_c_0067.htm Shows an example of calling a built-in DML function, 'remainder', within a Boolean expression. This function divides two parameters and returns the remainder. ```dml (remainder(%year, 4) = 0) and not (remainder(%year, 100) = 0) ``` -------------------------------- ### Generate Fax Text using loop on Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/8HandlingMultipleOccurences/dml_gsg_c_0064.htm Demonstrates the use of the 'loop on' instruction to iterate through order lines and accumulate a formatted string. It highlights the efficiency improvement from O(n²) to O(n) complexity. ```DML %text := ""; loop on order:\order\line { %text := %text + order:this\qty + " x " + order:this\!item! + "\n" }; %text ``` -------------------------------- ### Map Data Nodes using for each Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/8HandlingMultipleOccurences/dml_gsg_c_0064.htm Shows how to use 'for each' expressions to generate output nodes based on input node occurrences. This is used to map customer and supplier address lines to output structures. ```DML for each order: \order\customer\address\line do this for each order: \order\supplier\address\line do this ``` -------------------------------- ### Define Custom Message Attribute (.sh4) Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/11Appendices/dml_gsg_c_0113.htm This code snippet demonstrates how to define a user-defined message attribute named 'foo' with a public string field 'bar'. This allows for custom data transfer between activities in the integration engine. ```dml DECLARE PUBLIC RECORD foo { DECLARE PUBLIC FIELD $bar STRING; } ``` -------------------------------- ### Basic Arithmetic Operations Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/3NumbersOperators/dml_gsg_c_0022.htm Demonstrates the use of addition (+), subtraction (-), multiplication (*), and division (/) operators. It highlights operator precedence where multiplication and division are performed before addition and subtraction. ```mathematical expression 500 + 340 - 10 40 * 10 + 10 ``` -------------------------------- ### Testing for Node Existence in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Demonstrates how to check if a specific node or element exists within the input data using DML. This is important for error handling and ensuring that expected data is present before attempting to process it. The `exists()` function is typically used. ```DML if (exists(input.optionalField)) { output.value = input.optionalField; } else { output.value = "default"; } ``` -------------------------------- ### String Concatenation and Multiplication in DML Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0081a.htm Explains how to combine strings (concatenation) and repeat strings multiple times (multiplication) using DML. These operations are fundamental for text manipulation and generating formatted output strings. The '+' operator is used for concatenation and '*' for multiplication. ```DML output.fullName = input.firstName + " " + input.lastName; output.separator = "-" * 10; ``` -------------------------------- ### Conditional Logic Comparison: If-Then-Else vs Switch Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/6MakingDecisions/dml_gsg_c_0049.htm Demonstrates the transition from verbose if-then-else statements to a cleaner switch structure for mapping bottle capacities to labels. ```DML if \bottle\capacity = 75 then { "bottle" } if \bottle\capacity = 150 then { "magnum" } // ... additional if statements switch \bottle\capacity { case 75: { "bouteille" } case 150: { "magnum" } case 300: { "jeroboam" } case 600: { "maalem" } case 900: { "salmanazar" } case 1200: { "balthazar" } case 1500: { "nabuchodonosor" } } ``` -------------------------------- ### Basic while loop for address processing Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/7RepeatingStatements/dml_gsg_c_0054.htm This code snippet demonstrates a basic 'while' loop that iterates through lines of an address, concatenating them until a condition is met. It initializes variables, checks the number of lines, and appends each line to the address string. The loop continues as long as the index is less than the total number of lines. ```dml 1 %address := ""; 2 %index := 0; 3 while (%index < count(\address\lines)) 4 { 5 %index := %index + 1; 6 %address := %address + \address\lines[%index] + "\n" 7 }; 8 %address := %address + \address\zip + " " 9 + \address\city; 10 %address ``` -------------------------------- ### Iterate over node occurrences with loop on Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/8HandlingMultipleOccurences/dml_gsg_c_0058.htm Demonstrates the basic usage of the 'loop on' statement to concatenate address lines into a single string, providing a more efficient alternative to manual indexing. ```DML %address := ""; loop on \\address\lines { %address := %address + this + "\n"; }; %address := %address + \\address\zip + " " + \\address\city; %address ``` -------------------------------- ### Aggregate order lines using a loop Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/7RepeatingStatements/dml_gsg_c_0056.htm Uses a loop structure to dynamically iterate through all occurrences of the 'line' node to build a complete text string. While functional for smaller datasets, it exhibits O(n²) complexity due to repeated node access. ```DML %text := ""; %line_index := 1; loop (count (order:\\line)) { %text := %text + order:\order\line[%line_index]\qty + " x " + order:\order\line[%line_index]\!item! + "\n"; %line_index := %line_index + 1 }; %text ``` -------------------------------- ### Concatenate order lines using explicit indexing Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/7RepeatingStatements/dml_gsg_c_0056.htm Demonstrates manual concatenation of specific order line items using the [] operator and string concatenation. This approach is limited as it only processes a fixed number of lines. ```DML order:\order\line[1]\qty + " x " + order:\order\line[1]\!item! + "\n" + order:\order\line[2]\qty + " x " + order:\order\line[2]\!item! + "\n" ``` -------------------------------- ### C: Reworked LoadFile Function for Partner Rate Handling Source: https://docs.axway.com/bundle/MappingServices_36_GettingStartedGuide_DML_allOS_en_HTML5/page/Content/DML_GSG/Concepts/10Exceptions/dml_gsg_c_0086.htm This C function, LoadFile, is designed to load file contents into a raw-data container. It handles cases where the filename is null or absent by setting the output to null. It returns 'absent' if the file does not exist or is empty, and signals a system fatal error for other technical issues during file loading. Dependencies include xibrt library functions and standard C file I/O. ```c int LoadFile(EXE_HANDLE hCtx, EXE_hRegister hFileContents, EXE_hRegister hFileName) { char szFileName[MAXPATH + 1]; FILE *pFile; char *pBuffer; size_t ulSize; /* Reject calls with an empty filename */ if (xibrt_isNull(hCtx, hFilename) || xibrt_isNull(hCtx, hFilename)) { xibrt_setNull(hCtx, hFileContents); return XIBRT_SUCCESS; } /* Extract filename arguments * The contents of hFileName is cloned into a static buffer * theoricaly large enough to contain the whole filename. * Only a loss of data is possible here (truncated filename) * that occurs only when the filename is not * filesystem compatible. */ xibrt_getString(hCtx, hFileName, sizeof(szFilename), szFilename); /* Try to open the file and return ‘absent’ on failure */ pFile = fopen(szFilename, "r"); if (!pFile) { if (errno != ENOENT) { return XIBRT_SYSFATAL; } xibrt_setAbsent(hCtx, hFileContents); return XIBRT_SUCCESS; } /* Collect file size and allocate room for contents, then load the file into the buffer and close it */ ulSize = fseek(pFile, 0, SEEK_END); fseek(pFile, 0, SEEK_SET); if (ulSize == 0) { xibrt_setAbsent(hCtx, hFileContents); return XIBRT_SUCCESS; } pBuffer = (char *) malloc(ulSize); if (!pBuffer) { return XIBRT_SYSFATAL; } ulSize = fread(pBuffer, 1, ulSize, pFile); fclose(pFile); /* Copy the file contents into the result blob */ xibrt_setBinary(hCtx, ulSize, pBuffer, hFileContents); /* Perform some cleanup and return success */ free(pBuffer); return XIBRT_SUCCESS; } ```