This blog mainly describes how to input field values based on the conditions specified in the mapping file. I will explain two types of conditions: OR and AND. Because I could not find any resource that perfectly applies to my scenario, I am writing this blog. If you have any questions or suggestions to improve my solution, please kindly write in the comment. Thank you for reading in advance.
Scenario:
In this scenario, this is the outbound case, so S4 needs to send the data in the intermediate table through BTP CI to the target server. The data has four fields: the Number, the Date1, the Date2, and the Flag. Based on the condition, you need to input the value ‘X’ in the Flag field. For the condition, I will explain it in two types of conditional statements: OR and AND. Please refer to either of them which applies to your scenario.
A) OR
You need to input ‘X’ in the Flag field if the Date1 is equal to current date OR the Date2 is equal to the current date. Otherwise, the Flag field remains the same as a space ‘ ’.
B) AND
You need to input ‘X’ in the Flag field if Date1 is equal to current date AND the Date2 is equal to the current date. Otherwise, the Flag field remains the same as a space ‘ ’.
Note: It is always better if you can input values based on the condition inside of the CDS view, but if you cannot, use the way I explained in this blog.
Prerequisites:
・Create a CDS view and a OData service in the eclipse and in the S4 respectively.
iFlow components:
・Use a OData adopter to get the data from S4 to BTP.
・Use a SFTP adopter to send the output message from BTP to the target server.
・Use a message mapping to match the structure of fields in the message coming from the S4 and being sent to the target server and to input ‘X’ to the Flag field based on the condition.
Input Data and Expected Values
Values in the column Number, Date1 and Date2 are the input values coming from the S4. And values in the Flag field are the expected values produced by the message mapping. 20230516 is the current date.
Number | Date1 | Date2 | Flag(OR) | Flag(AND) |
1 | 20230510 | 20230510 | ||
2 | 20230510 | 20230516 | X | |
3 | 20230516 | 20230510 | X | |
4 | 20230516 | 20230516 | X | X |
Steps:
These are the important steps to achieve our goal: inputting ‘X’ in the Flag field based on the condition. I will explain the steps for the OR case and the AND case respectively.
A) OR case
1. Create a message mapping
There are two ways to create conditions with OR. The first one is easier to understand the logic. The second one is simpler. Make sure you input the false value. Otherwise, you will get an error and will not be able to deploy your iFlow.
The first way
The second way
Note: make sure that the date format in the currentDate function corresponds to the date format defined in your CDS view. For example, because the date format in my CDS view is yyyymmdd, I need to remove the ‘/’ from the date fromat in the currentDate. Otherwise, this mapping does not work correctly.
2. Check the result in the monitor.
Check_Data1: data before being processed by the message mapping
<Root>
<Record>
<Date1>20230510</Date1>
<Flag></Flag>
<Date2>20230510</Date2>
<Number>0000000001</Number>
</Record>
<Record>
<Date1>20230510</Date1>
<Flag></Flag>
<Date2>20230516</Date2>
<Number>0000000002</Number>
</Record>
<Record>
<Date1>20230516</Date1>
<Flag></Flag>
<Date2>20230510</Date2>
<Number>0000000003</Number>
</Record>
<Record>
<Date1>20230516</Date1>
<Flag></Flag>
<Date2>20230516</Date2>
<Number>0000000004</Number>
</Record>
</Root>
Check_Data2: data after being processed by the message mapping
As you can see, you could input ‘X’ in the Flag field when the Date1 is equal to current date OR the Date2 is equal to the current date. As expected, the record number 2, 3, and 4 got ‘X’ in the Flag field.
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Record>
<Number>0000000001</Number>
<Date1>20230510</Date1>
<Date2>20230510</Date2>
<Flag></Flag>
</Record>
<Record>
<Number>0000000002</Number>
<Date1>20230510</Date1>
<Date2>20230516</Date2>
<Flag>X</Flag>
</Record>
<Record>
<Number>0000000003</Number>
<Date1>20230516</Date1>
<Date2>20230510</Date2>
<Flag>X</Flag>
</Record>
<Record>
<Number>0000000004</Number>
<Date1>20230516</Date1>
<Date2>20230516</Date2>
<Flag>X</Flag>
</Record>
</Root>
B) AND case
1. Create a message mapping.
2. Check the result in the monitor.
Check_Data1: data before being processed by the message mapping
<Root>
<Record>
<Date1>20230510</Date1>
<Flag></Flag>
<Date2>20230510</Date2>
<Number>0000000001</Number>
</Record>
<Record>
<Date1>20230510</Date1>
<Flag></Flag>
<Date2>20230516</Date2>
<Number>0000000002</Number>
</Record>
<Record>
<Date1>20230516</Date1>
<Flag></Flag>
<Date2>20230510</Date2>
<Number>0000000003</Number>
</Record>
<Record>
<Date1>20230516</Date1>
<Flag></Flag>
<Date2>20230516</Date2>
<Number>0000000004</Number>
</Record>
</Root>
Check_Data2: data after being processed by the message mapping.
As you can see, you could input ‘X’ in the Flag field when the Date1 is equal to current date AND the Date2 is equal to the current date. As expected, only the record number 4 got ‘X’ in the Flag field.
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Record>
<Number>0000000001</Number>
<Date1>20230510</Date1>
<Date2>20230510</Date2>
<Flag></Flag>
</Record>
<Record>
<Number>0000000002</Number>
<Date1>20230510</Date1>
<Date2>20230516</Date2>
<Flag></Flag>
</Record>
<Record>
<Number>0000000003</Number>
<Date1>20230516</Date1>
<Date2>20230510</Date2>
<Flag></Flag>
</Record>
<Record>
<Number>0000000004</Number>
<Date1>20230516</Date1>
<Date2>20230516</Date2>
<Flag>X</Flag>
</Record>
</Root>