Application Development and Automation 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: 
Read only

Conversion from Char to Packed Number

Former Member
0 Likes
2,417

Hi,

How do we convert a 18 byte char field(Which contains all numerics) in to a 8 byte field ?

Regards,

Hari

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,377

Hi..

you can not do it with 8 bytes...1 char is missing in conversion if we do so. So, take type P(10) which will solves ur problem..in efficient way..

data w_char(18) type c value '200710311140000001'.

data w_p(10) type p.

<b> PACK W_CHAR TO W_P.</b>

WRITE: W_P.

CLEAR W_CHAR.

<b> UNPACK W_P TO W_CHAR.</b> WRITE:/ W_CHAR.

6 REPLIES 6
Read only

Former Member
0 Likes
1,377

Hi.,,

what is your actual requirement ??

if u want to move a character variable which contains all numerics into a P type field u can directly move it !!

<b>data w_char(18) type c value '1234567'.

data w_p type p decimals 2.

move w_char to w_p.

write w_p.</b>

<u>If you want to hold large numbers then increase the size of P type variable..</u>

<u>data w_p<b>(10)</b> type p decimals 2.</u>

reward if it helps u..

sai ramesh.

Read only

Former Member
0 Likes
1,377

Hi Ramesh,

My requirement is: The Char field(18) contains a value like '200710311140000001'. We have to move this to a packed no which packs it to a 8 byte field. If we unpack this field, we should get again 18 byte fields.

Regards,

Hari

Read only

0 Likes
1,377

Hi,

Check the syntax of PACK :

PACK f TO g.

<b>The field f can contain up to 16 characters.</b>

Places the character field f in packed format in the field g

You can only store maximum 16 characters.

Regards

L Appana

Read only

Former Member
0 Likes
1,377

Hari,

hi ,

chk this.

  • Converting type c to type n

DATA: SCN(4) VALUE '12x4',

T1CN(2) TYPE N,

T2CN(6) TYPE N.

MOVE: SCN TO T1CN,

SCN TO T2CN.

  • Converting type n to type p

DATA: SNP(6) TYPE N VALUE '012345',

T1NP(10) TYPE P,

T2NP(2) TYPE P.

MOVE SNP TO T1NP.

Don't forget to reward if useful....

Read only

Former Member
0 Likes
1,378

Hi..

you can not do it with 8 bytes...1 char is missing in conversion if we do so. So, take type P(10) which will solves ur problem..in efficient way..

data w_char(18) type c value '200710311140000001'.

data w_p(10) type p.

<b> PACK W_CHAR TO W_P.</b>

WRITE: W_P.

CLEAR W_CHAR.

<b> UNPACK W_P TO W_CHAR.</b> WRITE:/ W_CHAR.

Read only

0 Likes
1,377

Hi Rammohan,

Thanks, But the output file format given by the client has space to store only 8 bytes. We have to convert 18 char into 8 bytes and output to the file.

Regards,

Hari