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: 

function module

Former Member
0 Kudos

GUY's

i have created one z function module that will convert

date in formt dd.mm.yyyy (where mm is string like

JAN,FEB,MAR...) ,if customer input date as 06.may.2006,

he must get input as 06.05.2006 , this was working fine

,but there are scenario where we can get date in format

6.may.2006 or 6.may.06 ,program is written in such a way

that it will break data where it encounter (.) and then

convert it as requried and concatenate it back and give

the output,so what i required is wethere customer give

06 or 6 it should take as 06 ,beside this ,if customer

put 06 as 60 ,it should not accept ,same applied for year

also

1 ACCEPTED SOLUTION

Former Member
0 Kudos

After you derive the date using your function use the function DATE_CHECK_PLAUSIBILITY to check if the derived date is valid.

-Kiran

10 REPLIES 10

Former Member
0 Kudos

After you derive the date using your function use the function DATE_CHECK_PLAUSIBILITY to check if the derived date is valid.

-Kiran

Former Member
0 Kudos

Sanju,

In the function before formating, you can check with USR01 table.

USR01-DCPFM will gives format for numbers and USR01-DATFM will give Date format of the user. Based on that you can format the date accordingly.

Cheers,

Thomas.

andreas_mann3
Active Contributor
0 Kudos

hi,

so use abap command unpack or fm LINEITEM_ALPHAFORMAT

or external perform alphaformat(sapfs000)

Message was edited by: Andreas Mann

Former Member
0 Kudos

hi Sanju,

Convert date ie 6 to 06 by using the Packed statement. convert year also to four digits lenth.. then pass it to the Function Module..

Regards

Ashok P

0 Kudos

Once you have the date in the format of 5.28.06, you can use this function module to finish the formatting.



report zrich_0001.

data: date(20) type c value '28.5.06'.

data: in_datum type sy-datum.


call function 'CONVERT_DATE_TO_INTERNAL'
     exporting
          date_external            = date
     importing
          date_internal            = in_datum
     exceptions
          date_external_is_invalid = 1
          others                   = 2.


          write:/ in_datum.

Output is 28.05.2006

Regards,

Rich Heilman

PS.

Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.

Spread the wor(l)d!

Former Member
0 Kudos

Hi,

For the 6 to 06 issue, you could move the 6 to a 2-byte type N field to add the leading zero when only 1 digit is entered. To validate the day entry, you could add a check to see if the number entered for day is greater than 31 (or you could check how many days are in a particular month and use that as your max number in the check). To validate the year, I guess you'll have to decide what is a reasonable maximum year (e.g. is 60 converted to 2060 too big for your application?).

Regards,

James G.

Former Member
0 Kudos

Hi,



<b>form form1_convert_yyyymmdd</b>
                            using xv_date_full type char30
                         changing xyv_date type char10.


  data : lv_temp_data type char30,
         lv_dd        type char2,
         lv_mm        type char2,
         lv_yyyy      type char4,
         lv_mmm       type char3.

  lv_temp_data = xv_time_stamp.
  condense lv_temp_data  no-gaps.


     split lv_temp_data at '.' into  lv_dd  lv_mmm  lv_yyyy.

<b>      perform convert_mmm_to_mm changing lv_mmm
                                         lv_mm.</b>


      CONVERSION_EXIT_ALPHA_INPUT
       IMPORTING
             INPUT  = lv_dd
       EXPORTING
             OUTPUT = lv_dd.           

      concatenate lv_dd '.' lv_mm '.' lv_yyyy
             into xyv_date.


<b>endform.                    " form1_convert_yyyymmdd</b>


<b>form convert_mmm_to_mm  changing xv_mmm type char3
                                 yv_mm  type char2.</b>

  translate xv_mmm to upper case.

  case xv_mmm.

    when 'JAN'.
      yv_mm = '01'.

    when 'FEB'.
      yv_mm = '02'.

    when 'MAR'.
      yv_mm = '03'.

    when 'APR'.
      yv_mm = '04'.

    when 'MAY'.
      yv_mm = '05'.

    when 'JUN'.
      yv_mm = '06'.

    when 'JUL'.
      yv_mm = '07'.

    when 'AUG'.
      yv_mm = '08'.

    when 'SEP'.
      yv_mm = '09'.

    when 'OCT'.
      yv_mm = '10'.

    when 'NOV'.
      yv_mm = '11'.

    when 'DEC'.
      yv_mm = '12'.
  endcase.



Former Member
0 Kudos

I'm not sure what your question is but I think you are asking how to split the input string at the (.) into the different segments of the date and reformat them

Here is a little test program that shows the split command

&----


*& Report ZTEST

*&

&----


*&

*&

&----


REPORT ztest.

DATA: day(2) TYPE c,

month(3) TYPE c,

year(4) TYPE c,

date_out(10) TYPE c.

PARAMETERS: date_in(20) TYPE c DEFAULT '10.JAN.2006'.

START-OF-SELECTION.

SPLIT date_in AT '.' INTO day month year.

IF month CO 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

  • Do your month conversion from sring to number here

CASE month.

WHEN 'JAN'.

CLEAR month.

month = '01'.

WHEN 'FEB'.

CLEAR month.

month = '02'.

WHEN 'MAR'.

CLEAR month.

month = '03'.

  • Etc, Etc, Etc,

ENDCASE.

ENDIF.

  • Convert to new format

CONCATENATE month '/' day '/' year INTO date_out.

WRITE: / date_out.

Hope this helps.

Brent

former_member188685
Active Contributor
0 Kudos

Hi,

you can try with the FM <b>CONVERSION_EXIT_SDATE_INPUT</b>

 Import parameters               Value           
                                                 
 INPUT                           01.JAN.1994                                                                                
Export parameters               Value           
                                                 
 OUTPUT                          19940101

REPORT  ZZTEST       .
data: text(20), date type sy-datum.
text = '1.JAN.1994'.
CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'
  EXPORTING
    INPUT         = text
 IMPORTING
   OUTPUT        = date
          .
write date. 

Regards

vijay

Former Member
0 Kudos

Hi Sanju,

This program takes care of:

1)Improper years : 1.Jul.60 (Throws error)

2)Improper date : Greater then 31, less then 1.

3)User can put date in formats like.

         19.JUL.06
         19.JUL.2006
         19.Jul.06
         19.jul.2006

Consider the program.


REPORT zztest
NO STANDARD PAGE HEADING
LINE-COUNT 36(3)
LINE-SIZE 250.

PARAMETERS : date(11) DEFAULT  '19.Jul.06'.

DATA : day(2) ,
       month(3),
       year(4),
       final(9) ,
       out TYPE sy-datum.

SPLIT date AT '.' INTO day month year.

IF day LT 1 AND day GT 31.
  MESSAGE 'Enter valid date' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.

IF STRLEN( year ) EQ 2.
  year+2(2)  = year+0(2).
  year+0(2) =  sy-datum+0(2).

ENDIF.


IF year+2(2) NE sy-datum+2(2).
  MESSAGE 'Enter valid year' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.

IF STRLEN( year ) EQ 2.

  year+2(2) = sy-datum+0(2).

ENDIF.


CONCATENATE day month year INTO final.

TRANSLATE final TO UPPER CASE.

CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'
  EXPORTING
    input  = final
  IMPORTING
    output = out.


WRITE : / 'Entered   date :' , date,
        / 'Processed date :' , out  USING EDIT MASK '__:__:____'.

Regards,

Arun S.