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: 

move TYPE C varibale to TYPE N -

former_member181966
Active Contributor
0 Kudos

Hi

I just have a doubt which I need to clear. We’re using some code logic in which we are passing some "C" variables value to FM and return the value and replace (<b>.</b>) by Some Character ( A,b,c,d) . After that perform_call I am doing something like

Data:vari_n(11) type N,

vari_c(13) type c.

The value in vari_c is like '000000002224D'.

<b> MOVE Vari_c+2(11) TO vari_N.</b>

I was expecting that after move statement the value in Vari_n should be like '0000002224D' but in fact its not its like '00000002224'.

<b>It was working correct before , why its not working now ?</b>

Now I made a change into code and write code like

<b> write Vari_c+2(11) TO vari_N.</b>

But my question is that why its not working with move statement.

Please give your input/suggestions.

Thanks

*----


I read Move help and its says that ---

If the field types or lengths differ, the system automatically carries out type conversion. Type I fields are handled like type P fields. If you select the fixed point arithmetic attribute for an ABAP program, type P fields are either rounded according to the number of decimal places or filled with zeros.

See: Conversion Table for the MOVE Statement

If the assignment is allowed but the source field type cannot be converted to the target field type, the contents of the target field are undefined. This would be the case, if you were to assign a C field containing 'ABCD' to a type D or T field.

<b>The operation is terminated only if the target field is a numeric type ( I, P or F).</b>

If the target field has type C, you must decide between MOVE and WRITE TO. The MOVE statement is intended for assignments within a program, and it generates a standard display that is compatible with the source type. This can be converted back into the original value using MOVE again, as long as it was not truncated in the assignment. For this reason, the period (.) is always used as the decimal sign, and dates cannot be converted, regardless of the user defaults.

You use the WRITE TO statement to generate a readable ('external') display for the value of the source field. The target field is usually displayed on a screen or in a list, after further processing if necessary. Unlike MOVE, WRITE TO has several formatting options, which, for some data types, are user-defined. A conversion exit may be called implicitly.

**----


Message was edited by: Saquib Khan

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

We know that type N is a numeric field, you are moving a value to it that contains an alpha, the system will drop the alpha automatically.

This is a problem for you? Do you need the alpha. What is the end result that you need to achieve.

Regards,

Rich Heilman

former_member181966
Active Contributor
0 Kudos

I need to achieve the value '0000002224D'.

<b>I change the code to

write Vari_c+2(11) TO vari_N.

Its working fine..</b>

But the guys over here keep saying it was working fine earlier.. and they are getting their required result ..That’s why I asked ..

Thanks Rich for a prompt reply!!!

0 Kudos

I have never seen a move from c to N carry the alphas along. Again, what is the end result that you require?

In this example, i have put ABC in the middle, it will be stripped out and will only write the numeric value.

report  zrich_0001.

Data:vari_n(11) type N,
vari_c(13) type c.

vari_c =  '00000<b>ABC</b>2224D'.

MOVE Vari_c+2(11) TO vari_N.

write:/ vari_n.

Regards,

Rich Heilman

0 Kudos

<b>'0000002224D'.</b>

report zrich_0001.Data:vari_n(11)

type N,vari_c(13) type c.

vari_c = '00000ABC2224D'.

<b>MOVE Vari_c+2(11) TO vari_N.</b>

I changed it to :

<b>write Vari_c+2(11) TO vari_N.</b>

and it worked....as I posted earlier...

write:/ vari_n.

Thanks ..case closed:)

0 Kudos

type n variables with an alpha at the end are actually negative. The last character is an 'overtype' code, can't remember the exact sequence but it's something like a = -0, b = -1, c= -2 etc. This must be the only case where alpha values are tolerated within type n.

0 Kudos

Ok, this is kinda of strange to me. The reason for having a numeric field is to have a true numeric value. If you wanted the exact string as it was from the character field, then whats the point is using a numeric. Remember, if the N value is used in a calculation, you will get a runtime error for haveing alphas in your numeric field,.



report  zrich_0001.

Data:vari_n(11) type N,
     vari_c(13) type c,
     result type i.

vari_c =  '00000ABC2224D'.

write Vari_c+2(11) TO vari_N.

result =  vari_n + 1.

write:/ vari_n.

Regards,

Rich Heilman

0 Kudos

Rich, this is a special case. They are numeric values, but negative. It is a hangover from pre-historic days when they needed to save space on punched cards. Negative numbers didn't need an extra character they could be represented by using the 'overtype' code on the final character. for example -1134 could be 113D, -1135 113E etc(codes are not necessarily correct but the concept is).