2014 Aug 25 6:03 PM
Hallo everyone
I am currently working on an editable ALV Grid, that listens to the on data changed handler and assigns default values to the new inserted rows.
So far so good, but for some reason the internal table of the ALV gets changed after the "on data changed"-event. Could you please give me some advice?
Here is the relevant code section in the on_data_changed-event:
W_JOBSTEP
Note: GW_JOBSTEP / GT_JOBSTEP are the internal table / work area for the ALV grid.
<fs> is a fieldsymbol for p_data_changed->mp_mod_row.p_data_changed->mp_mod_rows->*p_data_changed->mp_mod_rows->*<fs>p_data_changed->mp_mod_rows->*
* V-----------------set default Value for new row---------------------------V*
" Loop at the inserted rows table and assign default values
LOOP AT p_data_changed->mt_inserted_rows INTO dl_ins_row.
ASSIGN p_data_changed->mp_mod_rows->* TO <fs>.
READ TABLE <fs> INTO GW_JOBSTEP INDEX sy-tabix.
"set default values
GW_JOBSTEP-MANDT = sy-mandt.
GW_JOBSTEP-JOBNAME = ZBC_JOB-JOBNAME.
GW_JOBSTEP-STEPCOUNT = sy-tabix.
GW_JOBSTEP-XPGFLAG = K_DEFAULT_XPGFLAG.
GW_JOBSTEP-PRNEW = 'X'.
GW_JOBSTEP-PDEST = K_DEFAULT_PRINTER.
GW_JOBSTEP-LANGUAGE = sy-LANGU.
"Find row index for GW_JOBSTEP Table according to matching table
READ TABLE p_data_changed->MT_ROID_FRONT WITH KEY ROW_ID = DL_INS_ROW-ROW_ID TRANSPORTING NO FIELDS.
""sy-tabix now contains row ID of MT_ROID_FRONT with the matching row.
IF sy-subrc EQ 0.
DATA: idx TYPE sy-tabix.
idx = sy-tabix.
ENDIF.
"update field symbol
MODIFY <fs> FROM GW_JOBSTEP INDEX sy-tabix.
INSERT GW_JOBSTEP INTO GT_JOBSTEP INDEX idx.
ENDLOOP. "Loop at the inserted rows
PERFORM JOBSTEP_DISABLE_FIELDS. "also calls G_ALV_GRID_REF->REFRESH_TABLE_DISPLAY.
After these lines, the GT_JOBSTEP table looks fine. But if I resume the programme, the internal table gets changed (not in the z-programme). I assume the problem lies in the field symbol, but I don't see the error.
If I let the debugger stop, when ever GT_JOBSTEP[] got changed it stops at my handler (ok), 2 CONVERSION_EXIT (ok) and the MODIFY_PROTOCOL_ENTRY Method of CL_ALV_CHANGED_DATA_PROTOCOL==CP.
If more details are needed, please just ask.
I thank everyone for their efforts in advance.
Best regards
Fabio
2014 Aug 26 11:09 AM
Hello everyone
After a night of sleep I found a solution for my problem. I found a way to not modify the itab directly, but the newly inserted row in the alv. This way the alv change protocol does not screw around with my data changes anymore.
Here is the code for reference:
* V-----------------set default Value for new row---------------------------V*
" read the inserted rows table and assign default values
READ TABLE p_data_changed->mt_inserted_rows INTO dl_ins_row INDEX 1.
"Find row index for GW_JOBSTEP Table according to matching table
READ TABLE p_data_changed->MT_ROID_FRONT WITH KEY ROW_ID = DL_INS_ROW-ROW_ID TRANSPORTING NO FIELDS.
"(sy-tabix contains row ID of MT_ROID_FRONT with the matching row.)
IF sy-subrc EQ 0.
DATA: idx TYPE sy-tabix.
idx = sy-tabix.
ENDIF.
"Set default values for new row
PERFORM modify_alv_cell USING dl_ins_row-row_id 'MANDT' sy-mandt CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'JOBNAME' ZBC_JOB-JOBNAME CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'STEPCOUNT' idx CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'XPGFLAG' K_DEFAULT_XPGFLAG CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'PRNEW' 'X' CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'PDEST' K_DEFAULT_PRINTER CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'LANGUAGE' sy-LANGU CHANGING p_data_changed.
"Diable certain fields for editing (in new row)
PERFORM ALV_DISABLE_FIELDS USING K_DEFAULT_XPGFLAG CHANGING it_style.
LOOP AT it_style INTO wa_style.
p_data_changed->MODIFY_STYLE(
I_ROW_ID = dl_ins_row-ROW_ID
I_FIELDNAME = wa_style-FIELDNAME
I_STYLE = wa_style-STYLE ).
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form modify_alv_cell *
*&---------------------------------------------------------------------*
*& change a value of a ALV cell *
*&---------------------------------------------------------------------*
FORM modify_alv_cell USING p_ROW_ID TYPE INT4
p_fieldname TYPE LVC_FNAME
p_value TYPE ANY
CHANGING p_data_changed TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
p_data_changed->modify_cell(
i_row_id = p_ROW_ID
i_fieldname = p_fieldname
i_value = p_value ).
ENDFORM. "modify_alv_cell
Best regards
Fabio
2014 Aug 25 6:10 PM
Hi
my first question is why you're using SY-TABIX to read <FS> table? (line 85);
READ TABLE <fs> INTO GW_JOBSTEP INDEX sy-tabix.
Max
2014 Aug 25 6:25 PM
Mi max
thanks for the fast reply.
Since you can only insert one row at the time, I used this line to assign the values of the first row of <fs> to my work area. (sy-tabix was always 1)
Since the <fs> (the new line) is always empty I changed the line to a simple CLEAR GW_JOBSTEP, which has the same effect.
This did not solve my problem however.
2014 Aug 26 11:09 AM
Hello everyone
After a night of sleep I found a solution for my problem. I found a way to not modify the itab directly, but the newly inserted row in the alv. This way the alv change protocol does not screw around with my data changes anymore.
Here is the code for reference:
* V-----------------set default Value for new row---------------------------V*
" read the inserted rows table and assign default values
READ TABLE p_data_changed->mt_inserted_rows INTO dl_ins_row INDEX 1.
"Find row index for GW_JOBSTEP Table according to matching table
READ TABLE p_data_changed->MT_ROID_FRONT WITH KEY ROW_ID = DL_INS_ROW-ROW_ID TRANSPORTING NO FIELDS.
"(sy-tabix contains row ID of MT_ROID_FRONT with the matching row.)
IF sy-subrc EQ 0.
DATA: idx TYPE sy-tabix.
idx = sy-tabix.
ENDIF.
"Set default values for new row
PERFORM modify_alv_cell USING dl_ins_row-row_id 'MANDT' sy-mandt CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'JOBNAME' ZBC_JOB-JOBNAME CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'STEPCOUNT' idx CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'XPGFLAG' K_DEFAULT_XPGFLAG CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'PRNEW' 'X' CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'PDEST' K_DEFAULT_PRINTER CHANGING p_data_changed.
PERFORM modify_alv_cell USING dl_ins_row-row_id 'LANGUAGE' sy-LANGU CHANGING p_data_changed.
"Diable certain fields for editing (in new row)
PERFORM ALV_DISABLE_FIELDS USING K_DEFAULT_XPGFLAG CHANGING it_style.
LOOP AT it_style INTO wa_style.
p_data_changed->MODIFY_STYLE(
I_ROW_ID = dl_ins_row-ROW_ID
I_FIELDNAME = wa_style-FIELDNAME
I_STYLE = wa_style-STYLE ).
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form modify_alv_cell *
*&---------------------------------------------------------------------*
*& change a value of a ALV cell *
*&---------------------------------------------------------------------*
FORM modify_alv_cell USING p_ROW_ID TYPE INT4
p_fieldname TYPE LVC_FNAME
p_value TYPE ANY
CHANGING p_data_changed TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
p_data_changed->modify_cell(
i_row_id = p_ROW_ID
i_fieldname = p_fieldname
i_value = p_value ).
ENDFORM. "modify_alv_cell
Best regards
Fabio
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |