2006 Apr 07 7:06 AM
Hi there,
I have an internal table of 1 field of length 200chars. I want to concatenate all the rows in this table and make them rows of 256 chars each and move it into another internal table having only 1 field of length 256 chars. How to do this? Any help is welcome please.
Regards,
Rashmi
2006 Apr 07 9:19 AM
Hi Igor,
The logic written by you works perfectly fine with the data that you have taken as example 'A C' etc etc. But when I try the same with my table which has 3 rows, it is not working correctly. It just displays only 1 row in the result.
My table data
first row = <SXPAssignmentUpdate Destination="CLICK_ID1">
<Engineers><Engineer><ID>1</ID><Name>Richard Hodges</Name>
</Engineer></Engineers><Task><CallID>000001008989</CallID>
<Number>10</Number
sec row
ish>2006-04-04 07:33:00</Finish><Key>22624</Key><Start>
2006-04-04 06:33:00</Start><Task><Status><Name>ASSN</Name>
third row
</Status></Task></Assignment></SXPAssignmentUpdate>
This is not giving the correct output.
What could be the reason?
Regards,
Rashmi
Hi Igor,
The logic written by you works perfectly fine with the data that you have taken as example 'A C' etc etc. But when I try the same with my table which has 3 rows, it is not working correctly. It just displays only 1 row in the result.
My table data
first row = <SXPAssignmentUpdate Destination="CLICK_ID1">
<Engineers><Engineer><ID>1</ID><Name>Richard Hodges</Name>
</Engineer></Engineers><Task><CallID>000001008989</CallID>
<Number>10</Number
sec row
ish>2006-04-04 07:33:00</Finish><Key>22624</Key><Start>
2006-04-04 06:33:00</Start><Task><Status><Name>ASSN</Name>
third row
</Status></Task></Assignment></SXPAssignmentUpdate>
This is not giving the correct output.
What could be the reason?
Regards,
Rashmi
2006 Apr 07 7:14 AM
HI
Perform a Loop and Use SPLIT command to split at the 256'th Character and then copy one by one in to the destination table of 256 Character's length.
Thanks & Regards,
Joseph Reddy.
2006 Apr 07 7:14 AM
hi rashmi,
check the below code..
data: begin of itab occurs 0,
char(200) type c,
end of itab.
data: begin of jtab occurs 0,
char(256) type c,
end of jtab.
itab-char = 'line 1'.append itab.
itab-char = 'line 2'.append itab.
itab-char = 'line 3'.append itab.
itab-char = 'line 4'.append itab.
loop at itab.
concatenate jtab-char itab-char into jtab-char separated by space.
at last.
append jtab.
endat.
endloop.
loop at jtab.
write / jtab-char.
endloop.
Cheers,
Abdul Hakim
2006 Apr 07 7:32 AM
Its basically that I have to pass an internal table of length 256 char to xml->parser. But the third party tool is already converting the xml file into internal table but that table field length is only 200 char.
How do u think I can move this xml data into 256 chars table which is being sent as 200 chars table?
I do not know the 256th char to do SPLIT or it is not just 1 line that i want to concatenate. it is an XML file in internal table format but length is only 200 chars.
Any help???
Thanks,
Rashmi
2006 Apr 07 7:46 AM
hi
read only 200 char each time and pass it to your 256 len itab.
Cheers,
Abdul Hakim
2006 Apr 07 7:59 AM
Hi,
You can do one thing perform our age old program with loops.
First copy the 200 char's into source. This is done. Now move the next 56 char's also to source. Now you have copied the first 256 char's.
Now move for the next 256 char's. For this now you are in the second field of your first internal table. How many character's are you left out with 144 read this 144 copy into destination and read the remaining char's to make 256. This all you write in the inner loops.
You can use concatenate operators. like eg: field 10(20)
Thanks & Regards,
YJR.
2006 Apr 07 8:06 AM
Hi Rashmi,
Use the following code:
Data: begin of itab1 occurs 0,
f1(200) type c,
end of itab1.
Data: begin of itab2 occurs 0,
f1(256) type c,
end of itab2.
data: v1(500) type c,
v2 type i.
Populate the data in internal table itab1
loop at itab1.
concatenate v1 itab1-f1 into v1.
clear: v2.
v2 = strlen( v1 ).
if v2 >= 256.
itab2-f1 = v1+0(256).
v1 = v1+256(244).
append itab2.
endif.
clear: itab1, itab2.
endloop.
Hope it helps.
Regards,
Neeraj Gupta
2006 Apr 07 8:31 AM
Rashmi,
don't use CONCATENATE statement as you may lose spaces within your character string. Please try the executable program below. For simplicity, I was moving table of char 3 to table of char 4. You can just change the variables v_max1 and v_max2 to 200 and 256, respectively, and you'll get what you want. I deliberately left spaces within table t_1 to see what will happen, and they remained as they should.
HTH,
Igor
Please reward points if you find this useful.
DATA: v_1 TYPE char200,
v_2 TYPE char256,
t_1 LIKE TABLE OF v_1,
t_2 LIKE TABLE OF v_2,
v_max1 TYPE i VALUE 3,
v_max2 TYPE i VALUE 4,
v_len_2 TYPE i,
v_len_con TYPE i,
v_total_len TYPE i,
v_diff TYPE i,
v_concatenate TYPE char600.
APPEND: 'A C' TO t_1,
'D F' TO t_1,
' HI' TO t_1,
'J L' TO t_1,
' NO' TO t_1.
WRITE v_1.
LOOP AT t_1 INTO v_1.
WRITE: v_1.
v_len_con = strlen( v_concatenate ).
v_concatenate+v_len_con = v_1(v_max1).
v_len_con = strlen( v_concatenate ).
v_len_2 = strlen( v_2 ).
v_total_len = v_len_con + v_len_2.
IF v_total_len < v_max2.
v_2+v_len_2 = v_concatenate.
CLEAR v_concatenate.
ELSE.
v_diff = v_max2 - v_len_2.
v_2+v_len_2 = v_concatenate(v_diff).
APPEND v_2 TO t_2.
CLEAR v_2.
v_concatenate = v_concatenate+v_diff.
ENDIF.
ENDLOOP.
IF NOT v_2 IS INITIAL.
APPEND v_2 TO t_2.
ENDIF.
ULINE.
LOOP AT t_2 INTO v_2.
WRITE: / v_2.
ENDLOOP.
2006 Apr 07 8:46 AM
Hi,
Don't know how much these links are Useful to you. But as you are dealing with XML-->Parser. Hope these will be of some Help.
http://ifr.sap.com/home/Documents/XML_index_E.htm
http://ifr.sap.com/home/Documents/ABAP_Serialization.htm
Cheers,
YJR.
2006 Apr 07 9:19 AM
Hi Igor,
The logic written by you works perfectly fine with the data that you have taken as example 'A C' etc etc. But when I try the same with my table which has 3 rows, it is not working correctly. It just displays only 1 row in the result.
My table data
first row = <SXPAssignmentUpdate Destination="CLICK_ID1">
<Engineers><Engineer><ID>1</ID><Name>Richard Hodges</Name>
</Engineer></Engineers><Task><CallID>000001008989</CallID>
<Number>10</Number
sec row
ish>2006-04-04 07:33:00</Finish><Key>22624</Key><Start>
2006-04-04 06:33:00</Start><Task><Status><Name>ASSN</Name>
third row
</Status></Task></Assignment></SXPAssignmentUpdate>
This is not giving the correct output.
What could be the reason?
Regards,
Rashmi
2006 Apr 07 10:41 AM
Rashmi,
there was an error in program. Please try this one. I don't know do you want to preserve trailing spaces or not. You have a parameter for both options.
HTH
Regards,
Igor
REPORT ZTEST LINE-SIZE 500.
DATA: v_1 TYPE char200,
v_2 TYPE char256,
t_1 LIKE TABLE OF v_1,
t_2 LIKE TABLE OF v_2,
v_max1 TYPE i VALUE 200,
v_max2 TYPE i VALUE 255,
v_len_2 TYPE i,
v_len_con TYPE i,
v_total_len TYPE i,
v_diff TYPE i,
v_concatenate TYPE char600.
PARAMETERS: p_tspace TYPE char1 AS CHECKBOX.
CONCATENATE:
'<SXPAssignmentUpdate Destination="CLICK_ID1">'
'<Engineers><Engineer><ID>1</ID><Name>Richard Hodges</Name>'
'</Engineer></Engineers><Task><CallID>000001008989</CallID>'
'<Number>10</Number' INTO v_1.
APPEND v_1 TO t_1.
CONCATENATE:
'ish>2006-04-04 07:33:00</Finish><Key>22624</Key><Start>'
'2006-04-04 06:33:00</Start><Task><Status><Name>ASSN</Name>' INTO v_1.
APPEND v_1 TO t_1.
APPEND '</Status></Task></Assignment></SXPAssignmentUpdate>' TO t_1.
FIELD-SYMBOLS: <line1> TYPE ANY,
<line2> TYPE ANY.
CLEAR t_2.
LOOP AT t_1 ASSIGNING <line1>.
v_concatenate+v_len_con = <line1>(v_max1).
IF p_tspace = 'X'.
ADD v_max1 TO v_len_con.
ELSE.
v_len_con = STRLEN( v_concatenate ).
ENDIF.
v_total_len = v_len_con + v_len_2.
IF v_total_len < v_max2.
v_2+v_len_2 = v_concatenate.
IF p_tspace = 'X'.
ADD v_len_con TO v_len_2.
ELSE.
v_len_2 = STRLEN( v_2 ).
ENDIF.
CLEAR: v_concatenate, v_len_con.
ELSE.
v_diff = v_max2 - v_len_2.
v_2+v_len_2 = v_concatenate(v_diff).
APPEND v_2 TO t_2.
CLEAR: v_2, v_len_2.
v_concatenate = v_concatenate+v_diff.
IF p_tspace = 'X'.
SUBTRACT v_diff FROM v_len_con.
ELSE.
v_len_con = STRLEN( v_concatenate ).
ENDIF.
ENDIF.
ENDLOOP.
IF NOT v_2 IS INITIAL.
APPEND v_2 TO t_2.
ENDIF.
LOOP AT t_1 INTO v_1.
WRITE / v_1.
ENDLOOP.
WRITE / 'result:'.
LOOP AT t_2 INTO v_2.
WRITE: / v_2.
ENDLOOP.
2006 Apr 09 12:41 AM
Hi Igor,
Your code works perfectly fine. Thanks a lot for that.
Now the problem I'm facing is that xml parser looks for an 'end of file' character in the last line of the table.
Do you know how to append 'end of file' char in 46c? In this case I want to append this 'eof' char at the end (in the last line) of the internal table before sending it to parser.
Thanks a lot for your help. It was a great code.
Regards,
Rashmi
2006 Apr 10 7:04 AM
Rashmi,
I am glad that my code was helpful to you.
Unfortunalely, I don't know how to append 'end of file' char.
Please notice radiobuttons on the left margin of each reply to your own messages (these appear for each person only with the questions that he or she has asked), saying "Solved Problem (10)", "Very helpful answer (6)" and "Helpful answer (2)". If you don't see these radiobuttons, then it's a kind of error in SDN application that sometimes happens too. It usually corrects if you logoff/logon to SDN.
However, by checking the radiobuttons (or not) your rate replies that people give to you and assign points to them (10, 6 or 2). Although it's always nice to say "than you" too, rating answers and assigning points is a common way of expressing thankfulness for provided help. Level of your satisfaction is totally your discretion, but I think you should rate answers taken into account only your original question, not the additional questions you might have asked in the same thread subsequently (like 'end of file' question in your thread).
So if you are happy with my reply (it seems to me that you are), please assign points.
Thanks!
Kind regards,
Igor
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |