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 validate when date format is diff Internally and externally

Former Member
0 Kudos

Hello,

How can I validate the Date format if Internal format and external format is different.

Ex : 

 *  SELECT SINGLE CRTSP
**                FROM /SAPSLL/PR
**                INTO L_CRTSP
**                WHERE CRTSP IN S_CRTSP .
*

CRTSP (YYYY/DD/MM HHMMSEC) Internal Format 

S_CRTSP (YYYY/DD/MM) External format - selection option

I had done following to convert the internal format to external format. 

DATA : LV_DT TYPE STRING.

DATA :  L_CRTSP TYPE /SAPSLL/CRTSP.

SELECT SINGLE CRTSP
                FROM /SAPSLL/PR
                INTO L_CRTSP.

MOVE : L_CRTSP TO LV_DT. "(YYYY/DD/MM HHMMSEC)

 L_LEN = STRLEN( LV_DT ).
 L_DATE = LV_DT+0(8).

I have the date format that i need in L_DATE."  (YYYY/DD/MM)

Now how should I validate? 


*  SELECT SINGLE CRTSP
**                FROM /SAPSLL/PR
**                INTO L_CRTSP
**                WHERE CRTSP IN S_CRTSP .

Please let me know how can I validate or how can I write the select query to validate this field. 

There should be some way using Wildcard or some function module...which I am not sure...

Any suggestions will be appreciated!

Regards,

Kittu

Edited by: Kittu on Jan 6, 2009 12:58 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello,

This is actual select query for data selection.

SELECT GUID_PR   "Primary Key as GUID in "RAW" Format
         CRTSP     "PRODUCT CREATED ON
         CHTSP     "PRODUCT CHANGED ON
         FROM /SAPSLL/PR
         INTO TABLE T_PR
          FOR ALL ENTRIES IN T_PRGEN    
         WHERE GUID_PR EQ T_PRGEN-GUID_PR 
                AND CRTSP IN *S_CRTSP*     
              AND CHTSP IN S_CHTSP.


Now I had changed the date format and it is in v_dat variable. 

How should i select the data based on this criteria. 

I mean should I write this select query like this : 

SELECT GUID_PR   "Primary Key as GUID in "RAW" Format
         CRTSP     "PRODUCT CREATED ON
         CHTSP     "PRODUCT CHANGED ON
         FROM /SAPSLL/PR
         INTO TABLE T_PR
          FOR ALL ENTRIES IN T_PRGEN    
         WHERE GUID_PR EQ T_PRGEN-GUID_PR 
                AND CRTSP IN *v_dat*     
              AND CHTSP IN S_CHTSP.

If I am doing so then it is throwing an error message.

Please suggest....

Regards,

Kittu

21 REPLIES 21

Former Member
0 Kudos

Hi,

Use the function module FORMAT_DATE_4_OUTPUT

DATA : DATE TYPE CHAR10.

CALL FUNCTION 'FORMAT_DATE_4_OUTPUT'

EXPORTING

DATIN = '20081013'

FORMAT = 'DD.MM.YYYY'

IMPORTING

DATEX = DATE.

IF DATE IS INITIAL.

give error message

ELSE:

WRITE : / DATE.

ENDIF. .

it solves your problem

Thanks!!

Former Member
0 Kudos

Hi Kittu,

Take date in string ..split at '/' adn comare the range like

yyyy shd be betwwen 1900-2008

dd btw 1-31 and

mm btw 1-12.

regards

vivek

Former Member
0 Kudos

Hi,

Use this FM to convert internal format

CONVERT_DATE_TO_INTERNAL

Former Member
0 Kudos

Hi,

Use conversion exit for date in your required format.

Thanks

Sanket sethi

Former Member
0 Kudos

hi,

do like dis...

DATA: time_stamp TYPE timestamp,

dat TYPE d,

SELECT SINGLE CRTSP

FROM /SAPSLL/PR

INTO time_stamp .

CONVERT TIME STAMP time_stamp INTO DATE dat .

IF dat IN s_CRTSP. "filter

" do the append or watever...

endif.

Former Member
0 Kudos

Hello,

Thank you for your quick response!

I had already converted into desired format...

My issue is how can I write screen validation?

I have the desired fromat date in L_DATE.

I had converted (YYYY/DD/MM HHMMSEC) Internal Format to

external format (YYYY/DD/MM).

How can I write validation for it...

TT, you got it right...i need to validate this field just like any other screen validation.

So what do you suggest if the condition satisfies?

Any suggestions will be appreciated and can you please eloborate your sugesstions!

Regards,

Kittu

Edited by: Kittu on Jan 6, 2009 1:17 PM

0 Kudos

Hi Kittu,

as i said in my previous post ....


Take date in string ..split at '/' and compare the range like
yyyy shd be betwwen 1900-2008
dd btw 1-31 and
mm btw 1-12.

