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

ALV gorus double dare: ALV Data_Changed issues.

yes_sapteam
Participant
0 Likes
3,065

Hi All.

This is a message I just posted to the OSS, let's see how clever you are:

<i>I am working on the subject for more than a week and a half now, posted the same question in 5 different forums (1 is SDN), followed SAP SLIS demo program (BCALV_EDIT_03) to the letter, and debugged SAP Standard code for 2 days and still I cannot find what I'm doing wrong.

Here are the issues:

1.

When I hit F4 in my program the DATA_CHANGED event is called BEFORE the

value list is displayed.

2.

I hit F4 in the 1st field and the MT_GOOD_CELLS have 1 record with the 1st field's data.

I hit F4 in the 2nd field and the MT_GOOD_CELLS have both 1st & 2nd fields data.

Like I said I followed program "BCALV_EDIT_03" very closely and still these issues are there.

I debugged the SAP Standard code and found the following:

1.

The reason why the "DATA_CHANGED" is called twice:

If the Check-table of the field we clicked F4 on has more than 1 fields

from the Check-table the FM "DD_SHLP_GET_HELPMETHOD" in the F4 method returns a table with more than 1 record and so the "SAVE_DATA" method is called, which, in turn, triggers the "DATA_CHANGED" event.

2.

The reason why the MT_GOOD_CELLS" has more than 1 record at a time:

a. For the program "BCALV_EDIT_03" the FM "DP_GET_STREAM_FROM_FRONT"

return a table with 1 record and the table is in the structure of

"LVC_S_MODI".

b. For my program this FM returns a table many records (1 for each field

in the Field-catalog) and this table has the structure of

"LVC_S_COLL".

I've reached the end of my ability to see what I'm doing wrong, and since

I can't get help from the different forums I have to turn to you.

Let me know if you want to enter our system to try it yourself and I'll open it for you and give you steps for reproduction.</i>

thanx.

ayal.

19 REPLIES 19
Read only

uwe_schieferstein
Active Contributor
0 Likes
2,866

Hello Ayal

I would not call myself an "ALV guru" yet I have decent understanding of (OO-based) ALV lists. However, I have one major problem with your query:

- <i>What is your question???</i>

Looking at the coding and description of report BCALV_EDIT_03 I assume that your task has something to do with validating search help values. Then let us see the coding and a brief description of the expected and actual results.

Regards

Uwe

Read only

0 Likes
2,866

Uwe,

Exactly... I am sure that SAP's OSS Team is as confused as we are.

Read only

0 Likes
2,866

Uwe & John.

I hope the OSS team will <i>not</i> be confused as you are.

I specified my 2 issues that I have, but let me repeat them briefly:

1. <b>DATA_CHANGED</b> is called <i>before</i> the cell's content has changed.

2. In my <b>DATA_CHANGED</b> the table that holds the cells that needs to be processed

holds <i>all</i> the cells that was previously touched and not only current cell.

These issues are very problematic and I couldn't and don't want to find a work around that.

thanx

ayal.

Read only

0 Likes
2,866

Hello Ayal

Perhaps the following coding in your event handler method for DATA_CHANGED may dissolve your problematic situation:

  IF ( e_onf4 = 'X'   AND e_onf4_before = 'X' ).
    RETURN.
  ENDIF.

The event handler method will not be passed anymore <i>before</i> the values are returned from the search help.

Regards

Uwe

Read only

0 Likes
2,866

Dear Uwe.

You suggested it in another thread I opened and it might work to solve issue #1 but not issue #2.

Another thing, as I said there is no apparent reason why method <b>DATA_CHANGED</b>

should be called <i>before</i> the cell's content changes.

I worked in Java for a while and I know that they have method <b>DATA_CHANGED</b> but it never called <i>before</i> cell's content changes.

For this they have the event <b>BEFORE_DATA_CHANGED</b> or something similar.

thanx

ayal.

Read only

uwe_schieferstein
Active Contributor
0 Likes
2,866

Hello Ayal

Based on the number of views of this thread there seems to be some interest in our discussion. Thus, let us continue.

Sorry to repeat myself but again:

<i>- What is real problem?</i>

Again, showing the coding of your report together with expected and actual results will be appreciated by all of us who want to solve this (not yet defined) problem.

Regards

Uwe

Read only

0 Likes
2,866

Dear Uwe.

Before I go into deep explanations let me say something: I guess, and it's probably certain, that I'm doing something wrong that cause this behavior.

The point is that SAP code should not be so delicate as to behave this way just because I did called statement A before statement B (for example).

Let me remind you that I followed demo programs extremely close and even have some programs that works OK, but I can't tell why !!!

Let me draw the problem in details:

Step 1.

