Application Development and Automation 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: 
Read only

append error where entry already exists

Former Member
0 Likes
1,153

I am adding line to this table and and getting an short dump about the items already existing.

TYPES: BEGIN OF ty_vbeln,

plant TYPE /BI0/OIPLANT,

subgrp TYPE /BIC/OIZSUBGROUP,

lprio TYPE /BI0/OIWM_PRIO,

vbeln TYPE /BI0/OIDELIV_NUMB,

END OF ty_vbeln.

DATA: it_vbeln TYPE SORTED TABLE OF ty_vbeln WITH UNIQUE KEY plant

subgrp lprio vbeln.

DATA: wa_it_vbeln LIKE LINE OF it_vbeln.

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.

wa_it_vbeln-plant = <RESULT_FIELDS>-PLANT.

wa_it_vbeln-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP.

wa_it_vbeln-lprio = <RESULT_FIELDS>-WM_PRIO.

wa_it_vbeln-vbeln = <RESULT_FIELDS>-DELIV_NUMB.

if sy-subrc > 0. " the fields are not in the table so add them

append wa_it_vbeln TO it_vbeln..

clear wa_it_vbeln.

endif.

ENDLOOP.

So I somehow need to capture the error so my pgm doesnt short dump.

What I ultimatly want is a table that I can find the unique number of vbelns.

So if my table looks like:

aaa 8 003 80008361

aaa 8 003 80008362

bbb 8 003 80009361

if I look up 80008361 I will 2.

if I look up 80008362 I will 2.

if I look up 80009361 I will 1.

Any help is appreciated.

Mike

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
989

Try this way


TYPES: BEGIN OF ty_vbeln,
plant TYPE /BI0/OIPLANT,
subgrp TYPE /BIC/OIZSUBGROUP,
lprio TYPE /BI0/OIWM_PRIO,
vbeln TYPE /BI0/OIDELIV_NUMB,
END OF ty_vbeln.

DATA: it_vbeln TYPE SORTED TABLE OF ty_vbeln WITH UNIQUE KEY plant
subgrp lprio vbeln.

DATA: wa_it_vbeln LIKE LINE OF it_vbeln.
DATA: wa_it_vbeln_temp  LIKE LINE OF it_vbeln.   "<<<<<< 
LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.
wa_it_vbeln-plant = <RESULT_FIELDS>-PLANT.
wa_it_vbeln-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP.
wa_it_vbeln-lprio = <RESULT_FIELDS>-WM_PRIO.
wa_it_vbeln-vbeln = <RESULT_FIELDS>-DELIV_NUMB.

read table it_vbeln into wa_it_vbeln_temp with key     "<<<<<<<<<
                    wa_it_vbeln_temp-plant = <RESULT_FIELDS>-PLANT
                    wa_it_vbeln_temp-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP
                    wa_it_vbeln_temp-lprio = <RESULT_FIELDS>-WM_PRIO
                    wa_it_vbeln_temp-vbeln = <RESULT_FIELDS>-DELIV_NUMB..
if sy-subrc > 0. 
append wa_it_vbeln TO it_vbeln..
clear wa_it_vbeln.
endif.
ENDLOOP.

I am adding line to this table and and getting an short dump about the items already existing.

TYPES: BEGIN OF ty_vbeln,

plant TYPE /BI0/OIPLANT,

subgrp TYPE /BIC/OIZSUBGROUP,

lprio TYPE /BI0/OIWM_PRIO,

vbeln TYPE /BI0/OIDELIV_NUMB,

END OF ty_vbeln.

DATA: it_vbeln TYPE SORTED TABLE OF ty_vbeln WITH UNIQUE KEY plant

subgrp lprio vbeln.

DATA: wa_it_vbeln LIKE LINE OF it_vbeln.

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.

wa_it_vbeln-plant = <RESULT_FIELDS>-PLANT.

wa_it_vbeln-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP.

wa_it_vbeln-lprio = <RESULT_FIELDS>-WM_PRIO.

wa_it_vbeln-vbeln = <RESULT_FIELDS>-DELIV_NUMB.

if sy-subrc > 0. " the fields are not in the table so add them

append wa_it_vbeln TO it_vbeln..

clear wa_it_vbeln.

endif.

ENDLOOP.

So I somehow need to capture the error so my pgm doesnt short dump.

What I ultimatly want is a table that I can find the unique number of vbelns.

So if my table looks like:

aaa 8 003 80008361

aaa 8 003 80008362

bbb 8 003 80009361

if I look up 80008361 I will 2.

if I look up 80008362 I will 2.

if I look up 80009361 I will 1.

Any help is appreciated.

Mike

6 REPLIES 6
Read only

former_member194669
Active Contributor
0 Likes
990

Try this way


TYPES: BEGIN OF ty_vbeln,
plant TYPE /BI0/OIPLANT,
subgrp TYPE /BIC/OIZSUBGROUP,
lprio TYPE /BI0/OIWM_PRIO,
vbeln TYPE /BI0/OIDELIV_NUMB,
END OF ty_vbeln.

