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: 

compare 2 date fields

Former Member
0 Kudos

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

former_member125931
Active Participant
0 Kudos

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

piyush_mathur
Active Participant
0 Kudos

Hi,

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

Thanks

Piyush

0 Kudos

Hi piyush ,

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

Plz help me..

former_member125931
Active Participant
0 Kudos

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.

0 Kudos

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.

0 Kudos

hi sree,

Did u got any solution for it.

Plz help me...

0 Kudos

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

0 Kudos

Hi,

ITAB-NET_DUE-DT < = ITAB-AUGDT.

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

0 Kudos

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.

0 Kudos

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

0 Kudos

hi

anil..

its date like '20040111'.

both date are in same formate.

Plz help me...

0 Kudos

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

Give one example.

0 Kudos

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.

0 Kudos

then u can write

write loop it into wa...endloop.

inside loop -


endloop

wa1_date6(2) > wa2_date6(2).

then u can compare dates.

0 Kudos

HI Ankita,

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

0 Kudos

> 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.