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

Regarding 2 internal tables manipulation

Former Member
0 Likes
789

Hi All,

I have 2 internal tables from which i have to filter data and get into next step.

I have <b>2</b> internal tables <b>i_tab1, i_tab2</b>

Now as per spec

<b>I need to Compare values in i_tab1 & i_tab2 where

i_tab1-EXGEN = i_tab2–EXGEN

i_tab1-GENNR = i_tab2–GENNR

i_tab1- GAUFW_DELT = i_tab2-NETWR

if they all match go to 4, if they don’t match go to 2</b>

What logic can i write over here.

DO i need to loop through the entries.

In this case after finishing all above process i have to goto step 3 right!

Thanks in advance.

Thanks & Regards,

Prasad.

Hi All,

I have 2 internal tables from which i have to filter data and get into next step.

I have <b>2</b> internal tables <b>i_tab1, i_tab2</b>

Now as per spec

<b>I need to Compare values in i_tab1 & i_tab2 where

i_tab1-EXGEN = i_tab2–EXGEN

i_tab1-GENNR = i_tab2–GENNR

i_tab1- GAUFW_DELT = i_tab2-NETWR

if they all match go to 4, if they don’t match go to 2</b>

What logic can i write over here.

DO i need to loop through the entries.

In this case after finishing all above process i have to goto step 3 right!

Thanks in advance.

Thanks & Regards,

Prasad.

5 REPLIES 5
Read only

guillaume-hrc
Active Contributor
0 Likes
742

Hi,

I would proceed with a :

LOOP AT ...
  READ TABLE ... TRANSPORTING NO FIELDS WITH KEY ... BINARY SEARCH.
  IF sy-subrc = 0. 
*   do stuff here
  ELSE.
*   do something else
  ENDIF.
ENDLOOP.

Best regards,

Guillaume

Read only

Former Member
0 Likes
742

hi Prasad,

One way is to loop i.e,

<b>loop at itab1

Read table ...

loop at itab2

Read table ....

Logic

endloop

endloop</b>

the other way is use <b>case endcase</b> statemnet

Regards,

Santosh

Read only

Former Member
0 Likes
742

Hi Prasad,

You can use the below logic.


  LOOP AT I_TAB1.

    READ I_TAB2 WITH KEY EXGEN = I_TAB1-EXGEN
                         GENNR = I_TAB1-GENNR.
    IF SY-SUBRC = 0.
    
      IF I_TAB1-EXGEN = I_TAB2–EXGEN
      AND I_TAB1-GENNR = I_TAB2–GENNR
      AND I_TAB1-GAUFW_DELT = I_TAB2-NETWR.
        " YOUR LOGIC.. GOTO 4
      ELSE.
        " GOTO 2
      
      ENDIF.
   
    ENDIF.

  ENDLOOP. "I_TAB1

Hope the above code will help you.

Thanks,

Ramya

Read only

Former Member
0 Likes
742

Hii Prasad ,

check this optimized code .


<b>SORT I_TAB1 BY EXGEN GENNR .</b>

LOOP AT I_TAB1.
 
    READ I_TAB2 WITH KEY EXGEN = I_TAB1-EXGEN
                         GENNR = I_TAB1-GENNR
      <b>BINARY SEARCH TRANSPORTING NO FIELDS</b>.
    
      IF SY-SUBRC = 0.
    
      IF I_TAB1-EXGEN = I_TAB2–EXGEN
      AND I_TAB1-GENNR = I_TAB2–GENNR
      AND I_TAB1-GAUFW_DELT = I_TAB2-NETWR.

       <b>FLAG_1 = X .</b>         
      ELSE.
        <b>CLEAR FLAG_1 .
 
        FLAG_1 = Y .</b> 
     
      ENDIF.
   
    ENDIF.
 
  ENDLOOP. "I_TAB1


Case FLAG_1.
		
When ‘X’.
        " GO TO CONDITION 4 .
	-------------
	-------------
When ‘Y’.
	" GO TO CONDITION 2.
        -------------
	-------------
When ‘Z’.

Endcase.

</b>

This way you can give as many conditions as you want

Regards

Naresh

Read only

rahulkavuri
Active Contributor
0 Likes
742

Hi the below loop talks about two internal tables, which go accroding to the condition checking condition and then check SY-SUBRC value....

LOOP AT T_VBRK_VBRP.

  T_FINAL = T_VBRK_VBRP.

        IF T_VBRK_VBRP-CHARG IS INITIAL.

          READ TABLE T_LIPS WITH KEY VBELN = T_VBRK_VBRP-VGBEL
                                     MATNR = T_VBRK_VBRP-MATNR.

              IF SY-SUBRC  = 0.

                T_FINAL-FKIMG = T_LIPS-LFIMG.
                T_FINAL-CHARG = T_LIPS-CHARG.
                T_FINAL-NETWR = T_LIPS-NETWR.

              ELSEIF SY-SUBRC <> 0.  " NO DELIVERY DETAILS FOUND

                CLEAR T_FINAL-VGBEL.

              ENDIF.

        ENDIF.

    APPEND T_FINAL.

  ENDLOOP.