06-30-2005 8:58 PM
hi,
is there a concept as array which you find in C,C++.
say for example, i want to store a string in an array format, str1(10) and i want to read the 5th array record that is str1(5) in ABAP,
thank you.
Aditya Varrier .
06-30-2005 9:01 PM
06-30-2005 9:01 PM
06-30-2005 9:04 PM
data: begin of itab occurs 0,
str type string,
end of itab.
itab-str = '1 Record'. append itab.
itab-str = '2 Record'. append itab.
itab-str = '3 Record'. append itab.
itab-str = '4 Record'. append itab.
itab-str = '5 Record'. append itab.
itab-str = '6 Record'. append itab.
itab-str = '7 Record'. append itab.
itab-str = '8 Record'. append itab.
itab-str = '9 Record'. append itab.
read table itab index 5.
check sy-subrc = 0.
write:/ itab-str.
Regards,
Rich Heilman
06-30-2005 9:55 PM
hi rich,
what i meant is ,say if you have a variable str1() declared as a string e.g str1(6) = 'ABCDEF'.
now i want to retrieve just 'D'. from the above string , that is the 4th element in the string 'ABCDEF'.
how can i do it...
My actual problem is say if i input a string like 'ABBA'
my output should be 'The string you entered is a palindrome'. so according to my logic what i would do is check each array parameter (if at all there is a concept like array) i.e check str1(1) with str1(4), then str1(2) with str2(3) and so on...
hope you got my point...
Aditya Varrier.
06-30-2005 10:26 PM
If you just want to check for palindrome:
DATA: p1(1000) TYPE c VALUE 'I PREFER PI'.
DATA: p2(1000) TYPE c.
DATA: s_len TYPE i.
CONDENSE p1 NO-GAPS.
s_len = NUMOFCHAR( p1 ).
DATA: position TYPE i VALUE '0'.
DATA: position2 TYPE i.
DATA: offset1 TYPE i.
DO s_len TIMES.
position2 = s_len - position - 1.
p2+position2(1) = p1+position(1).
position = position + 1.
ENDDO.
WRITE: / p1.
WRITE: / p2.
if p1 = p2.
write: / 'Palindrome!'.
endif.
06-30-2005 11:07 PM
Hi Aditya
In ABAP there is not an exactly corresponding definition for arrays in other languages. The closest one is the internal table concept which Rich explained.
Internal table records are read with "LOOP AT...ENDLOOP." and "READ TABLE" statements which retrieves the whole record. With the record you have, you address the field name to get the stored value there, e.g. <i>itab-field_name</i>. That is; an array-like structure can be constructed in ABAP with an internal table having one columns.
For your palindrome example, we may switch to a different concept that ABAP provides utilities to handle string operations as Thomas demonstrated. Mainly, the position and offset additions are used.
e.g.
var1 = 'Aditya'
var1+1(2) = 'di'
var1(2) = 'Ad'
var1+3 = 'tya'
var1(4) = 'Adit'
So, please get some further from the array understanding of other languages and try to be familiar to the intarnal table view concept which you can easily implement in your ABAP programs.
Regards
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>
04-21-2007 7:39 AM
yes i want know cocept of table.
i want to take name of 5 student from user and diplay on screen
06-30-2005 11:54 PM
hi guys,
thanks a lot,
it was awesome, as i am new to ABAP i found it difficult to find the solution,
Expecting such wonderful assistance from you guys in future,
thanks,
Aditya Varrier.
P.S
does anyone have notes on Netweaver and any CrossApplications, as i want to pursue a career in the same. (I am a total amateur...)
if you could help me out please send email to this id-
adityavarrier@yahoo.com
07-01-2005 12:05 AM
Hi Aditya
There are lots of documents, e-classes about Netweaver at SDN. Just surf around...
BTW, let me introduce the pointing system at SDN. You can assign points to posts which you find helpful using the scala on the left of each post. By assigning a 10-point to a post or choosing "Solved by my own" at the left of your original post you close a thread which saves SDNers' valuable times.
Regards
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>