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

compare 2 date fields

Former Member
0 Likes
1,709

hi all,

I want to compare 2 date fields in from internal table using loop how is this possible . I tried lot.

Plz help me.

1 ACCEPTED SOLUTION
Read only

former_member125931
Active Participant
0 Likes
1,665

suppose u have two internal tables ITAB1,ITAB2 and work areas WA!,WA2 respectively,suppose MATNR is the field u want to compare for ur condition.

if WA1-MATNR = WA2-MATNR .

write:/sy-subrc.

endif.

If you send your coding we will give u the exact solution.

15 REPLIES 15
Read only

piyush_mathur
Active Participant
0 Likes
1,665

Hi,

If both are date fields then u can compare using relational operation.

Thanks

Piyush

Read only

0 Likes
1,665

Hi piyush ,

If i m using '> ' condition then it gives wrong answer.

Plz help me..

Read only

former_member125931
Active Participant
0 Likes
1,666

suppose u have two internal tables ITAB1,ITAB2 and work areas WA!,WA2 respectively,suppose MATNR is the field u want to compare for ur condition.

if WA1-MATNR = WA2-MATNR .

write:/sy-subrc.

endif.

If you send your coding we will give u the exact solution.

Read only

0 Likes
1,665

SELECT BELNR BUDAT GJAHR BLDAT

INTO (ITAB-BELNR,ITAB-BUDAT,ITAB-GJAHR,ITAB-BLDAT)

FROM BKPF

WHERE BLDAT <= BUDAT

AND BUKRS = 'ABCB'

AND BLART = 'RV'.

SELECT KUNNR SHKZG WRBTR ZFBDT BSCHL VBELN AUGBL ZBD1T ZTERM AUGDT

BELNR

INTO (ITAB-KUNNR,ITAB-SHKZG,ITAB-WRBTR,ITAB-ZFBDT,ITAB-BSCHL,

ITAB-VBELN,ITAB-AUGBL,ITAB-ZBD1T,ITAB-ZTERM,ITAB-AUGDT,ITAB-BELNR1)

FROM BSEG

WHERE BELNR = ITAB-BELNR

AND BUKRS = 'ABCB'

AND KUNNR IN KUNNR

AND KOART = 'D'

AND GJAHR = ITAB-GJAHR.

APPEND ITAB.

ENDSELECT.

ENDSELECT.

LOOP AT ITAB.

ITAB-NET_DUE_DT = ITAB-ZBD1T + ITAB-ZFBDT.

MODIFY ITAB.

ENDLOOP.

in this coding i want to compare

ITAB-NET_DUE-DT < = ITAB-AUGDT.

PLZ. HELP ME.

Read only

0 Likes
1,665

hi sree,

Did u got any solution for it.

Plz help me...

Read only

0 Likes
1,665

Please let us know in what dates your conditions are failing.

Below code is working fine for me.

DAT1 = '20071231'.

DAT2 = '20070131'.

IF DAT1 <= DAT2.

BREAK-POINT.

ENDIF.

Piyush

Read only

0 Likes
1,665

Hi,

ITAB-NET_DUE-DT < = ITAB-AUGDT.

First check Is your ITAB having working OR not,otherwise declare work area explicitely.

Read only

0 Likes
1,665

what do u want to check?

if u want to compare dates?

wa_date1(2) > wa_date2(2).

date1 = 28102002

this will compare the first two numbers of ur work area..i.e first two numbers are 28..28 is the date.

Read only

0 Likes
1,665

I think it is ITAB-NET_DUE_DT < = ITAB-AUGDT not ITAB-NET_DUE-DT < = ITAB-AUGDT.

Read only

0 Likes
1,665

hi

anil..

its date like '20040111'.

both date are in same formate.

Plz help me...

Read only

0 Likes
1,665

What are the dates, in which ur condition is fails.

Give one example.

Read only

0 Likes
1,665

hi..

if i m using such condition then

1 date compares with another dates of second column.

i want to compare 1 date with only 1 date of another column.

Read only

0 Likes
1,665

then u can write

write loop it into wa...endloop.

inside loop -


endloop

wa1_date6(2) > wa2_date6(2).

then u can compare dates.

Read only

0 Likes
1,665

HI Ankita,

Did u solved u problem otherwise give me ur total code I'll try to help u

Read only

0 Likes
1,665

> SELECT BELNR BUDAT GJAHR BLDAT

> INTO (ITAB-BELNR,ITAB-BUDAT,ITAB-GJAHR,ITAB-BLDAT)

> FROM BKPF

> WHERE BLDAT <= ITAB-BUDAT

> AND BUKRS = 'ABCB'

> AND BLART = 'RV'.

>

Use ITAB-BUDAT in where condittion, as shown above.