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

problem date format

mrahhaoui
Participant
0 Likes
908

Hi Guru's

I have a problem with a field coming from a file upload in my internal table wich should be insert in a system table in date format.

When i do my test to check if the field has a correct date format I always receive the error: "Valid_to_date is invalid".

the field in my csv file has this format 02.03.2009.

I've written this code :

TYPES: BEGIN OF t_segm2,
   kokrs    TYPE kokrs,
    prctr   TYPE prctr,
    datbi   TYPE datbi,
    datab   TYPE datab,
END OF t_segm2.

DATA: 
          wa_cepc_segm TYPE t_segm2,
           i_cepc_segm TYPE STANDARD TABLE OF t_segm2,
          it_datatab TYPE STANDARD TABLE OF string,
          wa_datatab TYPE string,

LOOP AT it_datatab INTO wa_datatab.
    SPLIT wa_datatab at ';' into
                          wa_cepc_segm-kokrs
                          wa_cepc_segm-prctr
                          wa_cepc_segm-datbi
                          wa_cepc_segm-datab.

    CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
      EXPORTING
        date                      = wa_cepc_segm-datbi
      EXCEPTIONS
        plausibility_check_failed = 1
        OTHERS                    = 2.
    IF sy-subrc <> 0.
      WRITE:/ 'Valid To Date invalid'.
    ENDIF.
    append wa_cepc_segm to i_cepc_segm.
    CLEAR wa_cepc_segm.
  endloop.

Anyone can help me please?

Regards,

Mohamed.

8 REPLIES 8
Read only

Former Member
0 Likes
877

Probably the date in the file is in an external format like 07.05.2009, remeber the internal format is yyyymmdd

Read only

0 Likes
877

so what can I do for that

Read only

0 Likes
877

Hi,

First use FM CONVERSION_EXIT_IDATE_INPUT to convert date to internal format Eg: input = 01.02.2008 and Output = 20080201.

Next use DATE_CHECK_PLAUSIBILITY providing this converted date. It will work then.

Regards

Marcin

Read only

0 Likes
877

Hi Marcin,

When I save the external date in my internal table the data that I have in this internal table when in the debbuger is "30.02.20" it trunqued the last 2 digits of the year. the test is wrong and it is normal that I receive the error message.

I think it is because of the declaration of my date in the structure :

>datbi TYPE datbi,

datbi is on 8 char but the date field is on 10 because there are '.'.

Is there a solution for this?

Regards,

Mohamed.

Edited by: rahhaoui mohamed on May 7, 2009 11:56 PM

Read only

0 Likes
877

split the dates fields to temporal variables of the desired lenght (in your case 10) then create a routine or use the standard function modules to assign them to the date fields in wa_cepc.

Very easy

Read only

0 Likes
877

Yes they are at least 2 solutions:

1) provide date from file directly following internal date format used in SAP which is YYYYMMDD i.e 01.02.2009 should be 20090201

2) in internal table type this field not as D but as C(10). Then importing this column will result in 01.02.2009, but later you have to manually convert this value using FMs mentioned before, Then i.e you can store the result in separate column which is of type D and use this column for further calculation.

Regards

Marcin

Read only

0 Likes
877

I declared 2 variables :

DATA : fDate1(10),
       fDate2(10).

And I concatenate the date

LOOP AT it_datatab INTO wa_datatab.
    SPLIT wa_datatab at ';' into
                          wa_cepc_segm-kokrs
                          wa_cepc_segm-prctr
                          fDate1
                          fDate2.

concatenate fdate1+6(4) fdate1+3(2) fdate1(2) into wa_cepc_segm-datbi.
concatenate fdate2+6(4) fdate2+3(2) fdate2(2) into wa_cepc_segm-datab.

And after I call my function module but still the same error : 'Valid To Date invalid'

CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
      EXPORTING
        date                      = wa_cepc_segm-datbi
      EXCEPTIONS
        plausibility_check_failed = 1
        OTHERS                    = 2.
    IF sy-subrc <> 0.
      WRITE:/ 'Valid To Date invalid'.
    ENDIF.


    append wa_cepc_segm to i_cepc_segm.
    CLEAR wa_cepc_segm.
  endloop.

Read only

0 Likes
877

Everything seems fine with the code. I tried it myself and I got strange behaviour.

I used this code:


data: datbi TYPE datbi.

fdate1 = '02.03.2009'.

concatenate fdate1+6(4) fdate1+3(2) fdate1(2) into datbi.

CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
      EXPORTING
        date                      = datbi
      EXCEPTIONS
        plausibility_check_failed = 1
        OTHERS                    = 2.
    if sy-subrc ne 0.
      write 'Wrong date'.
"    else.
"      write 'Date ok'.
    endif.

When I leave ELSE block commented, the FM returns sy-subrc = 0 and doesn't display 'Wrong date' message. So this works as we want. But when I debug it, I can clearly see that processing goes inside IF block and tries to write the message out (even thought the condition is not fullfilled). But anyhow the message doens't appear on the screen. Strange.

Now when I uncomment the ELSE block, the processing seems to work fine. Don't know why it is happening but if we leave entire IF,ELSE it works fine. So try this solution. Everything else works fine.

Regards

Marcin

Right now I tried to see if this IF block really changes some data object using:


data var type i.

call fm....
if sy-subrc ne 0.
   var = 1.
endif.

write var.

And I could see that, thought processing is passed inside the block it doesn't change VAR contents. So it stays 0. But just right after it I run the program again to show it to my collegue and the processsing didn't go inside anymore. It must be something with debugger then. My collegue says once he spent some time investigating the same problem and finally he gave up. What the debugger was showing was different from what it was in fact calculating. Fortunatelly the calculation here doesn't change, just debugger is trying to cheat us showing what he is really NOT doing;)

Edited by: Marcin Pciak on May 8, 2009 9:31 AM