11-21-2007 9:39 AM
Hi guys,
I have a requirement wherein i need to capture the first 4 characters of a field into another variable.
For eg i have a field ' ABC' whose data contents are 200704 , 200606 , 200507...etc
I need the values 2007 , 2006 , 2005 from tha above field in the work area of another internal table.
How do i go about this??
Thanks and regards,
Frank.
11-21-2007 9:44 AM
Hi ,
Use offset(length)
check the below code
loop at itab1.
itad2-fields = itab1-abc+0(4).
append itab2.
endloop.
<b>Reward points if usefull.</b>
Regards,
Siva chalasani.
11-21-2007 9:42 AM
11-21-2007 9:44 AM
Hi ,
Use offset(length)
check the below code
loop at itab1.
itad2-fields = itab1-abc+0(4).
append itab2.
endloop.
<b>Reward points if usefull.</b>
Regards,
Siva chalasani.
11-21-2007 9:44 AM
i am not hardcoding the values in the field..... i am fetching the field values from a database table into an internal table.
11-21-2007 9:47 AM
Hi,
extract first the entire value and after that you process on internal table.
You can't modify the value at extraction time.
rgs
11-21-2007 9:50 AM
11-21-2007 9:45 AM
11-21-2007 10:06 AM
Hi Frank,
After fetching the data from Database table, when you are moving to internal table just offset the value for the first 4 characters and append it to internal table.
Regards,
Satish
11-21-2007 10:12 AM
Offsets and lengths is a bad way to program. Check out the programming concept of "Magic Numbers".
Far better to define a structure. Assume you've got your data into a variable type n length 6, called l_per, and you're wanting to get into a variable type n length 4, called l_year.
TYPES: BEGIN OF period type,
yyyy TYPE n,
mm TYPE n,
END OF period_type.
DATA: l_per_tmp TYPE period_type.
l_per_tmp = l_per.
l_year = l_per-yyyy.
This may seem long winded, but it is absolutely clear what the program is doing, and no-one needs to scratch their head over what the number 4 means, nor do they need to know the internal structure of l_per to understand the program.
Clarity is good. Ambiguity is bad. And most of the cost of a program is in maintenance, not development.
matt