Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to count the number of lines dynamically,

Former Member
0 Kudos
897

In the below code am trying to read the lines which are selected using a check box, also am categorizing the contents depending on the follow up material.

after displaying one category contents am displaying a line

which also counts to a line in the internal table.

My question is how to count the number of lines(ULINE) displayed dynamically.

FORM GET_LINES .

DATA: LV_LINES TYPE I,

LV_TIMES TYPE I,

LV_TABIX TYPE SY-TABIX.

DESCRIBE TABLE IT_REC LINES LV_LINES.

DO LV_LINES TIMES.

LV_TIMES = SY-INDEX .

READ LINE LV_TIMES FIELD VALUE IT_REC-CHECK INTO GV_CHECK.

IF SY-SUBRC EQ 0 AND GV_CHECK IS NOT INITIAL.

LV_TABIX = LV_TIMES.

READ TABLE IT_REC INDEX LV_TABIX INTO GWA_UPDATE.

IF SY-SUBRC EQ 0.

APPEND GWA_UPDATE TO GT_UPDATE.

ENDIF.

ENDIF.

ENDDO.

ENDFORM. " GET_LINES

2 REPLIES 2

Former Member
0 Kudos
203

In the below code am trying to read the lines which are selected using a check box, also am categorizing the contents depending on the follow up material.

after displaying one category contents am displaying a line

which also counts to a line in the internal table.

My question is how to count the number of lines(ULINE) displayed dynamically.

FORM GET_LINES .

DATA: LV_LINES TYPE I,

LV_TIMES TYPE I,

LV_TABIX TYPE SY-TABIX.

DESCRIBE TABLE IT_REC LINES LV_LINES.

DO LV_LINES TIMES.

LV_TIMES = SY-INDEX .

READ LINE LV_TIMES FIELD VALUE IT_REC-CHECK INTO GV_CHECK.

IF SY-SUBRC EQ 0 AND GV_CHECK IS NOT INITIAL.

LV_TABIX = LV_TIMES.

READ TABLE IT_REC INDEX LV_TABIX INTO GWA_UPDATE.

IF SY-SUBRC EQ 0.

APPEND GWA_UPDATE TO GT_UPDATE.

ENDIF.

ENDIF.

ENDDO.

ENDFORM. " GET_LINES

The display function is:

FORM DISPLAY_DATA .

ULINE.

WRITE : /1 SY-VLINE, 'check',

10 SY-VLINE, 'Plant',

20 SY-VLINE, 'Material number',

50 SY-VLINE, 'Follow up material',

70 SY-VLINE, 'Safety stock',

100 SY-VLINE, 'Partc'.

ULINE.

LOOP AT IT_MARC.

MOVE: IT_MARC-WERKS TO IT_REC-WERKS,

IT_MARC-MATNR TO IT_REC-MATNR,

IT_MARC-NFMAT TO IT_REC-NFMAT,

IT_MARC-EISBE TO IT_REC-EISBE,

IT_MARC-PARTC TO IT_REC-PARTC .

APPEND IT_REC.

CLEAR IT_MARC.

ENDLOOP.

DATA: GV_TABIX TYPE SY-TABIX.

LOOP AT IT_REC.

GV_TABIX = SY-TABIX.

READ TABLE GT_TOTAL WITH KEY WERKS = IT_REC-WERKS

NFMAT = IT_REC-NFMAT.

IF SY-SUBRC EQ 0.

IT_REC-PARTC = GT_TOTAL-PARTC.

MODIFY IT_REC INDEX GV_TABIX TRANSPORTING PARTC.

ENDIF.

ENDLOOP.

LOOP AT IT_REC.

WRITE : /1 SY-VLINE, IT_REC-CHECK AS CHECKBOX,

10 SY-VLINE, IT_REC-WERKS,

20 SY-VLINE, IT_REC-MATNR,

50 SY-VLINE, IT_REC-NFMAT,

70 SY-VLINE, IT_REC-EISBE,

100 SY-VLINE, IT_REC-PARTC.

AT END OF NFMAT.

ULINE.

ENDAT.

ENDLOOP.

ULINE.

ENDFORM. " DISPLAY_DATA

Solved

laurent_touillaud
Contributor
0 Kudos
203

Hi WD fans,

Just to complete the post for people who want an additional exemple code when you must do your treatment only in the modifyview method.

ALL IN THE MODIFYVIEW METHOD :

* Delete the UI element content when nodes have been refreshed by a reset/refresh method

TRY.

lr_node = wd_context->get_child_node( 'MY_NODE1' ).

CATCH cx_wd_context. "not yet created

lr_sumpack_cont ?= view->get_element( 'PACKSUMMARIES' ).

lr_sumpack_cont->remove_all_children( ).

ENDTRY.

DATA : l_node TYPE REF TO if_wd_context_node,

l_node_2 TYPE REF TO if_wd_context_node,

l_node_info TYPE REF TO if_wd_context_node_info,

l_table TYPE REF TO cl_wd_table,

nd_list TYPE wdr_context_child_map,

wa_list TYPE wdr_context_child.

* Create a dynamic table of a known structure

DATA: node_info TYPE REF TO if_wd_context_node_info,

comp_tab TYPE cl_abap_structdescr=>component_table,

comp LIKE LINE OF comp_tab,

