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

get only date rows from table

Former Member
0 Likes
1,360

Hi Genius,

I have an issue in filter the internal table entries .The entries is like this

Matnr    Value(20)

100  

Test1
200test2
3005
40020.05.2012
50026.06.2012
60023.65

Now in this internal table i have to get only date values rows .How can I achieve this .

Thanks in Advance

Regards

13 REPLIES 13
Read only

ThomasZloch
Active Contributor
0 Likes
1,326

I assume you want only valid dates? Are they always coming in the quoted external format?

While looping, you could try converting the value into an internal date field and e.g. subtracting 1 from it. If the result is not all zeroes, you are looking at a valid date.


Thomas

Read only

0 Likes
1,326

While looping ,checking values with FM 'CONVERT_DATE_TO_INTERNAL'.If the  Export parameters is not initial than it is date format.

Thanks,

Sivaji.

Read only

0 Likes
1,326

Hi Thomas,

How I can I convert the value into an internal date field.Any suggestions.

Regards

Shek

Read only

Former Member
0 Likes
1,326

Hi

Use the below code to filter only date value in the table.

assume that you have all those entries in ITAB.

data : n type i.

LOOP AT ITAB into WA_itab.

n = STRLEN (WA_ITAB-VALUE).

if n < 10 or

  n > 10.

delete table itab from wa_itab.

endif.

endloop.

Read only

0 Likes
1,326

Hi ,

If i have 10 digit numbers is not working.Thanks for ur response.

Shek

Read only

Former Member
0 Likes
1,326

Hi,

You could use FIND REGEX to validate if row contains a date value.

e.g.

DATA lv_pattern TYPE string.
lv_pattern = '(\d{1,2}[.|/]\d{1,2}[.|/]\d{4})|(\d{4}[.|/]\d{1,2}[.|/]\d{1,2})'.


loop at itab into wa_tab.

FIND REGEX lv_pattern IN wa_tab-value.
   IF sy-subrc NE 0.
     delete itab index sy-tabix.
   ENDIF.

endloop.

Regards,

Jake

Read only

0 Likes
1,326

Hi Jake ,

It works . Will u pls expalin clearly .

Shek

Read only

0 Likes
1,326

Hi Jake,

The regex accepts 32.05.2012 as a valid date ...Nice work anyways.

Kesav

Read only

0 Likes
1,326

As per your requirement, you need to validate a certain field if it contains a DATE value. So, what I did is that I used FIND REGEX. You can refer to this for your reference on how to use REGEX.

Syntax of Regular Expressions

Jake

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,326

You can try something like below:

types:begin of ty,

       matnr type matnr,

       value type char20,

       end of ty.

data:it type table of ty,

      wa type ty,

      l_datum type sy-datum.

wa-matnr = 100.wa-value = 'test1'.append wa to it.

wa-matnr = 100.wa-value = 'test2'.append wa to it.

wa-matnr = 100.wa-value = '20.05.2012'.append wa to it.

wa-matnr = 100.wa-value = '26.06.2012'.append wa to it.

loop at it into wa.

   if wa-value cp '**.**.****'.

     if wa-value+0(2) ca '1234567890' and

       wa-value+4(2) ca '1234567890' and

        wa-value+6(4) ca '1234567890'.

       CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

         EXPORTING

           DATE_EXTERNAL            = wa-value

         IMPORTING

           DATE_INTERNAL            = l_datum

         EXCEPTIONS

           DATE_EXTERNAL_IS_INVALID = 1

           OTHERS                   = 2.

       IF SY-SUBRC <> 0.

         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

       ENDIF.

       CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'

         EXPORTING

           DATE                      = l_datum

         EXCEPTIONS

           PLAUSIBILITY_CHECK_FAILED = 1

           OTHERS                    = 2.

       IF SY-SUBRC <> 0.

         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

       ENDIF.

     endif.

   endif.

endloop.

Read only

former_member186055
Active Participant
0 Likes
1,326

Hi Shek,

By using Comparing Strings you can identify the required patter of your field value.

Code posted by Kesavadas will works for your requirement.

Regards,

SuryaPraveen

Read only

Former Member
0 Likes
1,326

Hi,

Use the below code.

TYPES: BEGIN OF ty_test,

       m1 TYPE char5,

       m2 TYPE char20,

       END OF ty_test.

TYPES: BEGIN OF ty_res,

       m1 TYPE char5,

       m2 TYPE datum,

       END OF ty_res.

DATA: gt_test TYPE TABLE OF ty_test,

      wa_test TYPE ty_test,

      gt_res TYPE TABLE OF ty_test,

      wa_res TYPE ty_test.

START-OF-SELECTION.

  CLEAR wa_test.

  wa_test-m1 = '100'.

  wa_test-m2 = 'Test1'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '200'.

  wa_test-m2 = 'test2'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '300'.

  wa_test-m2 = '5'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '400'.

  wa_test-m2 = 'abcdefghij'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '500'.

  wa_test-m2 = '20.12.2010'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '600'.

  wa_test-m2 = '11.07.2012'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '700'.

  wa_test-m2 = '2345.65.44'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '800'.

  wa_test-m2 = '1234567890'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '900'.

  wa_test-m2 = '12.4 .6890'.

  APPEND wa_test TO gt_test.

  CLEAR wa_test.

  wa_test-m1 = '000'.

  wa_test-m2 = '12.01.6890'.

  APPEND wa_test TO gt_test.

  LOOP AT gt_test INTO wa_test.

    CONDENSE wa_test-m2.

    CHECK ( wa_test-m2(1) CA '0123' AND

            wa_test-m2+1(1) CA '0123456789' AND

            wa_test-m2+2(1) CA '.' AND

            wa_test-m2+3(1) CA '01' AND

            wa_test-m2+4(1) CA '0123456789' AND

            wa_test-m2+5(1) CA '.' AND

            wa_test-m2+6(1) CA '0123456789' AND

            wa_test-m2+7(1) CA '0123456789' AND

            wa_test-m2+8(1) CA '0123456789' AND

            wa_test-m2+9(1) CA '0123456789'  ).

    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

      EXPORTING

        date_external            = wa_test-m2

      EXCEPTIONS

        date_external_is_invalid = 1

        OTHERS                   = 2.

    CHECK sy-subrc = 0.

    CLEAR wa_res.

    MOVE-CORRESPONDING wa_test TO wa_res.

    APPEND wa_res TO gt_res.

  ENDLOOP.

  LOOP AT gt_res INTO wa_res.

    WRITE:/ wa_res.

  ENDLOOP.

Hope this is helpful.

Regards,

Manjesh.

Read only

NAeda
Contributor
0 Likes
1,326

Use FM  CONVERT_DATE_TO_INTERNAL

and pass the Value(20.05.2012) if sy-subrc = 0 then its a valid record other wise invalid record.