Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Which data type should I define my date value as when passing it from ABAP to MSSQL 2008

Hi,

I have been struggling for a few weeks now with a problem in my ABAP program.  I have an ABAP program where I need to supply a date which is then passed to MSSQL.  It seems that neither "String" nor "Type c" is the correct definition of this data type.  Could anyone please assist me as to what it should be?

Here is an extract of the full ABAP code:


----------------------------------------------------

FUNCTION Z_WB_EXT_TREK_00.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(WBCODE) TYPE  ZWB_TS_CODE

*"     REFERENCE(DATE_LOW) TYPE  DATS

*"     REFERENCE(DATE_HIGH) TYPE  DATS

*"  EXPORTING

*"     REFERENCE(WB02_EOF_RECS) TYPE  ZWB_TS_INT_EOF_WB02_TAB

*"----------------------------------------------------------------------

   tables: zwb_tS_DEF.

   data: begin of iTab occurs 0.

           include structure ZWB_TS_INT_EOF_WB02.

   data: end of iTab.

   data: SQLDbName TYPE dbcon-con_name.

   data: DataString(512) type c.

   data: RecCount type i.

   data: date1_Low             type ZWB_TS_DATETIME, " Parameter for selecting on SQL field DATE1 (lower bound)

         date1_high            type ZWB_TS_DATETIME. " Parameter for selecting on SQL field DATE1 (upper bound)

   data: date1_format          type ZWB_TS_DATETIME. " Format for selection date

   data: date1_low_string  type string,               " SQL query argument for date selection (lower bound)

         date1_high_string type string.               " SQL query argument for date selection (upper bound)

   data: SQLDelimiter(1)       type c value ''''.    " Character delimiter for strings passed to SQL server

*-----------------------------------------------------------------------

   Select single * from zwb_ts_def where wbcode = wbcode.

   check sy-subrc = 00.

   SQLDBName = Zwb_ts_def-DBCON_NAME.

** Properly format the selection criteria (dates, formats)

   date1_format = '121'.

   concatenate date_low(4'-' date_low+4(2'-' date_low+6(2' 00:00:00.000' into date1_low.

   concatenate date_high(4) '-' date_high+4(2) '-' date_high+6(2) ' 23:59:59.999' into date1_high.

   concatenate 'convert(datetime,' sqldelimiter date1_low sqldelimiter ',121)'

                            into date1_low_string.

   concatenate 'convert(datetime,' sqldelimiter date1_high sqldelimiter ',121)'

                            into date1_high_string.

   concatenate '''' date1_low  '''' into date1_low_string.

   concatenate '''' date1_high '''' into date1_high_string.

** Open the DB connection

   EXEC SQL.

     CONNECT TO :SQLDBName

   ENDEXEC.

   check sy-subrc = 0.

** Set up an extract dataset, using dbcur as cursor placeholder

   EXEC SQL.

     OPEN dbcur FOR

       SELECT

           CARDID,

           REGNO,

           DATE1,

           DATE2,

           MASS1,

           MASS2,

           NETT,

           CONSNO,

           FIRST,

           DIR,

           STOCKPILE,

           STOCKPILENO

        FROM eof

       WHERE

*          regno = 'DECOR001'

*          eof.DATE1 > '2014-06-05 00:00:00.000'    and eof.date1 <= '2014-06-05 23:59:59.999'

         eof.DATE1 > :DATE1_LOW_STRING and eof.DATE1 <= :DATE1_HIGH_STRING

   ENDEXEC.

** Read the database one record at a time

   refresh iTab. " Clear any existing entries from the internal table

   do.

     EXEC SQL.

       fetch next dbcur into

         :iTab-ZZCARDID,

         :iTab-ZZREGNO,

         :iTab-ZZDATE1,

         :iTab-ZZDATE2,

         :iTab-ZZMASS1,

         :iTab-ZZMASS2,

         :iTab-ZZNETT,

         :iTab-ZZCONSNO,

         :iTab-ZZFIRST,

         :iTab-ZZDIR,

         :iTab-zzSTOCKPILE,

         :iTab-ZZSTOCKPILENO

     ENDEXEC.

     if sy-subrc <> 0exitendif.

     append itab.

     add 1 to RecCount.

   enddo.

** Close the DB connection

   EXEC SQL.

     CLOSE dbcur

   ENDEXEC.

   EXEC SQL.

     DISCONNECT :SQLDBName

   ENDEXEC.

   refresh WB02_EOF_RECS.

   loop at itab.

     append itab to WB02_EOF_RECS.

   endloop.

ENDFUNCTION.



-----------------------------------------------------------------------------------------------------------------------


I have attached a screenshot of the error message I am getting when passing the following date:  05062014

Any help please, will be greatly appreciated.

Capture.PNG (35300 B)
Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question