cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert a new record in a table View?

617924547
Explorer
0 Kudos

Hello experts, I have a tableview and I need to insert records through a button.

I currently have several problems:

1. When I report the records with different data and press the ENTER key, all records are updated with the data from the last record.

2. When I select a record of the new ones that I just inserted and press the Delete button, all the new inserted records are deleted.

Please, I need help with the method code "EH_ONINSERT". I currently have this code:

DATA: lr_entity TYPE REF TO if_bol_bo_property_access,
lr_cn TYPE REF TO cl_bsp_wd_context_node,
ls_attr TYPE zhe_tarifas.

CLEAR: ls_attr.

DATA: lv_seltab TYPE int4.

CLEAR: ls_attr.
FIELD-SYMBOLS: <lr_cn> TYPE any.

ASSIGN me->context->('ZTARIFAS') TO <lr_cn>.
IF <lr_cn> IS ASSIGNED.
lr_cn ?= <lr_cn>.
lr_entity ?= lr_cn->collection_wrapper->get_first( ). "get_current( ).
ENDIF.

CHECK lr_entity IS BOUND.
lr_entity->set_properties( EXPORTING is_attributes = ls_attr ).
typed_context->ztarifas->get_collection_wrapper( )->add( iv_entity = lr_entity ).
typed_context->ztarifas->visible_first_row_index = typed_context->ztarifas->collection_wrapper->size( ).

Thank you,

Regards.

Accepted Solutions (1)

Accepted Solutions (1)

former_member223320
Participant

Hi Frankie...

Put the below code in EH_ONINSERT method. Each time you click the Insert button, it will add a new row to the table.

DATA: lr_current     TYPE REF TO if_bol_bo_property_access,
      lr_value_node       TYPE REF TO cl_bsp_wd_value_node,
      ls_attr TYPE zhe_tarifas,
      lr_attr TYPE REF TO zhe_tarifas.

TRY.
    CREATE DATA lr_attr.
    CREATE OBJECT lr_value_node
      EXPORTING
        iv_data_ref = lr_attr.

    lr_value_node->set_properties( ls_attr ).
    me->typed_context->ztarifas->collection_wrapper->add( lr_value_node ).
    me->typed_context->ztarifas->visible_first_row_index = me->typed_context->ztarifas->collection_wrapper->size( ).
  CATCH cx_root.
ENDTRY.

-Ricky.

617924547
Explorer
0 Kudos

Thank you very much Ricky, I solved my problem with this.

Regards.

Domi
Contributor
0 Kudos

Hi

But these are just value nodes - there is no BOL entity created, and therefore no DB update!? Or is there some stuff in the save handler?

regards

Domi

Answers (1)

Answers (1)

Domi
Contributor
0 Kudos

Hi

you use the 1st BO entity of the context collection, clear it and add it a second time:

lr_entity ?= lr_cn->collection_wrapper->get_first( ).
...
lr_entity->set_properties( EXPORTING is_attributes = ls_attr ).
typed_context->ztarifas->get_collection_wrapper( )->add( iv_entity = lr_entity ).

You need to create a new BO instance with via eg CREATE_RELATED_ENTITY or use a new value node CL_BSP_WD_VALUE_NODE.

you may have a lot at eg CL_BP_DATA_ACCOUNTIDNUMB1->EH_ONINSERT - similar behaviour

regards

Domi

617924547
Explorer
0 Kudos

Muchas gracias Domi por tu respuesta, pero resuelve mi problema con la respuesta anterior. Nuevamente, agradezco tu respuesta.

Regards.