You hit F4 for <i>FieldA</i> before the list of values is displayed you pass through the <b>DATA_CHANGED</b> method. This time, no harm is done since the <b>MT_GOOD_CELLS</b> is empty, just very strange.

Than the list of values comes up and you choose a value by double-clicking and than you pass <i>again</i> through the <b>DATA_CHANGED</b>, this time it's OK since the <i>FieldA</i> content has changed and you process it and everything is fine.

Step 2.

You hit F4 for <i>FieldB</i> and again, before the list of values is displayed, you pass through the <b>DATA_CHANGED</b> method. This time though, the <b>MT_GOOD_CELLS</b> contains the data of <i>FieldA</i> and the processing take place again, which may sometimes cause problems, but let's assume no harm is done.

When the list of values is displayed you choose a value again and again you go through the <b>DATA_CHANGED</b> method and again, <b>MT_GOOD_CELLS</b> contains data

for both fields and the process takes place for both of them.

If you throw in some more complication like <i>FieldA</i> & <i>FieldB</i> are not from the same column, which mean different process is needed, and when clicking <i>FieldA</i> you want to populate <i>FieldC</i> & <i>FieldD</i> since they relate logically.

Combining this complexity and the odd behavior you'll start getting all kind of error messages in your logic.

I hope this clears things up a little.

thanx

ayal.

Read only

0 Likes
2,866

Hello Ayal

Your report is definitely not following the trail of sample report BCALV_EDIT_03. Putting a break-point at the beginning of event handler method HANDLE_DATA_CHANGED the program never stops there irrespective of how often I call the F4 help.

Once again the only way to shed light on this enigma is to provide the source code.

Regards

Uwe

Read only

0 Likes
2,866

Dear Uwe.

