‎2009 Feb 19 11:32 AM
BELNR GSBER
10001 1007
10001
10001
10002
10002
10003
10003
THESE VALUES ARE IN IT_BSEG(INTERNAL TABLE WIT 2 FIELDS) AFTER SORTING.
MY QUESTION IS: I WONT TO SELECT ONLY THAT BELNR IF ALL ITS CORRESPONDING GSBER ARE NULL(BLANK FIELDS INDICATE NULL).
I CANT SELECT 10001 SINCE ATLEAST ONE OF ITS CORRESPONDING GSBER FIELD HAS A VALUE(1007). BUT I CAN SELECT 10002 & 10003 SINCE ALL ITS CORRESPONDING GSBER FIELDS ARE EMPTY.
THANKS IN ADVANCE
Edited by: Julius Bussche on Feb 19, 2009 2:02 PM
Please use more meaningfull subject titles and DO NOT write in CAPS-LOCK because it means SHOUTING
‎2009 Feb 19 11:38 AM
write as :
loop at itab.
if itab-gsber is initial.
v_flag = 'X'.
endif.
at end of belnr.
if v_flag is initial.
*Write your code to get BELNR
else.
*don't consider the Belnr.
endif.
clear v_flag.
endat.
endloop.
‎2009 Feb 19 11:36 AM
‎2009 Feb 19 11:41 AM
loop at it_bseg
if sy-subrc eq 0.
if it_bseg-gsber is initial . "this checks ur condition
*********move it to another int table ot ur desired loc
endif.
endloop
‎2009 Feb 19 11:38 AM
write as :
loop at itab.
if itab-gsber is initial.
v_flag = 'X'.
endif.
at end of belnr.
if v_flag is initial.
*Write your code to get BELNR
else.
*don't consider the Belnr.
endif.
clear v_flag.
endat.
endloop.
‎2009 Feb 19 11:40 AM
hi,
Loop at it_bseg where belnr = space.
ur code to move it to another internal table
endloop.
‎2009 Feb 19 11:40 AM
it_belnr1[] = it_belnr[].
loop at it_belnr1 into wa1.
if wa1-gsber is not initial.
read table it_belnr into wa with key belnr = wa1-belnr gsber = wa1-gsber.
if sy-subrc = 0.
loop at it_belnr into wa2 where belnr = wa1-belnr.
delete it_belnr from wa2.
endloop.
endif.
endif.
endloop.Edited by: saurabh asthana on Feb 19, 2009 5:10 PM
‎2009 Feb 19 11:44 AM
Hi:
way - 1
First use delete duplicate adjacent
then select the statement.
way - 2
prepare the 2 table - one table (a) would contain GSBER is not initial and another table(b) would contain GSBER is initial.
loop at b
read the record in table a.
if yes then delete it else continue.
endloop.
Regards
Shashi
‎2009 Feb 19 11:49 AM
Hi,
Try like this
ranges : r_belnr for bseg-belnr.
LOOP AT IT_BSEG.
IF IT_BSEG-GSBER IS INITIAL.
MOVE : IT_BSEG-BELNR TO IT_BSEG1-BELNR.
append IT_BSEG1.
ELSE.
r_belnr-sign = 'I'.
r_belnr-option = 'EQ'.
r_belnr-low = IT_BSEG-BELNR.
append r_belnr.
clear : r_belnr,
IT_BSEG,
IT_BSEG1.
ENDLOOP.
now ur second internal table will have the records whose GSBER is null.
Now u have the range table which have BELNR whose GSBER is not null.
In ur case in the internal table IT_BSEG1 u will have 10001
10001
10002
10002
10003
10003
and in the range table u will have 10001(as Gsber is there for first record).
now write.
if not r_belnr[] is initial.
delete IT_BSEG1 where belnr in r_belnr.
endif.
Now the record with 10001 will be deleted and finally u will have 10002 and 10003.
Regards,
Nagaraj
‎2009 Feb 19 11:54 AM
hi...
THIS IS A WORKING CODE AND TESTED ONE
types: begin of type_s_tab,
belnr type belnr,
gsber type gsber,
end of type_s_tab.
data: work_area type type_s_tab,
w_char1 type gsber,
t_table like standard table of work_area.
work_area-belnr = '10001'.
work_area-gsber = '1007'.
append work_area to t_table.
clear work_area.
work_area-belnr = '10001'.
append work_area to t_table.
clear work_area.
work_area-belnr = '10001'.
append work_area to t_table.
clear work_area.
work_area-belnr = '10002'.
append work_area to t_table.
clear work_area.
work_area-belnr = '10003'.
append work_area to t_table.
clear work_area.
work_area-belnr = '10004'.
append work_area to t_table.
clear work_area.
data: w_char type BELNR.
loop at t_table into work_area.
if sy-tabix = 1.
w_char = work_area-belnr.
endif.
check work_area-gsber is initial.
if w_char = work_area-belnr.
else.
write: work_area-belnr.
w_char = work_area-belnr.
endif.
endloop.
regards
‎2009 Feb 19 11:58 AM
Hi,
DATA:it_bseg LIKE bseg OCCURS 0 WITH HEADER LINE,
it_bseg_tmp LIKE bseg OCCURS 0 WITH HEADER LINE.
it_bseg-belnr = '10001'.
it_bseg-gsber = '1007'.
APPEND it_bseg.
it_bseg-belnr = '10001'.
it_bseg-gsber = ''.
APPEND it_bseg.
it_bseg-belnr = '10002'.
it_bseg-gsber = ''.
APPEND it_bseg.
it_bseg-belnr = '10002'.
it_bseg-gsber = ''.
APPEND it_bseg.
it_bseg-belnr = '10003'.
it_bseg-gsber = ''.
APPEND it_bseg.
it_bseg-belnr = '10003'.
it_bseg-gsber = ''.
APPEND it_bseg.
SORT it_bseg BY belnr ASCENDING gsber DESCENDING.
LOOP AT it_bseg.
AT NEW belnr.
IF it_bseg-gsber = ''.
MOVE-CORRESPONDING it_bseg TO it_bseg_tmp.
APPEND it_bseg_tmp.
CLEAR it_bseg_tmp.
ENDIF.
ENDAT.
ENDLOOP.
DELETE it_bseg FROM it_bseg_tmp WHERE belnr = it_bseg_tmp-belnr.
‎2009 Feb 19 12:12 PM
Hi,
THIS IS WORKING FINE.
refer this code.
DATA :
BEGIN OF fs,
belnr(5) TYPE n,
gsber(4) TYPE n,
END OF fs.
DATA itab LIKE STANDARD TABLE OF fs.
DATA :
BEGIN OF fs1,
belnr(5) TYPE n,
gsber(4) TYPE n,
END OF fs1.
DATA itab1 LIKE STANDARD TABLE OF fs1.
DATA w_c TYPE i.
DEFINE mac.
fs-belnr = &1.
fs-gsber = &2.
append fs to itab.
clear fs.
END-OF-DEFINITION.
mac '10001' '1007'.
mac '10001' ' '.
mac '10001' ' '.
mac '10002' ' '.
mac '10002' ' '.
mac '10003' ' ' .
mac '10003' ' ' .
LOOP AT itab INTO fs.
WRITE 😕 fs-belnr,
fs-gsber NO-ZERO.
COLLECT fs INTO itab1.
ENDLOOP.
SKIP.
LOOP AT itab1 INTO fs.
WRITE 😕 fs-belnr,
fs-gsber NO-ZERO.
ENDLOOP.
SKIP.
LOOP AT itab1 INTO fs1.
LOOP AT itab INTO fs WHERE belnr EQ fs1-belnr.
IF fs-gsber IS NOT INITIAL.
ADD 1 TO w_c.
ENDIF.
ENDLOOP.
IF w_c EQ 0.
WRITE 😕 fs1-belnr.
ENDIF.
w_c = 0.
ENDLOOP.
‎2009 Feb 19 12:12 PM
Hi Narasimha,
Try with this logic..this may be helpful....
loop at itab where gsber eq space.
w_belnr = itab-belnr.
read table itab with belnr = w_belnr and gsber ne space.
if sy-subrc ne 0.
write:/ itab-belnr.
endif.
endloop.
Regards,
Mdi.Deeba
‎2009 Feb 19 12:18 PM
declare one more internal table it_bseg1 like it_bseg.
it_bseg1[] = it_bseg[].
delete it_bseg1 where gsber ne space.
Now you have required entries in it_bseg1.you can use this for further processing.
‎2009 Feb 19 12:28 PM
Hi,
If the inetrnal table contains only two fields then after sorting it, write the statemnt for deleting the adjacent duplicates from IT_BSEG comparing BELNR.
This will remove the duplicated BELNR from the internal table and now it will hold the values as:
BELNR GSBER
10001 1007
10002
10003
Now u can loop the internal table and take the values required.
loop at IT_BSEG into WA_BSEG where gsber = space.
WA_BSEG1-BELNR = WA_BSEG-BELNR.
append this value to new intrnal table.
endloop.
Thanks,
Keerthi
‎2009 Feb 19 12:49 PM
hi,
The following code will help ,
I tried with it, its working.
REPORT z_sdn
types : begin of t_itab,
belnr(5) type c,
gsber(4) type c,
end of t_itab.
DATA: i_itab TYPE STANDARD TABLE OF t_itab,
i2_itab TYPE STANDARD TABLE OF t_itab,
wa_itab LIKE LINE OF i_itab.
wa_itab-belnr = '10001'.
wa_itab-gsber = '1007'.
APPEND wa_itab TO i_itab.
CLEAR wa_itab.
DO 2 TIMES.
wa_itab-belnr = '10001'.
wa_itab-gsber = ''.
APPEND wa_itab TO i_itab.
ENDDO.
CLEAR wa_itab.
DO 2 TIMES.
wa_itab-belnr = '10002'.
wa_itab-gsber = ''.
APPEND wa_itab TO i_itab.
ENDDO.
CLEAR wa_itab.
DO 2 TIMES.
wa_itab-belnr = '10003'.
wa_itab-gsber = ''.
APPEND wa_itab TO i_itab.
ENDDO.
CLEAR wa_itab.
LOOP AT i_itab INTO wa_itab.
IF wa_itab-belnr NE '' AND wa_itab-gsber = '' .
APPEND wa_itab TO i2_itab.
ENDIF.
ENDLOOP.
Please let me know if I am wrong.