Splitting a string into multiple parts from particular position (string has no delimiter )
Hello Gurus,
I need to make string of having length 1000 into multiple parts from a particular position which has some text without any delimiter and i want to populate each part into an internal table which has one filed...
eg : string = 'sap abap sap abap sap abap sap abap sap abap sap abap sap abap sap sap sap abap sap abap'
suppose i want to start splitting from 40th position...assume that i have 3 parts
and these 3 parts i have put into an internal table..
lt_itab = [sap abap sap abap sap abap sap abap,
sap abap sap abap sap abap sap abap,
sap abap sap sap sap abap sap abap]
plese help!
any help would be Appreciated ...thank you
Hi,
Try this code.
TYPES: BEGIN OF ty,
b TYPE string,
END OF ty,
tt TYPE STANDARD TABLE OF ty.
DATA: a TYPE string VALUE 'aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll',
tb TYPE tt,
wa TYPE ty,
off TYPE i,
len TYPE i,
count TYPE i,
count1 TYPE i,
temp TYPE i.
len = 8. "Position
off = 0.
count = strlen( a ).
count1 = count / 8.
temp = len - 1.
DO count1 times.
temp = off + len.
IF temp > count.
wa-b = a+off.
ELSE.
wa-b = a+off(len).
ENDIF.
off = off + len.
SHIFT wa-b LEFT DELETING LEADING space.
APPEND wa to tb.
ENDDO.
LOOP AT tb INTO wa.
write: / wa-b.
ENDLOOP.
Similar Messages
-
Easy Question: How to split concatenated string into multiple rows?
Hi folks,
this might be an easy question.
How can I split a concatenated string into multiple rows using SQL query?
INPUT:
select 'AAA,BBB,CC,DDDD' as data from dualDelimiter = ','
Expected output:
data
AAA
BBB
CCC
DDDDI'm looking for something kind of "an opposite for 'sys_connect_by_path'" function.
Thanks,
TomasHere is the SUBSTR/INSTR version of the solution:
SQL> WITH test_data AS
2 (
3 SELECT ',' || 'AAA,BBB,CC,DDDD' || ',' AS DATA FROM DUAL
4 )
5 SELECT SUBSTR
6 (
7 DATA
8 , INSTR
9 (
10 DATA
11 , ','
12 , 1
13 , LEVEL
14 ) + 1
15 , INSTR
16 (
17 DATA
18 , ','
19 , 1
20 , LEVEL + 1
21 ) -
22 INSTR
23 (
24 DATA
25 , ','
26 , 1
27 , LEVEL
28 ) - 1
29 ) AS NEW_STRING
30 FROM test_data
31 CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE(DATA,'[^,]','')) - 1
32 /
NEW_STRING
AAA
BBB
CC
DDDD -
Split single column into multiple column using sql /plsql
create table test (name varchar2(255);
insert into test values('DH RED 20 12/10 10 2 ');
insert into test values('PM STUD 20 15/10 20 29.55' );
insert into test values('LS MENTHOl FILTER ASC 18/70 60 240.66');
insert into test values('WINSTON WHITE CLASSIC 13 18/70 60 240.66');
My Output should be like as below in other table :
create table test_result (brand varchar2(255),packet varchar2(50),amount varchar2(25),total varchar2(25));
BRAND PACKET AMOUNT TOTAL
DH RED 20 12/10 10 2
PM STUD 20 15/10 20 29.55
LS MENTHOl FILTER ASC 18/70 60 240.66
WINSTON WHITE CLASSIC 13 18/70 60 240.66can you please help me to solve this issue
thanks in advance
Edited by: A on Apr 21, 2012 11:33 PM
Edited by: A on Apr 21, 2012 11:34 PM
Edited by: A on Apr 21, 2012 11:34 PMh4. # Database should be 10g. If version is below 10g query need to be modified as per string format.
h4. # Split string into two parts by '/'. First part contain brand + packet(1), Second part contain packet(2) + amount + total
h4. # Your brand name can be of any length.
String Format* : <Brand Name><space><packet(1)>/<packet(2)><space><amount><space><total>
SELECT name,
REGEXP_SUBSTR(first_part,'.+[[:space:]]',1,1) brand,
REGEXP_SUBSTR(first_part,'[^[:space:]]+/',1,1) || REGEXP_SUBSTR(second_part,'[^[:space:]]+[[:space:]]',1,1) packet,
REGEXP_SUBSTR(second_part,'[^[:space:]]+[[:space:]]',1,2) amount,
REGEXP_SUBSTR(second_part,'[^[:space:]]+$',1) total
FROM
(SELECT trim(name) name,
trim(substr(name,1, instr(name,'/'))) first_part,
trim(substr(name,instr(name,'/')+1)) second_part
FROM test )
{code} -
Breaking huge text into multiple parts.Please help..
Hi all..i'm urgently need any attention here..pliz help to solve this problem..
The description of my problem is like dis >> let say now i have 100 length of a text. Now , i need to break it into multiple parts, accordingly to the max lenght of a part for one time is 30.So, it should be to returned like dis >>
text [1]="blablabla.." -->text.length =30
text [2]="blablabla.." -->text.length =30
text [3]="blablabla.." -->text.length =30
text [4]="blablabla.." -->text.length =10
I have write a pieces of code that may explain what i try to do..but its not really work..i hope anybody out there can help me..thanks a lot..
code:
for (int i=0; i<fullMsg.length(); i++){
singlLen ++;
if (singlLen == LEN-1){
System.out.print("splitMsg: i="+i+"\n");
System.out.print("splitting new msg["+msgCnt+"]="+fullMsg.substring(beginPos, i)+"\n");
msg[msgCnt] = fullMsg.substring(beginPos, i);
singlLen = 0;
msgCnt ++;
beginPos = i+1;
}public static void main(String[] args) {
String LONG = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
int MAX_LEN = 30;
ArrayList<String> strList = new ArrayList<String>();
int i = 0;
while (i < Math.floor(LONG.length() / MAX_LEN)) {
strList.add(LONG.substring(i * MAX_LEN, MAX_LEN * (i + 1)));
i++;
// now get the remainder
i--; // decrement it to get how many MAX_LEN chunks we have
int remainder = LONG.length() % MAX_LEN;
strList.add(LONG.substring(MAX_LEN * (i + 1), MAX_LEN * (i + 1)
+ remainder));
System.err.println(strList.toString());
}I'm not sure if this is what you want... Say you have 75 chars in string.
Prepares an array with 3 strings,
first len 30,
second len 30,
last len 15
makes 75 in total -
Split the IDOC into multiple IDOC if the IDOC has more than 500 records
Hi All,
I developed an outbound IDOC in which we are facing an issue.
There is some limitation on the maximum idoc size it can handle.
If number of records is more than 500, split the idoc into multiple iDoc's, e.g. if it would have 1300 records , the result would be 2 iDoc's with 500 records, and the last one would have 300 records
How can i acheive this.
Regards
JaiHi,
1) first you need to know which message type/Idoc type you are triggering.
2) Get the Corresponding processcode from Partner profiles(WE20/ WE41).
3) Then the look for prper user-exit in the related processing FM.
4) write logic to split the IDoc accordingly.
if no proper user exit available then copy the standard processing FM and need to all ALE related configurations.
Catch hold any ABAP expert in your team to do all these.
Suresh -
Need to Divide the string into multiple integers
i have the String like below,that passed by user though one parameter.
200 300 400 500 600(This come from one parameter as a String with space between each value).
i need to use each above value in different column calculations.
anybody help me how can i divide whole string into multiple integer values and use it in other calculations.
Thanks in advance.You will need to use substr and instr functions to get each value. The instr function returns the location of a space in your parameter value..
To get the first value, use this: <?xdofx:substr(AMOUNT,1,(Instr(AMOUNT,' ',1,1)-1))?>
To get second value: <?xdofx:substr(AMOUNT,Instr(AMOUNT,' ',1,1)+1, (Instr(AMOUNT,' ',1,2)-1)- Instr(AMOUNT,' ',1,1)+1)?>
To get third value: <?xdofx:substr(AMOUNT, Instr(AMOUNT,' ',1,2)+1, (Instr(AMOUNT,' ',1,3)- 1) -Instr(AMOUNT,' ',1,2)+1)?>
and so on..
Thanks,
Bipuser -
Split a record into multiple records
Hi,
I have situation where i need to split a record into multiple records.
InputData :
value|BeginDate |EndDate
15 |2002/10/15|2002/10/16
13 |2002/10/13|2002/10/20
19 |2002/10/19|2002/10/23
10 |2002/10/10|2002/10/12
OutPut :
10 |2002/10/10|2002/10/12
13 |2002/10/13|2002/10/15
15 |2002/10/15|2002/10/16
13 |2002/10/16|2002/10/19
19 |2002/10/19|2002/10/23
ThanksHi ,
As a far I understood from your example ,
I have few questions...
1. You have information about the patient in a 1 source table.
2. how u are identifying for patient X u need 5 rows to be created. R u storing these informations in seprate table or how ...
3. if you have these information in a seperate tables ..... a simple cross join in ODI should get you the expected result.....
Or give some more information with a example ..that would be great ...
Thanks -
Split one row into multiple columns
Hi,
Data in one CLOB column in a table storing with delimiter, ##~~##. Ex. ##~~##abc##~~##defgh##~~##ijklm##~~##nopqr (data starts with delimiter). Please help me to split the data into multiple rows like below and it should be in the same order.
abc
defgh
ijklm
nopqr
I am using Oracle 11g.
Thanks.Thanks Hoek for your response. Before posting my question in the forum, I tried similar query. It is working with one character as delimiter.
with test as (select 'ABC,DEF,GHI,JKL,MNO' str from dual )
select regexp_substr (str, '[^,]+', 1, rownum) split
from test
connect by level <= length (regexp_replace (str, '[^,]+')) + 1;
Above query is giving correct result by fetching 5 rows. I have modified the query like below...
with test as (select 'ABC,,,DEF,,,GHI,,,JKL,,,MNO' str from dual )
select regexp_substr (str, '[^,,,]+', 1, rownum) split
from test
connect by level <= length (regexp_replace (str, '[^,,,]+')) + 1;
Above query resulting 13 rows and last 8 rows are nulls. Number of null rows are increasing, if I increase number of characters in delimiter. Could you please tell me how to avoid those null rows.
Thanks. -
Split single row into multiple rows containing time periods
Hi,
I have a table with rows like this:
id, intime, outtime
1, 2010-01-01 00:10, 2010-01-3 20:00
I would like to split this row into multiple rows, 1 for each 24hr period in the record.
i.e. The above should translate into:
id, starttime, endtime, period
1, 2010-01-01 00:10, 2010-01-02 00:10, 1
1, 2010-01-02 00:10, 2010-01-03 00:10, 2
1, 2010-01-03 00:10, 2010-01-03 20:00, 3
The first starttime should be the intime and the last endtime should be the outtime.
Is there a way to do this without hard-coding the 24hr periods?
Thanks,
Dan Scott
http://danieljamesscott.orgThanks for all the feedback, Dan.
It appears that the respective solutions provided will give you: a) different resultsets and b) different performance.
Regarding your 'truly desired resultset' you haven't answered all questions from my previous post (there are differences in the provided examples), but anyway:
I found that using CEIL or ROUND makes quite a difference, using my 'simple 3 record testset' (30 records vs. 66 records got initially returned, that's less than half of the original). That's quite a difference. However, I must call it a day (since it's almost midnight) for now, so there's room for more optimizement and I haven't thoroughly tested.
But this might hopefully make a difference performancewise when compared to my previous 'dreaded example':
SQL> drop table t;
Table dropped.
SQL> create table t as
2 select 1 id, to_date('2010-01-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-01-03 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
3 select 2 id, to_date('2010-02-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-02-05 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
4 select 3 id, to_date('2010-03-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-03-03 00:10', 'yyyy-mm-dd hh24:mi') outtime from dual;
Table created.
SQL> select id
2 , max(intime)+level-1 starttime
3 , case
4 when level = to_char(max(t.outtime), 'dd')
5 then max(t.outtime)
6 else max(t.intime)+level
7 end outtime
8 , level period
9 from t
10 connect by level <= round(outtime-intime)
11 group by id, level
12 order by 1,2;
ID STARTTIME OUTTIME PERIOD
1 01-01-2010 00:10:00 02-01-2010 00:10:00 1
1 02-01-2010 00:10:00 03-01-2010 00:10:00 2
1 03-01-2010 00:10:00 03-01-2010 20:00:00 3
2 01-02-2010 00:10:00 02-02-2010 00:10:00 1
2 02-02-2010 00:10:00 03-02-2010 00:10:00 2
2 03-02-2010 00:10:00 04-02-2010 00:10:00 3
2 04-02-2010 00:10:00 05-02-2010 00:10:00 4
2 05-02-2010 00:10:00 05-02-2010 20:00:00 5
3 01-03-2010 00:10:00 02-03-2010 00:10:00 1
3 02-03-2010 00:10:00 03-03-2010 00:10:00 2
10 rows selected.
SQL> By the way: I'm assuming you're on 10g, is that correct?
Can you give us some information regarding the indexes present on your table? -
Split MP3 file into multiple MP3 files
I've been through the help section and is till cant seem to figure out how to split a large (2 hour) mp3 file into multiple mp3 files.
I have a 2 hour MP3 recording (Stereo not mono), and I have added markers (by simply pressing keyboard shortcut 'M' to add marker), but now I would like to know how to split that one mp3 files into multiple files from the markers which I have made...
All my marker types are "Cue" when i pressed 'M' at the locations I want the track to end/startYou didn't say which version of the program you're using, but in general, there is a way to do this by adding one additional cue at the very end of the file, then "merging" the cues (which converts the space between each cue into a "range"), and batch processing each range out to a separate file. (Make sure there's a cue at the beginning of the file, or at least the first material you want in a new file.)
Now that you've done all that work, I'm going to tell you that what you're doing is probably a bad idea. Opening any mp3 in Audition and resaving back to mp3 means you've doubled the losses and distortion inherent with the mp3 compression. Audition can't do lossless editing of mp3s. The bottom line: are you really splitting the file, and does the result have to be mp3 format? If saving to a (wave file, or any other lossless format, then what I'm saying doesn't matter.
In any case, "mp3 Direct Cut" is a terrific freeware program that does lossless mp3 editing, and I'd highly recommend you try it. It's saved my neck a number of times. See http://www.mpesch3.de. -
Split Single IDOC into Multiple IDOC's Based on Segment Type
Hi Experts,
I have a scenario IDOC to FILE , Split Single IDOC into Multiple IDOC's based on Segment Type
Outbound:
ZIdocName
Control Record
Data Record
Segment 1
Segment 2
Segment 3
Status Record
I should get output like below
Inbound:
ZIdocName
Control Record
Data Record
Segment 1
Status Record
ZIdocName
Control Record
Data Record
Segment 2
Status Record
ZIdocName
Control Record
Data Record
Segment 3
Status Record
Please suggest me step by step process to achieve this task.
Thanks.Thanks a lot Harish for reply.
I have small doubt. According to your reply , If we have N number of segments in single IDOC with same fields in all segments then for splitting Single IDOC into Multiple IDOC's based on Segment Type we need to duplicate N number of target IDOC tree structure.
Is that possible to Split single IDOC into Multiple IDOC's based on Segment Type using only one Target IDOC structure without duplicating the Target IDOC structure tree. -
How can i prevent itunes from splitting individual albums into multiple albums?
How do prevent itunes from splitting albums with various artists into multiple albums?
Thanks for your help!It's probably better to put Various Artists into the Album Artist box rather than just "various". Make sure it's the Album Artist field though. In addition, you need to mark the album as a compilation. When setting the complete album, the Part of a compilation is on a drop-down menu on the File/Get Info/Options tab:
but if changing just one song, it's a tick-box on the Info tab:
and needless to say, the album name must be exactly the same for each track. -
Split a string into multiple internal tables
Hi all,
I need to split a string based internal table into multiple internal tables based on some sub strings in that string based internal table...
High priority help me out...
eg...
a | jhkhjk | kljdskj |lkjdlj |
b | kjhdkjh | kldjkj |
c | jndojkok |
d |
this data which is in the application server file is brought into a internal table as a text. Now i need to send 'a' to one internal table, 'b' to one internal table, so on... help me
<Priority downgraded>
Edited by: Suhas Saha on Oct 12, 2011 12:24 PMHi pradeep,
eg...
a | jhkhjk | kljdskj |lkjdlj |
b | kjhdkjh | kldjkj |
c | jndojkok |
d |
As per your statement "Now i need to send 'a' to one internal table, 'b' to one internal table"
Do you want only a to one internal table and b to one internal table
OR
Do you want the whole row of the internal table i mean
a | jhkhjk | kljdskj |lkjdlj | to 1 internal table
Having the case of an internal table which is of type string,
1) Loop through the internal table. LOOP AT lt_tab INTO lwa_tab.
2) Ge the work area contents and get the first char wa_tab-string+0(1)
3) FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.
w_tabname = p_table.
CREATE DATA w_dref TYPE TABLE OF (w_tabname).
ASSIGN w_dref->* TO <t_itab>.
Follow the link
http://www.sap-img.com/ab030.htm
http://www.sapdev.co.uk/tips/dynamic-structure.htm
and then based on the sy-tabix values you will get that many number of internal table
<FS> = wa_tab-string+0(1)
append <FS>
OR
USE SPLIT statement at the relevant seperator
revert for further clarification
Thanks
Sri
Edited by: SRIKANTH P on Oct 12, 2011 12:36 PM -
Issue with splitting string into multiple lines
Hi Experts,
I have a long string s. I want to split this string into several lines each having 72 characters. For this I have done following programming:
String s = "For the first time it includes a supplementary report attempting to determine if extreme weather
events can be linked to human-induced climate change. The research team, including members
of the UK Met Office, identified recent episodes of extreme weather then used a computer to
estimate the likelihood of the episode happening in a world without increased CO2." ;
s = s.replaceAll("[\r\n]+", " ");
char[] sAr = s.toCharArray();
AbstractList RecepitsList7 = new Bapitrtext.Bapitrtext_List();;
int start = 0; // start with
int i = 72 ;
// for (int i = 71; i < sAr.length; i++) {
while (i < sAr.length) {
// { if (sAr[i] == ' ')
Bapitrtext Recepits7 = new Bapitrtext();
Recepits7.setTextid("TEXT");
Recepits7.setTextline(s.substring(start, i).replaceAll("[\r\n]+", ""));
RecepitsList7.add(Recepits7);
start = i+1;
i += 72;
input.setText(RecepitsList7);
The output of program is as below:
For the first time it includes a supplementary report attempting to dete
mine if extreme weather events can be linked to human-induced climate
hange. The research team, including members of the UK Met Office, iden
ified recent episodes of extreme weather then used a computer to estim
te the likelihood of the episode happening in a world without increased
Here as we can see last characters are getting deleted by program. For example in first line
determine 'r' is missing in extreme right.
In 3rd line c is missing in extreme left (word change is needed. Program
prints hange.
Also in 3rd line extreme right 't' is missing
Also in 4th line extreme right 'a' is missing
Also the last line is not being printed. In last line "CO2." " should appear.
There are two issues:
1. Why last word of each sentence is not being printed?
2. Why last sentence is not being printed?
I am struggling since last 2 days. Please help. I made all changes like replacing 72 by 71 etc.
By making such changes, I am able to print first line correctly. However under all cases
last character of 2nd line onward is not getting displayed.
Also last line is not getting displayed. I did every thing like using while instead of for loop etc.
Kindly help.
Regards,
Gary
Edited by: 945655 on Jul 10, 2012 11:39 PMString s = wdContext.currentContextElement().getExpense_Text();
s = s.replaceAll("[\r\n]+", " ");
char[] sAr = s.toCharArray();
AbstractList RecepitsList7 = new Bapitrtext.Bapitrtext_List();;
int start = 0; // start with
int i = 72;
while (i < sAr.length) {
Bapitrtext Recepits7 = new Bapitrtext();
Recepits7.setTextid("TEXT");
System.out.println(s.substring(start, i));
RecepitsList7.add(Recepits7);
start = i+1;
i += 72;
input.setText(RecepitsList7);
Edited by: 945655 on Jul 11, 2012 2:25 AM -
How to split the records into two parts
Hi experts,
I have a field with 75 char length, this field have records also, Now i want to split the field into two differnt fields. That means upto first 40 char goes to one field, from 41st char to 70 char goes to another field, for that how to split record into two parts.
Plz advice this,
MohanaHi,
Do the following:
f1 = fsource(40).
f2 = fsource+40(30).
where fsource is the 70 character original string and target strings are f1 (length 40) and f2 (length 30).
Cheers,
Aditya
Edited by: Aditya Laud on Feb 22, 2008 2:10 AM
Maybe you are looking for
-
SSO from non-SAP application to EP system
Hi all, Is it possible to configure the Single sign-on from non-SAP application to SAP Enterprise portal? My requirement is I have a link to "Enterprise Portal" in my company's website home page. If I click on the link, it should directs to EP portal
-
Vendor open items report without page break after changing vendor account
Hi, I would like to get the vendor open items report without pagination when the vendor account changes. The option of deleting the * mark in the Filter page is not valid for me, because this way the vendor's name dissappear. I mean, it would be ok i
-
Little parasite noise sound coming out of the Ipod when charging
When the Ipod is plugged to the wall charger, there's a little parasite sound coming out. It's barely audible but I wonder if it's normal?
-
Flex Builder 3 new j2ee project using LDS
Hello I am using Eclipse Europa With flex builder v3 beta 2. My application server is apache geronimo v2. When i deploy my ear file into geronimo i recieve an exception: org.apache.geronimo.common.DeploymentException: Could not parse TLD file at file
-
Why can't I log in to any online banking on my iPad?
I have no problem loging in on my iPhone 4 but my iPad says time out or just kicks me back to the first log in page!!