Skip to Content
author's profile photo Former Member
Former Member

ALV: Quantity Field - Display whole number and decimal number only.

Hi Experts,

I am currently displaying quantity using FKIMG field.

This is my clients requirement:

1. Display only whole number.

Instead of Displaying 1.000, it should be displayed as 1.

2. Display the decimal number.

1.230 = should be 1.23

0.230 = should be 0.23

This two should be displayed on quantity column in my alv report.

The problem is, if I use "I" as my data type it only display the whole number and not the decimal.

If I use P and set decimal into 2, it displays the whole number but also display 2 decimal places.

What should I do?

Please help and thank you in advance.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 05, 2013 at 05:19 AM

    Use wa_fieldcatalog-no_zero = 'X' while you are passing value to fieldcatlog.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Use it where u are filling up you are assigning field to your internal table

      like this...

      wa_fieldcatalog-fieldname = 'NETPR'.
      wa_fieldcatalog-seltext_m = 'Net Price'.
      wa_fieldcatalog-col_pos = 7.
      wa_fieldcatalog-outputlen = 15.
      wa_fieldcatalog-no_zero = 'X'.

      append wa_fieldcatalog to it_fieldcatalog.

  • Posted on Dec 05, 2013 at 03:36 AM

    Hi,

    Use the ROUND function module.

    Regards,

    Josh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 05, 2013 at 05:01 AM

    Hi Neil ,

    If you want to display a quntity after rounding as whole number you can use function module below with example:

    COS6_QUANTITY_ROUND

    Import parameters Value

    I_QUANTITY 1.234 I_UNIT EA

    Export parameters Value

    E_QUANTITY

    2.000

    Or simply if want to cut off the decimals you can use the below example code.

    QTY1 = WA-LFIMG.

    CONDENSE QTY1 NO-GAPS.

    SHIFT QTY1 RIGHT DELETING TRAILING '0'.

    SHIFT QTY1 RIGHT DELETING TRAILING '.'.

    CONDENSE QTY1 NO-GAPS.

    Cheers,

    Sanjith N

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 05, 2013 at 05:16 AM

    Hi Neil,

    Use Split command and use offset....

    Regards,

    Ankit

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 05, 2013 at 05:26 AM

    try this,

    DATA: A TYPE mseg-MENGE VALUE '1.230'.

    DATA: B TYPE mseg-MENGE VALUE '1.234'.

    DATA: STR1 TYPE c LENGTH 25,

    STR2 TYPE c LENGTH 25,

    STR3 TYPE c LENGTH 25.

    data: dec type c LENGTH 2.

    move a to str1.

    SPLIT str1 at '.' INTO: str2 str3.

    CONDENSE str3.

    if str3+2(1) eq '0'.

    move str3 to dec.

    clear: str1.

    CONCATENATE str2 '.' dec INTO str1.

    else.

    clear: str1.

    CONDENSE: STR2,STR3.

    CONCATENATE str2 '.' str3 into str1.

    endif.

    CONDENSE STR1.

    write: str1.

    clear:str1.

    move b to str1.

    SPLIT str1 at '.' INTO: str2 str3.

    CONDENSE str3.

    if str3+2(1) eq '0'.

    move str3 to dec.

    clear: str1.

    CONCATENATE str2 '.' dec INTO str1.

    else.

    clear: str1.

    CONDENSE: STR2,STR3.

    CONCATENATE str2 '.' str3 into str1.

    endif.

    CONDNESE STR1.

    write: str1.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 05, 2013 at 05:44 AM

    Hi neil,

    use the below function module, before calling the REUSE_ALV_GRID_DISPLAY. just process the internal table and change the values of the numeric field by within loop endloop.

    DATA: WA_INPUT TYPE P DECIMALS 8,

    WA_OUTPUT TYPE P DECIMALS 2.

    *WA_INPUT = '5678.2342134444'.

    wa_input = '0.2300'.

    *

    CALL FUNCTION 'ROUND'

    EXPORTING

    INPUT = WA_INPUT

    IMPORTING

    OUTPUT = WA_OUTPUT

    EXCEPTIONS

    INPUT_INVALID = 1

    OVERFLOW = 2

    TYPE_INVALID = 3

    OTHERS = 4.

    IF SY-SUBRC <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    WRITE: WA_OUTPUT.


    Regards,

    sivaganesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2013 at 12:06 PM

    Hello Neil,

    I guess you have to do the calculation how many digits you need by yourself and then tell the ALV to display the needed number of decimals.

    Add an additional field to your output table that holds the number of decimals you want to output.

    See the following example that sets the decimal places in the column FKIMG to 0,1,2,3,0,1,2,....

    REPORT.

    TYPES: BEGIN OF gty_data.
    INCLUDE STRUCTURE vbrp.
    TYPES:
    my_decimals TYPE char1, "<-- needed to tell how many digits you need in this line
    END OF gty_data.

    DATA: gt_data TYPE STANDARD TABLE OF gty_data WITH NON-UNIQUE DEFAULT KEY.
    FIELD-SYMBOLS: <data> LIKE LINE OF gt_data.

    END-OF-SELECTION.
    SELECT * UP TO 20 ROWS INTO CORRESPONDING FIELDS OF TABLE gt_data FROM vbrp WHERE fkimg <> 0.
    LOOP AT gt_data ASSIGNING <data>.
    <data>-fkimg = 100.
    <data>-my_decimals = ( sy-tabix - 1 ) MOD 4. " Set number of digits
    ENDLOOP.
    PERFORM show_data.


    *&---------------------------------------------------------------------*
    *& Form SHOW_DATA
    *&---------------------------------------------------------------------*
    FORM show_data .
    TYPE-POOLS: slis.
    DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.
    FIELD-SYMBOLS: <fc> LIKE LINE OF lt_fieldcat.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    i_structure_name = 'VBRP'
    i_bypassing_buffer = 'X'
    CHANGING
    ct_fieldcat = lt_fieldcat
    EXCEPTIONS
    inconsistent_interface = 1
    program_error = 2
    OTHERS = 3.

    READ TABLE lt_fieldcat ASSIGNING <fc> WITH KEY fieldname = 'FKIMG'.
    CHECK sy-subrc = 0.
    CLEAR <fc>-ref_tabname. " Delete all references
    CLEAR <fc>-ref_fieldname. " to original decimals
    CLEAR <fc>-datatype. " Delete all references
    CLEAR <fc>-qfieldname. " to original decimals
    <fc>-decimalsfieldname = 'MY_DECIMALS'. " Tell ALV to use new field as digit count

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    it_fieldcat = lt_fieldcat
    TABLES
    t_outtab = gt_data
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    ENDFORM. " SHOW_DATA

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2013 at 08:06 AM

    Hi Neil,

    Create you field catalog manually.

    The structure LVC_S_FCAT has fields for setting the decimal and edit_mask.

    Try to set decimal field to 0 or use a custom mask with the field edit_mask.

    Regards,

    Pravin.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.