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

Comparing Internal Tables

sudhir_uppalapati
Participant
0 Likes
373

Hello All,

I am having 2 internal tables of same structure. I am retreiving the data from ZABC table based on some selection criteria.

{ SELECT * FROM ZABC

INTO TABLE t_innet

WHERE ytype = 'INNET'

AND ybukrs IN s_bukrs

AND ytlnr = p_ytlnr

AND yjahr = p_gjahr

AND ymonat = p_monat

AND yreceiver IN s_kunnr. }

{ SELECT * FROM ZABC

INTO TABLE t_sap

WHERE ytype = 'SAP'

AND ybukrs IN s_bukrs

AND ytlnr = p_ytlnr

AND yjahr = p_gjahr

AND ymonat = p_monat

AND yreceiver IN s_kunnr.}

Now, I have to compare the entries of these 2 Internal tables based on the below criteria and update a field in table ZABC with status 1,2,3.

- Match item

- Items in INNET but not in SAP

- Items in SAP but not in INNET

- Items with different amounts

Based on this comparison we update the ZABC table, the field status with:

1 - OK - INNET = SAP

2 - DIF - INNET <> SAP

3 - OPEN - Missing in INNET or SAP.

How to Compare the 2 tables in my scenario because I need to check each entry exists in both T_INNET & T_SAP.

If exists in T_INNET i need to check whether the entry is in T_SAP.

If exists in T_SAP i need to check whether the entry is in T_INNET.

Regards,

Sudhir

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
329

Hi,

Check the sample code


SELECT * FROM ZABC
INTO TABLE t_itab
WHERE ( ytype = 'INNET'
  or ytype = 'SAP' )
AND ybukrs IN s_bukrs
AND ytlnr = p_ytlnr
AND yjahr = p_gjahr
AND ymonat = p_monat
AND yreceiver IN s_kunnr.
  
  IF sy-subrc EQ 0.
    
    t_sap[] = t_itab[].
    
    t_innet[] = t_itab[].
    
    delete t_sap WHERE ytype EQ 'INNET'.
    
    delete t_innet WHERE ytype EQ 'SAP'.
    

  ENDIF.
  
  LOOP AT t_innet ASSIGNING <fs_innet>.
    
    READ TABLE t_sap ASSIGNING <fs_sap> WITH KEY (use ur key fields) = <fs_innet>-keyfields.
    
    IF sy-subrc EQ 0.
      
      IF <fs_innet>-item EQ <Fs_sap>-item.
        
        <fs_innet>-status = '1'.
        
        ELSE.
          
        <fs_innet>-status = '2'.  

      ENDIF.
      
      ELSE.
        
        <fs_innet>-status = '3'.  

    ENDIF.

  ENDLOOP.
  
    LOOP AT t_sap ASSIGNING <fs_sap>.
    
    READ TABLE t_innet ASSIGNING <fs_innet> WITH KEY item = <fs_sap>-item.
    
    IF sy-subrc EQ 0.
      
      IF <fs_innet>-item EQ <Fs_sap>-item.
        
        <fs_sap>-status = '1'.
        
        ELSE.
          
        <fs_sap>-status = '2'.  

      ENDIF.
      
      ELSE.
        
        <fs_sap>-status = '3'.  

    ENDIF.

  ENDLOOP.
  
  free t_itab.
  
  t_itab[] = t_sap.
  
  APPEND LINES OF t_innet[] to t_itab[].
  
* Now the updated values are in T_ITAB.. 
* Just update the ZABC table with the internal table T_ITAB.  

1 REPLY 1
Read only

Former Member
0 Likes
330

Hi,

Check the sample code


SELECT * FROM ZABC
INTO TABLE t_itab
WHERE ( ytype = 'INNET'
  or ytype = 'SAP' )
AND ybukrs IN s_bukrs
AND ytlnr = p_ytlnr
AND yjahr = p_gjahr
AND ymonat = p_monat
AND yreceiver IN s_kunnr.
  
  IF sy-subrc EQ 0.
    
    t_sap[] = t_itab[].
    
    t_innet[] = t_itab[].
    
    delete t_sap WHERE ytype EQ 'INNET'.
    
    delete t_innet WHERE ytype EQ 'SAP'.
    

  ENDIF.
  
  LOOP AT t_innet ASSIGNING <fs_innet>.
    
    READ TABLE t_sap ASSIGNING <fs_sap> WITH KEY (use ur key fields) = <fs_innet>-keyfields.
    
    IF sy-subrc EQ 0.
      
      IF <fs_innet>-item EQ <Fs_sap>-item.
        
        <fs_innet>-status = '1'.
        
        ELSE.
          
        <fs_innet>-status = '2'.  

      ENDIF.
      
      ELSE.
        
        <fs_innet>-status = '3'.  

    ENDIF.

  ENDLOOP.
  
    LOOP AT t_sap ASSIGNING <fs_sap>.
    
    READ TABLE t_innet ASSIGNING <fs_innet> WITH KEY item = <fs_sap>-item.
    
    IF sy-subrc EQ 0.
      
      IF <fs_innet>-item EQ <Fs_sap>-item.
        
        <fs_sap>-status = '1'.
        
        ELSE.
          
        <fs_sap>-status = '2'.  

      ENDIF.
      
      ELSE.
        
        <fs_sap>-status = '3'.  

    ENDIF.

  ENDLOOP.
  
  free t_itab.
  
  t_itab[] = t_sap.
  
  APPEND LINES OF t_innet[] to t_itab[].
  
* Now the updated values are in T_ITAB.. 
* Just update the ZABC table with the internal table T_ITAB.