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: 

Internal table non-unique key consequences

Former Member
0 Kudos

Hi Experts

I have a i_tab which is defined as follows:

i_tab TYPE STANDARD TABLE OF TAB_STRUCTURE
       WITH HEADER LINE
       WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 0

TAB_STRUCTURE is defined as follows:

TYPES:
  BEGIN OF TAB_STRUCTURE.
        INCLUDE STRUCTURE /BIC/CS8ZPURVEN5.
TYPES:
     cnfqty like /bic/azpurcscg00-cnfqty,
  END OF TAB_STRUCTURE.

Then the i_tab is filled and loop at. In the loop is a read on the new_data itab performed. If the read is successfull is a "Move-corresponding new_data to i_tab" performed. Will this cause double data in the i_tab (will the same line be present twice in i_tab after the "Move-corresponding new_data to i_tab"?)?

clear i_tab.
        refresh i_tab.
* Find key from active table.
        SELECT * FROM
        /bic/azpurcscg00
        WHERE oi_ebeln EQ DATA_PACKAGE-doc_num AND
              oi_ebelp EQ DATA_PACKAGE-doc_item AND
              sched_line EQ DATA_PACKAGE-sched_line.
          MOVE-CORRESPONDING /bic/azpurcscg00 to i_tab.
          MOVE /bic/azpurcscg00-oi_ebeln to i_tab-doc_num.
          MOVE /bic/azpurcscg00-oi_ebelp to i_tab-doc_item.
          APPEND i_tab.
        ENDSELECT.
        SORT i_tab BY doc_num doc_item sched_line conf_line.
* Find key from new table.
        LOOP at i_tab.
          READ TABLE NEW_DATA WITH KEY
                        oi_ebeln = DATA_PACKAGE-doc_num
                        oi_ebelp = DATA_PACKAGE-doc_item
                        sched_line = DATA_PACKAGE-sched_line
                        conf_line = i_tab-conf_line
                        BINARY SEARCH.
          IF sy-subrc = 0.
            Move-corresponding new_data to i_tab. <--------------------------------------------
            modify i_tab.
          ENDIF.
        ENDLOOP.

Thanks a lot in advance and kind regards,

Torben

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

The UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can accept duplicate entries.

If we are not specifying the key then table type is generic

5 REPLIES 5

former_member194669
Active Contributor
0 Kudos

The UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can accept duplicate entries.

If we are not specifying the key then table type is generic

0 Kudos

Hi

Thanks for your reply.

Yes I'm aware of that, but what I do not know is if the line "Move-corresponding new_data to i_tab" in the code I posted can cause duplicate records.

Kind regards,

Torben

EDIT: Arh, I guess it cannot add duplicated records since the "Move-corresponding new_data to i_tab" is followed by a modify i_tab statement and not a append i_tab statement - correct?

Edited by: Torben Pedersen on Oct 21, 2008 3:09 PM

0 Kudos

Yes, Your sy-subrc = 0 (after read) and table i_tab have NON_UNIQUE will create duplicate entries

0 Kudos

It just occured to me, that it cannot add duplicated records since the "Move-corresponding new_data to i_tab" is followed by a modify i_tab statement and not a append i_tab statement - is that correct?

0 Kudos

Try to change this way


LOOP at i_tab.
v_tabix = sy-tabix
          READ TABLE NEW_DATA WITH KEY
                        oi_ebeln = DATA_PACKAGE-doc_num
                        oi_ebelp = DATA_PACKAGE-doc_item
                        sched_line = DATA_PACKAGE-sched_line
                        conf_line = i_tab-conf_line
                        BINARY SEARCH.
          IF sy-subrc = 0.
            Move-corresponding new_data to i_tab. 
" Here after the read your sy-tabix value get changed so use v_tabix instead of sy-tabix
            modify i_tab index v_tabix " .
          ENDIF.
        ENDLOOP.