cancel
Showing results for 
Search instead for 
Did you mean: 

PI 7.1: UDF for creating multiple IDocs

arkesh_sharma
Active Participant
0 Kudos

Hi Experts,

IDoc has a limitation of 999 line items so I am trying to write a UDF to create multiple IDoc.

My Source structure looks like:

MT_Source   1..1

         Recordset   1..1

                Source_Data   0..unbounded

                          S1        0..1

                          S2        0..1

                          S3        0..1

                          S4        0..1

The UDF I wrote for testing is of form "Context" and the code is as mentioned below:

int idocCounter = 1;

for (int i=1;i<Source_Data.length;i++)

{

                     idocCounter++;

                    if ( idocCounter==5)

                    {

                              idocCounter = 1;

                              result.addContextChange();

                    }

}

I have put 6 occurences of "Source_Data" node in the "testing" tab and put the check at 5 in UDF. So, Now, 2 IDoc nodes should be created but I am getting the below error as:

Values missing in queue context. Target XSD requires a value for this element, but the target-field mapping does not create one. Check whether the XML instance is valid for the source XSD, and whether the target-field mapping fulfils the requirement of the target XSD

I request you to please help me in this regard and let me know what am I doing wrong here ?

Regards,

Arkesh

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi,

The problem doesn't seem to be connected with the UDF itself. Most probably you did not put any value to MT_Source or Recordset nodes, which are obligatory in your structure (1..1 occurrence). Map some value to them (even a constant would be fine) to get rid of this error.

Hope this helps,
Greg

arkesh_sharma
Active Participant
0 Kudos

Hi Greg,

The nodes (MT_Source and Recordset) are at the source side so I dont think this should be a problem even if I dont map anything at the source structure to the target IDoc.

I have already mapped MT_Source to the target IDoc node ACC_EMPLOYEE_EXP. I havent done anything for the recordset as it only occurs once. Let me try that as well and I will get back to you.

Thanks,

Arkesh

former_member184681
Active Contributor
0 Kudos

Dear Arkesh,

Ok, now I get it. I didn't notice initially that what you provided was the source, not the target structure. Anyway, this is what your error description says: the problem is caused by some mandatory element not being created, because it is either not mapped, or the source field for it has no values in your test case.

Hope this helps,
Greg

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Your error message is a typical message if your target structure does not get the values from the source for the mandatory fields.    Copy the payload from SXMB_Moni and test it using the queue in the mapping tool. This is the better approach.

arkesh_sharma
Active Participant
0 Kudos

Hi Greg,

The problem was that I did not import IDoc as an XSD and didnt change the occurence to "0..unbounded" in the target XSD so the issue was occurring. But now, I am stuck with a new problem.. The line in the UDF "result.addContextChange();" is Not working fine for me.. I am unable to identify the cause of the issue for this one now..

Former Member
0 Kudos

Hi,

u can chk below UDF (there can be diff ways i am just pointing one of them)

Input will be a

if(a.length%5==0)
{
for (int i=0;i<a.length/5;i++)
{                        
result.addValue("");
}
}
else
{
for (int i=0;i<a.length/5+1;i++)
{                        
result.addValue("");
}
}

Source_Data  ---UDF---IDOC

Thanks

Amit Srivastava

arkesh_sharma
Active Participant
0 Kudos

Hi Bhaskar,

Thank You for your response. I found the problem to my issue but there is a new issue to top that. The UDF that I wrote is not working for me. especially the line

"result.addContextChange();"

Can you please help me with that ?

Thanks,

Arkesh

arkesh_sharma
Active Participant
0 Kudos

Hi Amit,

Thank You for the response.

I am trying to insert a context change after every 5 IDocs. But in the code you provided there is not context change happening.

Thanks,

Arkesh

Former Member
0 Kudos

hI,

it seems that the req which u have posted previously is diff then what u want now??

From ur first post:

>>I have put 6 occurences of "Source_Data" node in the "testing" tab and put the check at 5 in UDF. So, Now, 2 IDoc nodes should be created

Thanks

Amit Srivastava

arkesh_sharma
Active Participant
0 Kudos

Hi Amit,

The requirement is not different.

I am just trying to insert a context change after every 5 records which is not happening in the code that I am trying to implement.

Thanks,
Arkesh

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Hope you have given execution type as "All Values of Queue".

You will find ResultList result as an argument in the method.

So, you are using the result object which is an instance of ResultList Class.

result.addContextChange();

http://scn.sap.com/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphi...

refer this thread

http://scn.sap.com/thread/870033

former_member184681
Active Contributor
0 Kudos

Hi,

I believe the code to add a context change is a little bit different. Try with the following: result.addValue(ResultList.CC);

Hope this helps,

Greg

Answers (1)

Answers (1)

arkesh_sharma
Active Participant
0 Kudos

The issue was resolved by modifying the code to suit the requirement and also by adding the statement

result.addValue(ResultList.CC);