Wednesday, 4 July 2018

Using Oracle Forms to load local files


using the below code In load file “button” using “when-button-pressed” trigger.
DECLARE
   l_userhome            VARCHAR2 (200)
         := webutil_clientinfo.get_system_property ('user.home')
            || '\Desktop';
   l_filename            VARCHAR2 (200) := NULL;
   l_bare_filename       VARCHAR2 (200) := NULL;
   l_fileprefix          VARCHAR2 (200) := NULL;
   l_serverfilename      VARCHAR2 (200) := NULL;
   l_upload_path         VARCHAR2 (200) := NULL;
   l_version_path        VARCHAR2 (200) := NULL;
   l_option_grade_path   VARCHAR2 (200) := NULL;
   l_size_curve_path     VARCHAR2 (200) := NULL;
   l_filesize            NUMBER;
   al_con                alert;
   l_status              BOOLEAN;
   os_name               VARCHAR2 (100)
                           := UPPER (webutil_clientinfo.get_operating_system);
   l_mainbrand           VARCHAR2 (100);
   l_country             VARCHAR2 (100);
   l_jobid               NUMBER;

   CURSOR c_upload_dir
   IS
      SELECT t.VALUE AS directory_path
        FROM sys_directories t
       WHERE t.NAME = 'OE_TRACKING_FILE';
BEGIN
   OPEN c_upload_dir;

   FETCH c_upload_dir
    INTO l_upload_path;

   CLOSE c_upload_dir;

   l_filename :=
      webutil_file.file_open_dialog
                                  (directory_name      => l_userhome,
                                   file_name           => NULL,
                                   file_filter         => 'CSV files (*.csv) |*.csv',
                                   title               => 'Dir Upload'
                                  );

   IF l_filename IS NOT NULL
   THEN
      --- to get the file size ---
      l_filesize := webutil_file.file_size (file_name => l_filename);

      --- to get the filename without the path ---
      IF os_name LIKE 'WINDOWS%'
      THEN
         l_bare_filename :=
                           SUBSTR (l_filename, INSTR (l_filename, '\', -1)
                                    + 1);
      ELSE
         l_bare_filename :=
                           SUBSTR (l_filename, INSTR (l_filename, '/', -1)
                                    + 1);
      END IF;

      IF webutil_file.file_exists (file_name => l_filename)
      THEN
         IF webutil_file.file_is_readable (file_name => l_filename)
         THEN
            IF l_filesize > 0
            THEN
               l_serverfilename :=
                     l_bare_filename
                  || '_'
                  || TO_CHAR (SYSDATE, 'DDMMYYYYHH24MISS');

               IF l_upload_path IS NOT NULL
               THEN
                  l_status :=
                     webutil_file_transfer.client_to_as_with_progress
                                 (clientfile            => l_filename,
                                  serverfile            =>    l_upload_path
                                                           || '/'
                                                           || REPLACE
                                                                 (l_serverfilename,
                                                                  '.csv',
                                                                  ''
                                                                 )
                                                           || '.csv',
                                  progresstitle         => 'File Upload in progress',
                                  progresssubtitle      => 'Please wait',
                                  asynchronous          => FALSE,
                                  callbacktrigger       => ''
                                 );
                  SYNCHRONIZE;

                  IF l_status = TRUE
                  THEN
                     MESSAGE ('done transfer');
                     MESSAGE ('done transfer');
                     l_status := FALSE;
                  ELSE
                     MESSAGE ('Not transfer');
                     MESSAGE ('Not transfer');
                  END IF;
               END IF;
            END IF;
         ELSE
            MESSAGE ('File ' || l_bare_filename || ' is blank');
         END IF;
      ELSE
         MESSAGE (   'Unable to read the file'
                  || CHR (10)
                  || 'File Name='
                  || l_bare_filename
                  || ', '
                  || CHR (10)
                  || 'File Size='
                  || l_filesize
                  || ' Byte'
                 );
      END IF;
   ELSE
      MESSAGE ('File ' || l_bare_filename || ' is not found');
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      MESSAGE (SQLERRM);
END;




1 comment:

  1. Such a nice blog, I really like what you write in this blog, I also have some relevant Information about Best HR Training In Hyderabad | Hr training institute in Hyderabad! if you want more information.
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training
    Oracle Fusion Financials Online Training
    Big Data and Hadoop Training In Hyderabad

    ReplyDelete