Supported by

Writing money without any decimal worries

Some people read the TCURX to find out the number of decimal places of a CURRENCY when they need to write a money field to an alphanumeric variable.

Are you one of those people? Don’t be.

You can’t, of course, simply assume that all currencies have two decimal places. Look at Japan, which doesn’t have any at all. Or the defunct Escudo, which also had none. So, if you’re like that person described above, you go to TCURX to see if your CURRENCY is there. And if it is, you save the number of decimal places in the CASAS_DECIMAIS variable. If it isn’t, you assume it has two decimal places. Then you do:

WRITE money TO alphanumeric DECIMALS casa_decimais.

And that sees you right.

But it’s not pretty. And it’s laborious.

Why not do something like:

WRITE money TO alphanumeric CURRENCY currency.

It’s prettier, cleaner and always comes out right. Because SAP does the work for you.

Thanks to Pierre Ameye for the tip.

Greetings from Abapinho.

Um comentário a “Writing money without any decimal worries”

  1. Bruno Esperança Diz:

    There is also addition UNIT.

    This was very useful for me when I wanted to write a quantity in a SAP Script but NOT right-aligned. By default SAP Script outputs any quantity or currency field as right-justified, but for my particular case, I didn’t want this, so I had to “write” the value to an alphanumeric field, but without the addition “UNIT” I always had 3 decimals.

Deixe um comentário

About Abapinho
Abapinho runs on WordPress
Articles (RSS) e Comments (RSS).