cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering by value

Former Member
0 Kudos

Hi,

I have a source message with that structure:

<item>

MATNR

DESCRIPTION

DATE

</item>

And I'm mapping to a target structure with the same fields.

But in my message mapping I want to ignore/delete the items where the value of field DATE is a DATE lower thatn system date.

For example if system date is 23/05/2008:

Source Message:

<item>

MATNR = '30'

DESCRIPTION = 'aaa'

DATE = '22/02/2008'

</item>

<item>

MATNR = '31'

DESCRIPTION = 'bbb'

DATE = '30/09/2008'

</item>

Target Message:

<item>

MATNR = '31'

DESCRIPTION = 'bbb'

DATE = '30/09/2008'

</item>

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Marshal

You can do it in normal mapping and you do not require to use any UDF.Always follow a simplest and elegant approch

Follow these steps

1) first you Take Current Date function from DATE category function

2)Then Use Compare Date function from DATE category function

3) Compare current date and Date field using Comapre date function.

4) then use Equals function (for the string) from text second input for Equals function is "TRUE" or u201C1u201D

5) after that use IF function and give the above condition in IF part and assign current date

6) in the else part assign a constant , double click on constant and make empty value to that constant.

By this way you can make comparision and if the value comes true then it will assign current date else it will assign blank value

Hope this may solve your problem

Thanks

Sandeep

If helpful reward points

Former Member
0 Kudos

Thanks again,

I've implemented a solution very similar of Rohit purpose and it worked fine but it's only comparing the first recordset item.

If the 1st Recordset item date is greater than current date the mapping maps all the items to the target

And if the 1st Recordset item date is lower than current date no item is mapped to the target recordset

aashish_sinha
Active Contributor
0 Kudos

Hi,

So here came the simplest approach.. just write one UDF and all will be done (as i suggested earlier). It checks values by one by one item and appends it to result. You will never see any problem and you can also reuse it when you need it later. anyway its your decesion but i'll prefer UDF for this case.

I know there is no need to write an UDF but it helps when you do these type of mapping again and again.

Regards

Aashish Sinha

PS : reward points if helpful

Edited by: Aashish Sinha on May 23, 2008 11:40 AM

Former Member
0 Kudos

Hi,

Use RemoveContext function after Date field value and follow all step as preveously mentioned.

Regards,

Rohit

Reward points if helpful.

Former Member
0 Kudos

Thanks Rohit! It worked!

Why is necessary use Remove Context? What's this doing?

To Aashish Sinha:

Maybe you are right that UDF is a good solution but I'm not a Java programmer and in spite of your solution looks simple I thought it's not the best with my knowledge. But thanks anyway

Former Member
0 Kudos

Hi,

That is context problem to know context refer following link.

http://help.sap.com/saphelp_nw04/helpdata/en/40/7b8e40496f6f1de10000000a1550b0/frameset.htm

Regards,

Rohit.

Reward points if helpful.

Answers (4)

Answers (4)

sunil_singh13
Active Contributor
0 Kudos

Hi Marshal,

Well no need to write UDF for this

Do this mapping for the node "item" at target side

1)take currentDate from date functions

2)take CompareDate give one input to it wil be currentDate and othe will be DATE field of your input structure.

3)use ifwithoutElse(Keeps = true) give one input as output of CompareDate and other as "item" of your input source

now everythiong is done .

Reward points if helpful

Thanks

Sunil Singh

Former Member
0 Kudos

Hi,

u can do it in normal mapping not require to use UDF.

1) Take Current Date function from DATE category.

2) Use Compare Date function from DATE category.

3) Compare current date and Date field using Comapre date function.

4) then use Equals function from text sencond input for Equals function is "1".

5) after that use Not function then use IfWithOutElse function with keeps == true.

5) after that use RemoveContext and map it to parent node (Item).

Regards,

Rohit

Reward points if helpful.

prateek
Active Contributor
0 Kudos

Use date function "currentDate" to get the system date.

Then use function "compareDate" and input the 2 dates. Then u can use the value in "if" function

Regards,

Prateek

Former Member
0 Kudos

Sorry, I didn't explained so well.

I already know how to compare the dates with "if" function but I don't know how to discard the full item in function of the result of the comparision

Edited by: Marshal Oliveras on May 23, 2008 10:42 AM

Former Member
0 Kudos

Marshal,

You need to implement the if condition at the <item> target node. Map the rest of the child nodes directly.

The condition : If <date> is less than Current date then map Item to item. Use If with out Else.

Regards,

Jaishankar

aashish_sinha
Active Contributor
0 Kudos

Hi,

For this purpose you need to write an advance udf.

Logic,

- it will take ur XML as input (that will be stringlist when you define the UDF)

- check the date of item or put it in some variable for comparision or in string anything you want.

- compare the date

if date is not equal to sysdate

don't add to resultset list

else

add to resultset list

return resultset.

Hope this will help you.

Regards

Aashish Sinha

PS : reward points if helpful