Skip to Content

15 Comments

You must be Logged on to comment or reply to a post.

  1. Community User
    Hi Thomas,

    I finally had the time to check out your pdf document and it is great. You clearly spent a lot of time thinking about the problem.

    Today while walking from the train station to work I thought about your coding and two questions came to my mind.

    1) Did you write unit tests? This should be very easy you just have to make sure that nobody ever deletes your testfiles 😉

    2) Just for curiousity did you think about using the java approach which means that you are using a additional file object? So the coding would be:

    data file type ref to cl_file.

    create object file exporting filename = ‘c:\test.txt’.
    file->openToRead( ).
    file->openForAppend( ).

    or using a filemanager class

    data filemanager type ref to cl_file_manager.
    data file type ref to cl_file.

    create object filemanager.
    file = filemanager->openFile( ‘c:\test.txt’ ).

    file->read( … ).
    file->append( … ).

    regards

    Thomas

    (0) 
    1. Thomas Jung
      1. Actually I did write a unit test.  You see when I share code on SDN it is rarely the code that exists in my company’s system.  I recreate my code samples in another development system running on my laptop before posting them to SDN.  That way I can remove anything specific or sensitive to my company.  That’s what happened here.  I probably just forgot to bring over the unit test class.  I will see what I can do to get the PDF updated on SDN.

      2.  Part of my code was actually adapted from old function modules I had written.  That was probably what played the biggest role in the structure of my object.  The methods have a rather function module like structure (they are all static methods). I wish I could say that I had some grand theme to the approach that I took, but really I went with the structure for the class that made it easy to integrate into the exsiting applications that I was cleaning up. I suppose since all of these methods are static, you could lay down a higher level class structured more like you described on top of it.

      (0) 
  2. Heiko Hänsel
    Hello Thomas,

    I read your Weblog today and wondered about your 8 variants of coding the OPEN DATASET commands.
    Some minutes ago I read the most recent ABAP Geek Weblog from Horst Keller “ABAP Geek 11 – Dynamic ABAP Objects”.
    I think it should be possible to generate a small helper class as a subroutine pool which performs the desired OPEN DATASET command. Probably you’ll have problems in debugging that dynamically generated class. I never used generating subroutine pools for session scope only.

    Heiko

    (0) 
    1. Thomas Jung
      Actually I thought about that.  I even wrote it into the weblog: “I toyed with the idea of dynamically generating the source code with the GENERATE SUBROUTINE POOL command”.

      In the end though I decided to not go that approach because it makes the coding harder to maintain and read.  It also makes debugging a real nightmare.  Don’t get me wrong – dynamic code generation has its place and I loved Horst Keller’s weblog.   I just didn’t think this was the right place to use that approach. 

      (0) 
      1. Heiko Hänsel
        Hi Thomas,

        looks like I did’nt read your paragraph of generating subroutine pools when I read your weblog yesterday. 🙂

        Regards,
        Heiko

        (0) 
    1. Thomas Jung Post author
      I believe you are correct.  I guess I never used this class in any application that was harmed by the extra empty line.  Actually it probably doesn’t need any check for or against 4 – just delete the work row if subrc was ne 0. 
      (0) 
  3. swapnil kubal
    Thomas,
          I am trying to open a file named ‘ABC XYZ.txt’
    located on application server. It gives me a short dump saying ‘Unable to open file ABC’. I think it is not accepting the space between file name. Is there a way to get around this. I am able to successfully access file named ‘ABC.txt’ from application server.
    I know this question is not related to your blog but i would really appreciate your help in this matter.
    (0) 
    1. Thomas Jung Post author
      I really don’t know about spaces. I don’t believe I have ever ran across that situation.  Of course the simple solution is to not use file names with spaces in them. 🙂

      I just tried this on my local system and it worked fine.  I tried reading from C:\New Doc.txt and it worked as it should:

      START-OF-SELECTION.

        DATA l_string TYPE string.

        OPEN DATASET ‘c:\New Doc.txt’ IN TEXT MODE for INPUT ENCODING DEFAULT.
        IF sy-subrc = 0.
          READ DATASET ‘c:\New Doc.txt’ INTO l_string.
        ENDIF.

        WRITE: / l_string.

      What release are you on?  I’m running NetWeaver 7.0 SP13.

      (0) 
      1. swapnil kubal
        I am currently using 4.6C and it doesnt seem to work. I even tried using upload_files FM which reads  file from application server. But this FM also fails when filename has spaces. But it works fine in ECC 6.0. Thanks for your help.

        Regards,
        Swapnil.

        (0) 
  4. swapnil kubal
    Thomas,
          I am able to read text files from application server. But reading excel file located on application server using open dataset in text mode is giving junk values along with the required data. Have searched for FM’s to do the same but havn’t found anything. Can you help me on this.

    Regards,
    Swapnil.

    (0) 
    1. Thomas Jung Post author
      >But reading excel file located on application server using open dataset in text mode is giving junk values along with the required data

      There is a fairly simple answer to that one – an Excel file is stored in Text! If you tried to open the same file on your client machine using notepad you would see the same junk values.  Excel is stored in binary format and before office 2007 – in a Microsoft Specific format.

      There are no function modules that I know of that can read the native Excel format from the server side.  There are a few that can read if via GUI calls, but they basically open Excel in Automation mode to do so.  If you want to read Excel files on the server side they would have to be converted within Excel to a Text based format first (text tab delimited is probably the easiest to work with – although XML is possible as well).  Now starting with Office 2007 the new native format for Excel is XML based.  You could at least upload it, but it can be a bit of a pain to parse still.

      (0) 
  5. Espen Leknes
    Hi,

    Another great blog from you. Would it be possible to make it available either as a transport, saplink file or some other quicker way to load it in?

    Regards,
    Espen Leknes

    (0) 

Leave a Reply