Are you ready for this? (I've only have here what I think is necessary).

Note: at first I worked with my F4 event but after things got wiered I went back to use the default F4 from the DDIC and I even declared my field with a Check-table exactly like the relevant field in the SLIS demo program.

Let me know if you need more of my code.


*----------------------------------------------------------------------*
*      Form  display_report
*
* This form will show the alv on screen
*----------------------------------------------------------------------*
FORM display_report.
* Write message line.
  message_line = 'Building ALV before display...'.
  PERFORM write_message_line.

* Set ALV properties.
  PERFORM build_gs_layout.

* Set Disvariant structure.
  PERFORM build_gs_disvariant.

* Set F4-Help to fields.
  PERFORM set_f4_help_to_field.

* Set fields with Drop-down list.
  PERFORM set_drop_down_for_fields.

* Build and create table's columns.
  PERFORM gt_fieldcat_build.

* Set edit mode for fields.
  PERFORM set_edit_mode.

* Build the ALV objects.
  PERFORM create_objects
                    USING gc_custom_container.

* Call ALV.
  PERFORM call_alv.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  build_gs_layout
*&---------------------------------------------------------------------*
* This function will build the table that holds the ALVs properties.
*----------------------------------------------------------------------*
FORM build_gs_layout.
  gs_layout-smalltitle = ' '.       "The list title has small fonts
  gs_layout-sel_mode   = 'A'.       "Allow multiple-selection

  IF gv_mode = gc_mode_insert OR
     gv_mode = gc_mode_edit.
    gs_layout-edit       = 'X'.       "Allow edit
    gs_layout-stylefname = 'LT_EDIT'. "Table with edit style
  ENDIF.
ENDFORM.                    "build_gs_layout

*----------------------------------------------------------------------*
*              Form  Set_F4_Help_To_Field
*
* This function will set which fields should have F4-Help functionality.
*----------------------------------------------------------------------*
FORM set_f4_help_to_field.
  DATA: ls_f4     TYPE lvc_s_f4.

* We only need to perform it on the first time.
  IF NOT gt_f4[] IS INITIAL.
    EXIT.
  ENDIF.

*******
* NOTE: GT_F4 is a sorted by FIELDNAME and so entries shold be
*       appended in an Alphabetical order.
*******
* Area code description.
  ls_f4-fieldname  = 'AREA_CODE_D'.
  ls_f4-register   = 'X'.
  ls_f4-getbefore  = 'X'.
  ls_f4-chngeafter = 'X'.
  APPEND ls_f4 TO gt_f4.
  CLEAR: ls_f4.
ENDFORM.

*----------------------------------------------------------------------*
*      Form  gt_fieldcat_build
*
* This function will fill the GT_FIELDCAT which is a table of all ALV
* columns and their properties.
*----------------------------------------------------------------------*
FORM gt_fieldcat_build.
  DATA: ls_fieldcat  TYPE lvc_s_fcat.

* We only need to perform it on the first time.
  IF NOT gt_fieldcat[] IS INITIAL.
    EXIT.
  ENDIF.

* Area Code (hidden).
  ls_fieldcat-fieldname   = 'AREA_CODE'.
  ls_fieldcat-ref_field   = 'AREA_CODE' .
  ls_fieldcat-ref_table   = 'ZSELECTION_CRETA'.
  ls_fieldcat-edit        = 'X'.
  ls_fieldcat-key         = 'X'.
* ls_fieldcat-no_out      = 'X'.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
.
.
.
ENDFORM.

*----------------------------------------------------------------------*
*                  Form  Call_ALV
*
* This function will display the ALV.
*----------------------------------------------------------------------*
FORM call_alv.
* Write message line.
  message_line = 'Displaying ALV...'.
  PERFORM write_message_line.

* Set FieldCatalog.
  CALL METHOD alv_control->set_frontend_fieldcatalog
    EXPORTING
      it_fieldcatalog = gt_fieldcat.

*     Enable Edit mode.
      CALL METHOD alv_control->set_ready_for_input
                       EXPORTING i_ready_for_input = 1.

* Call the method that displays the ALV Grid.
  CALL METHOD alv_control->set_table_for_first_display
       EXPORTING "i_structure_name     = 'TY_TYPE'
                 "is_variant           = gs_disvariant
                 is_layout            = gs_layout
                 "i_save               = 'X'
       CHANGING  it_outtab            = gt_tab
                 it_fieldcatalog      = gt_fieldcat.

************
************
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
  IF event_receiver IS INITIAL.
    CREATE OBJECT event_receiver.
  ENDIF.

* Register ENTER to raise event DATA_CHANGED.
  CALL METHOD alv_control->register_edit_event
                EXPORTING
                   i_event_id = cl_gui_alv_grid=>mc_evt_enter.

* Set event handlers.
  SET HANDLER event_receiver->handle_data_changed   FOR alv_control.
  SET HANDLER event_receiver->on_f4                 FOR alv_control.
ENDFORM.

Thanx

ayal.

Read only

0 Likes
2,866

Hello Ayal

We are getting closer and closer to solving your problem. I adjusted sample report BCALV_EDIT_03 (search for *$Added) with the coding provided by you. However, you did not let us look under the hood of event handler method ON_F4 (renamed in my sample report as HANDLE_ONF4).

In contrast to your results the sample report ZUS_SDN_BCALV_EDIT_03_F4 reveals the following:

(1) event before F4 -> no entries in MT_GOOD_CELLS
(2) event after F4 -> single (= selected) entry in MT_GOOD_CELLS

From these discrepancy I conclude that there must be something in event handler method ON_F4 that is responsible for your result.

PROGRAM ZUS_SDN_BCALV_EDIT_03_F4.

  • Based on: BCALV_EDIT_03.

*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  • Purpose:

  • ~~~~~~~~

  • In this example the user may change values of fields

  • SEATSOCC (occupied seats) and/or PLANETYPE. The report checks

  • the input value(s) semantically and provides protocol

  • messages in case of error.

*----

-


  • To check program behavior

  • ~~~~~~~~~~~~~~~~~~~~~~~~~

  • Change values of the column "occupied seats" or "Planetype" or

  • both (in the same line). Try to provocate errors.

  • Click on the check symbol or press return to initiate checking.

  • (ALV also checks input before any functions like sorting,

  • filtering or doubleclick are processed. These functions are

  • only active if the input does not contain any errors).

  • The ALV Grid Control first checks if the input is correct

  • according to DDIC-Information (Type, lenght). Then semantic

  • checks are made by the application using event handler method

  • HANDLE_DATA_CHANGED.

*----

-


  • Essential steps (search for '§')

  • ~~~~~~~~~~~~~~~

  • 1.Set status of columns PLANETYPE and SEATSOCC to editable.

  • 2.Optionally restrict generic functions to 'change only'.

  • (The user shall not be able to add new lines).

  • 3.Optionally register ENTER to raise event DATA_CHANGED.

  • (Per default the user may check data by using the check icon).

  • 4.Define and implement event handler to handle event DATA_CHANGED.

  • 5.Loop over table MT_GOOD_CELLS to check all values that are

  • valid due to checks according to information of the DDIC.

  • 6.Within a check cycle:

  • 6a.Get new cell value to check it using method GET_CELL_VALUE.

  • (In this case SEATSOCC).

  • 6b.If the value is valid you may want to change values of

  • other cells.

  • 6c.If the value is not valid create an protocol entry in

  • the application log.

  • 6d.To access old values (which where not changed in this check cycle)

  • use your output table GT_OUTTAB.

  • 7.Display application log if an error has occured.

*----

-


*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

DATA: ok_code LIKE sy-ucomm,

save_ok LIKE sy-ucomm,

g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',

g_grid TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container,

gt_fieldcat TYPE lvc_t_fcat,

gs_layout TYPE lvc_s_layo,

g_max TYPE i VALUE 100.

  • local class to handle semantic checks

CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA: g_event_receiver TYPE REF TO lcl_event_receiver.

DATA: gt_outtab TYPE TABLE OF sflight.

*$Added

DATA:

gt_f4 TYPE lvc_t_f4.

*$Added

**************************************************************

  • LOCAL CLASS Definition

**************************************************************

*§4.Define and implement event handler to handle event DATA_CHANGED.

*

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

*$Added

handle_onf4

FOR EVENT onf4 OF cl_gui_alv_grid,

*$Added

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed

e_onf4

e_onf4_before

e_onf4_after.

PRIVATE SECTION.

  • This flag is set if any error occured in one of the

  • following methods:

DATA: error_in_data TYPE c.

  • Methods to modularize event handler method HANDLE_DATA_CHANGED:

METHODS: check_planetype

IMPORTING

ps_good_planetype TYPE lvc_s_modi

pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

METHODS: ch_new_plane_v_new_seatsocc

IMPORTING

psg_plane TYPE lvc_s_modi

psg_socc TYPE lvc_s_modi

ps_saplane TYPE saplane

pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

METHODS: ch_new_plane_v_old_seatsocc

IMPORTING

psg_plane TYPE lvc_s_modi

ps_saplane TYPE saplane

pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

METHODS: check_seatsocc

IMPORTING

ps_good TYPE lvc_s_modi

pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

*....................................................................

  • This is a suggestion how you could comment your checks in each method:

*.....

  • CHECK: fieldname(old/new value) !<comp> fieldname(old/new value)

  • IF NOT: (What to tell the user is wrong about the input)

*......

  • Remarks:

  • fieldname: fieldname of table for the corresponding column

  • (old/new value): ckeck with value of GT_OUTTAB or MT_GOOD_CELLS.

  • !<comp> : the value is valid if the condition <comp> holds.

*

  • Example:

  • CHECK seatsocc(new) !>= seatsmax(old)

  • IF NOT: There are not enough number of seats according to this

  • planetype.

*.......................................................................

ENDCLASS. "lcl_event_receiver DEFINITION

*----

-


CLASS lcl_event_receiver IMPLEMENTATION.

*$Added

METHOD handle_onf4.

  • BREAK-POINT.

ENDMETHOD. "handle_onf4

*$Added

METHOD handle_data_changed.

DATA: ls_good TYPE lvc_s_modi.

error_in_data = space.

  • semantic checks

  • Identify columns which were changed and check input

  • against output table gt_outtab or other new input values of one row.

  • Table er_data_changed->mt_good_cells holds all cells that

  • are valid according to checks against their DDIC data.

  • No matter in which order the input was made this table is

  • ordered by rows (row_id). For each row, the entries are

  • sorted by columns according to their order in the fieldcatalog

  • (not the defined order using field COL_POS but the order

  • given by the position of the record in the fieldcatalog).

  • The order is relevant if new inputs in several columns of

  • the same row are dependent. In this example,

  • method 'ch_new_plane_v_new_seatsocc' needs only to be called

  • once since we know that the corresponding check is already done

  • when checking column PLANETYPE (see also method 'check_seatsocc').

*§5.Loop over table MT_GOOD_CELLS to check all values that are

  • valid due to checks according to information of the DDIC.

*$Added

  • BREAK-POINT.

IF ( e_onf4 = 'X' ).

MESSAGE 'e_onf4 = X' TYPE 'I'.

IF ( e_onf4_before = 'X' ).

MESSAGE 'e_onf4_before = X' TYPE 'I'.

ELSEIF ( e_onf4_after = 'X' ).

MESSAGE 'e_onf4_after = X' TYPE 'I'.

ELSE.

ENDIF.

  • Display contents of MT_GOOD_CELLS

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

EXPORTING

i_structure_name = 'LVC_S_MODI'

TABLES

t_outtab = er_data_changed->mt_good_cells

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDIF.

*$Added

LOOP AT er_data_changed->mt_good_cells INTO ls_good.

CASE ls_good-fieldname.

  • check if column PLANETYPE of this row was changed

WHEN 'PLANETYPE'.

CALL METHOD check_planetype

EXPORTING

ps_good_planetype = ls_good

pr_data_changed = er_data_changed.

  • check if column SEATSOCC of this row was changed

WHEN 'SEATSOCC'.

CALL METHOD check_seatsocc

EXPORTING

ps_good = ls_good

pr_data_changed = er_data_changed.

ENDCASE.

ENDLOOP.

*§7.Display application log if an error has occured.

IF error_in_data EQ 'X'.

CALL METHOD er_data_changed->display_protocol.

ENDIF.

ENDMETHOD. "handle_data_changed

*----

-


METHOD check_planetype.

*..................................................

  • Overview of checks according to field PLANETYPE

  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • a) Does the Planetype exists? (check against check table SAPLANE)

  • b) Are the number of seats (SEATSMAX) of the new planetype

  • sufficient to fullfill requested bookings (SEATSOCC)?

  • b1) SEATSOCC (occupied seats) also changed within

  • this check cycle.

  • b2) SEATSOCC has not changed within this cycle.

