× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: A basic file update program
  • From: zkhalid@xxxxxxxxxx
  • Date: Fri, 14 Jul 2000 10:10:23 -0500

Here is an example of deleting records from a file I wrote yesterday. Add
and Change is very similar.

import java.io.*;
import java.util.*;
import com.ibm.as400.access.*;

public class pwdrstprg {

// End of Class
/** Constructor for this class
 * @return nothing
 * @param mySystem com.ibm.as400.access.AS400
 *
 */
public pwdrstprg(AS400 mySystem)
{

     String Library = "ZAID";
     String myFile  = "DBFPPR30";
     String year = new String((new char[4]));
     String month = new String((new char[2]));
     String day = new String((new char[2]));


          // Specify File Location
          QSYSObjectPathName filePathName = new
QSYSObjectPathName(Library,myFile,"FILE");
          SequentialFile fileObj = new
SequentialFile(mySystem,filePathName.getPath());
     try
     {

          // Retrieve a record format
          AS400FileRecordDescription recDesc = new
AS400FileRecordDescription(mySystem,filePathName.getPath());
          fileObj.setRecordFormat(recDesc.retrieveRecordFormat()[0]);
          // Open the file

fileObj.open(AS400File.READ_WRITE,0,AS400File.COMMIT_LOCK_LEVEL_NONE);
          // Read a record
          Record record = fileObj.readNext();
          // Process all records in the file
          while (record != null)
          {
               // Process a record
               year = ((String)record.getField("TRYR1")).trim();
               month= ((String)record.getField("TRMM1")).trim();
               day  = ((String)record.getField("TRDD1")).trim();

               // This function will return true if password is expiring in
2 weeks
               if (isExpired(year,month,day))
               {
                    fileObj.deleteCurrentRecord();
               }
               record = fileObj.readNext();
         }
         fileObj.close();
     }
     catch (Exception e)
     {

               System.out.println("Error 1 - " + e.getMessage());
     // End of catch (Exception e)
     }
     finally
     {
          try
          {
               fileObj.close();
          }
          catch (Exception e1)
          {}
     }

     System.exit(0);

// End of function ID
}
/**
 * @return String
 * @param mySystem com.ibm.as400.access.AS400
 * @param CurrentUserProfile java.lang.String
 */
 // This method calculates password expiry date and returns a flag
private static boolean isExpired(String year, String month, String day)
{
     boolean flag = false;
     // First incomming date will be converted from string format to int
     // This is how to convert CHAR to int  ==> (int i =
Integer.valueOf("22").intValue())
     int yyyy = Integer.valueOf(year).intValue();
     int mm = Integer.valueOf(month).intValue();
     int dd = Integer.valueOf(day).intValue();
     int yy = yyyy - 1900;
     // Now create a Date Object with yymmdd
     java.util.Date pwd1 = new  java.util.Date(yy,mm,dd);

     // Add 14 Days to Last processed Date to get record expiry Date
     Timestamp ExpireDate = new Timestamp((pwd1).getTime());
     Calendar cal1 = Calendar.getInstance();
     cal1.setTime(ExpireDate);
     cal1.add(Calendar.DAY_OF_YEAR,14);
     ExpireDate.setTime(cal1.getTime().getTime());
     // Prepare Password Check Date
     Timestamp CheckDate = new Timestamp((new java.util.Date()).getTime());
     Calendar cal2 = Calendar.getInstance();
     cal2.setTime(CheckDate);
     CheckDate.setTime(cal2.getTime().getTime());
     if (CheckDate.after(ExpireDate))
     {
          flag = true;
     }
     return flag;
}

/**
 * @return void
 * @param
 * @param
 */
public static void main(String[] args)
{
     // Define AS400 object

     AS400 mySystem = new AS400("SYSTEM","USERID","PASSWORD");
     pwdrstprg readpf10 = new pwdrstprg(mySystem);
}

}

Dan Rasch <drasch@mail.win.org> on 07/14/2000 08:52:51 AM

Please respond to JAVA400-L@midrange.com

To:   JAVA400-L@midrange.com
cc:
Subject:  A basic file update program





I am new at JAVA (coming from an RPG and COBOL background), and looking
for an example of a basic file update program.  Something that will
perform the add, change and delete functions - in the simplest form, it
would look alot like a DFU program.

I have searched the web, but the examples I have seen have not dealt with
much file I/O.

Does anyone know of a good site where I could find such an example?

TIA,

Dan Rasch - because if the human species concentrated on the really
important things in life, there would be a shortage of fishing poles!


+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---



+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.