2013 Dec 05 2:47 AM
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.
2013 Dec 05 3:36 AM
2013 Dec 05 5: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
2013 Dec 05 5:17 AM
Hi sanjith natarajan,
Thank you for your help, but the program gives me error "FKIMG must be a character type data object".
But if we change the data type into character type, alv will not compute the Total and Sub-total of the quantity.
Thank you very much.
-neil
2013 Dec 09 5:31 AM
Hi neil,
You can use char type and try to compute the total and subtotal. most probably it will work .
cheers,
Sanjith N
2013 Dec 05 5:16 AM
2013 Dec 05 5:19 AM
2013 Dec 05 5:29 AM
REPORT ZDEMO.
DATA: VAR1 TYPE CHAR4 VALUE '1.00',
VAR2 TYPE CHAR4.
SPLIT VAR1 AT '.' INTO VAR1 VAR2.
WRITE: VAR1.
Regards,
Ankit
2013 Dec 05 5:19 AM
Use wa_fieldcatalog-no_zero = 'X' while you are passing value to fieldcatlog.
2013 Dec 05 5:24 AM
Hi Farid,
I used the function 'REUSE_ALV_GRID_DISPLAY'
How can use your idea with this function?
Thanks
neil
2013 Dec 10 8:50 AM
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.
2013 Dec 05 5: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.
2013 Dec 05 5: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
2013 Dec 09 8: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.
2013 Dec 09 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