*

*...................................................

DATA: l_planetype TYPE s_planetye,

ls_saplane TYPE saplane,

ls_good_seatsocc TYPE lvc_s_modi.

  • Get new cell value to check it.

  • (In this case: PLANETYPE).

CALL METHOD pr_data_changed->get_cell_value

EXPORTING

i_row_id = ps_good_planetype-row_id

i_fieldname = ps_good_planetype-fieldname

IMPORTING

e_value = l_planetype.

  • existence check: Does the plane exists?

SELECT SINGLE * FROM saplane INTO ls_saplane WHERE

planetype = l_planetype.

IF sy-subrc NE 0.

  • In case of error, create a protocol entry in the application log.

  • Possible values for message type ('i_msgty'):

*

  • 'A': Abort (Stop sign)

  • 'E': Error (red LED)

  • 'W': Warning (yellow LED)

  • 'I': Information (green LED)

*

CALL METHOD pr_data_changed->add_protocol_entry

EXPORTING

i_msgid = '0K'

i_msgno = '000'

i_msgty = 'E'

i_msgv1 = text-m03 "Flugzeugtyp

i_msgv2 = l_planetype

i_msgv3 = text-m05 "exitstiert nicht

i_fieldname = ps_good_planetype-fieldname

i_row_id = ps_good_planetype-row_id.

