cancel
Showing results for 
Search instead for 
Did you mean: 

Get last row

Former Member
0 Kudos

Hello,

I'm not very expierenced in ABAP Web Dynpro so please excuse me if this question is kinda easy to solve for you guys

I've got a table which displays the different items that are in a PO (via node). Now I need a way to select the LAST ROW from that table.

Thx

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Is this last row is a fixed one in the TABLE

Just get the elements (GET_ELEMENTS) of if_wd_context_node.

In this, read the element which is last by the above number.

You want to select the last row through coding or from SELECT(option) on TABLE UI.

Hope this is clear,

Regards,

Lekha.

Edited by: Lekha on Oct 22, 2009 2:34 PM

Former Member
0 Kudos

Hi Lekha, thanks for your information. What type does lo_el_po_items need? I tried WDR_CONTEXT_ELEMENT_SET cause that's what get_elements( ) returns but it doesn't seem to work.

The result type of the function method cannot be converted into the type of LO_EL_PO_ITEMS.

DATA lo_nd_po_items TYPE REF TO if_wd_context_node.

DATA lo_el_po_items TYPE REF TO WDR_CONTEXT_ELEMENT_SET.

DATA ls_po_items TYPE wd_this->element_po_items.

  • navigate from <CONTEXT> to <PO_ITEMS> via lead selection

lo_nd_po_items = wd_context->get_child_node( name = wd_this->wdctx_po_items ).

  • @TODO handle not set lead selection

IF lo_nd_po_items IS INITIAL.

ENDIF.

  • get element via lead selection

lo_el_po_items = lo_nd_po_items->get_elements( ).

Former Member
0 Kudos

lo_el_po_items - if_Wd_context_element.

You can refer the code given by me in my last answer.

It will give you last row's value into a work area.

Edited by: Saurav Mago on Oct 22, 2009 2:53 PM

Former Member
0 Kudos

Hi,

You can use GET_ELEMENT_COUNT of if_wd_contxt_node into lv_count.

lr_element type ref to if_wd_context_element.

lr_element = lr_node->get_element ( index = lv_count ). "returns last row

Regards,

Lekha.

Edited by: Lekha on Oct 22, 2009 2:53 PM

Former Member
0 Kudos

Thank you both for great answers

DATA lo_nd_po_items TYPE REF TO if_wd_context_node.

DATA lo_el_po_items TYPE REF TO if_wd_context_element.

DATA itab TYPE ref to wd_this->element_po_items.

DATA last_row type I.

DATA ls_po_items TYPE wd_this->element_po_items.

DATA lv_po_item LIKE ls_po_items-po_item.

  • navigate from <CONTEXT> to <PO_ITEMS> via lead selection

lo_nd_po_items = wd_context->get_child_node( name = wd_this->wdctx_po_items ).

CALL METHOD lo_nd_po_items->get_static_attributes

IMPORTING

static_attributes = itab

.

describe table itab lines last_row.

Itab is not an internal table... Can't use type table of or anything either

Former Member
0 Kudos

CALL METHOD lo_nd_po_items->get_static_attributes

IMPORTING

static_attributes = itab

Instead of this use get_static_Attributes_table.

As mentioned in my earlier post

.

DATA lo_nd_cn_popin TYPE REF TO if_wd_context_node.

DATA wa TYPE wd_this->element_cn_popin.

DATA itab TYPE wd_this->elements_cn_popin.

DATA last_row type I.

lo_nd_cn_popin = wd_context->get_child_node( name = wd_this->wdctx_cn_popin ).

lo_nd_cn_popin->get_static_attributes_table( IMPORTING table = itab ).

describe table itab lines last_row.

read table itab into wa index last_row.

I hope now it is clear.

Former Member
0 Kudos

use



DATA itab TYPE wd_this->elements_cn_table.

or 

DATA itab type standards table of <standard table name>

in either case u wud get the internal table as like the standard table , get the last index of ur internal table and simply read the work area

regards,

amit

Former Member
0 Kudos

Hi,