regards

vivek

0 Kudos

hi...can u tell me wat ur requirement is???

if u want the value of crstp field in ur program.

den

if dat IN s_crstp.

use value of field <timestamp > whereever u want

endif.

0 Kudos

Hi,

Convert screen input is same as internal format and then validate with internal field.

0 Kudos

Hi,

Convert screen input is same as internal format (Using FM wat I mentioned above) and then validate with internal field in AT SELECTION SCREEN.

Former Member
0 Kudos

Hi,

Would you want to try something like below...

CONCATENATE s_crtsp-low '%' INTO wa_crtsp.

SELECT SINGLE CRTSP

FROM /SAPSLL/PR

INTO L_CRTSP

WHERE CRTSP LIKE wa_crtsp .

But this would give you data for only a single date.

You could very well keep looping through for all dates from s_crtsp-low to s_crtsp-high.

Former Member
0 Kudos

Hi,

Convert screen input is same as internal format (Using FM wat I mentioned above) and then validate with internal field in AT SELECTION SCREEN.

Former Member
0 Kudos

Hello,

This is actual select query for data selection.

SELECT GUID_PR   "Primary Key as GUID in "RAW" Format
         CRTSP     "PRODUCT CREATED ON
         CHTSP     "PRODUCT CHANGED ON
         FROM /SAPSLL/PR
         INTO TABLE T_PR
          FOR ALL ENTRIES IN T_PRGEN    
         WHERE GUID_PR EQ T_PRGEN-GUID_PR 
                AND CRTSP IN *S_CRTSP*     
              AND CHTSP IN S_CHTSP.


Now I had changed the date format and it is in v_dat variable. 

How should i select the data based on this criteria. 

I mean should I write this select query like this : 

SELECT GUID_PR   "Primary Key as GUID in "RAW" Format
         CRTSP     "PRODUCT CREATED ON
         CHTSP     "PRODUCT CHANGED ON
         FROM /SAPSLL/PR
         INTO TABLE T_PR
          FOR ALL ENTRIES IN T_PRGEN    
         WHERE GUID_PR EQ T_PRGEN-GUID_PR 
                AND CRTSP IN *v_dat*     
              AND CHTSP IN S_CHTSP.

If I am doing so then it is throwing an error message.

Please suggest....

Regards,

Kittu

0 Kudos

Ok,here comes d solution...

S_CHTSP and S_CRTSP is of type D(date).

But in table /SAPSLL/PR ,crtsp and chtsp is of format timestamp.

so u have to convert the timestamp to date format and den validate it in a loop....

data: d1 type d,

d2 type d,

v_fg type c.

SELECT GUID_PR "Primary Key as GUID in "RAW" Format

CRTSP "PRODUCT CREATED ON

CHTSP "PRODUCT CHANGED ON

FROM /SAPSLL/PR

INTO TABLE T_PR

FOR ALL ENTRIES IN T_PRGEN

WHERE GUID_PR EQ T_PRGEN-GUID_PR .

loop at t_pr.

CONVERT TIME STAMP t_pr-crtsp INTO DATE d1 .

IF d1 NOT IN s_crtsp.

v_fg = 'X'.

delete t_pr index sy-tabix.

ENDIF.

IF chtsp NOT IN d2 and v_fg <> 'X'.

delete t_pr index sy-tabix.

ENDIF.

clear:v_fg.

endloop.

u get the records in t_pr with both filteration.

0 Kudos

Hello,

Thank you for youe response and I apprecaite the help so far.

This logic work if it is Parameter...When I have select option it is not working as it is not taking the range values...

SELECT GUID_PR "Primary Key as GUID in "RAW" Format
CRTSP "PRODUCT CREATED ON
CHTSP "PRODUCT CHANGED ON
FROM /SAPSLL/PR
INTO TABLE T_PR.


DATA : T_PR1 TYPE TY_PR OCCURS 0 WITH HEADER LINE.


DATA:  W_TEST    TYPE STRING,
       W_LV_LEN  TYPE I,
       W_LV_LEN1 TYPE I,
       W_LV_DATE(20)  TYPE C,
       W_LV_DATE1(20) TYPE C.

DATA : W_V(8) TYPE C,
       S_CT(11) TYPE C.

SORT T_PR BY CRTSP CHTSP.


LOOP AT T_PR INTO WA_PR.

  W_TEST = WA_PR-CRTSP.

  W_LV_LEN = STRLEN( W_TEST ).
  W_LV_DATE = W_TEST+0(8).

