There are several ways to create dynamic file names at receiver adapter in SAP PI/PO. In this example we will discuss how to create a dynamic file name at receiver file channel using a User Defined Function (UDF). Filename creation with UDF is a great way when the file name logic is too complicated to be handled by other file name creation methods such as variable substitution etc. Since you are writing a custom code, you can include complex logics for file name easily. You can write a simple UDF to create the file name in the message mapping. File name created in the message mapping can be set at the receiver using Adapter Specific Message Attributes (ASMA).
In this example (iDoc to File scenario) I am setting the iDoc Message type and Material number to the file name in the below format.
File name format: <Message Type>_<Material Number>_TimeStamp.XML
Lets look at the how to create file name in above format at receiver communication channel using a UDF.
Step 1: Create File Name User Defined Function (UDF).
UDF name: Set_FileName
Configure the parameters of the UDF. Since we require file name to have ‘Message Type’ and the ‘Material Number’ from the input, we need to create two import parameters in the UDF. One for ‘Message Type’ and another one for ‘Material Number’.
Step 2: Code UDF Logic to Set the File Name.
Here we need to set the file name to dynamic configuration key ‘FileName’. You can change the UDF code here as per your file format requirement.
File name generation UDF comes in handy when your file name logic is complex and it cannot be handled by other dynamic file name generation methods such as variable substitution.
Step 3: Configure the Message Mapping program.
Map the created file name generation UDF as above. In the example we import two values from the input structure to the UDF, they are Message type (MESTYP) and Material Number (MATNR).
Step 4: Configure the receiver file communication channel .
You can set any text as the ‘File Name Schema’ as it would be replaced by the ASMA.
Configure ASMA by checking ‘Use Adapter Specific Message Attributes’ (ASMA) and also ‘File Name’. These two settings should be activated in the receiver communication channel to runtime to override the hardcoded file name in ‘File Name Schema’ with the file name set from the UDF.
Set the time stamp since we need the timestamp at the end of the file name.
Hi, I am Isuru Fernando, Senior SAP Integration Consultant with 10 years of SAP full-cycle implementation and support project experience.From the early days, I had a passion for coding, software development, and everything tech-related. I started my carrier as an ABAP developer and soon found my love for system integration when I learned SAP XI 3.0 in 2008. Playing a variety of roles from an offshore technical consultant (ABAP, PI/PO, BW, BOBJ) at the beginning of my career to a technical lead managing a team of consultants in different countries, I have gained immense experience in SAP project implementation life cycle.Having the opportunity to work on SAP implementation projects in USA, EU, and Asia, I learned valuable ins and outs of global business processors in Sales and Distribution (SD), Material Management, Retail, Customer Relationship Management (CRM), and Finance and Controlling (FICO).Through this blog, I want to share my expertise in SAP technical areas such as SAP ABAP, PI/PO, AIF, and Basis. I also want to provide a platform for others with similar ambitions who would like to share their SAP technical expertise with the world!