DATA lo_nd_po_items TYPE REF TO if_wd_context_node.
DATA lo_el_po_items TYPE REF TO if_wd_context_element.
DATA itab TYPE ref to wd_this->element_po_items.
DATA last_row type I.
DATA ls_po_items TYPE wd_this->element_po_items.
DATA lv_po_item LIKE ls_po_items-po_item.
* navigate from <CONTEXT> to <PO_ITEMS> via lead selection
lo_nd_po_items = wd_context->get_child_node( name = wd_this->wdctx_po_items ).

CALL METHOD lo_nd_po_items->get_element_count
IMPORTING
count = lv_count

lo_el_po_items = lo_nd_po_items->get_element( index = lv_count).
CALL METHOD lo_el_po_items->get_static_attributes
IMPORTING
static_attributes = itab 

Regards,

Lekha.

Former Member
0 Kudos

Hi, thanks all... It works, code below.

DATA lo_nd_po_items TYPE REF TO if_wd_context_node.

DATA lo_el_po_items TYPE REF TO if_wd_context_element.

DATA itab TYPE standard table of wd_this->element_po_items.

DATA last_row type I.

DATA ls_po_items TYPE wd_this->element_po_items.

DATA lv_po_item LIKE ls_po_items-po_item.

  • navigate from <CONTEXT> to <PO_ITEMS> via lead selection

lo_nd_po_items = wd_context->get_child_node( name = wd_this->wdctx_po_items ).

CALL METHOD lo_nd_po_items->get_static_attributes_table

IMPORTING

table = itab

.

describe table itab lines last_row.

Answers (2)

Answers (2)

Former Member
0 Kudos

hi ,

u need to proceed as follow :

1 go to code wizard , press CONTROL + F7

2 click on the radio button read context node/attribute

3 read the context node which is binded to ur table UI element


  DATA lo_nd_cn_table TYPE REF TO if_wd_context_node.
    DATA lo_el_cn_table TYPE REF TO if_wd_context_element.
    DATA ls_cn_table TYPE wd_this->element_cn_table.
    DATA itab TYPE wd_this->elements_cn_table.
*   navigate from <CONTEXT> to <CN_TABLE> via lead selection
    lo_nd_cn_table = wd_context->get_child_node( name = wd_this->wdctx_cn_table ).

4 after u have taken the node reference thn u can take the values in a internal table using

get_static_attributes_table method



 lo_nd_cn_table ->get_static_attributes_table( IMPORTING table = itab ).

5 u can also get the work area value of the selected row of ur table , like this :



*   get element via lead selection
    lo_el_cn_table = lo_nd_cn_table->get_element(  ).


*   get all declared attributes
    lo_el_cn_table->get_static_attributes(
      IMPORTING
        static_attributes = ls_cn_table ).

6 for ur specific case , u need to get the values of the last row ,

u can do it thru DESCRIBE abap statement


DATA : lv_index
DESCRIBE TABLE itab LINES lv_index.

7 now as lv_index contains the last row index , u can simple use



READ TABLE itab into wa INDEX lv.

It wud serve the purpose

rgds,

amit

Former Member
0 Kudos

You want to select last row .

Does it mean that you have a Table with records and you want to fetch the records of last row.?

If so, get the index of last row and fetch the records.

For getting last row index :

describe table itab lines lv.

<lv has your last row index.>

- Get all records of table into an internal table using : get_Static_attributes_table method of if_wd_context_node .

Sample code to get last row' s value into a work area :

DATA lo_nd_cn_popin TYPE REF TO if_wd_context_node.

DATA wa TYPE wd_this->element_cn_popin.

DATA itab TYPE wd_this->elements_cn_popin.

DATA last_row type I.

lo_nd_cn_popin = wd_context->get_child_node( name = wd_this->wdctx_cn_popin ).

lo_nd_cn_popin->get_static_attributes_table( IMPORTING table = itab ).

describe table itab lines last_row.

read table itab into wa index last_row.

Here wa has your last row's value.

Edited by: Saurav Mago on Oct 22, 2009 2:46 PM