top of page

IMPEX Overview

​

Impex stands for "Import Export," is a powerful data manipulation language used in the SAP Hybris commerce platform. It allows you to import, export, and manipulate data in your e-commerce system efficiently. Impex scripts are written in a declarative manner and are commonly used for tasks such as data import, product catalog updates, and system configuration changes. 

​

Key Characteristics and use of Impex :

​

  1. Declarative Language: ImpEx is a declarative language, which means you describe what you want to achieve, and the system figures out how to do it. This makes it easier to work with than imperative programming languages.

  2. Data Import: ImpEx is frequently used for importing data into your e-commerce system. This can include product information, categories, pricing, customer data, and more. You define the structure and content of the data in the ImpEx script, and the system processes it accordingly.

  3. Data Export: ImpEx can also be used to export data from your e-commerce system. You can create scripts that extract data from the system and generate files in various formats, such as CSV or XML.

  4. Data Manipulation: ImpEx allows you to manipulate data during import and export. You can perform transformations, calculations, and data cleansing operations within your scripts.

  5. Batch Processing: ImpEx is often used in batch processing scenarios. You can create scheduled jobs or scripts that run at specific intervals to perform data updates or other tasks automatically.

 

 

​

​

​

Impex Components

​

1) Micros : ImpEx micros are reusable code snippets or functions that can be embedded within ImpEx scripts to perform specific tasks.  Micros enhance the modularity and maintainability of ImpEx scripts by allowing you to encapsulate logic, calculations, or custom transformations in a single place. Here's an example of micros:

​

;$catalogVersion=catalogVersion(catalog(id[default='electronicsProductCatalog']),version[default='Staged'])

​

2) Header : ImpEx scripts can include header lines to provide metadata and context information about the script. While header lines are not mandatory, they are useful for documenting and explaining the purpose of the ImpEx script. Here's an example of a header in an ImpEx script:

 

INSERT_UPDATE Product;code[unique=true];name;description;price;catalogVersion[default='electronicsProductCatalog:Staged']

​

3) Value Lines: ImpEx scripts use value lines to specify the actual data to be imported, updated, or manipulated. Value lines follow the item type declaration, operation, and attribute definitions in ImpEx scripts. They provide the data that should be associated with the attributes of the item type. Here's is an example of  value lines:

;P12345;Laptop;High-performance laptop;999.99;
;P67890;Tablet;Portable tablet;349.99;

​

4) Comments:  You can use comments in ImpEx scripts to provide explanations, notes, or documentation about the script. Comments are ignored by the ImpEx interpreter and are purely for human readability. They are useful for documenting the purpose of the script, providing context for specific actions, or leaving instructions for other developers who may work with the script. Here's an example of comments in ImpEx:

​

 # ImpEx Script for Importing Products into a Catalog
# Description: Importing products into the Electronics catalog

 

 

 

 

​

​

​

​

​

​

​

​

IMPEX OPERATION MODES

​

Impex supports different modes of operation that determine how data is processed during an import or update operation. These modes allow you to control how data is handled and provide flexibility in managing your data. Here are some common modes of ImpEx operations with examples:

​

a) INSERT Mode: INSERT mode is used to insert new data into the system. If data with the same unique identifier (e.g., code) already exists, it will not be updated but will be skipped.

​

INSERT Product;code[unique=true];name;price

;123;Laptop;999.99

​

b) UPDATE Mode: UPDATE mode is used to update existing data in the system. If data with the specified unique identifier does not exist, it will be skipped.

​

UPDATE Product;code[unique=true];name;price

;123;Updated Laptop;1099.99

​

c) INSERT_UPDATE Mode: INSERT_UPDATE mode is a combination of INSERT and UPDATE. It inserts new data and updates existing data if the unique identifier matches.

​

INSERT_UPDATE Product;code[unique=true];name;price

;123;Laptop;999.99 ;456;Tablet;549.99

​

D) REMOVE Mode: REMOVE mode is used to delete data from the system based on the specified criteria. Be cautious when using REMOVE mode, as it permanently removes data.

​

REMOVE Product;code[unique=true]

;789

  1. ​

E) REMOVEALL Mode: REMOVEALL mode is used to delete all instances of a specific item type from the system. Be extremely cautious when using REMOVEALL mode, as it deletes all records of that type.

​

REMOVEALL Product

 

 

IMPEX BATCH MODE 

 

 

Hybris uses batch mode, also known as bulk update, as a technique to update all the rows in a table at once. When modifying a column's value in a table for all rows with a default value, batch mode import is helpful.

​

We can also delete every entry from the table using batch mode. As a result, the attributes designated as non-unique are updated at all items that match the combination of unique attributes for a value line if more than one item is discovered that does so.

​

Practical Use Case 1:  Update the maximum allowed product quantity in single order for all the product. 

​

  1. $productCatalog=customProductCatalog

  2. $catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Online'])[unique=true,default=$productCatalog:Online]

  3.  

  4. UPDATE Product[batchmode=true];itemtype(code)[unique=true];$catalogVersion;maxOrderQuantity

  5. ;Product;;10

​

Practical Use Case 2:  Removing all the entries from the table ThirdPartyCredentials Table.

​

  1. Remove ThirdPartyCredentials[batchmode=true];itemtype(code)[unique=true];

  2. ;UrlMapping;;

Impex

About the Author

 

Piyush Singh is a seasoned technology enthusiast and educator with a passion for making complex concepts accessible to everyone. With over 10 years of experience in the tech industry working as consultant,  Piyush specializes in Java, Sap Hybris technology and has a knack for breaking down intricate topics into easy-to-follow tutorials.

​​​​​​​

   Connect with Author

LinkedIn

Email

​

​

bottom of page