Skip to Content

How to upload of date format 12/31/9999 to the table of type SY-DATUM (8 Characters)

Hi    when  I modiy standard table...pa001 or pa0002 usually I will sent data as yyyymmdd using HR_INFOTYPE_OPERATION.

I have created a custom table ..of which date field will be of type sy-datum. ( 8 characters only)

when I pass the value yyyymmdd how is it possible to convert to MM/DD/YYYY( 10 Characters size). Please throw some light.

Regards

sas

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Aug 01, 2013 at 09:39 AM

    Hello,

    Dates in SAP are stored as YYYYMMDD. When you want to display the date, say, in a report you can do the following:

    data: v_date type d.write v_date mm/dd/yyyy.

    The conversion is done on-the-fly.

    Dates will display in readable format in SE16 thanks to built-in conversion routines.

    If you want to copy the date to another variable and format it differently:

    data: v_date type d,          v_text(20) type c.write: v_date mm/dd/yyyy to v_text.      "check other formats in help for write command

    Obviously, the date should always be stored in DATS format (YYYYMMDD) or else it isn't  a date anymore! (and you work harder to convert and display it).

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 01, 2013 at 08:29 AM

    Hi,

    Means you pass the data as sy-datum and it should be stored in field as MM/DD/YYYY

    You can write custom conversion routine for the same.

    Create a Function Group ZDATE and create 2 FMs

    CONVERSION_EXIT_ZDATE_INPUT

    CONVERSION_EXIT_ZDATE_OUTPUT

    See standard conversion for more details

    Create a domain of 10 character length and assign the ZDATE routine to it

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 01, 2013 at 08:43 AM

    Hi saslove,

    To convert date from yyyymmdd to mm/dd/yyyy:-

    data: mydate(10).

    mydate = '20130101'.

    replace first occurrence of regex '(\d{4}) (\d{2}) (\d{2}) in mydate with '$3/$2/$1'.

    write :/ 'Converted date is ' ,mydate.

    Output:-

    01/01/2013.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi saslove,

      Just use the Conversion Routine. Its enough for your Requirement.

      just try this converstion routione.

      CONVERSION_EXIT_ZDATE_INPUT

      So if you pass the date in sy-datum format it will stored in mm/dd/yyyy format..

      It will work..

      Regards

      Raju

  • avatar image
    Former Member
    Aug 01, 2013 at 09:52 AM

    Hi

    Try like this

    data: gd_date(10),
           date(8).

       date = sy-datum.
       write sy-datum to gd_date USING EDIT MASK '__/__/_____'.


    write : / date.
    write : / gd_date.



    Add comment
    10|10000 characters needed characters exceeded

    • please see my requirement for god sake...

      I wana fit date format of requested in MM/DD/YYYY Format.

      rn1datum-datex is of 10 characters.. which is automated..

      Go to PA0001 OR PA0002 or where ever HR tables and see PN-BEGDA PN-ENDDA...

      and see its just 8 characters but it can accomdate mm/dd/yyyy format automatically ..request to let me know can we achieve this in Custom table...

      Regards

      Sas

  • Aug 01, 2013 at 10:34 AM

    Thanks folks...Ok might be I am not clear here see below ex..

    ztable has 2 fields :

    zPernr, zdate.

    This ZDATE should b3 of sy-datum (request from client side so that we can validate GearterEqual OR LE ).

    how to update ZDATE IN TABLE so that it will display as mm/yy/dddd in the table is my question... is it possible or not ? if yes please let me know..I taken example of pa0001 because although sy-datum is 8 characters it u displays as mm/dd/yyyy

    Regards

    Sas

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      For god sake, do a little research about domains and conversion exits.

      Internally, if you define a field of type datum, all values are stored in format yyyymmdd. This has been designed in that way, because date formatting change accordingly many locale settings around the world.

      if you are working with infotypes, for example, the dates stored in fields begda and endda are in yyyymmdd format internally ALWAYS!!!

      if your requirement is to DISPLAY the stored date in an specific format, as you needed, create a new domain for a new data element, with data type dats. Use the conversion rutine PDATE.

      With PDATE, when the info is been displayed to the end user, the domain will use the FM

      • CONVERSION_EXIT_PDATE_INPUT    Conversion Exit for Domain GBDAT: DD/MM/YYYY -> YYYYMMDD
      • CONVERSION_EXIT_PDATE_OUTPUT   Conversion Exit for Domain GBDAT: YYYYMMDD -> DD/MM/YYYY

      To display the correct  format.

      Please refer to the link for further info

      http://help.sap.com/saphelp_40b/helpdata/en/cf/21ee19446011d189700000e8322d00/content.htm

      Regards.

  • avatar image
    Former Member
    Aug 02, 2013 at 04:39 AM

    Hi ,

    what Archana is saying is right....

    Here is your solution:

    1)Create domain as ZDATS with

    Data type:dats

    No of chars: 08                                                

    Output length : 10

    Conver routine ZDATS.         

    (befoer activating ths domain you should create conversion routine as shown in point no )

    2) Create data element ZZDATE with

    domain type : ZDATS.

    3)Now, first create FG as ZDATE.

    4)Now create FM for conversion routine

    a) CONVERSION_EXIT_ZDATS_INPUT.

    Import : Input

    Export :Output

    Source code:

    DATA: number TYPE c LENGTH 10.

    number = input.

    replace all OCCURRENCES OF REGEX '[^\d]' in number WITH ''.

    output = number.

    (Save and activate)

    b) CONVERSION_EXIT_ZDATS_OUTPUT.

    Import : Input

    Export :Output

    Source code:

    data: mydate(10).

    mydate = input.

    replace first occurrence of regex '(\d{4})(\d{2})(\d{2})' in mydate with '$3/$2/$1'.

    output = mydate.

    Now, use the create data element in your table you will see the result.

    Reward if useful.

    Regards,

    Abdul


    Add comment
    10|10000 characters needed characters exceeded

  • Aug 02, 2013 at 05:38 AM

    check

    BAPI to change the date formate and FN module to separate the string

     

    1) to change the date formate


    data : date like sy-datum,
    data1(10) type c.
    call function 'CONVERT_DATE_TO_INTERNAL'
    exporting
    date_external = date1
    importing
    date_internal = date
    exceptions
    date_external_is_invalid = 1
    others = 2.


    http://anu-sapdiary.blogspot.com.au/2008/03/function-modules-for-date-conversion.html


    2) to divide the string into 2.

        CALL FUNCTION 'HR_HK_STRING_INTO_2_LINES'
         EXPORTING
           source_str      = ldf_pay_terms
           len_of_1st_line = lcf_thirty
           len_of_2nd_line = lcf_thirty
         IMPORTING
           1st_line_str    = ldf_pay_terms1
           2nd_line_str    = ldf_pay_terms2
         EXCEPTIONS
           error           = 1
           OTHERS          = 2.

       CONDENSE: ldf_pay_terms1,
                 ldf_pay_terms2.
       ldf_length = STRLEN( ldf_pay_terms1 ).
       ldf_length1 = STRLEN( ldf_pay_terms2 ).

    Add comment
    10|10000 characters needed characters exceeded