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: 

Read data sets from Internal Table between indexes

Deon_van_Zyl
Active Participant
0 Kudos
2,449

Hi,

With the new ABAP 7.5 statements, is there a quick way to read sets of data from 1 internal table to another?

For example: Your first table has 100 000 entries. I want to break that up in to 10 sets of data. So I want to read index 1 - 10 000, process it, and then the next 10 000, process it, etc etc. Is there a way to do that with the VALUE # statement? So basically i don't want to loop through the whole table building a new one with the loop statement but rather use the VALUE statement.

Kind Regards

Deon

1 ACCEPTED SOLUTION

Deon_van_Zyl
Active Participant
1,435

Solution by sandra.rossi


"/--- Get All Bookings to be Processed ---/"

SELECT pernr FROM zhr_autobook INTO TABLE lt_pernr
WHERE extr_date BETWEEN p_begda AND p_endda AND
cancel NE abap_true AND
booked NE abap_true AND
errorNE abap_true.



DATA(lv_package_size) = 5000.
DATA(lv_start) = 1.

"/--- Devide into Batches of 5000 records ---/"
WHILE lv_start < lines( lt_pernr ).
lv_batch = lv_batch + 1.
lt_package = VALUE #( ( LINES OF lt_pernr FROM lv_start TO lv_start + lv_package_size - 1 ) ).
DELETE ADJACENT DUPLICATES FROM lt_package COMPARING pernr.
CALL METHOD create_jobs
EXPORTING
it_pernr= lt_package
iv_batch= lv_batch
CHANGING
ct_out = ct_out.
lv_start = lv_start + lv_package_size.
ENDWHILE.

6 REPLIES 6

Sandra_Rossi
Active Contributor
1,435

Something like that?

DATA itab1 TYPE string_table.
DATA itab2 TYPE string_table.
itab1 = VALUE #( ( |France| ) ( |Germany| ) ( |India| ) ).
itab2 = VALUE #(
    LET package_size = 2 IN
    FOR i = 1 THEN i + package_size WHILE i <= lines( itab1 )
    FOR <line> IN itab1 FROM i TO i + package_size - 1
    ( |Package start { i }: { <line> }| ) ).
ASSERT itab2 = VALUE string_table(
    ( |Package start 1: France| )
    ( |Package start 1: Germany| )
    ( |Package start 3: India| ) ).

Sandra_Rossi
Active Contributor
1,435

Hmmm. I read again your question, but I don't get it in fact. 😄

Could you write the pseudo algorithm please?

Deon_van_Zyl
Active Participant
0 Kudos
1,435

Hi sandra.rossi,

Thanks for your response and sorry if my question was unclear. I have a huge table that needs to be processed by a program which is taking way to long. I am writing a wrapper program that should read read all the entries to be processed and then divide into sets of 5000 records at a time for which the program will schedule a job in the background.

SELECT pernr FROM zhr_autobook INTO TABLE @DATA(lt_autobook)
           WHERE extr_date BETWEEN @p_begda AND @p_endda AND
                 cancel NE @abap_true AND
                 booked NE @abap_true AND
                 error  NE @abap_true.

lt_autobook will for instance have 50 000 records. I want to take sets of 5000 at a time, index 1 - 5000, then index 5001-10 000 etc.

I hope that makes sense 🙂

Deon

Sandra_Rossi
Active Contributor
1,435

So I guess that this could be sufficient, I think that a constructor expression has no interest (I use one but it's almost equivalent to APPEND LINES OF ...):

package_size = 5000.
start = 0.
WHILE start < lines( lt_autobook ).
  package = VALUE #( ( LINES OF lt_autobook FROM start TO start + package_size - 1 ) ).
  " JOB program ran using SUBMIT ... WITH package = package AND RETURN.
  start = start + package_size.
ENDWHILE.

(NB: declare the internal table of the job program as a NO-DISPLAY parameter)

Deon_van_Zyl
Active Participant
0 Kudos
1,435

Hi sandra.rossi ,

Thank you so much for this! It worked perfectly! My code was as follow:

    "/--- Get All Bookings to be Processed ---/"
    SELECT pernr FROM zhr_autobook INTO TABLE lt_pernr
           WHERE extr_date BETWEEN p_begda AND p_endda AND
                 cancel NE abap_true AND
                 booked NE abap_true AND
                 error  NE abap_true.



    DATA(lv_package_size) = 5000.
    DATA(lv_start) = 1.

    "/--- Devide into Batches of 5000 records ---/"
    WHILE lv_start < lines( lt_pernr ).
      lv_batch = lv_batch + 1.
      lt_package = VALUE #( ( LINES OF lt_pernr FROM lv_start TO lv_start + lv_package_size - 1 ) ).
      DELETE ADJACENT DUPLICATES FROM lt_package COMPARING pernr.
      CALL METHOD create_jobs
        EXPORTING
          it_pernr  = lt_package
          iv_batch  = lv_batch
        CHANGING
          ct_out   = ct_out.
      lv_start = lv_start + lv_package_size.
    ENDWHILE.

Deon_van_Zyl
Active Participant
1,436

Solution by sandra.rossi


"/--- Get All Bookings to be Processed ---/"

SELECT pernr FROM zhr_autobook INTO TABLE lt_pernr
WHERE extr_date BETWEEN p_begda AND p_endda AND
cancel NE abap_true AND
booked NE abap_true AND
errorNE abap_true.



DATA(lv_package_size) = 5000.
DATA(lv_start) = 1.

"/--- Devide into Batches of 5000 records ---/"
WHILE lv_start < lines( lt_pernr ).
lv_batch = lv_batch + 1.
lt_package = VALUE #( ( LINES OF lt_pernr FROM lv_start TO lv_start + lv_package_size - 1 ) ).
DELETE ADJACENT DUPLICATES FROM lt_package COMPARING pernr.
CALL METHOD create_jobs
EXPORTING
it_pernr= lt_package
iv_batch= lv_batch
CHANGING
ct_out = ct_out.
lv_start = lv_start + lv_package_size.
ENDWHILE.