cancel
Showing results for 
Search instead for 
Did you mean: 

context function for getting a current segment field

venkatasap
Participant
0 Kudos

Hi Sap All.

here i have got a requirement in a message mapping from  IDOC To File Interface ,the Requirement is as follows :

this mapping is from a ZIDOC(Purchase Orders) to file :

The IDOC Structure is as follows :

THE Reciever File structure is as follows

Purchaseorder->OrderHeader(Substructure of Purchaseorder)->Orderdetail(Substructure of Purchaseorder)->CostDetail(Substructure of Order Detail)

Z1EDRPORDCR1->E1EDK01->E1EDP01->E1EDP05->Fields(KSCHL,KRATE)  ,here the IDOC will be having multiple E1EDP05 Segments (per PO Items),the requirement is :

1.if E1EDP05-KSCHL 'eq' 'PB00' Then pass E1EDP05-KRATE to target file structure field  CostDetail-Gross_cost

if E1EDP05-KSCHL 'eq' 'XXXX' Then ignore previous set value of  option 1 ' 'PB00'' & pass CURRENT E1EDP05-KRATE to target file structure field CostDetail-Gross_cost.

as for now i have defined the graphical mapping as follows

IF  KSCHL equals(Text function) 'PB00' or 

KSCHL equals(Text function) 'XXXX Then KRATE->CostDetail-Gross_cost  .

When i test the above mapping where having 2 E1EDP05's with 1st kschl as 'PB00' & 2nd kschl as 'XXXX'then iam getting 2nd krate to target but when i test vice versa like  1st kschl as 'XXXX' & 2nd kschl as 'PB00 ' then iam still getting the 2nd KRATE where i have to get 1st Krate.

will be waiting for your response.

regards.

Varma

Accepted Solutions (1)

Accepted Solutions (1)

venkatasap
Participant
0 Kudos

Hi SAPAll.

i still didnt get any reply on the above question,is my question not clear.please mention me if it is not clear so i will try to explain clearly.

will be waiting for the response.

regards.

Varma

former_member184681
Active Contributor
0 Kudos

Hi,

This looks complicated with standard graphical mapping, but should be fine with a simple UDF that takes two inputs (KSCHL and KRATE), with execution type: all values of context:

String conditionXXXX = "";

String conditionPB00 = "";

for (int i = 0; i < kschl.length; i++) {

   if (kschl[i] == "PB00") conditionPB00 = krate[i];

  if (kschl[i] == "XXXX") conditionXXXX = krate[i];

}

if (!conditionPB00.equals("")) result.addValue(conditionPB00);

else result.addValue(conditionXXXX);

Regards,

Greg

venkatasap
Participant
0 Kudos

Hi Mr Greg.

i have done as you said but when i pass the 2 parameters (Nodes :KSCHL,KRATE) to the udf iam getting the empty string as an output instead of the Respective KSCHL value.

pls advice me if i have to make any changes

will be waiting for your response.

regards.

Varma

former_member184681
Active Contributor
0 Kudos

Try with the following - I always forget that you need to use "equals" function to compare strings...

String conditionXXXX = "";

String conditionPB00 = "";

for (int i = 0; i < kschl.length; i++) {

   if (kschl[i].equals("PB00")) conditionPB00 = krate[i];

  if (kschl[i].equals("XXXX")) conditionXXXX = krate[i];

}

if (!conditionPB00.equals("")) result.addValue(conditionPB00);

else result.addValue(conditionXXXX);

Regards,

Greg

venkatasap
Participant
0 Kudos

Hi Greg.

thanks for your quick response.

after i have done the changes as you said ,it is working now  as per the requirement.

regards.

Varma

venkatasap
Participant
0 Kudos

Hi Greg.

just a quick question again.

when i try to use the same code for 3 conditions instead of 2 conditions ,it didnt work.so i have  modified  the code as below

*********************************************************************************************88

String conditionP101 = "";
String conditionZLRC = "";
String conditionPBXX = "";
String FLAG1 = "Y" ;
String FLAG2 =  "Y" ;
String  FLAG3 =  "Y" ;