my_table TYPE REF TO data,

my_row TYPE REF TO data.

FIELD-SYMBOLS: <table> TYPE table,

<row> TYPE data,

<flight> TYPE sflight.

DATA: lo_struct TYPE REF TO cl_abap_structdescr,

lt_comp TYPE cl_abap_structdescr=>component_table,

lo_run_st TYPE REF TO cl_abap_structdescr,

lo_run_tt TYPE REF TO cl_abap_tabledescr,

lo_struc TYPE REF TO data,

lo_ttype TYPE REF TO data.

* fill new node

DATA: ls_gap TYPE zsnc_packing_gap_st.

DATA: lv_node TYPE string.

DATA: lv_table TYPE string.

DATA: lv_numi TYPE i.

DATA: lv_num(1).

DATA: lv_table_header TYPE string.

DATA: lo_table TYPE REF TO cl_wd_table.

DATA: lo_caption TYPE REF TO cl_wd_caption.

DATA: lt_attributes TYPE wdr_context_attr_info_map.

DATA: ls_deltol TYPE zsnc_del_toleran.

DATA: lv_undertol TYPE string.

DATA: lv_lines TYPE i.

FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,

<fs_line> TYPE any,

<fs_node> TYPE REF TO if_wd_context_node.

* principal table

IF wd_this->lt_gap[] IS NOT INITIAL.

lo_struct ?= cl_abap_structdescr=>describe_by_name( 'ZSNC_PACK_SUMMARY' ).

lt_comp = lo_struct->get_components( ).

lo_run_st = cl_abap_structdescr=>create( lt_comp ).

lo_run_tt ?= cl_abap_tabledescr=>create( p_line_type = lo_run_st ).

* create table for each stock category

* l_root ?= view->get_root_element( ).

lr_sumpack_cont ?= view->get_element( 'PACKSUMMARIES' ).

CREATE DATA lo_ttype TYPE HANDLE lo_run_tt.

ASSIGN lo_ttype->* TO <fs_table>.

CREATE DATA lo_struc TYPE HANDLE lo_run_st.

ASSIGN lo_struc->* TO <fs_line>.

LOOP AT wd_this->lt_gap INTO ls_gap.

MOVE-CORRESPONDING ls_gap TO <fs_line>.

APPEND <fs_line> TO <fs_table>.

AT END OF stock_category. "create one table by stock category

* handle runtime data type by means of generic variables

ADD 1 TO lv_numi. lv_num = lv_numi.

CONCATENATE 'MY_NODE' lv_num INTO lv_node.

CONCATENATE 'MY_TABLE' lv_num INTO lv_table.

* now created the node

TRY.

l_node = wd_context->get_child_node( lv_node ).

CATCH cx_wd_context. "not yet created

node_info = wd_context->get_node_info( ).

l_node_info = node_info->add_new_child_node(

name = lv_node

is_mandatory = abap_true

is_multiple = abap_true

static_element_rtti = lo_run_st

is_initialize_lead_selection = abap_false

is_static = abap_false ).

* attributes = lt_attributes ).

* bind table to node

l_node = wd_context->get_child_node( lv_node ).

l_node->bind_table( <fs_table> )."( new_items = <fs_table> set_initial_elements = abap_true ).

* create the ui element table

l_node_2 = wd_context->get_child_node( lv_node ).

cl_wd_dynamic_tool=>create_table_from_node(

EXPORTING

ui_parent = lr_sumpack_cont

table_id = lv_table

node = l_node_2

RECEIVING

table = lo_table ).

IF lo_table IS BOUND.

CLEAR lv_undertol.

READ TABLE wd_this->lt_deltol INTO ls_deltol

WITH KEY stock_category = ls_gap-stock_category.

IF sy-subrc IS INITIAL.

lv_undertol = ls_deltol-under_tol_perc.

ELSE.

READ TABLE wd_this->lt_deltol INTO ls_deltol

WITH KEY stock_category = space.

IF sy-subrc IS INITIAL.

lv_undertol = ls_deltol-under_tol_perc.

ENDIF.

ENDIF.

CONCATENATE 'PACKING SUMMARY' ls_gap-stock_category lv_undertol

INTO lv_table_header SEPARATED BY space.

lo_caption = cl_wd_caption=>new_caption( text = lv_table_header ).

lo_table->set_header( lo_caption ).

* set visible rows

DESCRIBE TABLE <fs_table> LINES lv_lines.

lo_table->set_visible_row_count( value = lv_lines ).

ENDIF.

FREE : <fs_table>, <fs_line>.

ENDTRY.

ENDAT.

ENDLOOP.

ENDIF.

Reset method

node_info = wd_context->get_node_info( ).
DO.
ADD 1 TO lv_numi. lv_num = lv_numi.
CONCATENATE 'MY_NODE' lv_num INTO lv_node.
CONCATENATE 'MY_TABLE' lv_num INTO lv_table.
TRY.
l_node = wd_context->get_child_node( lv_node ).
CATCH cx_wd_context.
EXIT.
ENDTRY.
node_info = node_info->get_child_node( lv_node ). "node to be removed
node_info->remove_dynamic_attributes( ).
node_info = node_info->get_parent( ).
node_info->remove_child_node( lv_node ).
ENDDO.