Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

select new records (records not in archive table)

Hello,

I need to select records from an internal table that do not exist in an archive table. If I was using SQL Server (new to ABAP) i'd use the following syntax:

SELECT a.*

FROM tab1 a LEFT JOIN tab2 ON

a.key = b.key

WHERE b.key IS NULL

I'm doing attempting to do this with ABAP and am receiving table incompatible error. Can someone see what I'm doing incorrect, is this the best way to do it?

-


DATA: wa LIKE zSAP_CRDN.

DATA: itab LIKE STANDARD TABLE OF wa.

DATA: wa_arch LIKE zSAP_CRDN.

DATA: it_arch LIKE STANDARD TABLE OF wa_arch.

TYPES:

BEGIN OF ty_ceridian,

werks TYPE persa,

nachn TYPE nachn,

vorna TYPE vorna,

pernr TYPE persno,

persk TYPE persk,

stat2 TYPE stat2,

hire_dt TYPE begda,

eff_dt TYPE begda,

kostl TYPE kostl,

stell TYPE stell,

regio TYPE regio,

btrtl TYPE btrtl,

END OF ty_ceridian.

SELECT werks nachn vorna

pernr persk stat2

dat02 begda kostl

stell regio btrtl

INTO wa_new

FROM zSAP_CRDN

WHERE stat2 = 3.

INSERT wa_new INTO it_new INDEX 1.

CLEAR wa_new.

SELECT *

INTO wa_arch

FROM zSAP_CRDN_ARCH.

ENDSELECT.

DELETE TABLE it_new

FROM wa_arch.

ENDSELECT.

Tags:
Former Member
Former Member replied

It completely depends how your tables are defined. If you've created 2 Z tables through SE11 then you can join these together.

SELECT / ENDSELECT loops are the spawn of the devil, it's much better performance-wise to instead use INTO TABLE :

SELECT werks nachn vorna

pernr persk stat2

dat02 begda kostl

stell regio btrtl

INTO TABLE it_new

FROM zSAP_CRDN

WHERE stat2 = 3.

Also ABAP supports EXISTS and NOT EXISTS subqueries if you want to try coding it that way.

Check your code for typos , eg DATA: wa_arch LIKE zSAP_CRDN. looks wrong to me, don't you mean something like DATA: wa_arch TYPE <b>zSAP_CRDN_ARCH</b>

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question