error_in_data = 'X'.

EXIT. "plane does not exit, so we're finished here!

ENDIF.

  • Check if other relevant fields of this row have been changed, too.

READ TABLE pr_data_changed->mt_good_cells INTO ls_good_seatsocc

WITH KEY row_id = ps_good_planetype-row_id

fieldname = 'SEATSOCC'.

IF sy-subrc = 0.

CALL METHOD ch_new_plane_v_new_seatsocc

EXPORTING

psg_plane = ps_good_planetype

psg_socc = ls_good_seatsocc

ps_saplane = ls_saplane

pr_data_changed = pr_data_changed.

ELSE.

CALL METHOD ch_new_plane_v_old_seatsocc

EXPORTING

psg_plane = ps_good_planetype

ps_saplane = ls_saplane

pr_data_changed = pr_data_changed.

ENDIF.

ENDMETHOD. " CHECK_PLANETYPE

*----


*

METHOD ch_new_plane_v_new_seatsocc.

DATA: l_seatsocc TYPE s_seatsocc.

*§5a.Get new cell value to check it using method GET_CELL_VALUE.

  • (In this case SEATSOCC).

CALL METHOD pr_data_changed->get_cell_value

EXPORTING

i_row_id = psg_socc-row_id

i_fieldname = psg_socc-fieldname

IMPORTING

e_value = l_seatsocc.

*----

-


  • CHECK: SEATSMAX(of new planetype) !>= SEATSOCC(new value)

  • IF NOT: Message for wrong planetype

*----

-


IF ps_saplane-seatsmax GE l_seatsocc.

*§5b.If the value is valid you may want to change values of

  • other cells.

CALL METHOD pr_data_changed->modify_cell

EXPORTING

i_row_id = psg_plane-row_id

i_fieldname = 'SEATSMAX'

i_value = ps_saplane-seatsmax.

ELSE.

*§5c.If the value is not valid create an protocol entry in

  • the application log.

  • Possible values for message type ('i_msgty'):

*

  • 'A': Abort (Stop sign)

  • 'E': Error (red LED)

  • 'W': Warning (yellow LED)

  • 'I': Information (green LED)

*

CALL METHOD pr_data_changed->add_protocol_entry

EXPORTING

i_msgid = '0K'

i_msgno = '000'

i_msgty = 'E'

i_msgv1 = text-m03 "Flugzeugtyp

i_msgv2 = ps_saplane-planetype

i_msgv3 = text-m04 "hat nicht genug Sitzplätze

i_fieldname = psg_plane-fieldname

i_row_id = psg_plane-row_id.

error_in_data = 'X'.

ENDIF.

ENDMETHOD. "ch_new_plane_v_new_seatsocc

*----


*

METHOD ch_new_plane_v_old_seatsocc.

DATA: l_old_seatsocc TYPE s_seatsocc,

ls_outtab TYPE sflight.

*§5d.To access old values (which where not changed in this check cycle)

  • use your output table GT_OUTTAB.

READ TABLE gt_outtab INTO ls_outtab INDEX psg_plane-row_id.

l_old_seatsocc = ls_outtab-seatsocc.

*----

