Here is a SAP Quick Knowledge bite for you.
There are 5 Pre-defined character datatypes available for you to use in an ABAP program.
D, T are used to define Date and Time variables.
C,N are similar as in they can both be used to hold alphanumeric characters, while String is used to hold lengthy text string.
While others are self evident, confusion usually happens when you have to make a choice between defining a variable to use C or N.
In that case remember this, a variable when defined as
DATA GV_NAME(3) TYPE C. will hold a blank value as initial.
However a variable defined as
DATA GV_NAME(3) TYPE N. will hold ‘000’ as a its initial value.
So when is this useful ?
If you are wondering, then here is how I used it.
DATA GV_C_NAME(2) TYPE C.
DATA GV_N_NAME(2) TYPE N.
ADD 1 to GV_C_NAME.
ADD 1 to GV_N_NAME.
WRITE GV_C_NAME. // This will print 1
WRITE GV_N_NAME. // This will print 01.
This is useful when you have to loop through fields which have same name but only the last 2 numbers are changing.
For example a table which has columns as FNAME01, FNAME02, FNAME03, FNAME04 and you have to loop through all the columns in your program, then you could simply define a variable of type GV_N_NAME, keep incrementing it and access the field that way.
Very nice tips.
Just one question can a numeric data type(N) can hold the value like ‘abcd’ made up of only alphabets or it should contain value like ‘1234’.