cancel
Showing results for 
Search instead for 
Did you mean: 

help to write UDF function

former_member249399
Active Participant
0 Kudos

HI Experts,

I am new in sap pi, do not kow how to write UDF.

In my complex mapping scenario, I need to write UDF.

Source IDOC :

Z1WHCONS

   Z1WHCUSTC

     Z1WHCUSTCH

       Z1WHCUTM

           comment

       Z1WHCUTM

           comment

       Z1CUSTCD   

Target:

BOX                  --     Z1WHCUSTC when Z1WHCONS is initial

MIXPLT            --      Z1WHCONS

    BOX               --  --     Z1WHCUSTC when Z1WHCONS is not initial

       Line              --        Z1CUSTCD

         comment   ---    Z1WHCUTM-comment field

         comment   ---    Z1WHCUTM-comment field

I am not getting proper data when BOX and BOS with MIxplt data is coming in source xml.

How can I do it using graphical mapping or UDF.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member249399
Active Participant
0 Kudos

Source IDOC :

Z1WHCONS        0..n

  Z1WHCUSTC    0..n

    Z1WHCUSTCH    0..n

      Z1WHCUTM      0..n

          comment        0..1

      Z1CUSTCD        0..n

Z1WHCUTM and Z1CUSTCD are at same level under node  Z1WHCUSTCH.

Target:

BOX            0..n                  --    Z1WHCUSTC when Z1WHCONS is initial

  Line            0..n                  --        Z1CUSTCD

     comment    0..n              ---    Z1WHCUTM-comment field

MIXPLT        0..n                    --      Z1WHCONS

    BOX            0..n                    --  --    Z1WHCUSTC when Z1WHCONS is not initial

      Line            0..n                  --        Z1CUSTCD

        comment    0..n              ---    Z1WHCUTM-comment field

           

First Box and Mixplt are at same level.

I am not getting comment  data when BOX and BOX with MIxplt data is coming in source xml.

How can I do comment mapping  using graphical mapping or UDF.

Former Member
0 Kudos

Hello,

Z1WHCUSTC when Z1WHCONS is initial this condition is not possible as Z1WHCUSTC is a child element of Z1WHCONS.

Regards

Diptee

former_member249399
Active Participant
0 Kudos

when Z1WHCONS-fields  not exist then we populated data in first BOX. ans it is working fine.

comment lines are also populating when only BOX or only Mixplt data is there.

Only problem is when multiple BOX data is coming out.

Target:

BOX            0..n                  --    Z1WHCUSTC when Z1WHCONS is initial

  Line            0..n                  --        Z1CUSTCD

     comment    0..n              ---    Z1WHCUTM-comment field

MIXPLT        0..n                    --      Z1WHCONS

    BOX            0..n                    --  --    Z1WHCUSTC when Z1WHCONS is not initial

      Line            0..n                  --        Z1CUSTCD

        comment    0..n              ---    Z1WHCUTM-comment field

Former Member
0 Kudos

hello,

The structure of Z1WHCONS segment is like below, what do you exactly mean to say when you say Z1WHCONS is initial

former_member249399
Active Participant
0 Kudos

if CONS_CONTR_ID does not exist.

Former Member
0 Kudos

hello,

You may use the below mapping and tweak it as necessary

Regards,

Diptee


former_member249399
Active Participant
0 Kudos

Diptee,

Please send last screen shot again.

Former Member
0 Kudos

The context of COMMENT and Z1WHCUSTCD have been set to Z1WHCONS.

Regards

Diptee

former_member249399
Active Participant
0 Kudos

Hi Diptee,

Thanks for quick reply.

Which  field is mapped for  one as to many  as 2 field .

and you are saying that Context has changed for Z1WHCUSTCD, where is that field?

Former Member
0 Kudos

Hello,

For box field the 2nd field in oneToMany is Z1WHCUSTC and for line it is Z1WHCUSTCD.

Z1WHCUSTCD is being used for line field.

Regards,

Diptee

former_member249399
Active Participant
0 Kudos

Hi Diptee,

I tried your solution , it is working for box and  line.

But when I am trying to get comment data when only BOX (first BOX , not MIXPLT-BOX) appears more than 1 times ,  it is not working.

because I think sequence gets change for queue.

Former Member
0 Kudos

Please send me the test paylaod.

Rgds

Diptee

former_member249399
Active Participant
0 Kudos

It is already attached , Please check.

if not found tell me , I will send it again.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Ranj,

The comment output is correct for me, I use this logic

Hope this helps,

Mark

former_member249399
Active Participant
0 Kudos

Hi Mark,

Not customercomment filed , but Z1WHCMTH-COMMENT field should mapped to Ordercomment field.

one field should create for each comment.

Thanks,

Ranj

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Ranj,

This needs UDF indeed. The trick is to combine all the values of the COMMENT field so that it will have the same number of contexts as Z1WHCUSTC.

1. First UDF for combining the values:

2. Second UDF for splitting the values:

Mapping for first comment

Mapping for mixPlt comment

Test:

Only CU0 and CU4 have comments which is the desired output.

Regards,

Mark

former_member249399
Active Participant
0 Kudos

Hi Mark,

Could you please share your mail id on my mail sapranjana@gmail.com?

Thanks.

former_member249399
Active Participant
0 Kudos

Hi MArk,

You are getting correct comment at correct lines . I followed all your previously mentioned steps. but getting error. Could you please send screen shot at BOX, mixplt, mixplt-box, box-line, mixplt-box-line level,

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Ranj,

Here you go:

Box

Box-line

Box-line-comment

mixPlt

mixPlt-box

mixPlt-box-line

mixPlt-box-line-comment

Hope this helps,

Mark

Former Member
0 Kudos

Hi Ranj

The structure/requirement provided is not clear.

You have mentioned about BOS field, but i cannot see it in the target structure.

Can you provide more details? Also provide the cardinality of the fields.

Regards

Osman