Suppose I have 2 internal tables:
TYPES:BEGIN OF LTY_FILE,
SOKEY TYPE CHAR5,
SOPONO TYPE CHAR15,
SOCONO TYPE CHAR15,
FLAG TYPE C,
END OF LTY_FILE.
data:IT_ARCHIVE TYPE TABLE OF LTY_FILE,
IT_SAP TYPE TABLE OF LTY_FILE.
it_archive = VALUE #(
( sokey = 'Key1' sopono = 'PO#12' socono = 'Three' flag = 'A' )
( sokey = 'Key2' sopono = 'PO#34' socono = 'Four' flag = 'B' ) ).
it_sap = VALUE #(
( sokey = 'Key1' sopono = 'PO#12' socono = 'Three' flag = 'A' ) ).
IT_ARCHIVE
:
SOKEY | SOPONO | SOCONO | FLAG |
---|---|---|---|
Key1 | PO#12 | Three | A |
Key2 | PO#34 | Four | B |
IT_SAP
:
SOKEY | SOPONO | SOCONO | FLAG |
---|---|---|---|
Key1 | PO#12 | Three | A |
Now I want the lines from IT_ARCHIVE
which don't exist in IT_SAP
, based on keys SOKEY
, SOPONO
and SOCONO
, to be added to IT_SAP
with FLAG = D
:
SOKEY | SOPONO | SOCONO | FLAG |
---|---|---|---|
Key2 | PO#34 | Four | B |
So, new IT_SAP
should look like:
SOKEY | SOPONO | SOCONO | FLAG |
---|---|---|---|
Key1 | PO#12 | Three | A |
Key2 | PO#34 | Four | D |
Until now, I have tried following ways,but failed in ABAP 7.4, but as the data is quite huge (more than 400K in each run), I am looking for performance centric code to achieve this.
DATA(ls_wa) = it_sap[ 1 ]. " Temporary workarea for insertion.
CLEAR:ls_wa
LOOP AT IT_ARCHIVE ASSIGNING FIELD SYMBOL(<lfs_archive>).
IF NOT LINE_EXISTS( it_sap[ sokey = <lfs_Archive>-sokey
sopono = <lfs_Archive>-sopono
socono = <lfs_archive>-socono ] ).
ls_wa = <lfs_archive>.
ls_wa-flag = 'D'.
APPEND ls_wa to IT_SAP.
CLEAR:ls_wa.
ENDIF.
ENDLOOP.
Second approach I tried:
data(LT_FINAL) = IT_SAP[].
REFRESH:LT_FINAL[].
lt_final = VALUE #( FOR ls_ar IN IT_ARCHIVE
FOR ls_sap IN IT_SAP WHERE ( sokey <> <lfs_Archive>-sokey
sopono <> <lfs_Archive>-sopono
socono <> <lfs_archive>-socono )
(
"Explicitly mentioning all fields as have to change FLAG value
sokey = ls_Ar-sokey
sopono = ls_ar-sopono
socono = ls_ar-socono
flag = 'D'
) ).
The first approach, takes too much of time as have huge number of data. The second approach, to my surprise is not giving me the same result as the first one.
Is there any better way in ABAP 7.4+ to achieve this?