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: 

adding of character field to char field with preceding zero

Former Member
0 Kudos
106

Hi,

I am adding char field to char field, but if field1 has preceeding zero's and when we add field2 to it the zero's are removed , how to take care of this. zeros can vary from 1 to any number of preceding zero

ie.

field1(40) type c.

field2(2) type c.

field1 = '035567011'.

field2 = '11'.

field1 = field1 + field2

currently I have the result field1 = 35567022, but I need the result as field1 = 035567022

please suggest how to do this.

thanks

bobby

6 REPLIES 6

Former Member
0 Kudos
62

count = 0.

do 15 times.

if field1+0(1) = '0'.

shift field1 left.

concateante count ' 0'.

else.

exit.

endif.

enddo.

then after adding ur filedls concatenae count with field1

shaik_sajid
Active Contributor
0 Kudos
62

Hi Bobby,

Use the Function Module CONVERSION_EXIT_ALPHA_INPUT to add leading zeroes to the result.

Regards

Sajid

vattekrishna
Participant
0 Kudos
62

use type n instead of type c.

Former Member
0 Kudos
62

Hello


data: field1(40) type c.
data: field2(2) type c.
data: len1 type i.
data: len2 type i.

field1 = '00035567011'.
len1 = strlen( field1 ).
shift field1 left deleting leading '0'.
len2 = strlen( field1 ).
len1 = len1 - len2.
field2 = '11'.
field1 = field1 + field2.
shift field1 left deleting leading space.
do len1 times.
  concatenate '0' field1 into field1.
enddo.

write field1.

former_member536879
Active Contributor
0 Kudos
62

Hi Bobby,

This is a FAQ. Please search in SCN before Posting.

Use Conversion_exit_alpha_input. Function Module.

With Regards,

Sumodh.P

Former Member
0 Kudos
62

HI Bobby,

Declare one more variable as N.... as shown below... This will solve your requirent.

DATA:

field1(40) TYPE c,

field2(2) TYPE c,

field3 TYPE N LENGTH 9.

field1 = '035567011'.

field2 = '11'.

field3 = field1 + field2.

WRITE field3.

please let me know if that solved your problem.

Thanks

Suraj