Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

STRINGS

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

8 REPLIES 8

Former Member
0 Kudos

Hi frank,

field = '200712'.
write field(4).    "will write 2007

rgs

Former Member
0 Kudos

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.

Former Member
0 Kudos

i am not hardcoding the values in the field..... i am fetching the field values from a database table into an internal table.

0 Kudos

Hi,

extract first the entire value and after that you process on internal table.

You can't modify the value at extraction time.

rgs

0 Kudos

select substr(abc,1,4) from ztable into table itab.

Former Member
0 Kudos

write ABC(4) to <variable>

Former Member
0 Kudos

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

matt
Active Contributor
0 Kudos

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