cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping mandatory field with no blank value

Former Member
0 Kudos

Hi Team,

I have to map 2 mandatory fields. Requirement is when ever there is blank value in source target field, I have to generate an mapping error in Graphical
Mapping.

I tried with the logic.

F1 -> Substring(Text) ->if Withelse ->F2

Any new suggestion, would be appreciated.

Regards
Rebecca

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Everyone,

Thanks for the input.

I suppose i didnt made the clear picture. I have both the fields F1 and F2 as mandatory field i.e. whenever the node occurs this fields will also be generated.

So while fetching the data from ECC to the mandatory source field F1 , I want that the data from ECC should populate the field F1 and in case the field is blank,it should not allow to pass to the receiver system and should display exception in SAP PI that the field F1 is empty.That means what ever the value is passed to F1,the same value should be passed to F2 not any other value.

Although it can be done in Proxy and Schema Validation, the requirement is to catch the exception in PI itself.

Kindly refer to the attachment for the graphical mapping.I am not sure what to pass in the "Then" node as I cannot drag the F2 field from the target structure.

Regards
Rebecca

Former Member
0 Kudos

Hi,

U want to check if the input field F1 is empty (means filed exist but having no value or blank value, something like <PurchDocument></PurchDocument>) and then throw an exception?? If yes then u can follow the approach which i have posted above but u wont get the cutsom exception is that case.

But if u want to throw custom exception then use below UDF:

Input will be var1

execution type: single value

if(var1.equals(""))

{

throw new RuntimeException("F1 is empty");

}

else

return var1;

Mapping:

F1----TRIM-----UDF---F2

If in case you want to throw an exception if the field itself doesnt exist then just use MapwithDeafult along with the above UDF:

F1---MapWithDefault----TRIM---UDF---F2

Thanks

Amit Srivastava

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>I am not sure what to pass in the "Then" node

Use F1 as input  in the then node.

Former Member
0 Kudos

Hi Amit,

Excellent your piece of code is working for 1 field <Purchase Document>.

1.     I have 2 other fields which are mandatory i.e. <ItemNo> and <Name> in the same order and want to include in this piece of code.

2.    Also suggest what I have to change in the Signature Function ( Signature Variable) of the UDF since we are now taking 3 fields and all are in the same level.

Please suggest.

Thanks!!

Rebecca

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi Experts,

I have add UDF according to the thread of Amit in my mapping in order to produce runtime exception.

In the Mapping Test Module it works fine and give the exception as belows:

