Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Read table index sy-tabix

Hi Experts,

As per my requirment I need fetch two different categories of matnr based on movment type

from mseg..

For eg: If I have two itab's : itab1 and itab2.

In itab1 the available records are:

matnr    werks     lifnr
mat1     unit1      ABC
mat2     unit1      ABC
mat3     unit1      ABC
mat4     unit1      ABC

In itab2 the available records are:

matnr_1  werks_1  lifnr_1
mat5       unit1       ABC
mat6       unit1       ABC
mat7       unit1       ABC
mat8       unit1       ABC

and I want to move this itab1 and itab2 to another itab ie. itab3.

and my o/p shud look like:

matnr    werks     lifnr     matnr_1
 mat1     unit1     ABC     mat5
 mat2     unit1     ABC     mat6
 mat3     unit1     ABC     mat7
 mat4     unit1     ABC     mat8.

Please advice

Karthik

Edited by: Karthik R on Jun 18, 2009 6:33 PM

Former Member
replied

Hello,

I am not sure about the req. but still try this :

DATA:
 
BEGIN OF ITAB3 OCCURS 0,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
LIFNR TYPE LIFNR,
MATNR_1 TYPE MATNR,
END OF ITAB3,

V_INDEX TYPE SY-TABIX.
 
SORT ITAB1 BY WERKS LIFNR.
 
SORT ITAB2 BY WERKS LIFNR. "-->This is important for READ TABLE
 
LOOP AT ITAB1.
 
ITAB3-MATNR = ITAB1-MATNR.
ITAB3-WERKS = ITAB1-MATNR.
ITAB3-LIFNR = ITAB1-LIFNR.
 
READ TABLE ITAB2 INDEX SY-TABIX.
 
IF SY-SUBRC = 0.
ITAB3-MATNR_1 = ITAB2-MATNR_1.
ENDIF.
 
APPEND ITAB3.

"--> Add this code to achieve your req.
AT LAST.
V_INDEX = SY-TABIX + 1.
LOOP AT ITAB2 FROM V_INDEX.
ITAB3-MATNR_1 = ITAB2-MATNR_1.
APPEND ITAB3.
ENDLOOP.
ENDAT.
 
ENDLOOP.

BR,

Suhas

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question