2005 Oct 20 11:43 AM
Hi,
How do you format a field of type CHAR when it has a numeric figure. The following example explains it all;
12000000.00 > after formatting > 12,000,000.00
Thanks,
Kishan
2005 Oct 20 11:55 AM
data: mychar(16) value '12000000.00',
mypack type p decimals 2.
mypack = mychar.
write mypack to mychar.
Svetlin
data: mychar(16) value '12000000.00',
mypack type p decimals 2.
mypack = mychar.
write mypack to mychar.
Svetlin
2005 Oct 20 11:55 AM
Hi
You can use the command write with option CURRENCY or UNIT (depend on the type of information on your field).
DATA: WA TYPE WRBTR.
MOVE NUM_CHAR TO WA.
WRITE WA CURRENCY 'EUR' TO NUM_CHAR.
Max
2005 Oct 20 11:55 AM
data: mychar(16) value '12000000.00',
mypack type p decimals 2.
mypack = mychar.
write mypack to mychar.
Svetlin
2005 Oct 20 11:57 AM
Hi,
If you do not specify any format or length specification on the write statement, the default format and length of the field are used. These defaults originate in the ABAP/4 data types. DDIC fields are based on ABAP/4 data types, and they thereby inherit the default format and length. In addition, format specifications such as number of decimal places and output length can also be specified in the domain; these override the inherited values.
You specify one of these formats via the user profile setting Decimal Notation (from any screen, choose the menu path System->User Profile->User Defaults
You can use Edit masks. It enable you to:
Insert characters into the output
Move the sign to the beginning of a numeric field
Artificially insert or move a decimal point
Display a floating-point number without using scientific notation
Anywhere within an edit mask, the underscore character (_) has special meaning. At the beginning of an edit mask, V, LL, RR, and == have special meaning. All other characters are transferred without change to the output.
Underscores within an edit mask are replaced one-by-one with the characters from the source field (the field you are writing out). The number of characters taken from the source field will be equal to the number of underscores in the edit mask. For example, if there are three characters in the edit mask, at most three characters from the source field will be output. All other characters in the edit mask are inserted into the output. You also usually need to increase the length of the output field to accommodate the extra characters inserted by the mask.
For example, the statement write (6) 'ABCD' using edit mask '_:__:_' writes A:BC:D. Characters are taken from the source field one at a time, and characters from the edit mask are inserted at the points indicated by the mask. The statement write 'ABCD' using edit mask '_:__:_' only writes A:BC because the default output length is equal to the length of the source field (4).
If there are fewer underscores in the mask than there are in the source field, the default is to take the left-most n characters from the source field, where n equals the number of underscores in the edit mask. This can also be explicitly specified by preceding the edit mask with LL. For example, write 'ABCD' using edit mask 'LL__:_' takes the left-most three characters and writes out AB:C. Using RR instead takes the right-most three characters, so write 'ABCD' using edit mask 'RR__:_' will write out BC:D.
If there are more underscores than there are source field characters, the effect of LL is to left-justify the value in the output; RR right-justifies the value (see Listing 14.7 for an example).
An edit mask beginning with a V, when applied to a numeric field (types i, p, and f), causes the sign field to be displayed at the beginning. If applied to a character field, a V is actually output.
Example:
The Effect of Various Edit Masks
1 report ztx1407.
2 data: f1(4) value 'ABCD',
3 f2 type i value '1234-'.
4
5 write: / ' 5. ', f1,
6 / ' 6. ', (6) f1 using edit mask '_:__:_',
7 / ' 7. ', f1 using edit mask 'LL_:__',
8 / ' 8. ', f1 using edit mask 'RR_:__',
9 / ' 9. ', f2 using edit mask 'LLV______',
10 / '10. ', f2 using edit mask 'RRV______',
11 / '11. ', f2 using edit mask 'RRV___,___',
12 / '12. ', f2 using edit mask 'LLV___,___',
13 / '13. ', f1 using edit mask 'V___'.
Output:
5. ABCD
6. A:BC:D
7. A:BC
8. B:CD
9. -1234
10. - 1234
11. - 1,234
12. -123,4
13. VABC
Regards
Afsal
2005 Oct 20 12:37 PM
2005 Oct 20 11:58 AM
Hi Kishan,
Just assign the char field to one of type curr, or quan (however you want it to be formatted).
In the example below, I have taken the data element called FRATH, which is CURR 13,2.
DATA : c1(20) TYPE c,
c2 TYPE FRATH.
c1 = '120000.00'.
c2 = c1.
WRITE : c1, c2.
Sudha
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |