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

simple check

Former Member
0 Likes
732

hi,

i have three records in my internal table , i need to check if the delivery date of the three records is same or different .

if they are same then i need to pass that date to a variable if not i need to pass a constant .

can any one help me in writing this logic'

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
713

Hi,

U can use this logic,

Delete adjacent duplicates on the internal table Itab comparing only date field.

and use

Describe table to find no.of records in the table...

If those three record dates are same, then u'll get only one record.

If those three record dates are not same, then u'll get more then one record.

If no.of record is one, then move that date to variable else pass constant to variable.

I think this should work for ur requirement.

9 REPLIES 9
Read only

Former Member
0 Likes
713

HI,


" When Delivery date is same 
ITAB-FIELD = DATE
MODIFY ITAB TRANSPORTING <FIELD> WHERE DELIVERY_date EQ DATE.

" When Delivery date is different pass the constant 
ITAB-FIELD = CONSTAN 
MODIFY ITAB TRANSPORTING <FIELD> WHERE DELIVERY_date NE DATE.

Read only

Former Member
0 Likes
713

hi,

Loop through the internal table

put a variable var= 'X'.

for the first time i.e if its initial.

and if date changes clear the variable and exit the loop using EXIT.

after the loop depending on var value you can do ur coding

Or

Loop through the internal table

pass your first record date to another variable,

compare the date value with next record value

if changes pass the constant directly and EXIT

jope it helps

regards

if the value

Read only

Former Member
0 Likes
713

Hi,

declare one variable type dats.

fetch single record in that from db table from which ur selecting in itab.

now code like this -

 data : d_date type dats.
                   select single (del_date) from table into d_date. ( use proper db table & field)
 loop at itab into wa.
  if wa-del_date = d_date.
  variable_date = d_date.
else.
      variable_date = constant.
    exit.
endif.

endloop.

regards

Edited by: Vishal Chavan on May 7, 2009 8:26 AM

Edited by: Vishal Chavan on May 7, 2009 8:47 AM

Read only

Former Member
0 Likes
713

Hi Krishna,

take a temp variable temp_date and initialize with the first record of internal table.

temp_date = itab-date.

loop at itab.

if itab-date = temp_date.

flag = 1.

else

flag = 0.

exit.

endif.

endloop.

if flag = 1.

variable = temp_date.

else

variable = constant.

endif.

Hope this wil lbe helpful

Regards

Karan Arya

Read only

Former Member
0 Likes
713

data : date1 type sy-datum,

date2 type sy-datum,

date3 type sy-datum.

data wa like line of itab.

read table itab into wa index 1.

date1 = wa-date. " ur delivery date field.

read table itab into wa index 2.

date2 = wa-date. " ur delivery date field.

read table itab into wa index 3.

date3 = wa-date. " ur delivery date field.

if date1 eq date2 and date2 eq date3.

date = date1.

else.

loop at itab.

wa-date = constant.

modify itab with wa.

endloop.

endif.

Read only

Former Member
0 Likes
713
Sort Itab BY <Delivery Date>.
Data: W_date type sy-datum.
Loop at Itab.
If sy-tabix Ge 1 and W_date = itab-deliverydate.
Pass variable.
ELSEIF sy-tabix Ge 1 and W_date NE itab-deliverydate.
Constant.
ENDIF.
w_date = itab-deliverydate.
ENDLOOP.

If W_date = itab-deliverydate.                " Last loop pass third record
Pass variable.
ELSEIF sy-tabix Ge 1 and W_date NE itab-deliverydate.
Constant.
ENDIF.

Regards,

Gurpreet

Read only

Former Member
0 Likes
714

Hi,

U can use this logic,

Delete adjacent duplicates on the internal table Itab comparing only date field.

and use

Describe table to find no.of records in the table...

If those three record dates are same, then u'll get only one record.

If those three record dates are not same, then u'll get more then one record.

If no.of record is one, then move that date to variable else pass constant to variable.

I think this should work for ur requirement.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
713

Hi,

describe table itab lines ln.

read table itab into wa index 1.

if sy-subrc eq 0.

lv_date = wa-date1.

endif.

cnt = 0.

loop at itab into wa where date1 eq lv_date.

cnt = cnt + 1.

endloop.

if ln = cnt.

lv_var = lv_date.

else.

lv_var = lc_date.

endif.

Read only

Former Member
0 Likes
713

Loop at itab into wa_itab.

at new commom field in that itab.

w_date = wa_itab-delivery_date.

endat.

if w_date = wa_itab-delivery_date.

w_date1 = wa_itab-delivery_date.

else.

add 1 to counter.

endif.

clear wa_itab.

modify itab.

endloop.

clear : w_date.

if not counter is intial.

w_date1 = constant.

endif.

modify itab.