for (int i = 0; i < KSCHL.length; i++) {

if (KSCHL[i].equals("P101")) conditionP101 = KRATE[i];
   if (KSCHL[i].equals("PBXX")) conditionPBXX = KRATE[i];
  if (KSCHL[i] .equals("ZLRC")) conditionZLRC = KRATE[i];
}
if (!conditionP101.equals(""))
{
FLAG1 = "Y";
}
else if  (!conditionZLRC.equals(""))
{
FLAG2 = "Y" ;
FLAG1 = "N";
}
else  if  (!conditionPBXX.equals(""))
{
FLAG3 = "Y";
FLAG1 ="N";
FLAG2 = "N";
}
if (FLAG1.equals ("Y"))
{
result.addValue(conditionP101);
}
else if  (FLAG2.equals ("Y"))
{
result.addValue(conditionZLRC);
}
else if (FLAG3.equals ("Y"))
{
result.addValue(conditionPBXX);
}

**************************************************************************************************************************************

but still when i the tested the message mapping using the above code with the below shown test cases ,the result is (P101) in all the cases

1.PBXX
MVKO
P101
ZLRC         ->P101

2.
P101
MBKO
PBXX
ZLRC         ->P101


3.ZLRC
MVKO
PBXX
P101          ->P101


4.ZLRC
MVKO
P101
PBXX           ->P101

will be waiitg for your response again

regards.

Varma .

former_member184681
Active Contributor
0 Kudos

Hi,

Here is how I would make the changes you require:

String conditionP101 = "";

String conditionZLRC = "";

String conditionPBXX = "";

for (int i = 0; i < KSCHL.length; i++) {

  if (KSCHL[i].equals("P101")) conditionP101 = KRATE[i];

  if (KSCHL[i].equals("PBXX")) conditionPBXX = KRATE[i];

  if (KSCHL[i] .equals("ZLRC")) conditionZLRC = KRATE[i];

}

if (!conditionP101.equals("")) result.addValue(conditionP101);

else if (!conditionZLRC.equals("")) result.addValue(conditionZLRC);

else result.addValue(conditionPBXX);

Regards,

Greg

venkatasap
Participant
0 Kudos

Hi Greg

i have done the changes as you said and have tested the mapping program ,the following below are the test cases & the results

PBXX
MVKO
P101
ZLRC         ->P101

2.
P101
MBKO
PBXX
ZLRC         ->P101


3.ZLRC
MVKO
PBXX
P101          ->P101


4.ZLRC
MVKO
P101
PBXX           ->P101


5.PBXX
  MVK0
  ZLRC
  P101       ->P101

the result of all the above shown test cases is P101 but it should be PBXX.pls guide me in what change i have to do to make it correct.

regards.

Varma

former_member184681
Active Contributor
0 Kudos

So what is the desired "priority" of the conditions?

venkatasap
Participant
0 Kudos

Hi Greg.

the desired priority conditions are as below

1.     If only a P101 condition type exists, then this condition type and value is sent to Target.

2.     If a ZLRC condition is found, then only the ZLRC  will be sent,  P101 will not be interface to target

3.     If a PBXX condition is found , then only the PBXX Cost Price will be sent to target, P101 &/or ZLRC will be ignored.

regards.

Varma

former_member184681
Active Contributor
0 Kudos

Ok, I thought it was meant to be the opposite way, based on your code. Here is the final version:

String conditionP101 = "";

String conditionZLRC = "";

String conditionPBXX = "";

for (int i = 0; i < KSCHL.length; i++) {

  if (KSCHL[i].equals("P101")) conditionP101 = KRATE[i];

  if (KSCHL[i].equals("PBXX")) conditionPBXX = KRATE[i];

  if (KSCHL[i] .equals("ZLRC")) conditionZLRC = KRATE[i];

}

if (!conditionPBXX.equals("")) result.addValue(conditionPBXX);

else if (!conditionZLRC.equals("")) result.addValue(conditionZLRC);

else result.addValue(conditionP101);

Regards,

Greg

Answers (0)