** IF WE SELECT ONLY ONE DATE IN SELECT OPTION

    • s_crtsp VALUE IS - IEQ20040101..bY REMOVING FIRST THRID DIGITS

    • WE ARE GETTING THE S_CRTSP VALUE IS 20040101 AND THIS LOGIC IS WORKING FINE..

      
         MOVE S_CRTSP TO S_CT. 
      
        W_LV_LEN1 = STRLEN( S_CT ).
        W_LV_DATE1 = S_CT+3(8).
      
      *  IF W_LV_DATE NE S_CRTSP
      
       IF W_LV_DATE NE W_LV_DATE1.
      
        W_FLG = 'X'.
          DELETE T_PR INDEX SY-TABIX.
        ENDIF.
        CLEAR W_FLG.
      
      ENDLOOP.

Can we do anything for this...

ANy suggestions would be apprecaited!

Regards,

Kittu

0 Kudos

Hello Kittu,

PLEASE come out from the way u have coded..the code i gave u before in d post is considering s_crtsp and s_chtsp as select-options only.... nyways m pasting the code again...

please read the code below with patience ...

S_CHTSP and S_CRTSP is of type D(date).

But in table /SAPSLL/PR ,crtsp and chtsp is of format timestamp.

so u have to convert the timestamp to date format and den validate it in a loop....

data: d1 type d,

d2 type d,

v_fg type c.

SELECT GUID_PR "Primary Key as GUID in "RAW" Format

CRTSP "PRODUCT CREATED ON

CHTSP "PRODUCT CHANGED ON

FROM /SAPSLL/PR

INTO TABLE T_PR

FOR ALL ENTRIES IN T_PRGEN

WHERE GUID_PR EQ T_PRGEN-GUID_PR .

loop at t_pr.

CONVERT TIME STAMP t_pr-crtsp INTO DATE d1 .

IF d1 NOT IN s_crtsp.

v_fg = 'X'.

delete t_pr index sy-tabix.

ENDIF.

IF chtsp NOT IN d2 and v_fg 'X'.

delete t_pr index sy-tabix.

ENDIF.

clear:v_fg.

endloop.

u get the records in t_pr with both filteration.

0 Kudos

now m putting the full code...

data: d1 type d,

d2 type d,

v_fg type c.

SELECT GUID_PR "Primary Key as GUID in "RAW" Format

CRTSP "PRODUCT CREATED ON

CHTSP "PRODUCT CHANGED ON

FROM /SAPSLL/PR

INTO TABLE T_PR

FOR ALL ENTRIES IN T_PRGEN

WHERE GUID_PR EQ T_PRGEN-GUID_PR .

loop at t_pr.

CONVERT TIME STAMP t_pr-crtsp INTO DATE d1 .

IF d1 NOT IN s_crtsp.

v_fg = 'X'.

delete t_pr index sy-tabix.

ENDIF.

IF v_fg <> 'X'.

CONVERT TIME STAMP t_pr-chtsp INTO DATE d2 .

IF d2 NOT IN s_chtsp.

delete t_pr index sy-tabix.

ENDIF.

ENDIF.

clear:v_fg.

endloop.

0 Kudos

Hello Kittu,

You can use this code:


*  MOVE S_CRTSP TO S_CT. 
 
* W_LV_LEN1 = STRLEN( S_CT ).
*  W_LV_DATE1 = S_CT+3(8).
 
*  IF W_LV_DATE NE S_CRTSP
 
*  IF W_LV_DATE NE W_LV_DATE1.

IF W_LV_DATE NOT IN S_CRTSP 
  W_FLG = 'X'.
    DELETE T_PR INDEX SY-TABIX.
  ENDIF.
  CLEAR W_FLG.
 
ENDLOOP.

You have to use NOT IN S_CRTSP with the select-option.

I think this should work.

BR,

Suhas

Edited by: Suhas Saha on Jan 12, 2009 11:02 AM

0 Kudos

Hi TT,

Thank you so much for being patient with me...

I take time to understand things....

CONVERT TIME STAMP t_pr-crtsp INTO DATE d1 .

Here i have issue with the syntax.....

I tried with this by using the help...

CONVERT TIME STAMP t_pr-crtsp TIME ZONE INTO DATE d1.

Should I also need to add anything here like Time ZONE tz ...etc....

Becayse it says INTO expected afetr INTO..it behaves as this syntax is incomplete.....

Any suggestions..

Thanks & Regards,

Kittu

Edited by: Kittu on Jan 12, 2009 11:22 AM

0 Kudos

i dont think its necessary to pass the time zone..nyways here is d syntax example for the same...

DATA: time_stamp TYPE timestamp,

dat TYPE d,

dat TYPE d,

tz TYPE ttzz-tzone,

dst TYPE c LENGTH 1.

tz = 'BRAZIL'.

time_stamp = 20030309033000.

CONVERT TIME STAMP time_stamp TIME ZONE tz

INTO DATE dat .

Former Member
0 Kudos

Hello TT & Everybody!

Thank you for all your suggestions and solutions...

TT- Thank you for your solution...

They were really helpful and I apprecaiate it!

Regards,

Kittu