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: 

Incorrect onversion of values in ALV

YayatiEkbote
Contributor
0 Kudos

Hello experts,

I am using editable ALV to calculate the values runtime. The field spn is editable where as other three columns are based on the values of the field spn. Initially, when first display is shown, all the values are picked from it_tab correctly. But when i edit the values of field spn and i refresh the screen, the decimal values of the figure are converted automatically.

For example, my initial value for 1st row and column 'spn' is 111234.234. Now when i change it to '50000.000' and say refresh then the value is taken as '50.000'. Hence the rest calculations are being done on the value of 50.000 and not 50000.000. And the field is of standard type MSEG-MENGE. what is the problem? How does the value gets converted internally? I have found that the value is multiplied by 10^-3. What is the solution to this?

Here is my code

TYPES: BEGIN OF st_tab,

spn TYPE MSEG-MENGE,

crs TYPE MSEG-MENGE,

pdp TYPE MSEG-MENGE,

cls TYPE MSEG-MENGE,

END OF st_tab.

DATA: it_tab TYPE STANDARD TABLE OF st_tab,

wa_tab LIKE LINE OF IT_TAB.

DATA: pdp_cap TYPE MSEG-MENGE VALUE '100000.500',

stk TYPE MSEG-MENGE,

ok_code TYPE sy-ucomm,

RE_FLAG type C VALUE ''.

DATA: t_fieldcat TYPE lvc_t_fcat,

lv_fieldcat TYPE lvc_s_fcat,

it_layout TYPE lvc_s_layo,

c_ccont TYPE REF TO cl_gui_custom_container, "Custom container object

c_alvgd TYPE REF TO cl_gui_alv_grid. "ALV grid object

wa_tab-spn = '111234.234'.

wa_tab-crs = '2000000'.

APPEND wa_tab TO it_tab.

wa_tab-spn = '546000.500'.

wa_tab-crs = '5000000.500'.

APPEND wa_tab TO it_tab.

wa_tab-spn = '999'.

wa_tab-crs = '3000'.

APPEND wa_tab TO it_tab.

PERFORM calc.

CALL SCREEN 100.

FORM calc.

LOOP AT it_tab INTO wa_tab.

stk = wa_tab-crs - wa_tab-spn.

IF stk > 0.

wa_tab-pdp = stk.

ELSE.

wa_tab-pdp = 0.

ENDIF.

wa_tab-cls = wa_tab-pdp + wa_tab-crs - wa_tab-spn.

MODIFY it_tab FROM wa_tab.

ENDLOOP.

ENDFORM.

FORM create_fieldcatalog.

PERFORM fieldcatalog USING '1' 'SPN' 'sales plan'.

PERFORM fieldcatalog USING '2' 'CRS' 'current stock'.

PERFORM fieldcatalog USING '3' 'PDP' 'production plan'.

PERFORM fieldcatalog USING '4' 'CLS' 'closing stock'.

ENDFORM.

FORM fieldcatalog USING value(col_pos) value(fldname) value(fldlabel).

lv_fieldcat-col_pos = col_pos.

lv_fieldcat-fieldname = fldname.

IF fldname = 'SPN'.

lv_fieldcat-edit = 'X'.

ELSE.

lv_fieldcat-edit = ' '.

ENDIF.

lv_fieldcat-scrtext_m = fldlabel.

APPEND lv_fieldcat TO t_fieldcat.

ENDFORM. "fieldcatalog

FORM build_layout.

it_layout-cwidth_opt = 'X'.

it_layout-zebra = 'X'.

ENDFORM.

MODULE status_0100 OUTPUT.

SET PF-STATUS 'CLICK'.

IF RE_FLAG = ''.

CREATE OBJECT c_ccont

EXPORTING

container_name = 'CCONT'.

CREATE OBJECT c_alvgd

EXPORTING

i_parent = c_ccont.

PERFORM create_fieldcatalog.

PERFORM build_layout.

CHECK NOT c_alvgd IS INITIAL.

ELSEIF .

RE_FLAG = 'X'.

PERFORM create_fieldcatalog.

PERFORM build_layout.

ENDIF.

PERFORM grid_display.

ENDMODULE.

MODULE user_command_0100 INPUT.

c_alvgd->check_changed_data( ).

CASE ok_code.

WHEN 'REFRESH'.

PERFORM calc.

CALL SCREEN 200.

WHEN 'BACK'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE.

FORM grid_display.

CALL METHOD c_alvgd->set_table_for_first_display

EXPORTING

is_layout = it_layout

i_save = 'A'

CHANGING

it_outtab = it_tab

it_fieldcatalog = t_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 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.

ENDFORM.

module STATUS_0200 output.

RE_FLAG = 'X'.

clear t_fieldcat.

LEAVE TO SCREEN 100.

endmodule.

1 ACCEPTED SOLUTION

former_member184578
Active Contributor
0 Kudos

Hi Yayati.,

Instead of giving '50000.000' try using '50000' .. since it is of 'QUAN' datatype 3 decimal places will be taken automatically..

Thanks,

Regards,

kiran

2 REPLIES 2

former_member184578
Active Contributor
0 Kudos

Hi Yayati.,

Instead of giving '50000.000' try using '50000' .. since it is of 'QUAN' datatype 3 decimal places will be taken automatically..

Thanks,

Regards,

kiran

YayatiEkbote
Contributor
0 Kudos

Thanks, Problem solved.