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: 

How to get single records form internal table loop?

Former Member
0 Kudos

Hello friends,

I have one internal table i_tab like


MATNR	RUN
3000101	
3000101	X
3000102	
3000102	X
3000103	
3000103	X
3000104	X
3000105	

I want to check first if RUN = balnk, then take this record.

If it is not blank then take 'X' record.

How to do it with the same internal table?

Regards,

RH

8 REPLIES 8

Former Member
0 Kudos

Did you try to program something yourself and what does that piece of program look like?

Former Member
0 Kudos

Hello,

Try this:


loop at i_tab.
  at new matnr.
    wa_aux = i_tab-run.
  endat.
endloop.

Regards.

Former Member
0 Kudos

Loop the itab into wa.

if wa-run = space.

then take wa_run-matnr.

else

take 'X'.

endif.

endloop.

hope this is wht u r looking for..

Former Member
0 Kudos

the above replies shd suffice your issue.

Edited by: Poornima Madhusudhan on Oct 8, 2008 1:15 PM

Former Member
0 Kudos

Hi Ronny

Just check the below code.


TYPES : BEGIN OF TY_ITAB,
          N(10) TYPE C,
          F     TYPE C,
        END OF TY_ITAB.

DATA : ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE,
       ITAB1 TYPE TABLE OF TY_ITAB WITH HEADER LINE,
       W_ITAB TYPE TY_ITAB.

ITAB-N = '3000101'.
ITAB-F = 'X'.
APPEND ITAB.

ITAB-N = '3000101'.
ITAB-F = ' '.
APPEND ITAB.

ITAB-N = '3000101'.
ITAB-F = ' '.
APPEND ITAB.

ITAB-N = '3000101'.
ITAB-F = 'X'.
APPEND ITAB.


ITAB-N = '3000102'.
ITAB-F = 'X'.
APPEND ITAB.

ITAB-N = '3000103'.
ITAB-F = 'X'.
APPEND ITAB.

ITAB-N = '3000103'.
ITAB-F = ' '.
APPEND ITAB.

ITAB-N = '3000104'.
ITAB-F = ' '.
APPEND ITAB.



SORT ITAB BY N  F.

LOOP AT ITAB.
  W_ITAB = ITAB.
  AT NEW N.
    ITAB1-N = W_ITAB-N.
    ITAB1-F = W_ITAB-F.
    APPEND ITAB1.
    CLEAR : ITAB, ITAB1.
  ENDAT.
ENDLOOP.

LOOP AT ITAB1.
  WRITE 😕 ITAB1-N,
          ITAB1-F.
ENDLOOP.

Comment on it.

Regards

M kumar

Former Member
0 Kudos

hi,

Try this out

data : matnr like mara-matnr.

sort i_itab.

loop at i_itab.

if i_itab-matnr eq matnr and i_itab-run eq 'X'.

i_itab-run = 'X'.

elseif i_itab-matnr ne matnr and i_itab-run eq ' '.

i_itab-run = ' '.

elseif i_itab-matnr ne matnr and i_itab-run eq 'X'.

i_itab-run = ' '.

endif.

matnr = i_itab-matnr.

endloop.

Former Member
0 Kudos

Hello Ronny,

Can you say what the expected output would be for your example itab?

Should it be getting the ones in red?

MATNR RUN

3000101

3000101 X

3000102

3000102 X

3000103

3000103 X

3000104 X

3000105

If yes


* make sure run = blank is comes first
sort itab by matnr run.

loop at itab into wa.
  at new matnr.
* do whatever you're trying to do    
  endat.
endloop.

Former Member
0 Kudos

Thanks !!