-


  • CHECK: SEATSMAX(of new planetype) !>= SEATSOCC(old value)

  • IF NOT: Message for wrong planetype

*----

-


IF ps_saplane-seatsmax GE l_old_seatsocc.

  • ok->field seatsmax can be changed

CALL METHOD pr_data_changed->modify_cell

EXPORTING

i_row_id = psg_plane-row_id

i_fieldname = 'SEATSMAX'

i_value = ps_saplane-seatsmax.

ELSE.

CALL METHOD pr_data_changed->add_protocol_entry

EXPORTING

i_msgid = '0K'

i_msgno = '000'

i_msgty = 'E'

i_msgv1 = text-m03 "Flugzeugtyp

i_msgv2 = ps_saplane-planetype

i_msgv3 = text-m04 "hat nicht genug Sitzplätze

i_fieldname = psg_plane-fieldname

i_row_id = psg_plane-row_id.

error_in_data = 'X'.

ENDIF.

ENDMETHOD. "ch_new_plane_v_old_seatsocc

*&----


*

*& Form CHECK_SEATSOCC

*&----


*

  • text

*----


*

  • -->P_LS_GOOD text

  • -->P_ER_DATA_CHANGED text

*----


*

METHOD check_seatsocc.

DATA: l_seatsocc TYPE s_seatsocc,

l_old_seatsmax TYPE s_seatsmax,

ls_outtab TYPE sflight,

ls_good TYPE lvc_s_modi.

*.................................................................

  • Check if the planetype has changed, too.

*.................................................................

READ TABLE pr_data_changed->mt_good_cells INTO ls_good

WITH KEY row_id = ps_good-row_id

fieldname = 'PLANETYPE'.

IF sy-subrc EQ 0.

*....................................................

  • remark: the check

  • seatsocc (new value) <= seatsmax (new value)

  • was already handled by form 'ch_new_plane_v_new_seatsocc'.

  • so we are finished here.

*.................................................

EXIT.

ENDIF.

*.....................................................

  • CHECK: seatsocc (new value) <= seatsmax (old value)

  • IF NOT: Message that SEATSOCC is to high.

*.....................................................

  • get new cell value of SEATSOCC.

CALL METHOD pr_data_changed->get_cell_value

EXPORTING

i_row_id = ps_good-row_id

i_fieldname = ps_good-fieldname

IMPORTING

e_value = l_seatsocc.

  • get old cell value of SEATSMAX

READ TABLE gt_outtab INTO ls_outtab INDEX ps_good-row_id.

l_old_seatsmax = ls_outtab-seatsmax.

IF l_seatsocc > l_old_seatsmax.

CALL METHOD pr_data_changed->add_protocol_entry

EXPORTING

i_msgid = '0K'

i_msgno = '000'

i_msgty = 'E'

i_msgv1 = text-m01 "Die Anzahl der belegten Plätze

i_msgv2 = text-m02 "übersteigt die Kapazität des Flugzeugs

i_msgv3 = ls_outtab-planetype

i_fieldname = ps_good-fieldname

i_row_id = ps_good-row_id.

error_in_data = 'X'.

ENDIF.

ENDMETHOD. " CHECK_SEATSOCC

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

***************************************************************

*----


*

  • MAIN *

*----


*

END-OF-SELECTION.

CALL SCREEN 100.

*----


*

  • MODULE PBO OUTPUT *

*----


*

MODULE pbo OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF g_custom_container IS INITIAL.

PERFORM create_and_init_alv CHANGING gt_outtab

gt_fieldcat

gs_layout.

ENDIF.

ENDMODULE. "pbo OUTPUT

*----


*

  • MODULE PAI INPUT *

*----


*

MODULE pai INPUT.

save_ok = ok_code.

CLEAR ok_code.

CASE save_ok.

WHEN 'EXIT'.

PERFORM exit_program.

WHEN OTHERS.

  • do nothing

ENDCASE.

ENDMODULE. "pai INPUT

*----


*

  • FORM EXIT_PROGRAM *

*----


*

FORM exit_program.

LEAVE PROGRAM.

ENDFORM. "exit_program

*&----


*

*& Form BUILD_FIELDCAT

*&----


*

  • text

*----


*

  • <--P_GT_FIELDCAT text

*----


*

FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.

DATA ls_fcat TYPE lvc_s_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

ct_fieldcat = pt_fieldcat.

LOOP AT pt_fieldcat INTO ls_fcat.

IF ls_fcat-fieldname EQ 'PLANETYPE'

OR ls_fcat-fieldname EQ 'SEATSOCC'.

*§1.Set status of columns PLANETYPE and SEATSOCC to editable.

ls_fcat-edit = 'X'.

  • Field 'checktable' is set to avoid shortdumps that are caused

  • by inconsistend data in check tables. You may comment this out

  • when the test data of the flight model is consistent in your system.

