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: 

Need to change the format of date when using gui upload

Former Member
0 Kudos

I am doing a report to upload a csv file into a custom database table but the problem is that in the fields of date I am having issues because the value in my csv is in DD/MM/YYYY and the sap one is YYYY/MM/DD .

I need to change the date in the DD/MM/YYYY format because when the file will be uploaded it will have that format, do you know how can I do it with gui upload I tried using some function modules but they didn't work for me because they are still displaying the date in the sap default format.

The date in my csv file is 31/03/17 but when checking entries in my database table it's 17.3/.31/0

The date I have now is

Here is my code:

data: gt_upload type table of z01_file_update.
data: gt_upload2 type table of z01_file_update.
data: lv_file type string .

  field-symbols <fs_upload> like line of gt_upload .

types: begin of tab1 ,

  str(255),

  end of tab1.

data itab1 type table of tab1 .

  field-symbols <fs_itab1> like line of itab1 .

  DATA : lit_filetable TYPE filetable,

         lv_rc TYPE i,

         fwa type line of filetable .
  CALL METHOD cl_gui_frontend_services=>file_open_dialog

    EXPORTING

      window_title            = 'Find File'

*    DEFAULT_EXTENSION       =

*    DEFAULT_FILENAME        =

      file_filter             = '*.*'

      initial_directory       = 'C:\'

*    MULTISELECTION          =

*    WITH_ENCODING           =

    CHANGING

      file_table              = lit_filetable

      rc                      = lv_rc

*    USER_ACTION             =

*    FILE_ENCODING           =

    EXCEPTIONS

      file_open_dialog_failed = 1

      cntl_error              = 2

      error_no_gui            = 3

      not_supported_by_gui    = 4

      OTHERS                  = 5.

read table lit_filetable into fwa index 1.

if sy-subrc = 0.

lv_file = fwa-filename.

endif.


call method cl_gui_frontend_services=>gui_upload

  exporting

    filename                = lv_file

    filetype                = 'DAT'

  changing

    data_tab                = itab1

  exceptions

    file_open_error         = 1

    file_read_error         = 2

    no_batch                = 3

    gui_refuse_filetransfer = 4

    invalid_type            = 5

    no_authority            = 6

    unknown_error           = 7

    bad_data_format         = 8

    header_not_allowed      = 9

    separator_not_allowed   = 10

    header_too_long         = 11

    unknown_dp_error        = 12

    access_denied           = 13

    dp_out_of_memory        = 14

    disk_full               = 15

    dp_timeout              = 16

    not_supported_by_gui    = 17

    error_no_gui            = 18

    others                  = 19

        .

if sy-subrc <> 0.

 Message 'You did something wrong!' type 'E' display like 'I' .

endif.

  data dtab type table of char50 .

  field-symbols <fs_dtab> like line of dtab.


  loop at itab1 assigning <fs_itab1> ."from 2 based on the description row.

    split <fs_itab1> at ';' into table dtab .

    append initial line to gt_upload assigning <fs_upload> .

    loop at dtab assigning <fs_dtab> .

      case sy-tabix.

        when 1 .

          <fs_upload>-bukrs = <fs_dtab> .

        when 2 .

          <fs_upload>-gjahr = <fs_dtab> .

        when 3 .

          <fs_upload>-budat = <fs_dtab> .

        when 4.

          <fs_upload>-bldat = <fs_dtab> .

        when 5 .

          <fs_upload>-blart = <fs_dtab> .

        when 6 .

          <fs_upload>-belnr = <fs_dtab> .

        when 7.

          <fs_upload>-xblnr = <fs_dtab> .

        when 8.

          <fs_upload>-hkont = <fs_dtab> .

        when 9 .

          <fs_upload>-sgtxt = <fs_dtab> .

        when 10.

          <fs_upload>-buzei = <fs_dtab> .

        when 11.

          <fs_upload>-dmbtr = <fs_dtab> .

        when 12.

          <fs_upload>-shkzg = <fs_dtab> .

        when 13.

          <fs_upload>-bschl = <fs_dtab> .

        when 14.

          <fs_upload>-umsks = <fs_dtab> .

        when 15.

          <fs_upload>-kostl = <fs_dtab> .

      endcase.

    endloop.

  endloop.

data lv_line type i .
select * from z01_file_update into table gt_upload2 .
describe table gt_upload2 lines lv_line.
if lv_line = 0.
INSERT z01_file_update from table gt_upload accepting duplicate keys .
else.
delete z01_file_update from table gt_upload .
endif.
1 ACCEPTED SOLUTION

Florian
Active Contributor

And why not just use the offset..

date = |20{ <fs_dtab>+6(2) }{ <fs_dtab>+3(2) }{ <fs_dtab>(2) }|.

Take a while, until this will not be valid anymore 🙂 at least for your file-upload

5 REPLIES 5

Florian
Active Contributor

And why not just use the offset..

date = |20{ <fs_dtab>+6(2) }{ <fs_dtab>+3(2) }{ <fs_dtab>(2) }|.

Take a while, until this will not be valid anymore 🙂 at least for your file-upload

Former Member

Thank you that worked for me !!

rameez_khan
Active Participant
0 Kudos

Put a break point on following line and check what value is getting passed

<fs_upload>-bldat =<fs_dtab>.
<fs_upload>-bldat =<fs_dtab>.

Also what data type have you used in table: Z01_FILE_UPLOAD.?

I can see that you are directly passing values from field symbol rather the date should be converted to internal format YYYYMMDD before you update database table.

Refer to Florian's solution, you can use that too.

Also check if there are conversion exits for other fields too. Eg: BELNR.

0 Kudos

I have used data element bldat

DoanManhQuynh
Active Contributor
0 Kudos

you should use conversion function module.