UDF mapping to split string
Hi,
I'm starting with UDF functions.
How can i split source string at '-' and take first part into target.
ex : 123-456 -> 123
Easy points for those who know...
Thanks in advance,
Laurent.
Hi Laurent,
Use an Advanced User Defined Function. Adavnced user Defined Functions can return Multiple values.
UDF1:
1.Takes renmark as input.
2.Does the split on the basis of ;
3. Splits each split of step 2 on the basis of /
4. Add the output of step 3 to the resultlist with a context change.
UDF2:
1.Takes renmark as input.
2.Does the split on the basis of ;
3. Splits each split of step 2 on the basis of /
4. Add the output of step 3 to the resultlist with a context change.
For Advanced UDF's,
http://help.sap.com/saphelp_nw04/helpdata/en/f8/2857cbc374da48993c8eb7d3c8c87a/content.htm.
You can try this piece of code in your mapping...
You need 3 UDFs each for <detail>, <field1>,<field2>
UDF1: For <detail>
String arr[] = a[0].split(";");
for (int i=0;i<arr.length;i++)
result.addValue(arr);
UDF2: For ><field1>
String str = a[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length;i++)
str1 = sarr1;
String sarr2[] = str1.split("/");
for (int j=0; j><sarr2.length;j++){
result.addValue(sarr2[j]);
j++;
result.addContextChange();
UDF2: For ><field2>
String str = a[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length;i++)
str1 = sarr1;
String sarr2[] = str1.split("/");
for (int j=0; j><sarr2.length;j++){
j++;
result.addValue(sarr2[j]);
result.addContextChange();
..All these functions requires one input <remark>
Hope this helps you ..
*Reward with points if helpful*
Regards,
Shibani
Similar Messages
-
Mapping - Split string separated by value ;
Hi,
I have a mapping where 4 source values makes the key for 1 target value.
In the target string (result after value mapping) i want to get the last value in the string "TargetValue1.
<i>SourceValue1;SourceValue2;SourceValue3;SourceValue4;TargetValue1</i>
Can this be done without UDF? If not how should the UDF look like?
Best Regards
/Claes
Message was edited by:
Claes WidestadhHi,
Yes I have concatenated 4 source values into one string to use them as key in a value mapping to get the target value. The result from the value mapping is a string with the 4 source value + the target value. What I want to do now after the value mapping is to spit this string to get only the target value.
The string looks like this
Source sting
example 1) CC;-;ADJ;fre;
example 2) CR;+;ADJH;TD;
Target string:
example 1) CC;-;ADJ;fre;<b>985</b>
example 2) CR;+;ADJH;TD;<b>553</b>
It is the value 985 or 553 that i want to map into the target field. The position for the target value (985, 553) is not a fixed position because of that the length of the source values can vary (see example obove). That means that I cant use the substring right?
/Claes
Message was edited by:
Claes Widestadh
null
null -
hai friends
iam created one UDF function for splitting multiple storage locations in to create deffarent segments based on ,(cama)
test mapping working good .
but at runtime the mapping is not working
it is giving runtime error at mapping convertion .
like this
com.sap.aii.utilxi.misc.api.BaseRuntimeException was thrown: RuntimeException in Message-Mapping transformatio
pls help me what is the problem.
with regards
srikanth vipparla
Edited by: srikanth vipparla on Apr 24, 2008 3:44 PMno iam not using the same message in testing
it is comming from mdm system.
and my udf code is like this .
String testString = a[0];
StringTokenizer st = new StringTokenizer(testString,",");
while(st.hasMoreTokens())
result.addValue(st.nextToken());
and way it is giving error pls help me .
with regards
srikanth vipparla
Edited by: srikanth vipparla on Apr 24, 2008 3:51 PM
Edited by: srikanth vipparla on Apr 24, 2008 3:52 PM -
HELP URGENT:; Splitting strings in servlets
hi ...
I am trying to access the below servlet from another servlet in iplanet . I have to access a file and arrange the '|' delimited data in the file in a table format like in html ...
I have used my own function inside the servlets which splits a string based on character ...But I always get
Internal error: exception thrown from the servlet service function (uri=/servlet/ReportsDataServlet): java.lang.NullPointerException, Stack: java.lang.NullPointerException
at ReportsDataServlet.split(ReportsDataServlet.java:82)
at ReportsDataServlet.doPost(ReportsDataServlet.java:56)
at ReportsDataServlet.doGet(ReportsDataServlet.java:14)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:919)
at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:483)
The sample code is shown below....I get the same error when i tries with stringokenizer as well....Pls help me fix this.....
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, Se
rvletException
response.setContentType("text/html");
PrintWriter out = response.getWriter();
cont=getServletContext();
out.println("<html><head><title>Reports Data</title></head><body bgcolor=DBD0E2>");
String repType = request.getParameter("Rep");
String mon = request.getParameter("month");
String day = request.getParameter("day");
String year = request.getParameter("year");
String repName = repType+"."+mon+"-"+day+"-"+year+".txt";
BufferedReader in = new BufferedReader( new FileReader("/home/lnayar/baais/xmlServlet/"+rep
Name));
String st;
st = in.readLine();
cont.log(st);
int c =0;
out.println("<table border=\"3\" cellpadding=\"0\" cellspacing=\"0\" width=\"800\"><tr><td>L
ATA</td><td>WC CLLI</td><td>WC NAME</td><td>ADSL_LOCATION</td><td>ATM FLAG</td><td>ATM RELIEF DATE</td><t
d>FRAME FLAG</td><td>FRAME RELIEF DATE</td><td>GOLD FLAG</td><td>GOLD RELIEF DATE</td><td>OVERLAY INDICAT
OR</td><td>COUNT</td></tr>");
while (st != null)
c++;
st = in.readLine();
StringTokenizer stt = new StringTokenizer(st);
out.println("<tr>");
while (stt.hasMoreTokens())
//out.println("<td>"+stt.nextToken("|")+"</td>");
out.println("<td>hello</td>");
out.println("</tr>");
while (st != null)
c++;
st = in.readLine();
out.println("<tr>");
Enumeration en = split(st,"|");
while(en.hasMoreElements())
out.println("<td>"+en.nextElement()+"</td>");
out.println("</tr>");
cont.log("out while");
out.println("</table>");
out.println("</body></html>");
public Enumeration split (String str, String delim)
Vector v = new Vector();
int pos_1;
int pos_2;
//Set initial delimiter positions...
pos_1 = 0;
pos_2 = 0;
//Start chopping off bits from the string
//until left boundary reaches the length of string
while ( pos_1 <= str.length() )
pos_2 = str.indexOf(delim, pos_1);
if ( pos_2 < 0 )
pos_2 = str.length();
String sub = str.substring (pos_1, pos_2);
pos_1 = pos_2 + 1;
v.addElement(sub);
return v.elements();
d deeply appreciate if soeone could take a look at the code and tell me exactly where i am going wrong ..... Its URGENT ...
Thx
klvBut there is the while statement which filters null
values..Which is useless in your case, because you proceed to change the value of st to something else which you don't check for null.
At any rate, what you have to do is this:
1. Look at the stack trace to find the line number where the error occurs.
2. Look at that line in your code.
3. Look at each object variable in that line. Find out how it became null and fix that. -
Problem with Mulit Mapping/Message Split
Hi,
I am a newbie to XI trying to set up a file2file scenario with multi-mapping/message splitting without BPM.
System is XI 3.0 SP14
Scenario is:
read an XML-File and multiply it and write 2 XML-files using the File adaptor.
For reference I used "multimapping without BPM".
- setting occurancy of Message types to unbounded in both Message Mapping and Interface Mapping.
- using the RB_Split button
- setting up one business service containing 2 message interfaces and 2 communication channels for output.
Designing and Konfiguring worked fine.
File is read but no file is written.
XML-Moni tells me "Mapping did not create Messages"
I did extensive studies in sap.help, forum and various blogs. Also to verify Messagetypes and Kommunication channels I set up similar file2file scenario without splitting. Nothing really helped.
Any clues?Hi again,
very efficient method to test XML-source file. - Thanks.
Unfortunately it did not solve my problem.
Again: "Split mapping did not create messages"
Below you can find a part of the trace created when processing this message:
<Trace level="3" type="T">Multi mapping required.</Trace>
<Trace level="3" type="T">Creating Java mapping com/sap/xi/tf/_MM_data_duplic_async_.</Trace>
<Trace level="3" type="T">Load ac6179b0-a92e-11da-be15-e51f0a000472, http://MyTutorial/SHeinz05, -1, com/sap/xi/tf/_MM_data_duplic_async_.class.</Trace>
<Trace level="3" type="T">Search com/sap/xi/tf/_MM_data_duplic_async_.class (http://MyTutorial/SHeinz05, -1) in swcv ac6179b0-a92e-11da-be15-e51f0a000472.</Trace>
<Trace level="3" type="T">Loaded class com.sap.xi.tf._MM_data_duplic_async_</Trace>
<Trace level="2" type="T">Call method execute of the application Java mapping com.sap.xi.tf._MM_data_duplic_async_</Trace>
<Trace level="2" type="T">Java mapping com/sap/xi/tf/_MM_data_duplic_async_ completed. (executeStep() of com.sap.xi.tf._MM_data_duplic_async_</Trace>
<Trace level="3" type="T">Nachrichtentyp 1 Anzahl der Nachrichten 0</Trace>
<Trace level="3" type="T">Nachrichtentyp 2 Anzahl der Nachrichten 0</Trace>
<Trace level="1" type="E">CL_XMS_PLSRV_MAPPING~ENTER_PLSRV</Trace>
</Trace>
- <Trace level="1" type="B" name="CL_XMS_MAIN-WRITE_MESSAGE_LOG_TO_PERSIST">
<Trace level="3" type="T">Persisting message after plsrv call</Trace>
<Trace level="3" type="T">Message-Version = 005</Trace>
<Trace level="3" type="T">Message version 005</Trace>
<Trace level="3" type="T">Pipeline CENTRAL</Trace>
</Trace>
<Trace level="3" type="System_Error">Error exception return from pipeline processing!</Trace>
<Trace level="1" type="B" name="CL_XMS_MAIN-WRITE_MESSAGE_TO_PERSIST" />
- <!-- ************************************
-->
<Trace level="3" type="T">Persisting message Status = 014</Trace>
<Trace level="3" type="T">Message version 006</Trace>
<Trace level="3" type="T">Pipeline CENTRAL</Trace>
</SAP:Trace>
Test of MM and IM is always successful.
Any clues? -
Split string function in oracle ...
Hello,
Little question, is there any split string function available in Oracle.
SQL> select more_info
2 from dba_advisor_findings;
MORE_INFO
Allocated Space:4390912: Used Space:4237403: Reclaimable Space :153509:
select more_info as Allocated_Space,
more_info as Used_Space,
more_info as Reclaimable_Space
from dba_advisor_findings
Allocated_Space Used_Space Reclaimable_Space
4390912 4237403 153509
Thanks,
Manish GuptaI explored more on SUBSTR and INSTR string functions ... and below is the solution
select substr(more_info,instr(more_info,':',1,1)+1,instr(more_info,':',1,2)-instr(more_info,':',1,1)-1) as "Allocated_Space",
substr(more_info,instr(more_info,':',1,3)+1,instr(more_info,':',1,4)-instr(more_info,':',1,3)-1) as "Used_Space",
substr(more_info,instr(more_info,':',1,5)+1,instr(more_info,':',1,6)-instr(more_info,':',1,5)-1) as "Reclaimable_Space"
from dba_advisor_findings;
Allocated_Space
Used_Space
Reclaimable_Space
4390912
4237403
153509
Thanks... -
Hi All,
Is there a FM available which can split string based on seprator e.g ABC XYZ needs to be separated using space delimeter.
Thanks!
Prakash D. Naikif you dont know the number of occurrences of the delimeter you can use the following code.
data: source type string ,
target type standard table of string .
source = 'This is for test.' .
split source at ' ' into table target .
Regards
Raja
PS Kindly post ABAP related questions at
ABAP Development -
ImmutableArrayList default for Map Long, Collection String
Hi,
There are a few topics out there about the com.tangosol.util.ImmutableArrayList default, but the actual fix still seems a bit unclear to me.
In my example there is a Map with each entry containing a Collection of Strings (i.e. Map<Long, Collection<String>>). Objects will be placed in the Map as ArrayLists, but they seem to come out as ImmutableArrayLists.
The Oracle site mentions wrapping the Collection (http://extranet.tangosol.com/display/COH35UG/Best+Practices+for+Coherence+Extend).
There is another Oracle forum post that suggests using more general classes (List instead of ArrayList). (Serialize an ArrayList<ArrayList>
It seems like you have to make a new collection anytime you wish to reserialize the object. Is there a better way?
Thanks for taking the time,
MikeThis problem comes up for us when persisting documents. We are torn between saving as XML vice saving a normalized object model or something else: like your database solution.
Since you have already designed the database, then you can reverse out the TopLink class from that database design in the mapping workbench. You then have to perform a transform in the middle tier to extract your business model.
Alternatively, if you want your business model to map via ORM to the data model, then you would have a database design that more closely maps the business model design then you get three tables:
TopLevel
Integer primaryKey; //This table may just have the PK
SetMap theSets;
SetMap
TopLevel parent; //FK to the Parent table
Long primaryKey; //Assumes the Longs are globally unique. If not, the PK will include the parent
SetList theSet;
SetList
SepMap parent; //Part of PK. This can get complicated if the PK migrates all the way from TopLevel. We insert a surrogate key at this point.
String setMember; //Rest of PK
The database constraints ensure that the SetList is unique. The equivalent string may exist in different SetMaps, but may not be duplicated for a particular parent. -
Split String at delimiter into table.
Hi Experts,
I have a requirement wherein i need to split aaaa#bbbbbbbbbbbb#ccc#dddddddddddddddddddddd#e# into internal table as below:
Header 1
Header 2
1
aaaa
2
bbbbbbbbbbbb
3
ccc
4
dddddddddddddddddddddd
5
e
how can this be done.
Thanks & Regards,
AnilHi Ashok,
split <string> at '#' into table it. -Doesn't work
split <string> at SPACE into table it. - Works
But same statement with '#' is not working.
Feeling strange.
Thanks,
Anil -
HI,
How to Split String into two parts at delimiterHI,
REPORT ZSTRING.
DATA: LENGTH TYPE I,
REMAINING_LENGTH TYPE I ,
NEXT_POINTER TYPE I ,
FIRST_HALF(20) TYPE C ,
SECOND_HALF(20) TYPE C ,
TEMP TYPE I .
PARAMETER: WORD(35) TYPE C . "INPUT WORD
START-OF-SELECTION.
LENGTH = STRLEN( WORD ). "Length of the input String
SEARCH WORD FOR '/'.
IF SY-SUBRC = 0 .
IF SY-FDPOS > 0.
MOVE WORD+0(SY-FDPOS) TO FIRST_HALF.
ENDIF.
TEMP = SY-FDPOS + 1.
IF TEMP <> LENGTH.
NEXT_POINTER = SY-FDPOS + 1.
REMAINING_LENGTH = ( LENGTH - SY-FDPOS ) - 1.
MOVE WORD+NEXT_POINTER(REMAINING_LENGTH) TO SECOND_HALF.
ENDIF.
ENDIF.
WRITE:/'Input String:', WORD .
WRITE:/'First Half:', FIRST_HALF.
WRITE:/'Second Half:', SECOND_HALF.
*-- End of Program
Reward Points if found helpfull..
Cheers,
Chandra Sekhar. -
Function module to split strings
Hi,
I have a string value ' DBTABLE-FIELDNAME'. I need to split this into 2 strings - The first one is the database table name and the second one is the fieldname. So, the character '-' is the point where the split needs to be done. How can this be achieved. Any FM that I could use?
Thanks for your help!
Regards,
Divyaman Singh RawatUse FM 'STRING_SPLIT'
REPORT ZEXAMPLE.
DATA: V_HEAD(10), V_TAIL(10).
PARAMETERS: P_STR(20),
P_DEM.
CALL FUNCTION 'STRING_SPLIT'
EXPORTING
DELIMITER = P_DEM
STRING = P_STR
IMPORTING
HEAD = V_HEAD
TAIL = V_TAIL
EXCEPTIONS
NOT_FOUND = 1
NOT_VALID = 2
TOO_LONG = 3
TOO_SMALL = 4
OTHERS = 5.
IF SY-SUBRC EQ 0.
WRITE:/ 'HEAD:', V_HEAD,
/ 'TAIL:', V_TAIL.
ELSE.
WRITE:/ 'ERROR SPLITTING STRING'.
ENDIF.
Regards,
Joy. -
Split string into two based on end of word and max length
I have the following procedure, which is passed a comma separated string as it input, and it has to split it into two, and the split has to occur at the end of a word, and the first split part can't be more than 15 in length.
Is there an more efficient way of achieving this? I have a loop in my main code that calls this procedure and in effect a nested loop has been created here.
e.g. Hello, everyone, welcome, to, split, string' would be split into 'Hello' and 'everyone, welcome, to, split, string'
create or replace procedure split_str
(pi_str in varchar2,
po_str1 out nocopy varchar2,
po_str2 out nocopy varchar2) is
i number;
begin
if (len(pi_str) <= 15) then
po_str1 := pi_str;
po_str2 := NULL;
else
i := 1;
loop
exit when len(SUBSTR(pi_str, 1 ,INSTR(pi_str, ',', 1, i)-1)) > 15;
po_str1 := SUBSTR(pi_str, 1 ,INSTR(pi_str, ',', 1, i)-1);
po_str2 := SUBSTR(pi_str, INSTR(pi_str, ',', 1, i)+2);
i := i+1;
end loop;
end if;
end split_str;You want to find the last space character before the 15th character.
x := INSTR ( SUBSTR ( pi_str, 1, 15) , ' ' , -1)Then the first string is SUBSTR(pi_str,1,x) and the second string is SUBSTR(pi_str,x+1) -
Hi All,
Hoping you are able to help.
I have a table of approx 16 items that I need to split,
EG:
CUSTOMER ACCEPTANCE - HAS BEEN DECLINED - DO NOT APPLY TO ACCOUNT
CUSTOMER ACCEPTANCE - HAS BEEN ACCEPTED - APPLY TO ACCOUNT
CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED - RAISED IN PORTAL
ESCALATION - RAISED - PENDING
ESCALATION - NOT RAISED - STILL TO BE PROCESSED
I need to Keep the first two sections, eg CUSTOMER ACCEPTANCE - HAS BEEN DECLINED in one column, and split off the remaining, eg DO NOT APPLY TO ACCOUNT into a new TEMP table to insert as a column into an existing table.
With little SQL experience, I am having difficulties as they are all of different lengths / criteria etc. Some have 3 hyphens whilst others have 4+
Is anyone able to help point me in the right direction with this request? I will be greatly appreciated.
Kind Regards,
BTMMPIf you're trying to do this all in a SQL query or stored procedure, then you'll probably get better results on the SQL Server forums. However, if you're working with a PowerShell or VBScript that's doing the work, you're in the right place.
Here's one example of how you could do what you're describing. By the way, what do you want to do with the string "CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED - RAISED IN PORTAL"? Should that be split into "CUSTOMER ACCEPTANCE
- PENDING DECLINE" and "ESCALATION REQUIRED - RAISED IN PORTAL", or "CUSTOMER ACCEPTANCE - PENDING DECLINE - ESCALATION REQUIRED" and "RAISED IN PORTAL"?
(In other words, should the script only split off whatever's after the final hyphen, or should it grab the first two pieces of text and split off everything else?)
Here's an example in PowerShell which assumes that you want to separate out all text after the final hyphen in a string. It uses a regular expression, though you could accomplish the same thing with Split, Join and Trim operations, if you prefer.
$string = 'CUSTOMER ACCEPTANCE - HAS BEEN ACCEPTED - APPLY TO ACCOUNT'
if ($string -match '(.*?)\s*-\s*([^-]*)$')
$split = $matches[1], $matches[2]
else
$split = $string, ''
Write-Host "Original String: $string"
Write-Host "First Text : $($split[0])"
Write-Host "Second Text : $($split[1])" -
String.class without split(String regex)
hello,
This is my problem:
I am using eclipse with j2sdk1.4.2 which
implement
the clase String.class with
method replaceAll(String regex, String replacement) and
method split(String regex)
PAth: home_j2sdk1.4.2/jre/lib/rt.jar 25.762kb
In this way:
String columns[] = line.split("\t");
for (int i=0; i<columns.length; i++)
ws.addCell(new Label(i,row,columns.replaceAll("\"","")));
I move the code above to websphere Application Developer 5.1.2
which use Home_Websphere/eclipse/jre/lib/rt.jar 8.827 kb
this jar in yours String.class not contains the
method replaceAll(String regex, String replacement) and
method split(String regex)
I need to find the use my code above with that methods,
what i need to do ???
possible,i need to find the source to String.java of j2sdk1.4.2
which implement the methods, but where ???
or there is another way to do it ???
Any help is greatly appreciated.If websphere is supposedly 1.4 compatible, arethey
"allowed" to leave out methods from the JFC? Not sure what the JFC is, but no, they would not be
allowed to leave out any methods.
JFC - Java Foundation Classes. I think they started calling what might be considered the Java Core the JFC when they first added Swing to the distribution. Maybe the term is no longer used.
RRD-R
� {� -
JPA2 Question: Is it possible to map a Map(enum, List String ) in JPA2?
Is it possible to map a Map(enum, List<String>) in JPA2? Or do I have to create a separate Entity class that maps each List<String> collections for each possible value in the enum?
Edited by: user7976113 on Jan 22, 2010 7:51 PM
Edited by: user7976113 on Jan 22, 2010 7:51 PMNo, JPA does not support this or any nested collection type of mappings directly.
The best solution is to create an Entity or Embeddable to contain the collection data.
See,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Nested_Collections.2C_Maps_and_Matrices
James : http://www.eclipselink.org
Maybe you are looking for
-
hello my i phone was dropped and i changed its battery now i need to activate it but i forgot my apple id and password who can unlock my i phone 5 with IOS 8.1.3 your answer will be highly appreciated
-
HT1657 can I watch a rented movie on apple tv that was purchased on my phone
Can I watch a rented movie on apple tv that was purchased on my phone
-
since I move to china a week ago i realize base on my personal experience that the country is definitely no mac friendly, which is unfortunate for me since i own a macbook pro, iphone and ipad, and i tell you why. ever since i move to china it seems
-
Create a PDF Form and Email the entire form w/ responses
I created a form in PDF and I want to e-mail the form with the responses in the fields... like a file-->send to-->mail reciepents as attachment... I want to e-mail the form with responses not just email the data file of the form...any suggestions..pl
-
2011 macbook pro cannot turn on
Hello everyone. After I replaced my MBP's hard disk with a SSD, it cannot turn on. There is no reaction when I press the power button. The 6th light of the battery indicator (side) is green and is always on. There's no change of the indicator lights