Skip to Content
0

How to insert a new record in a table View?

Feb 13 at 03:53 PM

42

avatar image
Former Member

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.

1.png (10.9 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Ricky J Feb 20 at 08:56 AM
1

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

Regards.

0

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

0
Domi Bigl Feb 20 at 09:05 AM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

Regards.

0