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: 

Formatting a packed field to display correctly

Former Member
0 Kudos

Functionally we've configured the system to store display whole numbers only. No decimals. The way it's stored in the ANLC table is with decimals. For example:

acquisition value in ANLC = 28,726.92 when the actual value is 2,872,692. The latter is number we want to report. I'm able to do that in a custom report with the write: anlc-kansw round -2 decimals 0. That will do it, but I'm converting this program to ALV. I can't seem to make this work for the ALV. If I move it to a character field, then it will work, but I'm sure they'll be able sum correctly if I do that. I may be wrong about that.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Linda,

Currency fields, quantity fields require units when writing them out to the reports. So if you give the currency key, you should get the output without decimals if that is how your currency is defined in config.

WRITE ANLC-KANSW CURRENCY 'USD'(or a variable storing the currency key)

or for quantity fields

WRITE MSEG-MENGE UNIT 'CS'.

7 REPLIES 7

Former Member
0 Kudos

Hi

ANLC-KANSW is an amount field and need a reference CUKY field to be displayed in correct format in ALV.

Cheers

0 Kudos

Thanks. It solved the problem.

Former Member
0 Kudos

Hi Linda,

Currency fields, quantity fields require units when writing them out to the reports. So if you give the currency key, you should get the output without decimals if that is how your currency is defined in config.

WRITE ANLC-KANSW CURRENCY 'USD'(or a variable storing the currency key)

or for quantity fields

WRITE MSEG-MENGE UNIT 'CS'.

0 Kudos

I understand the WRITE statement, but when you code for ALV, you don't use a write statement. I need to play with it some. I can't seem to get it to work.

0 Kudos

In ALV, your fieldcat has two fields cfieldname and ctabname. You need to give these values.

Look at the documentation below

<i>


Reference to fields with currency units/units of measure

Each amount or quantity field of the internal output table whose decimal places are to be displayed with the proper unit in the list output, must comply with the following conventions:
The field is of data type QUAN or CURR (internal type P).
(Physically, the field must actually belong to this data type. Overriding the physical data type with parameter FIELDCAT-DATATYPE has no effect.)
There is one field in the internal output table that contains the relevant unit.
There is also an entry for the unit field in the field catalog.
(If the unit should not be displayed as a column in the list and the user should not be able to show the unit interactively, for example, because the unit is always unique and therefore explicitly output by the caller in the list header, then you can assign parameter FIELDCAT-TECH = 'X' to the field catalog entry for the unit field. 
If a value field has a reference to a unit, this has the following effects when the list is output:
The decimal places are displayed with the proper unit.
An initial value field with reference to a non-initial unit is displayed as '0' (provided that FIELDCAT-NO_ZERO is initial). If unit-specific totals are calculated for this value field, the unit is considered in the analysis of whether homogeneous units exist. 
An initial value field with reference to an initial unit is displayed as SPACE. If unit-specific totals are calculated for this value field, the unit SPACE has no effect on the homogeneity of the unit if the value field is initial.
For non-initial value fields with initial unit, the unit SPACE is considered as a unit when unit-specific totals are calculated.
Reference to the currency unit

cfieldname (field name of the currency unit field)
Value range: SPACE, name of a field of the output table
Only relevant to amount columns with unit reference.
Field name of the field in the internal output table that contains the currency unit for the amount field FIELDCAT-FIELDNAME. 
There must be a separate field catalog entry for the field specified in FIELDCAT-CFIELDNAME.
Reference to the unit of measure

qfieldname (field name of the unit of measure field)
Value range: SPACE, name of a field of the output table
Only relevant to quantity columns with unit reference.
Field name of the field in the internal output table that contains the unit of measure for the amount field FIELDCAT-FIELDNAME. 
There must be a separate field catalog entry for the field specified in FIELDCAT-QFIELDNAME.

</i>

0 Kudos

Hi Linda,

As suggested by Sanjay Sinha, you need to have currency key attached to this amount in order to display it correctly. See following link from SAP help -

http://help.sap.com/saphelp_erp2004/helpdata/en/ff/4649b1f17411d2b486006094192fe3/content.htm

Cheers,

Sanjeev

0 Kudos

Thank you. It's working