Writing File and File Member to AS400 using Access Classes

Hi! All,
I am in a fix here and would sincerely appreciate any help I can get. I need to write a pogram that will allow me to write a file and many FileMembers to the File in the AS400.
I have the following method which I thought would help me do it, but I get exceptions.
public static void writeFileOnAS400(String pFileName, String pFileMemberName, String pContents ) throws Exception
AS400 as400 = new AS400();
String as400FileName = "/QSYS.LIB/MYLIB.LIB/" + pFileName + ".FILE";
String as400MemberName = pFileMemberName + ".MBR";
// Create a file object that represents the file
SequentialFile newFile = new SequentialFile(as400, as400FileName + "/" + as400MemberName);
// Create the file
newFile.create(pContents.getBytes().length, "*DATA", "Data file created with " + pContents.getBytes().length + "byte record." );
// Open the file for writing only.
// Note: The record format for the file
// has already been set by create()
newFile.open(AS400File.WRITE_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
// Write a record to the file. Because the record
// format was set on the create(), getRecordFormat()
// can be called to get a record properly formatted
// for this file.
Record writeRec = newFile.getRecordFormat().getNewRecord();
writeRec.setField(0, pContents);
newFile.write(writeRec);
// Close the file since I am done using it
newFile.close();
// Disconnect since I am done using
// record-level access
as400.disconnectService(AS400.RECORDACCESS);
This works the first time for the 1st Member(ie; when te file or Member is not yet created). When I want to add a new Member to the same file, by passing in the same fileName, but a different fileMemberName, it does not work. The string pContents is what I need to write to the Member.
Anyone Know about the AS400?
Thanks

The whole class is as shown below
import com.ibm.as400.access.*;
public class AS400Utility
public static void writeFileOnAS400(String pFileName, String pFileMemberName, String pContents ) throws Exception
AS400 as400 = new AS400();
String as400FileName = "/QSYS.LIB/IQFILES.LIB/" + pFileName + ".FILE";
String as400MemberName = pFileMemberName + ".MBR";
// Create a file object that represents the file
SequentialFile newFile = new SequentialFile(as400, as400FileName + "/" + as400MemberName);
// Create the file
newFile.create(pContents.getBytes().length, "*DATA", "Data file created with " + pContents.getBytes().length + "byte record." );
// Open the file for writing only.
// Note: The record format for the file
// has already been set by create()
newFile.open(AS400File.WRITE_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
// Write a record to the file. Because the record
// format was set on the create(), getRecordFormat()
// can be called to get a record properly formatted
// for this file.
Record writeRec = newFile.getRecordFormat().getNewRecord();
writeRec.setField(0, pContents);
newFile.write(writeRec);
// Close the file since I am done using it
newFile.close();
// Disconnect since I am done using
// record-level access
as400.disconnectService(AS400.RECORDACCESS);
public static void main(String args[])
System.out.println("Writing file to AS400...");
try
writeFileOnAS400_2("BPL0000004", "M001", "<SampleXML>The sample file 1</SampleXML>");
System.out.println("Finished writing file 1");
writeFileOnAS400_2("BPL0000004", "M002", "<SampleXML>The sample file 2</SampleXML>");
catch(Exception e)
e.printStackTrace();
System.out.println("Completed file writing to AS400...");
}

Similar Messages

  • To extract the users permission on files and folders in sharepoint 2010 using client object model

    To extract the users permission on files and folders in sharepoint 2010 using client object model

    Hello,
    This is sample code to get item level permisison: (Just written in notepad so it is not tested)
    public void ItemLevelPermission()
    SecurableObject curObj = null;
    ListItem curItem = ctx.Web.Lists.GetByTitle("LibraryName").GetItemById(ItemId); -> Use Id of file or folder.
    IEnumerable roles = null;
    roles = ctx.LoadQuery(
    curObj.RoleAssignments.Include(
    roleAsg => roleAsg.Member,
    roleAsg => roleAsg.RoleDefinitionBindings.Include(
    roleDef => roleDef.Name, // for each role definition, include roleDef’s Name
    roleDef => roleDef.Description)));
    ctx.ExecuteQuery();
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • My external hard drive is 'seen' by my iMac and I can go into the Finder and open files and folders. I am using the hard drive for Time Machine back up. However Time Machine says it can't find the drive. Same thing has happened with Final Cut Express.

    My new LaCie external hard drive is 'seen' by my iMac and I can go into the Finder and open files and folders. I am using the hard drive for Time Machine back up. However Time Machine says it can't find the drive.
    The same thing happened recently between Final Cut Express and my other LaCie external hard drive used as the Scratch disk. It fixed itself.
    I've run out of ideas. Help would be very much appreciated. Thanks.

    have you done some searches on FCPx and time machine? Is there a known issue with using a TM drive with FCPx? dunno but ...wait...I'll take 60 sec for you cause I'm just that kind of guy....   google...." fcpx time machine problem"  Frist page link 
    http://www.premiumbeat.com/blog/fcpx-bug-best-practices-for-using-external-hard- drives-and-final-cut-pro-x/
           You cannot have time machine backups on your hard drive if you intend to use it in FCPX.
    booya!

  • Everytime I try to enter something into the search box a further box appears to tell me this is a json file and what program should I use to open it. How can I

    I am using Linux mint 12 with firefox.
    Everytime I try to type something in the search box a further box appears to tell me this is a JSON file and what program should I use to open it.
    This has only happened since reinstalling my system a couple of weeks ago.
    I am not really interested in what a json file is I simply want to get rid of this pop up box.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    See also:
    *[[/questions/921535]]

  • Step by Step Guide Details for RFC to File and File to RFC scenario

    Hi Guru's
    Good day to you. I am tyring to develop some scenarios based on RFC adaptor. so i want to start up with basic scenarios like RFC to File  scenario(Here i just want to pull some data from SAP using RFC and put it in destination folder as an text file) and FILE to RFC scenario (Here i just want to take some data from the file and update into SAP).
    For doing these scenarios i would like to request you people to send me the step by step guide which explains me about the complete steps of configurations required to do the RFC to FILE scenario and FILE to RFC scenario.
    I found some scenarios and i am in confused state. so i request you to please put your experience to help me out.
    thanks in advance.
    Regards
    Raj

    Hi Aaron,
    I don't know your scenario and your ECC and PI versions but I learned how to use ABAP Proxy more than 1 year ago with the following tutorial:
    Edit--> The forum doesn't allow me to post external link, just search "ABAP Proxy Communication Scenario" in google and visit the 1st result
    The way to develop ABAP Proxys has changed a little if your PI is 7.1. In the ECC side, the transaction SPROXY looks much better too if you have a recent version of the ECC.
    Edited by: Marshal on Oct 8, 2009 5:08 PM
    I've found that SDN Document. Maybe the scenario is not the most simple to start with ABAP Proxy but is very well documented and is for PI 7.1. The document also handles the inbound and outbound proxys
    [http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/c00ca32e-f991-2b10-f5be-97114bd2b08f&overridelayout=true]
    Edited by: Marshal on Oct 8, 2009 5:22 PM

  • I am trying to create a panorama, when I enter File New I don't get the Photomerge Panorama option, the only options that appear are Blank file and File from clipboard.  How do I get photomerge panorama

    I am trying to create a panorama.  When I enter FILE > NEW > the Photomere panorama option does not appear.  the only options are Blank file and file from clipboard.  This is in Elements 11 on Windows 8.1 OS.  How do I get Photomerge Panorama to appear.

    Since PSE11, you access the photomerge option in the 'Enhance' menu, last option. Or you can use the organizer (menu Edit / Photomerge).

  • HT1386 My computer was stolen with all my iTunes on it. However, my iPod was not stolen. How do I transfer all files from my iPod to my new computer (purchased files and files I copied from CDs)?

    My computer was stolen with all my iTunes on it. However, my iPod was not stolen. How do I transfer all files from my iPod to my new computer (purchased files and files I copied from CDs)?

    http://www.wideanglesoftware.com/touchcopy/index.php

  • Purpose of message protocol file and file content conversion

    hi
       i am currently working in idoc to file scenario, 
          In what cases we will go file and file content conversion in message protocol for file adapter.
    can anyone specify the real significance of it? bcoz this may help me and continue my scenario in its suitable path.
    Regards
    Saravanakumar PK

    Hi,
    In XI (internal) all XML message are based on the XI Message Protocol.
    See: http://help.sap.com/saphelp_nw70/helpdata/en/b6/0b733cb7d61952e10000000a11405a/frameset.htm
    XI Protocol is nothing but an SAP XI extension of SOAP protocol and SOAP protocol is nothing but a SOAP request in a HTTP protocol. SOAP request is nothing but SOAP extension of an XML message. Hence finally it drill downs to the fact that XI message is in fact an XML message with some extra information in the header which are SAP specific like the SAP Runtime, SAP Hoplist, etc...
    File Content Conversion
    Integration Engine understands only XML messages.Now if u r handling normal text file such as 'tab separated' file,'# separated' file, or a CSV file, you need to convert the content of the file to XML and File Content Conversion mechanism helps to do this job.This File Content conversion mechanism(option)is present with the File Adapters.both Sender and Receiver.
    How to do FCC:
    http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    /people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/shabarish.vijayakumar/blog/2006/04/03/xi-in-the-role-of-a-ftp
    Thanks
    Swarup

  • HOW TO READ DATA FROM A FILE AND INSERT INTO A TABLE USING UTL_FILE

    Hi..
    I have a file.I want to read the data from file and load it into a table using utl_file.
    how can I do it?
    Any reply apreciated...

    Hi,
    This is not your requirment but u can try this :
    CREATE OR REPLACE DIRECTORY text_file AS 'D:\TEXT_FILE\';
    GRANT READ ON DIRECTORY text_file TO fah;
    GRANT WRITE ON DIRECTORY text_file TO fah;
    DROP TABLE load_a;
    CREATE TABLE load_a
    (a1 varchar2(20),
    a2 varchar2(200))
    ORGANIZATION EXTERNAL
    (TYPE ORACLE_LOADER
    DEFAULT DIRECTORY text_file
    ACCESS PARAMETERS
    (FIELDS TERMINATED BY ','
    LOCATION ('data.txt')
    select * from load_a;
    CREATE TABLE A AS select * from load_a;
    SELECT * FROM A
    Regards
    Faheem Latif

  • I tried opening a pdf file and I set it to use always and firefox which did not work, I was wondering how to undo that and what I should use to open pdf files in the future?

    I was attempting to open a document from a frequently used site, I had never been on, on my new mac however. I attempted to open the pdf file and was given the option of which program to use to open it, I mistakenly clicked use always and firefox as the program with which to open pdf files. I do not know how to undo this or what I should do in the future to access the pdf files.

    Hi Melfour-
    Here is a Support article detailing how to work with your Firefox PDF preferences:
    [[Opening PDF files within Firefox]]
    Hope that helps.

  • Writing Import and FIle Format Plug-Ins for Photoshop CS1

    Hi All,
    I have written two plug-ins (Import and File Format) which work fine using CS2. Unfortunately we need to be able to have them work in CS1 too. I downed the "Adobe Photoshop CS SDK" but when when I looked at the API document ("Photoshop API Guide.pdf"), chapters 6 and 9 are missing and there is no sample code for these plug-in types.
    Could anyone explain why this is?
    How do I write these types of plug-in's for CS1?
    Thanks for your Help
    All the Best
    Dave

    I have published
    GPL source code to many plugins all of which are compatible with Photoshop 3.0 through CS2, on Windows and Mac. Unless you are using CS2 specific features, the your Import and Format DLLs should already work with CS on Windows.
    On the Mac, the executable format changed between CS and CS2, and you would need to build a PEF plugin for CS. MPW and CodeWarrior can do that; Xcode cannot.

  • Cannot download .pdf files and word docs from KM using Web Dynpro

    Dear Portal Gurus,
    Using KM API, I am trying to download, documents from KM in my Web Dynpro Application. But .pdf files and word docs with screenshots are not getting retrieved from KM. Word docs opens with no content and Adobe opens with an error saying "Either it is a damaged file or It is not a supported file".
    I am using the following KM service to download the content.
    public byte[] retrieveResourceInBytes(String strRid){                    
    /////  after a few lines  ////
         if (this.loggedOnUser.isAuthenticated()) {
    // create a resource context with the authenticated user
         rContext = new ResourceContext(this.loggedOnUser);
    // create a RID to handle a resource
          aRid = RID.getRID(strRid);
              try {
              // get an instance of a resource factory
                     final IResourceFactory aResourceFactory = ResourceFactory.getInstance();
    // retrieve a folder/file  with context
                                                 aResource =  aResourceFactory.getResource(aRid, rContext);
         if(aResource.isCollection()) {
                                                                      aResource = (ICollection) aResource;
                                                      IPropertyMap objIPropertyMap = aResource.getProperties();               
                                                 IMutablePropertyMap objIMutablePropertyMap =objIPropertyMap.getMutable();
                                                 objHashMap = new HashMap();
         if (aResource != null) {
                                                                         IContent oldContent = aResource.getContent();
                            InputStream objInputStream=oldContent.getInputStream();
                 byte[] theBytes = new byte[objInputStream.available()];
                 objInputStream.read(theBytes);
                        return theBytes;
         } //  catches all the exceptions here///
    Could you please advise if I am doing something wrong else could you please advise me for any corrections which would help?
    Thanks a lot in advance,
    Zeena
    Edited by: Zeena Ali on Mar 25, 2009 8:13 AM

    On Apr 10, 2013, at 4:10 PM, AdityaKalania wrote: Replies in RED below:
    Re: Cannot download pdf files from web sites
    created by AdityaKalania in Adobe Reader - View the full discussion
    Hi,
    Which web browser are you using to view the PDF? Safari 5.1.8
    When you open the PDF in Adobe Reader add-in you will either see a floating toolbar
    http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-5224223-317859/430-90/floating +toolbar.JPG
    or a normal toolbar
    http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-5224223-317860/450-11/normalto olbar.JPG
    both the toolbars have save button, use the button to save the file locally. I do not see these toolbars. I do, however see this
    and it works! Thanks
    Hope this will help you.
    Thanks
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5224223#5224223
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5224223#5224223
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5224223#5224223. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Adobe Reader by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • What programme creates a .ggi file and why would it be used?

    Have been asked to create a .ggi file and I have never come across this file extension before.
    I have googles it and got as much information as possible but can't seem to find the answer - why would it be used, what is it used for and what software creates it.
    Also, not sure where to ask this question so apologies if this is in the wrong forum!
    Any help greatly appreciated!!!!

    We can't know. File extensions are completely arbitrary and if whoever requested the format can't tell you what he/ she needs, then we can't either. If it were a commonly used file format we would probably not, but since we don't, it is probably a proprietary format associated with some lesser known or even exotic software. That being so, the request to provide such a file is actually even pretty stupid, since the only way to create it would be to have access to that program. Causal loop.
    Mylenium

  • How do I turn a list of files and paths into this format using AS?

    Hi everyone,
    I'm a complete novice with Applescript and I need some help to script turning a list of files from the Finder into a specific format in a text doc, so I can save as CSV and import into another app (Anki, for learning language).
    Here's an example list of files:
    I can get Automator to spit out the files names and paths into a text file, but I think I need Applescript to turn the result into this:
    <img src="12-1.jpg">;[sound:12-1.caf];;
    <img src="12-2.jpg">;[sound:12-2.caf];;
    <img src="12-3.jpg">;[sound:12-3.caf];;
    <img src="12-4.jpg">;[sound:12-4.caf];;
    Any help would be appreciated.

    This processes the JPG files, and then assumes that the CAF files are in the flle structure you provided.
    Select files in the Image Folder:
    The Run Shell Script [pass input as arguments] is:
    for f in "$@"
    do
         caf="$f"
         caf=${caf/Images/Audio}
         caf=${caf%.*}.caf
         echo \<img src=\""$f"\"\>\;\;[sound:$caf\]\;\;
    done

  • Reading file and dump data into database using BPEL process

    I have to read CSV files and insert data into database.. To achieve this, I have created asynchronous bpel process. Added Filed Adapter and associated it with Receive activity.. Added DB adapter and associated with Invoke activity. Total two receive activity are available in  process, when tried to Test through EM, only first receive activity is completed, and waiting on second receive activity. Please suggest how to proceed with..
    Thanks, Manoj.

    Deepak, thank for your reply.. As per your suggestion I created BPEL composite with
    template "Define Service Later". I followed below steps, please correct me if I am wrong/missing anything. Your help is highly appreciated...
    Step 1-
    Created File adapter and corresponding Receive Activity (checkbox create instance is checked) with input variable.
    Step 2 - Then in composite.xml, dragged the
    web service under "Exposed Services" and linked the web service with Bpel process.
    Step 3 - Opened .bpel file and added the DB adapter with corresponding Invoke activity, created input variable. Web service is created of Type "Service" with existing WSDL(first option aginst WSDL URL).
    and added Assign activity between receive and invoke activities.
    Deployed the composite to server, when triedTest it
    manually through EM, it is promting for input like "subElmArray Size", then I entered value as 1 with corresponding values for two elements and click on Test We Service button.. Ptocess is completing in error. The error is
    Error Message:
    Fault ID
    service:80020
    Fault Time
    Sep 20, 2013 11:09:49 AM
    Non Recoverable System Fault :
    Correlation definition not registered. The correlation set definition for operation Read, process default/FileUpload18!1.0*soa_3feb622a-f47e-4a53-8051-855f0bf93715/FileUpload18, is not registered with the server. The correlation set was not defined in the process. Redeploy the process to the containe

Maybe you are looking for

  • How to send sms from gsm modem(AT commands) to j2me application(not inbox)

    hi i want to send sms from gsm modem to a j2me application, for this to happen i have to send sms to a specific port in which j2me application is running.when i m trying to send sms from modem it doesnt go to application it goes to inbox. is it relat

  • Internet explorer 9 support for WD ABAP?

    SAP support for IE9 for Webdynpro ABAP exists already says notes 1496565 ja 1583947 with some exceptions like 64-bit version of IE9 is not supported. This happened around april-june this year according to release dates of those notes. But I did not q

  • How can find what are the customers are created in my earlier version.

    Hi all,I am trying to find out how can I check the  what are the customers are created in my earlier version of sap (i.e 4.7B) My client  Upgrade d the 5.0 in 2007. Now my client asking, list of WDs which are created in the 4.7B.

  • Outlook Calender sync fails despite mobile.de

    I've got membership to mobile.me and treid to sync my outlook (2003 - windows XP)with mobile.me for my new iPhone 4. Nothing happens? The contacts are OK. What is wrong? Thanks for your support and best regards Ronwa

  • Kernal Panic in MacBook Pro 10.8.4

    I have been getting kernal panics about once a week, starting about 2 months ago.  I have not installed any new software. The memory has always been the same. The Mac always ran flawlessly, but now I'm getting a these panics. Any thoughts? Thanks Int