Exception:[java.lang.RuntimeException: The field XXX in IDoc: 0000000027180117 is missing] in class com.sap.xi.tf._MM_ORERS_ORDERS05_to_InsertOrders_ method CheckMandatory[[Ljava.lang.String;@6b237f5b, [Ljava.lang.String;@677e6650, [Ljava.lang.String;@1b6f4345, com.sap.aii.mappingtool.tf7.rt.ResultListImpl@25a97515, com.sap.aii.mappingtool.tf7.rt.Context@1845c904]

But, in the Runtime Workbench, I send the same message over "Message Test".

It gives the normal Error in the SXMB_MONI:

<SAP:Stack>Während des Anwendungs-Mappings com/sap/xi/tf/_MM_ORERS_ORDERS05_to_InsertOrders_ ist eine RuntimeException aufgetreten. com.sap.aii.mappingtool.tf7.MessageMappingException: Runtime exception when processing target-fieldmapping /ns0:INSERT_Orders/StatementPosition/dbTa~</SAP:Stack>

And the alert has the same texts as above.

Could anyone give me tips?

Thanks a lot!

Regards

Rene

Former Member
0 Kudos

Hi Everyone,

The piece of code is working for 1 field <Purchase Document>.

1.     I have 2 other fields which are mandatory i.e. <ItemNo> and <Name> in the same order and want to include in this piece of code.

2.    Also suggest what I have to change in the Signature Function ( Signature Variable) of the UDF since we are now taking 3 fields and all are in the same level.

Please suggest.

Thanks!!

Rebecca

Former Member
0 Kudos

Hi,

The mapping for Name and ItemNo will be different.... right?? If that so then u dont have to change anything in the UDF just use the same UDF for other fields also..(may be u can just make the text under Runtime Exception more generic) ....Please correct me if i have misunderstood u.

Name ---UDF--TargetName

ItemNo --UDF---TaregtItemNo

Thanks

Amit Srivastava

baskar_gopalakrishnan2
Active Contributor
0 Kudos

I think Rebecca wants to combine the feature for all the three mandatory fields in one UDF. I would recommend to use same UDF three times seperately for the three mandatory fields like what you were referring.

Former Member
0 Kudos

Hi Amit,

Yes I want to use the same UDF1 for these three mandatory fields ( as Bhaskar mentioned).So the input for UDF would be 3 different values for these 3 different mapping and have to use seperatly with the 3 fields.

<PurchaseOrder> UDF1 <PurchaseOrder>

<ItemNo> UDF1  <ItemNo>

<Name> UDF1 <Name>

As I never did UDF before, please suggest how to perform mapping.

Regards

Rebecca

Former Member
0 Kudos

Hi Bhaskar ,

Yes I want to use the same UDF for these three mandatory fields.So the input for UDF would be 3 different values for these 3 different mapping and have to use seperatly with the 3 fields.

<PurchaseOrder> UDF1 <PurchaseOrder>

<ItemNo> UDF1  <ItemNo>

<Name> UDF1 <Name>

As I never did UDF before, please suggest how to perform mapping.

Regards

Rebecca

baskar_gopalakrishnan2
Active Contributor
0 Kudos

The answer is so simple. I believe you already activated the UDF logic and using it for PurchaseOrder field. Is that right? If that works, use the same UDF as similar to standard function  (click that UDF fucntion in mapping editor)  and Pass the input as Name to the UDF and map the output of UDF to the target Name field. Similarly you repeat the steps for ItemNo. Amit already explained it.

Example

Source <Name> -> UDF1->< target Name>

Source < ItemNo> --> UDF1 -><ItemNo>

After adding three times same UDF for the above three fields then activate and test.

Former Member
0 Kudos

Hi Bhaskar,

Thanks for making the clear oicture. I actually used the Var1 as <PurchOrder> name itself.

So here comes the whole flip flop.

Well let me try !!!

Tnx a lot

Rebecca

Former Member
0 Kudos

Hi,

To be precise, technically it hardly matters what variable name you are using inside UDF.

In a mapping, UDF will take the input values and put inside ur variable -> So, first input value will be put in first variable (ur variable name can be var1, purchase, XXX etc, but having said that its always advisable to give meaningful generic variable names inside ur UDF).

So the overall essence is you can use the same UDF in as many target fields mapping as u want  which obviously requires same logic.

Thanks

Amit Srivastava

hemant_chahal
Contributor
0 Kudos

Hi Rebecca,

Another approach would be to use equalsS to compare with CONSTANT with no values (Delete the value) followed by "Not"  then use IfWithoutElse. to pass the source value. It will throw error when blank comes.

Please check the attachement "checkBlank.JPG"

Regards

Hemant

gagandeep_batra
Active Contributor
0 Kudos

Hi Rebecca,

Use Exist function as michal said.

F1 -> Exist() ->if true then map F1->F2

other wise not map with F2

F2 is mandatory it will automatically through error.

Regard

Gagandeep

Former Member
0 Kudos

Hi,

>>Requirement is when ever there is blank value in source target field, I have to generate an mapping error in Graphical

To check if there is a balnk value and then throw an exception:

U can use length function and check if the length is greater than zero and then use IfWithoutElse and map the target field.

Thanks

Amit Srivastava

iaki_vila
Active Contributor
0 Kudos

Hi Rebbeca,

I have to generate an mapping error in Graphical

I don't know what do you want exactly, do you need a special xml with the error to response and not to reach the receiver?

I've thought another alternative, this is to use the SAP PI schema validation (For SAP 7.1 and above). You could check this links, may be could be interesting to deal with another point of view:

XML validation step by step: http://scn.sap.com/docs/DOC-17696

http://scn.sap.com/people/shilpa.kchakravarthy/blog/2008/01/17/xml-validation

This Shabarish's blog  with an alternative to SAP PI validation: http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/01/30/xml-xsd-validation--an-alternativ...

Regards.

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

use exist function (in the link you will find eample on how to use ifelse with this function)

http://help.sap.com/saphelp_nw04/helpdata/en/db/83f7b88528424c9113b15d5e0fb516/content.htm

for sending errors with info please have a look at my blog:

http://scn.sap.com/community/pi-and-soa-middleware/blog/2007/04/26/xipi-throwing-generic-exceptions-...

Regards,

Michal Krawczyk