DATA: it_vbeln TYPE SORTED TABLE OF ty_vbeln WITH UNIQUE KEY plant
subgrp lprio vbeln.

DATA: wa_it_vbeln LIKE LINE OF it_vbeln.
DATA: wa_it_vbeln_temp  LIKE LINE OF it_vbeln.   "<<<<<< 
LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.
wa_it_vbeln-plant = <RESULT_FIELDS>-PLANT.
wa_it_vbeln-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP.
wa_it_vbeln-lprio = <RESULT_FIELDS>-WM_PRIO.
wa_it_vbeln-vbeln = <RESULT_FIELDS>-DELIV_NUMB.

read table it_vbeln into wa_it_vbeln_temp with key     "<<<<<<<<<
                    wa_it_vbeln_temp-plant = <RESULT_FIELDS>-PLANT
                    wa_it_vbeln_temp-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP
                    wa_it_vbeln_temp-lprio = <RESULT_FIELDS>-WM_PRIO
                    wa_it_vbeln_temp-vbeln = <RESULT_FIELDS>-DELIV_NUMB..
if sy-subrc > 0. 
append wa_it_vbeln TO it_vbeln..
clear wa_it_vbeln.
endif.
ENDLOOP.

Read only

0 Likes
989

I tried that and I still got short dump.

My code was that I commented out.:

  • DATA: st_it_vbeln LIKE LINE OF it_vbeln.

  • read table it_vbeln into st_it_vbeln

  • with table key

  • plant = <RESULT_FIELDS>-PLANT

  • subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP

  • lprio = <RESULT_FIELDS>-WM_PRIO

  • vbeln = <RESULT_FIELDS>-DELIV_NUMB.

Arggg.

Mike

Edited by: Michael Hill on Apr 17, 2009 5:18 AM

Read only

0 Likes
989

Something with UNIQUE KEY , remove it and use SORT


TYPES: BEGIN OF ty_vbeln,
plant TYPE /BI0/OIPLANT,
subgrp TYPE /BIC/OIZSUBGROUP,
lprio TYPE /BI0/OIWM_PRIO,
vbeln TYPE /BI0/OIDELIV_NUMB,
END OF ty_vbeln.
 
DATA: it_vbeln type ty_vbeln

sort it_vbeln by plant subgrp lprio vbeln.
 
DATA: wa_it_vbeln LIKE LINE OF it_vbeln.

DATA: wa_it_vbeln_temp  LIKE LINE OF it_vbeln.   "<<<<<< 

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.
wa_it_vbeln-plant = <RESULT_FIELDS>-PLANT.
wa_it_vbeln-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP.
wa_it_vbeln-lprio = <RESULT_FIELDS>-WM_PRIO.
wa_it_vbeln-vbeln = <RESULT_FIELDS>-DELIV_NUMB.
 
read table it_vbeln into wa_it_vbeln_temp with key     "<<<<<<<<<
                    wa_it_vbeln_temp-plant = <RESULT_FIELDS>-PLANT
                    wa_it_vbeln_temp-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP
                    wa_it_vbeln_temp-lprio = <RESULT_FIELDS>-WM_PRIO
                    wa_it_vbeln_temp-vbeln = <RESULT_FIELDS>-DELIV_NUMB..
if sy-subrc > 0. 
append wa_it_vbeln TO it_vbeln..
clear wa_it_vbeln.
endif.
ENDLOOP.

Read only

0 Likes
989

you have specified unique keys plant, subgrp, lprio, vblen

DATA: it_vbeln TYPE SORTED TABLE OF ty_vbeln WITH UNIQUE KEY plant

subgrp lprio vbeln.

if you try to append data with these keys and a record exists with similar keys to the table you will get this error.

My Suggestion Increase number of keys in the it_vbeln table.

Read only

0 Likes
989

I don't need any other fields there, just those and I want unique records.

I was hoping to be able to trap that error that the key already exists and simply skip it.

Not possible?

Mike

Read only

Former Member
0 Likes
989

Hi,

Your code:

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.
wa_it_vbeln-plant = <RESULT_FIELDS>-PLANT.
wa_it_vbeln-subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP.
wa_it_vbeln-lprio = <RESULT_FIELDS>-WM_PRIO.
wa_it_vbeln-vbeln = <RESULT_FIELDS>-DELIV_NUMB.

if sy-subrc > 0. " the fields are not in the table so add them
append wa_it_vbeln TO it_vbeln..
clear wa_it_vbeln.
endif.
ENDLOOP.

Over here yo want to check for equality right? So, change it to:

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.
  READ TABLE it_vbeln WITH TABLE KEY
 plant = <RESULT_FIELDS>-PLANT
 subgrp = <RESULT_FIELDS>-/BIC/ZSUBGROUP
 lprio = <RESULT_FIELDS>-WM_PRIO
 vbeln = <RESULT_FIELDS>-DELIV_NUMB TRANSPORTING NO FIELDS.

IF SY-SUBRC NE 0.
append wa_it_vbeln TO it_vbeln..
clear wa_it_vbeln.
endif.
ENDLOOP.

Regards,

Lim...

Edited by: Ruslim Chang on Apr 17, 2009 5:32 AM