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

Abap code not working - deleting based on master data table information

bhat_vaidya2
Active Participant
0 Likes
841

Hi,

I wrote a piece of code earlier which is working and during test we found out that it will be hard for the support guys to maintain because it was hard coded and there is possibility that users will include more code nums in the future

sample code

DELETE it_source WHERE /M/SOURCE EQ 'USA' AND

/M/CODENUM NE '0999' AND

/MCODENUM NE '0888' AND.

-


Now I created a new InfoObject master data so that the support people can maintain the source and code number manually.

master data table - the codenum is the key.

XCODENUM XSOURCE

0999 IND01

0888 IND01

now I wrote this routine all the data gets deleted.

-


tables /M/PGICTABLE.

Data tab like /M/PGICTABLE occurs 0 with header line.

Select * from /M/PGICTABLE into table tab where objvers = 'A'.

if sy-subrc = 0.

LOOP at tab.

DELETE it_source WHERE /M/SOURCE EQ tab-XSOURCE AND /M/CODENUM NE tab-XCODENUM.

ENDLOOP.

Endif.

-


But when I chage the sign to EQ, I get opposite values , Not what I require.

DELETE it_source WHERE /M/SOURCE EQ tab-XSOURCE AND /M/CODENUM EQ tab-XCODENUM.

Cube table that I want to extract from

/M/SOURCE /M/CODENUM

IND01 0999

IND01 0888

IND01 0555

IND01 0444

FRF01 0111

I want to only the rows where the /M/CODENUM = 0999 and 0888 and i would also need FRF101

and the rows in bold should be deleted.

thanks

Edited by: Bhat Vaidya on Jun 17, 2010 12:38 PM

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
799

Why do you want to change the sign in your delete statement ? And logically while deleting you have to use the Not Equals operator.

BR,

Suhas

5 REPLIES 5
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
800

Why do you want to change the sign in your delete statement ? And logically while deleting you have to use the Not Equals operator.

BR,

Suhas

Read only

0 Likes
799

Hi,

Changing the sign is for testing. It should be NE but all records gets deleted.

and thats what I don't understand

thanks

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
799

What is the data in your internal table ITAB ?

Read only

0 Likes
799

Hi,

the data in my internal table is same as master data.

Data tab like /M/PGICTABLE occurs 0 with header line.

master data table - the codenum is the key.

XCODENUM XSOURCE

0999 IND01

0888 IND01

thanks

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
799

It's obvious why it deletes all the records. Debug & get your answer i wont spoon feed

Anyways on to achieve your requirement try this code:

DATA:
      r_srce TYPE RANGE OF char5, "Range Table for Source
      s_srce LIKE LINE OF r_srce,
      r_code TYPE RANGE OF numc04,"Range table for Code
      s_code LIKE LINE OF r_code.

s_srce-sign = s_code-sign = 'I'.
s_srce-option = s_code-option = 'EQ'.

* Populate the range tables using /M/PGICTABLE
LOOP AT itab INTO wa.
  s_code-low = wa1-code.
  s_srce-low = wa1-srce.

  APPEND: s_code TO r_code,
          s_srce TO r_srce.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM:
r_code COMPARING ALL FIELDS,
r_srce COMPARING ALL FIELDS.

* Delete from Cube
DELETE it_source WHERE srce IN r_srce AND code IN r_code.