StringIndexOutOfBoundException In UDF in mapping
Hi ,
I have a UDF via which I am taking the input string and for every 132 characters of input string I split in show it in a different line of an idoc.
It is working fine for 2 lines .However when I get 3 lines i.e. anything more then
395 characters I get this error
StringIndexOutOfBoundException
following is the code I am using in the udf.
public void deriveTEXT(String[] a,ResultList result,Container container){
for(int i=0;i<a.length;i++)
int len=a<i>.length();
int variant=132;
int count=len/variant;
int initial=0;
int fin=0;
if(count>=1)
fin=variant;
else
fin=a<i>.length();
for(int j=0;j<count;j++)
result.addValue(a<i>.substring(initial,fin));
initial=fin;
fin=2*fin;
result.addValue(a<i>.substring(initial,a<i>.length()));
if(i<a.length-1)
result.addContextChange();
Kindly help.
Hi ,
Just small change required .
your code
for(int j=0;j<count;j++)
result.addValue(a.substring(initial,fin));
initial=fin;
fin=2*fin;
Change it to
for(int j=0;j<count;j++)
result.addValue(a.substring(initial,fin));
initial=fin;
fin=fin+132;
Thanks ,
Suvarna
Award pts if it helps .
Similar Messages
-
Java Mapping/UDF/ABAP mapping to capture payload
Hi,
could you please provide me Java mapping code samples (or UDF code) to save payloads of a message based on Message ID
i have a synchronous scenario where i have payloads in sxmb_moni for request and response with different message IDs. So pelase let me know how to save those request and response payloads to a file.
it would be great if you provide the stpes to implement and java code samples....if it is possible with ABAP mapping also please let me know te steps.
Best Regards....SARANTry with this code
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
public class PayloadExtractor {
// The MySAP.com system we gonna be using
static final String SID = "SID";
// The repository we will be using
IRepository repository;
JCO.Field msgkeyField;
public PayloadExtractor() {
try {
System.out.println("*** Creating the Pool... ***");
JCO.addClientPool(SID, 10, "001", "user", "pwd", "EN", "host", "00");
repository = JCO.createRepository("RecoverRepository", SID);
} catch (JCO.Exception ex) {
System.out.println("RecoverXI Caught an exception: \n" + ex);
// Retrieves and prints information about the remote system
public void getPayload() {
// A messageID from your XI/PI
String key = "48CD01EB3D27021BE1008000C0A8477D";
final String pipelineID = "CENTRAL";
byte[] msgkey = key.getBytes();
try {
IFunctionTemplate ftemplate = repository.getFunctionTemplate("SXMB_READ_MESSAGE_VERSION_RAW");
if (ftemplate != null) {
System.out.println("*** Creating client and function... ***");
JCO.Function function = ftemplate.getFunction();
JCO.Client client = JCO.getClient(SID);
JCO.Structure struct = function.getImportParameterList().getStructure("MESSAGEKEY");
struct.setValue(key, "MSGID");
struct.setValue(pipelineID, "PID");
// SELECTION must be like this!
function.getImportParameterList().getField("SELECTION").setValue("2");
// This is the msg version number, where 000 is the first (Inbound); the last can be caught from the function output (see below).
// Setting this strongly depends on what you want to get: basically before or after the mapping...
function.getImportParameterList().getField("VERSION_REQUEST").setValue("000");
System.out.println("*** Calling... ***");
client.execute(function);
JCO.Table tb = function.getExportParameterList().getTable("MESSAGEPAYLOAD");
if (tb.getNumRows() > 0) {
// There could be multiple payloads (even if usually it's only one)
do {
String plstr = new String(tb.getField("PAYLOAD").getByteArray());
System.out.println(
"*** Payload found *** " + tb.getField("NAME").getString() + " *** BEGIN ***");
System.out.println(
"Message Last Version: "
+ function.getExportParameterList().getField("MAXVERSION").getString());
System.out.println(plstr);
System.out.println(
"*** Payload found *** " + tb.getField("NAME").getString() + " *** END ***");
} while (tb.nextRow());
} else {
System.out.println("*** No payload found! ***");
// Release the client into the pool
JCO.releaseClient(client);
} else {
System.out.println("Function SXMB_READ_MESSAGE_VERSION_RAW not found in backend system.");
} catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
protected void cleanUp() {
System.out.println("*** Cleaning... ***");
JCO.removeClientPool(SID);
public static void main(String[] argv) {
PayloadExtractor e = new PayloadExtractor();
e.getPayload();
e.cleanUp();
-Madhu -
Cannot resovle the Symbol error in UDF - Java mapping - RFC Lookup ?
Hi Friends ,
We are working on Java mapping - UDF for RFC Lookup . It is giving the Cannot resolve Symbol for all imported archive java class files even if we give again all imported files in import section of UDF we are still getting the same cannot resolve error .
We are using SP 12 of XI 3.0 . What could be the reason ?
Thanks.,
V.RangarajanHi,
Can you try to open imported archive in IR and check if the path(folder structure like com.abc.xyz.etc) for classes is same as in import statement in UDF.Since we had experienced the same problem.
Thanks.
Regards,
Shweta -
BAPI call via UDF in mapping - error handling/stopping processing
Hi,
We are calling a BAPI in an ECC system from a UDF in message mapping. The BAPI then calls other BAPIs to perform translations and validations on the message data. An error could occur during a translation (for example), and an error flag would be passed back to the UDF (the actual error is persisted and handled in ECC). What should be done in the UDF to stop further processing of the message?
Latest PI and ECC releases and service packs.
Thanks in advance,
BrianBhavesh,
Thanks for the replay.
You guys are scaring me a little....I've reviewed a bunch of blogs, threads and docs about the RFC API...such as Alessandro's SAP XI Lookup API: the Killer .../3404 and the "Mapping Lookups - RFC API" document. Why would we have something like an RFC API available via a UDF if we can't react to an error should it occur?? In my case, all I want to do is "cancel" the message, or perhaps cause a controlled failure in the mapping so that the message doesn't get to the next step (load into ECC).
What happens in Alessandro's process if an error is caught (trace.addWarning.....)? I see that null is returned, but how does that affect the mapping process?
I appreciate any help
Brian -
UDF or Mapping for removing more items
Hi
I'm in a need to implement a data validation using UDF or Graphical Mapping
File has the data like ONE header record (5 fileds) and ONE item record (8 fields) as follows
header:field1field2 field3 field4 field5
item:field1field2 field3 field4 field5 field6 field7 field8
header:field1field2 field3 field4 field5
item:field1field2 field3 field4 field5 field6 field7 field8
header:field1field2 field3 field4 field5
item:field1field2 field3 field4 field5 field6 field7 field8
and so on.
Here my requirement is one header should have only one item. Sometimes either header or items are repeating more than one time .. in that case lastest header or item should be updated in target fields.
To say clearly ... one header and one item & one header and one item and so on to be updated.
In case any header has two items then first item to be deleted and second item to be updated.
Kindly advise me how to go about this requirement.
Thanks.Do the mapping as
Direct assignment of Source header to Target Header and same for fields inside the Header.
create a UDF (choose context).very simple UDF with a single statement.
result.addValue(a[a.length-1]);
Item Node mapping and Its Fields
Item------>UDF------>Item(Target)
field1(Change the context to Header)------->UDF----->field1(under Target Item)
Do the same mapping for remaining fields Under Item as you do for field1
I have tested the above UDF and the mapping..It is working according to your requirement. -
Steps for creating UDF in Mapping
Can any one help me by giving steps that should be followed in creating UDF.the UDF should be used for mapping.
Rupesh,
Refer to url http://help.sap.com/saphelp_nw70/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
Also here is some sample code for different scenarios
<b>Example 1</b>
This example copies the value of the Dynamic Configuration variable DCJMSCorrelationID into the message field CORRELID
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get
(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create
("http://sap.com/xi/XI/System/JMS","DCJMSCorreleationID");
String Corrid = conf.get(key);
return Corrid;
<b>Example 2</b>
This example prefills the input with zeros (if required)
NumberFormat f = new DecimalFormat("0000000000");
if(a.equals("") || a.equals(null))
return a;
else
return f.format(Integer.parseInt(a));
<b>Example 3</b>
This example checks and if the input string is null returns a message
if(a.equals("") || a.equals(null))
a = "No query data returned";
return a;
Regards,
Mike -
I have the following requirement.
At the source side i have:
Employee 1..n Employee 1..n
Type 1..1 A
Name 1..1 abc
Id 1..1 123
If my Type is 'A' then i should get the following output else these fields should be blank
At the target side i have
Employee Employee
Details 1..n Details
Data abc
Details
123
Its something like the node 'Details' should repeat twice with the elements under it if the Type is 'A'.
I have tried using a UDF but 'Details' is repeating as a field and not as a node with 'Data' under it.Hi Jayalaxmi,
Can you post ur source structure and input file data here.In UDF, u should have two for 'for' loops and according to ur requirement u should change the logic.
reply back with source , target str and iput file data.
Regards,
srinivas -
Java mapping for Dynamic File name: stuctures?
Hi,
Scenario: Sender AS2 adapter --> PI --> Receiver File (NFS) Adapter. Just a file pass through, no mapping
Requirement: Want to have the receiver file name as C1.yymmdd.C2 where C1 and C2 are contants and yymmdd is current date.
I was told in sdn forum that I have to write java mapping and provided the sample code also. However, I am not sure how and where to use that sample code. Could you please help on following questions:
1) What is the source and target data type structures for mapping?
2) Where do I develop java mapping? How do I import to PI?
3) How do I get access to SAP Netweaver Developer Studio? Can I download it to my laptop? or if I dont have access, can I use any other tool to develop? ( NetBeans, Eclipse ??) and how?
4) what are the files and libraries that we need to import to java mapping? (e.g., Import aii_map_api.jar library)
5) How to generate .jar file?
If someone has already developed java mapping (.jar file) ready to import into PI, please provide the same.
Thanks in advance
- Riya PatilHi Sarvesh,
Is this UDF work if I dont select ASMP on sender side? (We tested selecting ASMP on both sender & receiver file adapters, it works fine and it works without UDF also).
In my requirement I have to use sender AS2 adpter, please confirm if I can use this UDF without selecting ASMP on sender side.
I have done the following tests:
Test-1) Select ASMP with 'File Name' on both sender and receiver file adapters without any mapping (UDF)
It works great. No UDF or mapping required. It is just pass through of file having the receiver file name same as in sender channel.
Test-2) Select ASMP with 'File Name', only on receiver file adapter without any mapping (UDF)
It is obvious, it doesn't work. I am getting the following error:
Could not process due to error: com.sap.aii.adapter.file.configuration.DynamicConfigurationException: The Adapter Message Property 'FileName' was configured as mandatory element, but there is no 'DynamicConfiguration' element in the XI Message header
Test-3) Select ASMP with 'File Name', only on receiver file adapter with mapping (using DynamicConfiguratio UDF)
We are getting the following error message in SXMB_MONI:
Fatal Error: com.sap.engine.lib.xml.parser.Parser~
<SAP:Stack>com.sap.aii.utilxi.misc.api.BaseRuntimeException thrown during application mapping com/sap/xi/tf/_MM_Filename_: Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:Stack>
Here is the code we have in UDF:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String SourceFileName = "C1." + a + ".C2";
conf.put(key, SourceFileName);
return " ";
So looks like UDF is not working and it is failing in mapping. If I could make it work, I think there is good chance that I can see DynamicConfiguration under SOAP Header, which what required for the error we see in out test-2.
Can someone please help me to straighten this UDF and make it work.
Thanks in advance.
- Riya Patil -
Problem in mapping-BAPI to file.
Hi all,
I am working on an bapi to file scenerio.My requirement is 2 files need to created in the target ,
First file has the payload and its name(filename) needs to hav message id.
Second file is a catalog file which only holds the name of the first file(Howmany ever file are reaching target,this file wil hav names of all those files.).
I have used multi mapping wherein for the first structure i hav done dynamic configuration to generate filename and its wrking fine.
For the second stucture (has only 1 field for passing filename)i wrote following UDF and mapped it
String constant;
java.util.Map map;
map = container.getTransformationParameters();
constant = (String) map.get(StreamTransformationConstants.MESSAGE_ID);
String fileName = constant + ".txt";
return constant;
but now output of the second file is empty ie the filenames of the first file is not present in it.
Please help as its very urget.heyy...thanks for that, but that was a typing mistake..problem is elsewhere, i had tested by mapping that field to a constant, even then no value was present in output.
My structure looks like below.
Messages
Message1
mt_abcd
. field1
field2
field3
Message2
mt_abcd2
filename
Message1 and message2 are 2 separate files in output.
Message1's output is correctly generated.But for message2 no output atall. -
Message Mapping - Node's sub-levels navigation
Hi all,
How should I code in order to navigate between different levels of a given node of the source structure?
example:
Main
Struct_11
Struct1101
Field_1101_A
Field_1101_B
Struct1102
Field_1102_A
Field_1102_B
Struct_22
Struct2201
Field_2201_A
Field_2201_B
Struct2202
Field_2202_A
Field_2202_B
In the sample above, how should I do to map the node Struct_11 and, within a UDF (or some other way, but I only imagine through a Java UDF), access and validate Struct1101-Field_1101_A, or Struct1102-Field_1102_B, etc?
If someone could provide me with a sample code, it'd help me.
Thank you!Mark, tks. It helped.
I could do all that I needed withing the XML working as a text.
The only problem now is that, the target structure must be built according to the source cardinality (N..N).
In the sample bellow, see that in the source structure, the Struct_11 repeat 3 times. In the 1st and 3rd, it contains the substructure Struct1101. I have to check if Struct1101 exists, if so, I have to take the Field_1101_A and validate if it's equal to WE. If yes, then the correspondent Field_1101_B has to be sent to target <row> field.
In the 2nd occurrence, there NO Struct1101, so the UDF returns #void#.
UDF to map Struct_11:
int v_pos1, v_pos2, v_start = 0;
String v_Struct1101 = "Struct1101";
String v_WE = "WE";
String v_FieldA = "<Field_1101_A>WE</Field_1101_A>";
String v_FieldB = "";
v_pos1 = Item.indexOf(v_Struct1101);
if(v_pos1 >= 0){
v_pos2 = Item.indexOf(v_FieldA);
v_start = v_pos2 + 32;
v_FieldB = Item.substring(v_start, v_start+10);
}else{
v_FieldB = "#void#";
return v_FieldB;
Source
<Main>
<Struct_11>
<Struct1101>
<Field_1101_A>WE</Field_1101_A>
<Field_1101_B>110</Field_1101_B>
</Struct1101>
<Struct1102>
<Field_1102_A>ZS</Field_1102_A>
<Field_1102_B>222</Field_1102_B>
</Struct1102>
</Struct_11>
<Struct_11>
<Struct1102>
<Field_1102_A>ZS</Field_1102_A>
<Field_1102_B>222</Field_1102_B>
</Struct1102>
</Struct_11>
<Struct_11>
<Struct1101>
<Field_1101_A>WE</Field_1101_A>
<Field_1101_B>112</Field_1101_B>
</Struct1101>
<Struct1102>
<Field_1102_A>ZS</Field_1102_A>
<Field_1102_B>222</Field_1102_B>
</Struct1102>
</Struct_11>
<Struct_22>
<Struct2201>
</Field_2201_A>
</Field_2201_B>
<Struct2202>
</Field_2202_A>
</Field_2202_B>
</Main>
Target
<result>
<row>110</row></result>
<result>
<row>#void#</row></result>
<result> <row>112</row></result>
<result> is mapped to <Struct_11>, so that for each <Struct_11>, one <result> is created.
I've insert this sample payload and in the Definition tab, Display Queue option shows me the right result:
110
#void#
112
However, during the MM test, it throws error:
Cannot create target element /ns0:MT_TARGET/result[2]/row. 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
Any clue?
Thank you !
Edited by: rvsilvax on Sep 14, 2011 9:00 PM -
Renaming a File to File without Mapping
Hi All,
I am having a scenario where there is a text file transfer without any conversion i.e. basically a file to file scenario with no mapping. The only requirement is to rename source file which has .csv extn to .dat. For instance if the sender file is XYZ.csv, the file at the receiver side should be XYZ.dat.
As there is no mapping, I cannot use Dynamic Configuration UDF in mapping. One other option is to write an adapter module which seems too bulky for this small requirement. So as of now I am looking at any option which I can use without having to create IR objects or do text ->XML -> text conversion.
I hope experts here can help in resolving the current problem and/or give some pointers
Best Regards,
Pratik> OS Command in File Receiver Channel: mv %f `basename %f .csv`.dat
I think you should use the full path address, the same as you used for the folder.
You can also use an adapter module, it is just a couple of lines:
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)
throws ModuleException{
try {
Message msg = (Message) inputModuleData.getPrincipalData();
Payload payload = msg.getDocument();
String fileName = msg.getMessageProperty("http://sap.com/xi/XI/System/File","FileName");
// do something with the filename
msg.setMessageProperty("http://sap.com/xi/XI/System/File","FileName", fileName);
inputModuleData.setPrincipalData(msg);
} catch (Exception e) {
throw new ModuleException(e);
return inputModuleData; -
Retrieving Message Id in to Mapping
Hi,
How to retrive the message id in to message mapping.
Thanks,
Kiran.Hi Kiran,
How to retrive the message id in to message mapping.
This can be easily achived by using a simple UDF and map it with message ID filed in target side.
Use the same piece of code given above.
Regards,
Pinangshuk. -
Hello,
I've a interface RFC to File (.txt).
The name file is dynamic. In message mapping we have a target field only for file name (i haven't can mapiing with other fields because all target fields are mapping with source fields).
My problem is file name appears in content of file and i don't want this.
What can i do?
Thanks very much.Hi dear,
Use the Dynamic config. method because I also faced this prob in variable substitution method.
Use the UDF in mapping as shown here.
public String Set_Output_File_Name(String var_Filename, String var_Directory, Container container) throws StreamTransformationException{
DynamicConfiguration conf = (DynamicConfiguration) container
.getTransformationParameters()
.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
conf.put(key, var_Filename);
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
conf.put(key1, var_Directory);
return "TRUE";
Here var_Filename = Pass Filename from the source field
var_Directory = Pass Directory name from the source field
In Mapping:-
output of this UDF is to mapped with one of the Target field say(TEMP) with occurce 0..1.
since this UDF always return TRUE in the output so use the Graphical function 'equalsS' which compares the output of this UDF with some value like '1234'. and then use the IF--without Else Graphical function and then map with the TEMP so it never be generated in the target message.
Set the Adapter specific message attribute property for the File receiver adapter.
Regards
Jagesh -
Message Mapping on the Target side
Hi
I am working on Proxy to SOAP in PI 7.1, and have node which is defined on the target side as Unbounded (table)
Here is the structure of the table that has been defined on the target side,
CodeList - 0- Unbounded (Table)
Id XSD Id
CodeList Name String
CodeList Version String
CodeListOwnerCd String
Source System(ECC) is not sending any values and the values which needs to be assigned to the above structure are fixed on the target side,
how can I assign multiple values to the Code List table
Ex CodelistName Should contain ClaimsPartyRoleCdList, PolicyTypeCdLis , PaymentTypeCdList
Please let me know how can I assign Multiple values to the target side table
Thanks
PRHey
You can easily do this via advanced UDF.
Map the root node to the below UDF.Make sure that you have set the Cache as Queue for this.There will be no input values to this UDF
//write your code here
result.addValue(" ");
result.addValue(" ");
Map the underlying Nodes to the below UDF.Make sure that you have set the Cache as Context for this.There will be no input values to this UDF
//write your code here
result.addValue("3");
result.addContextChange();
result.addValue("4");
result.addContextChange();
I was able to acheieve the below XML by using the above two
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MI_Multiple xmlns:ns0="http://fxp.com">
<Record>
<First>3</First>
<Second>3</Second>
</Record>
<Record>
<First>4</First>
<Second>4</Second>
</Record>
</ns0:MI_Multiple>
Hope this works for you.
Thanks
Aamir -
Capturing Outbound Interface (In UDF)
Hi,
I have designed a Outbound Interface:
<?xml version="1.0" encoding="UTF-8"?>
<MT_DMS_FINAL>
<Record>
<Row>
<FirstName/>
</Row>
</Record>
</MT_DMS_FINAL>
Now i write a Adapter Module to get the File name when the Sender File Adapter picks up the file iot reads the filename with the help of the Adapter Module and adds a element name called Filename to the outbound interface when i see it in the SXMB_MONI.
<MT_DMS_FINAL>
<Record>
<Row>
<FirstName/>
</Row>
</Record>
<FileName>test.xml</FileName> // This element has to be captured
</MT_DMS_FINAL>
Now how to get the element to be used in the Mapping (UDF) i mean .kindly help how to capture the entire xml and write the code to get the "FileName" element in specific,.
Advice
regards
SriniHi Venkateswarlu,
For capturing the file name, Adapter Modules are not required. You can directly access it in the mapping using the UDF in the Message mapping using Dynamic Configuration. Use the following UDF. Map it directly to the output field in which you want the filename.
Code:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
return ourSourceFileName;
You can follow this blog:
/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14
Regards,
Sanjeev.
Maybe you are looking for
-
Just recently whenever I use Preview and annotate my documents I get this weird triangular shade on the word I highlighted instead of the usual blocked look. How do I change this back?? Here is how it looks: http://i248.photobucket.com/albums/gg175/m
-
Hey there, my program is finished and its the below one. Can u just make sure it all looks good and can u add a simple procedure to make sure that the user has types the correct data. For example in the number of cable and jobs they type numbers and
-
1. OK, I'm stumped. How can I accomplish this simple task. I refer to adding the "dots" one normally adds between the section entries on the left and the page number reference on the right. 2. How can I keep references to books italicized in the TOC
-
Some albums revert to alphabetical listing, how can I stop th
For some reason the tracks on my Zen Micro revert to being listed alphabetically even though on the track details the track number will be there. It's really frustrating, apart from putting 0,02,03 before each track name how can I ensure that the alb
-
Using an external css in Flex 4
I'm using the Flex 4 beta and the ability to load an external css seems to be broken. Running the code below shows no styling at all. Have I missed something? components.MainPanel.as: package components { import flash.events.Event; import flash.net.U