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: 

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

former_member184119
Active Contributor
0 Kudos

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

17 REPLIES 17

Former Member
0 Kudos

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

0 Kudos

But my client is insisting to keep as sy-datum, so they can validate accordingly for future purposes...

Regards

Satish.v

Former Member
0 Kudos

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.

0 Kudos

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

Phillip_Morgan
Contributor
0 Kudos

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

former_member209120
Active Contributor
0 Kudos

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.


0 Kudos

Hi,

Use the Function module   FORMAT_DATE_4_OUTPUT

data :  w_date TYPE rn1datum-datex.

   CALL FUNCTION 'FORMAT_DATE_4_OUTPUT'
       EXPORTING
         datin  = sy-datum
         format = 'MM/DD/YYYY'
       IMPORTING
         datex  = w_date.

     write w_date1.

Input    : 20130801

Output : 08/01/2013

Regards,

Archana

0 Kudos

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

former_member184119
Active Contributor
0 Kudos

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

0 Kudos

Hi Sas,

It is possible. PA0001 displays the date based on the format maintained in user profile.

In your ztable you can create a zdataelement whose domain has data type DATS, No of characters 8 and output length as 10. The other option is to use the standard dataelement DATUM instead of creating a Z dataement.Assign this data element to your date field in the ztable. This will display the date in the format maintained in user profile when you display the table.

If you want the date format to be MM/DD/YYYY irrespective of the user profile date format, you need to create a Zdomain for your dataelement and assign an input and output conversion routine.

Regards,

Archana

0 Kudos

where to asign input output conversion routine??

Regards

Sas

0 Kudos

Hi Sas,

You need to provide conversion routine in output characteristics in the definition tab of domain.

Regards,

Monami

0 Kudos

I'm struggling to get to the specific problem you've got here, but as I see it the first two paragraphs of

Archana's reply is everything you need.

Look at the standard date fields (SY-DATUM, PA0001-BEGDA etc.) the domains for those don't use a conversion exit, when the date is output the conversion is performed as a consequence of the data type.

In your Z table use Data element SYDATS (if you don't mind the generic description) or create your own data element based on domain SYDATS.  It will work.

Regards,

Nick

0 Kudos

Hi,

Conversion routines are assigned in the domain. You have to create a Zdomain and assign the conversion routines created by you.

You can create conversion routine function modules in se37 using the below format

CONVERSION_EXIT_xxxxx_INPUT

CONVERSION_EXIT_xxxxx_OUTPUT

XXXXX specifies the name of the conversion routine and should be of length 5 chars. After creating the function module, assign the conversion routine XXXXX in the Zdomain

0 Kudos

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.

Former Member
0 Kudos

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


former_member182915
Active Contributor
0 Kudos

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