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

Dividing multiple internal tables

Former Member
0 Likes
1,002

Hi Experts,

I have four internal tables having 4 records each.

But, I want to take one record of each at a time and pass this one record  of each itab to a BAPI. After the BAPI has processed first records of all the four itabs, then I have to pass the second record of the itabs to the BAPI to process and so on.

Lets say I have internal tables itab1, itab2, itab3 and itab4, each having 4 records each.

BAPI takes 4 itabs as input (each having one row) and processes accordingly.

Can anyone please help me in the logic.

I think we can play with sy-tabix, but not sure how to implement it!

Regards,

Narsingh

1 ACCEPTED SOLUTION
Read only

Arun_Prabhu_K
Active Contributor
0 Likes
972

Hello Narsingh.

     1) Get the record count of any one internal table.

          describe table itab1.

     2) Declare a temporary variable for loop counter.

          DATA: cnt like sy-tabix.

          cnt = 1.

     3) Use While..Endwhile to fetch each record of 4 itabs and pass to BAPI.

          While cnt <= sy-tfill.

                READ TABLE: itab1 INDEX cnt,

                                      itab2 INDEX cnt,

                                      itab3 INDEX cnt,

                                      itab4 INDEX cnt.

                CALL BAPI.

                cnt = cnt + 1.

          EndWhile.

Regards.

8 REPLIES 8
Read only

former_member192854
Active Participant
0 Likes
972

Hi Narsingh,

How about:

DO.

lv_index = sy-index.

READ TABLE tab1 ASSIGNING <fs_1> INDEX lv_index.

IF sy-subrc NE 0.

EXIT.

ENDIF.

READ TABLE tab2 ASSIGNING <fs_2> INDEX lv_index.

READ TABLE tab3 ASSIGNING <fs_3> INDEX lv_index.

READ TABLE tab4 ASSIGNING <fs_4> INDEX lv_index.

CALL FUNCTION 'YOURFUNCTION'.

ENDDO.

Read only

VijayaKrishnaG
Active Contributor
0 Likes
972

Hi Narsingh,

I think this can be achieved by following logic,

DO 4 TIMES. " 4 or number of records

READ ITAB1 INTO WA_1 INDEX SY-INDEX.

READ ITAB2 INTO WA_2 INDEX SY-INDEX.

READ ITAB3 INTO WA_3 INDEX SY-INDEX.

READ ITAB4 INTO WA_4 INDEX SY-INDEX.

WA_MAIN-FIELD_1 = WA_1-FIELD_1.

WA_MAIN-FIELD_2 = WA_1-FIELD_2.

.

.

WA_MAIN-FIELD_n = WA_2-FIELD_1.

.

.

WA_MAIN-FIELD_n = WA_3-FIELD_1.

.

.

WA_MAIN-FIELD_n = WA_4-FIELD_1.

CALL BAPI_FUNCTION_MODULE.     " by passing WA_MAIN

CLEAR WA_MAIN, WA_1, WA_2, WA_3, WA_4.

ENDDO.

Hope this helps you.

Thanks & Regards,

-Vijay

Read only

Arun_Prabhu_K
Active Contributor
0 Likes
973

Hello Narsingh.

     1) Get the record count of any one internal table.

          describe table itab1.

     2) Declare a temporary variable for loop counter.

          DATA: cnt like sy-tabix.

          cnt = 1.

     3) Use While..Endwhile to fetch each record of 4 itabs and pass to BAPI.

          While cnt <= sy-tfill.

                READ TABLE: itab1 INDEX cnt,

                                      itab2 INDEX cnt,

                                      itab3 INDEX cnt,

                                      itab4 INDEX cnt.

                CALL BAPI.

                cnt = cnt + 1.

          EndWhile.

Regards.

Read only

0 Likes
972

Hi Arun,

Thanx for d reply.

But can u pls say where we will be using the record count of step 1?

And what will be the value of sy-tfill initially?

Read only

0 Likes
972

Narsingh,

     Initially sy-tfill will be zero.

     Only after execution of describe table statement, SY-TFILL will be filled with the total number of records in the internal table.

     We are using this value in step 3 to read each record of 4 itabs.

Regards.

Read only

0 Likes
972

Hi Narsingh,

The value of the sy-tfill always remain same during the execution of loop. It always contain the value of no. of records in your internal table.

Important :-- if u are using the DO operation please check the proper sorting of all the internal table before DO operation..

and in the while & do-loop  sy-tfill and sy-tabix are blank sy-index is used in while and do while loop.

take one counter variable and update the variable + 1 after your bapi execute.

if you conform that all the internal table contains the same number of record then u can use this logic also.

data i type i .

data count type i value 1 .

DESCRIBE TABLE itab LINES i.

now i contains the number of record fill in the itab.

**************** Before this ensure that all internal table must be in sequence .. according to your requirement .

do i times. " now u can use do loop use dynamically

read table1 index  = sy-index

    

read table1 index  = sy-index

    

read table1 index  = sy-index

     

read table1 index  = sy-index

    

call BAPI

count = count + 1. " now count variable update every time after your bapi is execute.

endddo.

Thanks

Nishant Bansal

Read only

nishantbansal91
Active Contributor
0 Likes
972

Hi Nargish,

There are multiple solution for your problem,Some logic are already written by expert.

One more logic is there,

If you have some common value or key based value  inside the four internal table example if you are using bapi for matnr field then matnr field must present in each internal table, then use the loop. Using this logic you can do more validation in your program.

Loop at (one of your internal table has the max. entries that must present in each remaining 3 table) .

read itab2 with key = INTERNAL-TABLE-FIELDNAME.

read itab3 with key  = INTERNAL-TABLE-FIELDNAME.  

read itab4 with key   = INTERNAL-TABLE-FIELDNAME.

CALL 'BAPI' by passing all these field.

endloop.

Thanks

Nishant Bansal

Read only

former_member188282
Active Participant
0 Likes
972

Hi Narasingh,

Try with below process.

LOOP at itab1.

Inside loop write READ Statement if you have any common keys from itab1 to itab2, itab3, itab4.

if you dont have any common keys.

Read the record by using INDEX values.

ENDLOOP.