Application Development and Automation 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: 
Read only

CHECK_CHANGED_DATA: update fields with decimal places

Former Member
0 Likes
961

Hi Experts,

In my ALV display there is a field which can be modified.

While doing that I'm using CHECK_CHANGED_DATA, but it is allowing me to update numbers before the decimal places, e.g., 123.00 can be modified as 555.00.

But it is not allowing me to update numbers after the decimal place, e.g., 123.99 is not being modified as 123.55.

Please suggest as slowly as possible.

Code snippet:

Declarations

TYPES: BEGIN OF x_share_stock, 
         chk TYPE c , 
          share_price TYPE zstock-share_price, "DEC len 13, dec 2 
          color(4), 
         field_style TYPE lvc_t_styl, 
       END OF x_share_stock. 

wa_share_stock1 TYPE x_share_stock, 
it_share_stock1_prev TYPE TABLE OF x_share_stock.

Field Catalog:

form build_catalog . 
  wa_fieldcat-fieldname   = 'CHK'. 
  wa_fieldcat-scrtext_m   = 'Check'. 
  wa_fieldcat-col_pos     = 0. 
  wa_fieldcat-outputlen   = 10. 
  wa_fieldcat-emphasize   = 'X'. 
  wa_fieldcat-key         = 'X'. 
  wa_fieldcat-edit        = 'X'. 
  wa_fieldcat-checkbox    = 'X'. 
  append wa_fieldcat to it_fieldcat. 
  clear  wa_fieldcat. 

  wa_fieldcat-fieldname = 'SHARE_PRICE'. 
  wa_fieldcat-col_pos = 3. 
  wa_fieldcat-outputlen   = 10. 
  wa_fieldcat-scrtext_m = 'Price'. 
  append wa_fieldcat to it_fieldcat. 
  clear wa_fieldcat.

Update:

WHEN 'UPDATE'. 
IF ref_grid IS INITIAL. 
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 
          IMPORTING 
            e_grid = ref_grid. 
      ENDIF. 
      CALL METHOD ref_grid->check_changed_data . 
      CALL METHOD ref_grid->refresh_table_display. 
      CLEAR: v_share_out, 
             v_zshare. 
*  Read the table it_share_stock1 with first checkbox checked. 
      READ TABLE it_share_stock1 INTO wa_share_stock1 WITH KEY chk = 'X'. 
      IF sy-subrc EQ 0. 
        v_tabix = sy-tabix. 
        v_share_out = wa_share_stock1-share_out. 
        v_zshare = wa_share_stock1-zshare. 
      ENDIF. 
* Read the table it_share_stock1_prev which gives the values before EDIT. 
      READ TABLE it_share_stock1_prev INTO wa_share_stock1_prev INDEX v_tabix. 
      IF sy-subrc EQ 0. 
        v_tabix = sy-tabix. 
        v_share_out1 = wa_share_stock1_prev-share_out. 
        v_zshare_prev = wa_share_stock1_prev-zshare. 
      ENDIF. 
* Get the difference between EDITED value and Previous value 
      v_diff = v_zshare - v_zshare_prev. 
* Modify it_share_stock1 with new values for the first check box checked row. 
      wa_share_stock1-share_out  = v_share_out + v_diff. 
      IF wa_share_stock1_prev-share_price NE wa_share_stock1-share_price. 
        wa_share_stock1-share_price = wa_share_stock1-share_price * 100. 
      ENDIF.

Thanks in advance,

Anirban.

Edited by: Thomas Zloch on Jan 17, 2011 2:27 PM - priority reduced by moderator

Hi Experts,

In my ALV display there is a field which can be modified.

While doing that I'm using CHECK_CHANGED_DATA, but it is allowing me to update numbers before the decimal places, e.g., 123.00 can be modified as 555.00.

But it is not allowing me to update numbers after the decimal place, e.g., 123.99 is not being modified as 123.55.

Please suggest as slowly as possible.

Code snippet:

Declarations

