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: 

Logic for populating internal table

Former Member
0 Kudos

Hi Abapers,

I have two internal tables it_bseg and it_bseg_ven with header lines. the key fields common to these two tables are bukrs, belnr and gjahr. My requirement is to move records of it_bseg_ven to it_bseg which are not there in it_bseg by comparing key fields.

I coded this way. but 'ne' is not supported in read. how can i achieve this. because no.of records are more.

LOOP AT it_bseg.

READ TABLE it_bseg_ven WITH KEY bukrs ne it_bseg-bukrs

belnr ne it_bseg-belnr

gjahr ne it_bseg-gjahr.

IF sy-subrc EQ 0.

MOVE it_bseg_ven-bukrs TO it_bseg-bukrs.

MOVE it_bseg_ven-belnr TO it_bseg-belnr.

MOVE it_bseg_ven-gjahr TO it_bseg-gjahr.

APPEND it_bseg.

ENDIF.

ENDLOOP.

SORT it_bseg BY bukrs belnr gjahr.

pointa are sure.

Message was edited by:

Premraj Cheguri

5 REPLIES 5

Former Member
0 Kudos

Hi Premraj,

You loop at it_bseg_ven and read table it_bseg with the keys u mentioned.

If record not found in it_bseg (SY_SUBRC <> 0); append that record in it_bseg.

Hope it wil solve your problem

Regards,

Pankaj Sharma

0 Kudos

Yeah i can do this but the problem is there could be 5000 records in it_bseg and it_bseg_ven. almost many records are common between these two tables. because of not doing correct archiving for the database table bseg some records are missing in it_bseg. so is there any way to move records which are not there with minimal execution time without effecting performance.

please help me ....

Regards,

Radhika.

0 Kudos

The TRANSPORTING NO FIELDS addition checks for existance, and doesn't have the overhead of moving the record to the work area. Much quicker

Former Member
0 Kudos

Why don't you do it the other way around?

LOOP AT it_bseg_ven.

READ TABLE it_bseg TRANSPORTING NO FIELDS

WITH KEY bukrs = it_bseg_ven-bukrs

belnr = it_bseg_ven-belnr

gjahr = it_bseg_ven-gjahr.

IF sy-subrc NE 0.

MOVE it_bseg_ven-bukrs TO it_bseg-bukrs.

MOVE it_bseg_ven-belnr TO it_bseg-belnr.

MOVE it_bseg_ven-gjahr TO it_bseg-gjahr.

APPEND it_bseg.

ENDIF.

ENDLOOP.

Clemenss
Active Contributor
0 Kudos

Hi Premraj ,

since release 4.5 you can LOOP ASSIGNING <field-symbol>. This removes the overhead of moving every table body line to the header line completely. Especially for tables with that much fields as BSEG it will ibrease processing time 5 to 10 times.

You may do like this:


field-symbols:
  <bseg> like line of it_bseg[].
sort:
  it_bseg_ven by bukrs belnr jhahr.
loop at it_bseg assigning <bseg>. 
* check if record is already present
  read table it_bseg_ven transporting no fields
    with key 
    bukrs = <bseg>-bukrs
    belnr = <bseg>-belnr
    gjahr = <bseg>-gjahr
    binary search.
  check sy-subrc = 0.
* yes this record is already in it_bseg - don't need
  delete it_bseg_ven index sy-tabix.
endloop.
append lines of it_bseg_ven to it_bseg. 

I think this will be pretty fast - any better idea around?

Or like this:


append lines of it_bseg_ven to it_bseg.
sort it_bseg.
delete adjacent duplicates from it_bseg comparing bukrs belnr gjahr.

Just depend on if all other fields in the 2 internal tables are just the same.

Regards,

Clemens