ls_fcat-checktable = '!'. "do not check foreign keys

MODIFY pt_fieldcat FROM ls_fcat.

ENDIF.

ENDLOOP.

ENDFORM. "build_fieldcat

*&----


*

*& Form CREATE_AND_INIT_ALV

*&----


*

  • text

*----


*

  • <--P_GT_OUTTAB text

  • <--P_GT_FIELDCAT text

  • <--P_GS_LAYOUT text

*----


*

FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]

pt_fieldcat TYPE lvc_t_fcat

ps_layout TYPE lvc_s_layo.

DATA: lt_exclude TYPE ui_functions.

CREATE OBJECT g_custom_container

EXPORTING container_name = g_container.

CREATE OBJECT g_grid

EXPORTING i_parent = g_custom_container.

  • Build fieldcat and set columns PLANETYPE and SEATSOCC

  • edit enabled.

PERFORM build_fieldcat CHANGING pt_fieldcat.

*§2.Optionally restrict generic functions to 'change only'.

  • (The user shall not be able to add new lines).

PERFORM exclude_tb_functions CHANGING lt_exclude.

SELECT * FROM sflight INTO TABLE pt_outtab UP TO g_max ROWS.

CALL METHOD g_grid->set_table_for_first_display

EXPORTING

is_layout = ps_layout

it_toolbar_excluding = lt_exclude

CHANGING

it_fieldcatalog = pt_fieldcat

it_outtab = pt_outtab.

  • set editable cells to ready for input

CALL METHOD g_grid->set_ready_for_input

EXPORTING

i_ready_for_input = 1.

*$Added

PERFORM set_f4_help_to_field.

CALL METHOD g_grid->register_f4_for_fields

EXPORTING

it_f4 = gt_f4.

*$Added

*§3.Optionally register ENTER to raise event DATA_CHANGED.

  • (Per default the user may check data by using the check icon).

CALL METHOD g_grid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

  • Set event handler

CREATE OBJECT g_event_receiver.

SET HANDLER g_event_receiver->handle_data_changed FOR g_grid.

*$Added

SET HANDLER g_event_receiver->handle_onf4 FOR g_grid.

*$Added

ENDFORM. "CREATE_AND_INIT_ALV

*----


*

  • Form Set_F4_Help_To_Field

*

  • This function will set which fields should have F4-Help functionality.

*----


*

FORM set_f4_help_to_field.

DATA: ls_f4 TYPE lvc_s_f4.

      • We only need to perform it on the first time.

    • IF NOT gt_f4[] IS INITIAL.

    • EXIT.

    • ENDIF.

*******

  • NOTE: GT_F4 is a sorted by FIELDNAME and so entries shold be

  • appended in an Alphabetical order.

*******

  • Planetype

ls_f4-fieldname = 'PLANETYPE'.

ls_f4-register = 'X'.

ls_f4-getbefore = 'X'.

ls_f4-chngeafter = 'X'.

APPEND ls_f4 TO gt_f4.

CLEAR: ls_f4.

ENDFORM. "set_f4_help_to_field

*&----


*

*& Form EXCLUDE_TB_FUNCTIONS

*&----


*

  • text

*----


*

  • <--P_LT_EXCLUDE text

*----


*

FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.

  • Only allow to change data not to create new entries (exclude

  • generic functions).

DATA ls_exclude TYPE ui_func.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.

APPEND ls_exclude TO pt_exclude.

ENDFORM. " EXCLUDE_TB_FUNCTIONS[/code]

Regards

Uwe

Read only

0 Likes
2,866

Dear Uwe.

I haven't look at your code yet (I will later), but to answer your request of seeing my F4 event. I think this is irrelevant since I get the same problems with a field (from my Z table) that I designed as close as I can to the corresponding field from the SLIS demo program, so this field requires no special F4 handling and all the F4 is done by the default F4 method and I still get these problems.

thanx

ayal.

Read only

0 Likes
2,866

Hello Ayal

What a pitty since I hoped to achieve a technical K.O. of the problem in this round. Well, there are still three rounds to go...

To test my sample report simply copy BCALV_EDIT_03 to a z-program, remove the entire coding and paste my coding into the program.

For me it is clear that the problematic coding resides within the event handler method for event ONF4.

Regards

Uwe

Read only

0 Likes
2,866

> For me it is clear that the problematic coding

> resides within the event handler method for event

> ONF4.

>

> Regards

> Uwe

Uwe my friend.

I sorry to be the one who breaks your clarity, but a man's got to do what a man's got to do...

The point is, like I said in my last post, the field I'm testing with does <i>not</i> have a special F4 method for, and the list of values is displayed by the standard F4 method from the <i>CL_GUI_ALV_GRID</i>.