TYPES: BEGIN OF x_share_stock, 
         chk TYPE c , 
          share_price TYPE zstock-share_price, "DEC len 13, dec 2 
          color(4), 
         field_style TYPE lvc_t_styl, 
       END OF x_share_stock. 

wa_share_stock1 TYPE x_share_stock, 
it_share_stock1_prev TYPE TABLE OF x_share_stock.

Field Catalog:

form build_catalog . 
  wa_fieldcat-fieldname   = 'CHK'. 
  wa_fieldcat-scrtext_m   = 'Check'. 
  wa_fieldcat-col_pos     = 0. 
  wa_fieldcat-outputlen   = 10. 
  wa_fieldcat-emphasize   = 'X'. 
  wa_fieldcat-key         = 'X'. 
  wa_fieldcat-edit        = 'X'. 
  wa_fieldcat-checkbox    = 'X'. 
  append wa_fieldcat to it_fieldcat. 
  clear  wa_fieldcat. 

  wa_fieldcat-fieldname = 'SHARE_PRICE'. 
  wa_fieldcat-col_pos = 3. 
  wa_fieldcat-outputlen   = 10. 
  wa_fieldcat-scrtext_m = 'Price'. 
  append wa_fieldcat to it_fieldcat. 
  clear wa_fieldcat.

Update:

WHEN 'UPDATE'. 
IF ref_grid IS INITIAL. 
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' 
          IMPORTING 
            e_grid = ref_grid. 
      ENDIF. 
      CALL METHOD ref_grid->check_changed_data . 
      CALL METHOD ref_grid->refresh_table_display. 
      CLEAR: v_share_out, 
             v_zshare. 
*  Read the table it_share_stock1 with first checkbox checked. 
      READ TABLE it_share_stock1 INTO wa_share_stock1 WITH KEY chk = 'X'. 
      IF sy-subrc EQ 0. 
        v_tabix = sy-tabix. 
        v_share_out = wa_share_stock1-share_out. 
        v_zshare = wa_share_stock1-zshare. 
      ENDIF. 
* Read the table it_share_stock1_prev which gives the values before EDIT. 
      READ TABLE it_share_stock1_prev INTO wa_share_stock1_prev INDEX v_tabix. 
      IF sy-subrc EQ 0. 
        v_tabix = sy-tabix. 
        v_share_out1 = wa_share_stock1_prev-share_out. 
        v_zshare_prev = wa_share_stock1_prev-zshare. 
      ENDIF. 
* Get the difference between EDITED value and Previous value 
      v_diff = v_zshare - v_zshare_prev. 
* Modify it_share_stock1 with new values for the first check box checked row. 
      wa_share_stock1-share_out  = v_share_out + v_diff. 
      IF wa_share_stock1_prev-share_price NE wa_share_stock1-share_price. 
        wa_share_stock1-share_price = wa_share_stock1-share_price * 100. 
      ENDIF.

Thanks in advance,

Anirban.

Edited by: Thomas Zloch on Jan 17, 2011 2:27 PM - priority reduced by moderator

3 REPLIES 3
Read only

Clemenss
Active Contributor
0 Likes
743

Hi Anirban_Mallick ,

probably zstock-share_price is a currency field. You need to set a reference field that has the currency key or you can define the currency key hard coded in field catalog.

What does CHECK_CHANGED_DATA code look like?

Regards,

Clemens

Read only

Former Member
0 Likes
743

Thank you all.

Problem resolved.

Needed to modify the field catalog.

wa_fieldcat-fieldname = 'SHARE_PRICE'.
  wa_fieldcat-col_pos = 3.
  wa_fieldcat-outputlen   = 13.   "Modified this line
  wa_fieldcat-decimals  = 4.      "Added this line
  wa_fieldcat-scrtext_m = 'Price'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

Cheers..!!

Anirban.

Edited by: Anirban_Mallick on Jan 18, 2011 7:32 AM

Edited by: Anirban_Mallick on Jan 18, 2011 7:33 AM

Read only

Former Member
0 Likes
743

Resolved.