2009 Apr 22 4:57 AM
Hi Experts ,
I am doing a report on material history where I need to find out open orders....if suppose a matnr does'nt have Po then also I need to display as it will have open PR.
Now I want to delete the line where ebeln eq space but I can't put the condition as:
delete it_first where ebeln = space as single lines will also get deleted.
My condition should be if a matnr is displayed in more than 1 line and if ebeln eq space
delete it_first.
loop at it_first. " I facing problem with this code
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
modify it_first.
endif.
endloop.after the above statement my O/P is as below
werks , matnr , ebeln , menge , wemng
UNIT1 , ABCD , 450025612 , 256 , 125
UNIT1 , ABCD , 450012345 , 756 , 456
UNIT1 , ABCD , --SPACE-- , 0.00 , 0.00 "Need to delete this line
UNIT1 , ABCD , --SPACE-- , 0.00 , 0.00 "Need to delete this line
UNIT2 , BEDF , --SPACE-- , 0.00 , 0.00 " this needs to be displayed (just 4 matnr)Please advice
Karthik
2009 Apr 22 8:48 AM
Hi Karthik,
Did you try the code I given to you,,,
It was working fine in my system..
delete it_first where ebeln is initial.
it_first1 = it_first.
Select * from into it_first
for all entries in it_first1
where matnr ne it_first1-matnr and vbeln eq (initial or null or space or what ever it is)
loop at it_first.
apend it_first to it_first1.
endloop.
sort it_first1.
Thanks & regards,
Dileep .C
Hi Experts ,
I am doing a report on material history where I need to find out open orders....if suppose a matnr does'nt have Po then also I need to display as it will have open PR.
Now I want to delete the line where ebeln eq space but I can't put the condition as:
delete it_first where ebeln = space as single lines will also get deleted.
My condition should be if a matnr is displayed in more than 1 line and if ebeln eq space
delete it_first.
loop at it_first. " I facing problem with this code
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
modify it_first.
endif.
endloop.after the above statement my O/P is as below
werks , matnr , ebeln , menge , wemng
UNIT1 , ABCD , 450025612 , 256 , 125
UNIT1 , ABCD , 450012345 , 756 , 456
UNIT1 , ABCD , --SPACE-- , 0.00 , 0.00 "Need to delete this line
UNIT1 , ABCD , --SPACE-- , 0.00 , 0.00 "Need to delete this line
UNIT2 , BEDF , --SPACE-- , 0.00 , 0.00 " this needs to be displayed (just 4 matnr)Please advice
Karthik
2009 Apr 22 5:08 AM
hello,
Try this way
data : g_prev_eblen like it_first-eblen.
loop at it_first. " I facing problem with this code
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
if it_First-eblen ne g_prev_ebeln.
modify it_first.
endif.
g_prev_ebeln = it_first-eblen. "store previosu entry in g_prev_ebeln to compare at next level. if not equal
" then it wont be apended to table.
endif.
endloop.
Regards,
Mansi.
2009 Apr 22 5:34 AM
Hi Sap user,
Thank u !!
But the below condition is not satisfying, Please advice.
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge.
move ' ' to it_first-wemng.
2009 Apr 22 5:14 AM
Hi,
The following code will work.
loop at it_first.
move matnr to w_matnr.
if matnr = w_matnr and ebeln = ' '.
delete it_first where matnr = w_matnr and eblen = ' '.
modify it_first.
clear w_matnr.
endif.
endloop.
2009 Apr 22 5:17 AM
hi karthik,
You can use a counter. and increment it everytime a entry is found.
loop at it_first.
at new matnr.
clear v_counter.
endat.
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
v_counter = v_counter +1.
if v_counter gt 1 and it_first-ebeln is iitial.
delete it_first.
else.
modify it_first.
endif.
endloop.
Hope this helps.
Regards,
Komal
2009 Apr 22 5:38 AM
Hi Komal,
thank u ...but ur logic is not working..
as per ur statement. space is getting moved to ebeln ,menge and * wemng*
but my problem is remaining da same.
Please advice
Karthik
2009 Apr 22 6:05 AM
Hello,
TRy this. it wil surely work.
data : g_prev_eblen like it_first-eblen.
loop at it_first. " I facing problem with this code
if it_first-wemng GE it_first-menge.
clear : it_first-ebeln, it_first-menge,it_first-wenge.
if it_First-eblen ne g_prev_ebeln.
modify it_first.
endif.
g_prev_ebeln = it_first-eblen. "store previosu entry in g_prev_ebeln to compare at next level. if not equal
" then it wont be apended to table.
endif.
endloop.
Regards,
Mansi.
2009 Apr 22 8:02 AM
2009 Apr 22 8:39 AM
Please give me an idea such that I can get sy-tabix for each repeated matnr
so that I can delete by giving da condition if sy-tabix > 1 and ebeln = ' '.
eg:
SI. No material no:
1. matnr 1
2. matnr 1
3. matnr 1
4. matnr 1
1.matnr 2
2.matnr 2
3.matnr 2
1.matnr 3
1.matnr 4
2.matnr 4.
Thanks
Karthik
2009 Apr 22 8:49 AM
Hi,
Please try the below code.
loop at it_first.
move matnr to w_matnr.
if matnr = w_matnr and ebeln = ' '.
delete it_first where matnr = w_matnr and eblen = ' '.
modify it_first.
clear w_matnr.
endif.
endloop.
2009 Apr 22 11:05 AM
Hi,
Now try this
data : g_prev_eblen like it_first-eblen.
loop at it_first. " I facing problem with this code
if it_first-wemng GE it_first-menge.
clear : it_first-ebeln, it_first-menge,it_first-wenge.
modify it_first.
if it_First-eblen ne g_prev_ebeln.
modify it_first.
endif.
g_prev_ebeln = it_first-eblen. "store previosu entry in g_prev_ebeln to compare at next level. if not equal
" then it wont be apended to table.
endif.
endloop.
2009 Apr 22 5:18 AM
hi,
use
sort itab by matnr.
delete adjacent duplicates from itab
comparing matnr.
hope it works.
regards,
Lokesh
2009 Apr 22 5:28 AM
Hi Karthik,
I would have do like this in your situation,...
delete it_first where ebeln is initial.
it_first1 = it_first.
Select * from into it_first
for all entries in it_first1
where matnr ne it_first1-matnr and vbeln eq (initial or null or space or what ever it is)
loop at it_first.
apend it_first to it_first1.
endloop.
sort it_first1.
Thanks & regards,
Dileep .C
2009 Apr 22 5:29 AM
Try like below.
Report ZTEST.
DATA: BEGIN OF it_first OCCURS 0,
werks TYPE werks,
matnr TYPE matnr,
ebeln TYPE ebeln,
menge TYPE menge,
wemng TYPE wemng,
END OF it_first,
wa LIKE it_first,
v_matnr TYPE matnr,
v1_matnr TYPE matnr,
it_final LIKE it_first OCCURS 0. <----- Final output table
wa-werks = 'UNIT1'.
wa-matnr = 'ABCD'.
wa-ebeln = '450025612'.
wa-menge = '256'.
wa-wemng = '125'.
APPEND wa TO it_first.
wa-werks = 'UNIT1'.
wa-matnr = 'ABCD'.
wa-ebeln = '450012345'.
wa-menge = '756'.
wa-wemng = '456'.
APPEND wa TO it_first.
wa-werks = 'UNIT1'.
wa-matnr = 'ABCD'.
wa-ebeln = ' '.
wa-menge = '0'.
wa-wemng = '0'.
APPEND wa TO it_first.
wa-werks = 'UNIT1'.
wa-matnr = 'ABCD'.
wa-ebeln = ' '.
wa-menge = '0'.
wa-wemng = '0'.
APPEND wa TO it_first.
wa-werks = 'UNIT2'.
wa-matnr = 'BEDF'.
wa-ebeln = ' '.
wa-menge = '0'.
wa-wemng = '0'.
APPEND wa TO it_first.
LOOP AT it_first INTO wa.
v1_matnr = wa-matnr.
IF sy-tabix NE 1.
IF v_matnr = v1_matnr.
IF wa-ebeln NE ''.
APPEND wa TO it_final.
ENDIF.
ELSE.
APPEND wa TO it_final.
ENDIF.
ELSE.
APPEND wa TO it_final.
ENDIF.
v_matnr = wa-matnr.
ENDLOOP.
Edited by: Sap Fan on Apr 22, 2009 6:29 AM
2009 Apr 22 5:37 AM
hi,
use this code.
loop at it_first. " I facing problem with this code
on change of it_first matnr.
move all values .
else.
if it_first-ebeln eq space
delete it_first.
endif.
endon.
endloop.
modify according u r internal fields . hope it will work.
~linganna
2009 Apr 22 5:54 AM
Check this code.
loop at it_first. " Add conditions in your if.
if it_first-wemng GE it_first-menge or ( it_first-wemng eq it_first-menge and it_first-wemng ne '0' and it_first-menge ne '0' ).
" Here you wont get entries with wemng and menge as 0.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
modify it_first.
endif.
endloop.Hope this works for you.
Regards,
Lalit Mohan Gupta.
2009 Apr 22 5:58 AM
Hi Karthik,
You can IT_first-ebeln to space instead of initial then instead of checking for initial.
Regards,
Komal
2009 Apr 22 5:58 AM
hi Karthik,
Mabbe u get the solution.
loop at it_first. " I facing problem with this code
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
modify it_first INDEX sy-tabix transporting ebeln menge wenge.
endif.
endloop.
i think this should work...
2009 Apr 22 8:48 AM
Hi Karthik,
Did you try the code I given to you,,,
It was working fine in my system..
delete it_first where ebeln is initial.
it_first1 = it_first.
Select * from into it_first
for all entries in it_first1
where matnr ne it_first1-matnr and vbeln eq (initial or null or space or what ever it is)
loop at it_first.
apend it_first to it_first1.
endloop.
sort it_first1.
Thanks & regards,
Dileep .C
2009 Apr 22 8:52 AM
Hi Dileep,
Thank u ...4 ur kind help, but u have understood my requirement wrongly !!
In ur code u have mentioned..
Select * from {table} into it_first
for all entries in it_first1
where matnr ne it_first1-matnr and vbeln eq (initial or null or space or *what ever it is*)
but I don't want to fetch any thing from any table...only problem I facing is in displaying my O/P.
Please refer my first post and help me.
Thanks
Karthik
2009 Apr 22 9:10 AM
Hi Karthik,
Now try this,
DATA P_MATNR TYPE MATNR.
LOOP AT IT_FIRST.
IF P_MATNR EQ IT_FIRST-MATNR AND EBELN EQ SPACE.
DELETE IT_FIRST.
ENDIF.
P_MATNR = IT_FIRST-MATNR .
ENDLOOP.
I Hope it solves the problem.
Thanks & regards,
Dileep .C
2009 Apr 22 10:57 AM
Hi Dileep,
Its working, but only for the first matnr ....but the matnr diplayed after the first matnr is not working..
Thanks
Karthik
2009 Apr 23 2:42 AM
Hi Karthik,
Hi Dileep,
Its working, but only for the first matnr ....but the matnr diplayed after the first matnr is not working..
Thanks
Karthik
Just to Memorise and confirm, in your post I seen you need to delete only EBELN's when space(null or blank)
Only if there is an order or duplicate... {as commented beside in the code}.
The code works fine... Here is the code What i tested in my system and working fine.
If problem still exists, please update with more records, lets say 7 -15 records,,,,
REPORT ZSAMPLE.
DATA P_MATNR TYPE MATNR.
DATA: BEGIN OF IT_FIRST OCCURS 0,
WERKS TYPE WERKS,
MATNR TYPE MATNR,
EBELN TYPE EBELN,
MENGE TYPE MENGE,
WEMNG TYPE WEMNG,
END OF IT_FIRST.
IT_FIRST-WERKS = 'UNIT1'.IT_FIRST-MATNR = 'ABCD'.IT_FIRST-EBELN = '450025612'.IT_FIRST-MENGE = '256'.IT_FIRST-WEMNG = '125'.
APPEND IT_FIRST.
IT_FIRST-WERKS = 'UNIT1'.IT_FIRST-MATNR = 'ABCD'.IT_FIRST-EBELN = '450012345'.IT_FIRST-MENGE = '756'.IT_FIRST-WEMNG = '456'.
APPEND IT_FIRST.
IT_FIRST-WERKS = 'UNIT1'.IT_FIRST-MATNR = 'ABCD'.IT_FIRST-EBELN = ' '.IT_FIRST-MENGE = '0'.IT_FIRST-WEMNG = '0'.
APPEND IT_FIRST.
IT_FIRST-WERKS = 'UNIT1'.IT_FIRST-MATNR = 'ABCD'.IT_FIRST-EBELN = ' '.IT_FIRST-MENGE = '0'.IT_FIRST-WEMNG = '0'.
APPEND IT_FIRST.
IT_FIRST-WERKS = 'UNIT2'.IT_FIRST-MATNR = 'BEDF'.IT_FIRST-EBELN = ' '.IT_FIRST-MENGE = '0'.IT_FIRST-WEMNG = '0'.
APPEND IT_FIRST.
IT_FIRST-WERKS = 'UNIT2'.IT_FIRST-MATNR = 'BEDF'.IT_FIRST-EBELN = ' '.IT_FIRST-MENGE = '0'.IT_FIRST-WEMNG = '0'.
APPEND IT_FIRST.
IT_FIRST-WERKS = 'UNIT1'.IT_FIRST-MATNR = 'BEDF'.IT_FIRST-EBELN = '450012345'.IT_FIRST-MENGE = '756'.IT_FIRST-WEMNG = '456'.
APPEND IT_FIRST.
SORT IT_FIRST BY MATNR ASCENDING EBELN DESCENDING.
LOOP AT IT_FIRST.
IF P_MATNR EQ IT_FIRST-MATNR AND IT_FIRST-EBELN EQ SPACE.
DELETE IT_FIRST.
ENDIF.
P_MATNR = IT_FIRST-MATNR .
ENDLOOP.
Thanks & regards,
Dileep .C
2009 Apr 22 9:08 AM
loop at it_first. " I facing problem with this code
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
*>>>
clear: l_count.
loop at it_first into l_wa_first
where werks = it_first-werks
and matnr = it_first-matnr.
l_count = l_count + 1.
endloop.
if l_count > 1.
delete it_first.
else.
modify it_first.
endif.
*<<<
modify it_first.
endif.
endloop.
2009 Apr 22 9:17 AM
sort table i_tab1 by matnr.
loop at i_tab1.
if i_tab1-ebeln = space.
delete adjacent duplicates from i_tab1 comparing matnr.
endif.
endloop.
Regards,
Joan
2009 Apr 22 11:01 AM
Hi,
Try this code
IT_OUTPUT is the table which ur displaying currently.
Now with this table do the below operation
add a field called as flag(char01) to your current table it_output and declare similar table it_output_new with same structure.
Now,
IT_OUTPUT_NEW[] = IT_OUTPUT[].
SORT IT_OUTPUT BY MATNR.
SORT IT_OUTPUT_NEW BY MATNR.
DELETE ADJACENT DUPLICATES FROM IT_OUTPUT_NEW COMPARING MATNR.
*Now it_output_new will contain only unique matnr.
loop at it_output_new assigning <fs_out>.
loop at it_output assigning <fs_new> where matnr = <fs_out>-matnr
and ebeln = space.
*if this condition is sucess it means u have a record with blank ebeln. but now u need to check if u have a record with valid ebeln as well!!!! this is our req!!!!!! so read the table and find if u have such an entry and if yes then delete that entry by making a flag field in ouput table.
read table it_output assigning <fs_new> where matnr = <fs_out>-matnr
and ebeln <> space.
if sy-subrc is initial.
sucess so delete the current record from it_output...for this apply flag.
<fs_new>-flag = 'X'.
endif.
endloop.
endloop.
*finally delete it_output where flag is set so that u have the correct records
delete it_output where flag = 'X'.
hope this works and close the thread.
regards,
Jayaram Maganti
Edited by: JAYARAM MAGANTI on Apr 22, 2009 12:28 PM
2009 Apr 22 11:45 AM
Try this code !
Hope this works.
data: tempmatnr type matnr,
l_tabix type sy-tabix.
loop at it_first.
if it_first-wemng GE it_first-menge
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
modify it_first.
endif.
endloop.
loop at it_first.
l_tabix = sy-tabix.
if it_first-matnr eq tempmatnr and it_first-menge eq ' ' and it_first-wenge eq ' '.
delete it_first index l_tabix.
endif.
endloop.Regards,
Lalit Mohan Gupta.
2009 Apr 23 6:59 AM
Hi ,
Try this it will resolve your problem
SORT it_first BY matnr.
data: count like sy-tabix.
loop at it_first.
if it_first-wemng GE it_first-menge.
move ' ' to it_first-ebeln.
move ' ' to it_first-menge
move ' ' to it_first-wenge
modify it_first.
endif.
if it_first-ebeln is initial.
add 1 to count.
endif.
AT END OF MATNR.
if count > 1.
delete it_first where matnr = it_first-matnr.
endif.
clear count.
ENDON.
endloop.
Regards,
Peranandam
2009 Apr 23 8:38 AM
Hi Karthik,
Did you try the below ?
sort it_first by werks matnr ebeln.
delete adjacent duplicates comparing werks matnr ebeln.
Regards,
Girish