True, at the begining I was using my F4 method, but when all these issues started I needed to draw closer and closer to the SLIS demo program and they don't have a special F4 method for their field so now I twisted my fied in the DB so it will have (almost) the same properties as their field has.

Their field is drawing his F4 bahviour from a Check-table, so does mine.

By the way, tomorrow I'll try using their field in my code and I'll see what happen.

Maybe the strange behaviour is coming from there.

I'll keep you posted.

thanx and good night (it's 00:03 here).

ayal.

Read only

0 Likes
2,866

>By the way, tomorrow I'll try using their field in my

> code and I'll see what happen.

> Maybe the strange behaviour is coming from there.

>

> I'll keep you posted.

>

>

> thanx and good night (it's 00:03 here).

> ayal.

Dear Uwe.

I promised that I'll update you about the result, so here it is: no change, when I visit the <b>DATA_CHANGED</b> the <b>MT_GOOD_CELLS</b> still have data of <i>all</i> the changed cells from all rounds, and not just the last cell, as it should have.

This proves that what ever is "wrong" with my code is not coming from the F4.

It also proves that it is not coming from the way the field is designed in the DDIC.

The question is where does it come from...

thanx

ayal.

Read only

0 Likes
2,866

Hello Ayal

There are only two ways to solve the problem:

(1) Asking the Oracle at Delphi

OR

(2) Provide the ENTIRE coding including the definition of your table (domain with fixed values, check table, search help assigned to field/data element).

Regards

Uwe

Read only

0 Likes
2,866

Dear Uwe.

Placing the entire code and the tables defininitions is too much and anyway Option 1 is more appealing...

If you look back at 1 of the first posts I did, you'll see that the <b>DATA_CHANGED</b> is visited <i>before</i> if you're field has a Check-table and there are more than 1 fields incommon between the tables.

I have debugged the SAP <b>F4</b> method and I saw that if this is the case the <b>SAVE_DATA</b> method is called and <b>SAVE_DATA</b> is calling <b>DATA_CHANGED</b>.

Why it happens? Hell if I know. <i>I</i> can see no reason for that.

So basically you see that the 1st issue is a coming from DDIC definition.

The other issue I know which SAP code line causes it but I don't know why it's doing this since this is a Function call that I can't debug even in System Debugging.

For the time being I'm waiting for the OSS to reply.

I'll keep you posted as to the progress I'll made with them.

thanx

ayal.

Read only

0 Likes
2,866

Hello Ayal

According to one of your previous replies you have two event handler methods

* Set event handlers.
  SET HANDLER event_receiver->handle_data_changed   FOR alv_control.
  SET HANDLER event_receiver->on_f4                 FOR alv_control.

whose coding you have not yet revealed. Furthermore, the question whether the table containing field 'AREA_CODE_D' has a check table or contains a domain with fixed values is still unanswered.

Thus, provides us with these answers an we will disclose your secret.

Regards

<i>Oracle at Delphi</i>

Read only

0 Likes
2,866

Oh, The Great Oracle at Delphi.

You are right that my code does have these events in it, but when the issues started I took off the F4 event implementation (I don't declare it to the ALV engine with the <b>REGISTER_F4_FOR_FIELDS</b>) so you can disregard this event.

Regarding the "AREA_CODE_D". This is not the field I am trying on. This is the field that had the F4 event attached to it but like I said before, when the problems started I retreated back to basic and to follow the "BCALV_EDIT_03" demo program as close as I can I am using a field from my Z table which defined as close as possible to their field.

This solved the issue that the <b>DATA_CAHNGED</b> was visited <i>before</i> the list of values was displayed (i.e. before anything was changed).

The reason the <b>DATA_CAHNGED</b> is visited <i>before</i> cell content is changed is because I had a Check-table with 2 fields-connection and they had a Check-table with only 1 field-connection.

When you have more than 1 field-connection there is an FM is the SAP <b>F4</b> that checks something and if it returns a table with 1 record everything is OK but if there is more than 1 record in that table (as in my case) the <b>SAVE_DATA</b> is called and this method calls the <b>DATA_CAHNGED</b>.

Just a quick update: I'm arguing with the OSS if this falls inside their scope or not.

Last 2 times I had this argue with them (different issues of course) I won, so pray to who ever you want that I'll win this time also.

thanx

ayal.

Read only

0 Likes
2,866

Dear Uwe and all others.

I got a reply from the OSS and this is a summary of what they say:

All the editability functionality of the ALV is not realesed for customer yet, which mean that SAP is not supporting it.

Currently there is no plan at all, to work on this functionality so it can be released to customers.

For more info you can read Note <b><u>695910</u></b>

Like I said in previous posts I can come-up with work-arounds for these issues but I wanted to take the high-way and I found out that there is no high-way here and basically everybody has to find his/her own path.

As far as I consert, this thread is closed.

enjoy

ayal.