Refresh ALV grid after deleting a row - abap

So after I deleted a specific row in a database Table, it isn't removed on my screen. I have to end the programm and start it again to see the changes.
I've used alv->refresh( ). but this does not work for me. Is there a way to refresh the screen properly?

the refresh method has to have an importing parameter called is_stable. This structure has two fields (rwo and col) set both to 'X':
alv->refresh( is_stable = 'XX' ).

If the answer above doesn't work, you can use this method, it gets current ALV from global memory.
METHOD refresh_alv.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid, valid TYPE c.
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
ref_grid->check_changed_data(
IMPORTING
e_valid = valid ).
ENDIF.
IF valid IS NOT INITIAL.
ref_grid->refresh_table_display( ) .
ENDIF.
ENDMETHOD.

Related

Access shadowed variable from subroutine?

How to call a shadowed variable from subroutine?
Below is code sample, where I do want to print shadowed variable value:
data i type i value 13.
perform _form.
form _form.
data i like i.
i = 17.
" write shadowed i value here
endform.
There is a possibility to do it dynamically with ASSIGN ('(PROGRAMM)VARIABLE') TO FIELD-SYMBOL(<lv_fs>).
Here's an example.
REPORT zz_test.
DATA i TYPE i VALUE 13.
PERFORM _form.
FORM _form.
FIELD-SYMBOLS <lv_shadow> TYPE i.
DATA i LIKE i.
i = 17.
" write shadowed i value here
ASSIGN ('(ZZ_TEST)I') TO <lv_shadow> CASTING.
IF <lv_shadow> IS ASSIGNED.
WRITE <lv_shadow>.
ENDIF.
ENDFORM.

No data returned from class method to PBO

I want to return record of table from abap method, which is field of class
but nothing is returned to the variable in PBO
definition in class
data MS_ZORK_JG_SETTING type ZORK_JG_SETTING .
methods GET_MS_ZORK_JG_SETTING
returning
value(MS_ZORK_JG_SETTING) type ZORK_JG_SETTING .
MS_ZORK_JG_SETTING is a data type which contains data from ZORK_JG_SETTING transparent table, filled properly using other method, so there is a correct data in this variable
in pbo of the screen i wanted to assign returned value to variable of the same type as returned
MODULE pbo_0102 OUTPUT.
DATA: wa_jg_setting TYPE zork_jg_setting.
wa_jg_setting = go_bukrs_conf->get_ms_zork_jg_setting( ).
MOVE-CORRESPONDING wa_jg_setting TO zork_jg_setting.
ENDMODULE.
But wa_jg_setting is empty. Tell me why and how to repair that?
Place of invoking screen
DATA: go_bukrs_conf TYPE REF TO zork_cl_scr_bukrs_conf.
CREATE OBJECT go_bukrs_conf
EXPORTING
pa_bukrs = '3020'.
CALL SCREEN 102.
And get_ms_zork_jg_settings method. I am assigning a value of field to a formal parameter
method GET_MS_ZORK_JG_SETTING.
ms_zork_jg_setting = ms_zork_jg_setting."zwracana wartosc to pole/ atrybut
endmethod.
The line
ms_zork_jg_setting = ms_zork_jg_setting.
is useless, as you assign the value of the return parameter to itself.
Generally speaking, var = var is always non-sense.
Probably you want to do:
ms_zork_jg_setting = me->ms_zork_jg_setting.

Why is the result of `cl_gui_textedit->get_textstream` empty?

I'm using the ABAP standard class cl_gui_textedit to read text from a textarea on my selection screen. But the result after calling the method get_textstream on the instance is empty.
Minimal working example:
REPORT z_mwe_textarea_bug.
DATA lr_edit TYPE REF TO cl_gui_textedit.
DATA lr_docker TYPE REF TO cl_gui_docking_container.
PARAMETERS p_dummy TYPE string DEFAULT 'just for testing'. ""// <--- need this to show selection screen.
INITIALIZATION.
CREATE OBJECT lr_docker
EXPORTING
ratio = 60.
CREATE OBJECT lr_edit
EXPORTING
parent = lr_docker.
lr_docker->dock_at( EXPORTING side = cl_gui_docking_container=>dock_at_left ).
START-OF-SELECTION.
DATA lv_text_from_textarea TYPE string.
lr_edit->get_textstream( IMPORTING text = lv_text_from_textarea ). ""// <-- why is lv_text_from_textarea empty??
You (or I, answering my own question) have to call cl_gui_cfw=>flush( ) afterwards. Like this:
lr_edit->get_textstream( IMPORTING text = lv_text_from_textarea ). ""// <-- lv_text_from_textarea still empty
cl_gui_cfw=>flush( ). ""//<-- now it's not empty anymore.
Disclaimer: Found the answer on abapforum.de but removed all the useless (and german) discussions and added a minimal working example to my question.

