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: 

Truncate long variable into a short one

Former Member
0 Kudos

Hi,

I have a 40 character variable that needs to be truncated in a 20 character variable.

How do I do this?

Thanks,

John

4 REPLIES 4

Former Member
0 Kudos

data: var1(40) type c.

data: var2(20) type c.

if u want first 20 chars of var1 to be moved to var2..

then simply use... var2 = var1. " First 20 chars will be moved to var2 from var1

If u want last 20 chars then

var2 = var1+20(20).

if u want 20 chars of specific position like pos 10 to 30.. then

var2 = var1+10(20).

Reward if helpful

Regards

Prax

Simha_
Employee
Employee
0 Kudos

Hi,

declare two variables of length 40 and 20.

Then move 40 character variable to 20 character variable .

That will do...

Cheers,

Simha.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
data: char40(40) type c value 'This is a 40 character field and needs to be moved'.
data: char20(20) type c.

char20 =  char40.

Regards,

RIch Heilman

former_member208856
Active Contributor
0 Kudos

Hi,

use code as below :

data : a(40), b(20), c(20).

a = 'abcdefghijklmnopqrstuvwxyz0123456789'.

b = a+0(20).

c = a+20(20).

write : / a.

write : / b.

write : / c.

Reward points, if helpful,

Sandeep Kaushik