Pass a read-only variable to a CHANGING parameter

I'd like to display a table from a class instance using CL_SALV_TABLE. However, my table is read-only and it's to be passed to a CHANGING parameter, I'm not allowed to do so.
How can I copy my dynamic reference to something that I can pass? The data type of the attribute can by any table.
Call of method FACTORY of the class CL_SALV_TABLE has failed; the
actual parameter for T_TABLE is write-protected.
DATA(lv_attribute) = 'mt_attribute'. "Dynamic name of class attribute
ASSIGN lr_appclass->(lv_attribute) TO FIELD-SYMBOL(<lt_table>).
cl_salv_table=>factory(
IMPORTING r_salv_table = DATA(lr_salv_table)
CHANGING t_table = <lt_table> ).
You can use RTTS to generate dynamic variables.
To generate a dynamic internal table with same type of original:
DATA: lo_table_desc TYPE REF TO cl_abap_tabledescr, " RTTS table descriptor
lrt_copy TYPE REF TO DATA. " temp data ref
FIELD-SYMBOLS:
<lt_copy> TYPE ANY TABLE.
" original type determination
lo_table_desc ?= cl_abap_tabledescr=>describe_by_data( {HERE_GOES_THE_MEMBER_TABLE} ).
" dynamic allocation
CREATE DATA lrt_copy TYPE HANDLE lo_table_desc.
ASSIGN lrt_copy->* TO <lt_copy>.
" {NOW_USE_<lt_copy>}
Without runtime typing:
ASSIGN lr_appclass->('MT_ATTRIBUTE') TO FIELD-SYMBOL(<member>).
DATA(copied_member) = copy( <member> ).
ASSIGN copied_member->* TO FIELD-SYMBOL(<table>).
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(lr_salv_table)
CHANGING
t_table = <table> ).
with
METHODS copy
IMPORTING
data TYPE any
RETURNING
VALUE(result) TYPE REF TO data.
METHOD copy.
CREATE DATA result LIKE data.
ASSIGN result->* TO FIELD-SYMBOL(<result>).
<result> = data.
ENDMETHOD.
I added the method copy to clarify what's happening. Its code can also be added to the main function.

Change order of table rows in a user-friendly way

Before starting development I'm looking for a standard way of doing something like that: I need to implement user-friendly way for ordering table rows in standard Dynpro ALV grid. I think it should look like a form where filter columns are defined, like it implemented, for example, in standard function module LVC_FILTER.
No, there is no standard functionality for this. However you can do this (manual table sort by drag-and-drop) programmatically by inserting/deleting itab rows in runtime. This can be be implemented using standard ALV events: ondrag, ondrop, and ondropcomplete.
Try these code samples for implementing methods:
method handle_grid_ondrag.
data: data_object type ref to drag_drop_object,
help_row like line of gt_outtab. "#EC NEEDED
read table gt_outtab_2 into help_row index es_row_no-row_id.
create object data_object.
move es_row_no-row_id to data_object->index.
read table gt_outtab_2 into data_object->wa_test index
es_row_no-row_id.
e_dragdropobj->object = data_object.
endmethod.
_
method handle_grid_ondrop.
data: data_object type ref to drag_drop_object,
drop_index type i,
help_row like line of gt_outtab. "#EC NEEDED
delete gt_outtab_2 index data_object->index.
insert data_object->wa_test into gt_outtab_2 index e_row-index
endmethod.
_
method handle_grid_ondropcomplete.
if data_cel = ' '.
call method grid->refresh_table_display.
endif.
endmethod.
Refer to sample program BCALV_TEST_DRAG_DROP_02 if you have difficulties.