How can I load a flat file into a ZTABLE dynamically

I need to create a program which can Load a ZTABLE from a flat file structure (delimited and fixed options required).  We have many ZTables where this will be required so I was hoping to do it dynamically somehow.  Otherwise I will have to create one ABAP for every ZTable we have to load.
My Inputs should be
PARAMETERS:  p_ztable TYPE ddobjname,         "Z Table Name
             p_infile(132) LOWER CASE,        "File Name
             p_delim(1).                      "Delimiter
  I know that I can read the file by using gui_upload
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = c_infile
      has_field_separator     = p_delim
    TABLES
      data_tab                = indata
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
        OTHERS                  = 9.
I know that  I can split the contents of this file (if a delimiter is used).  However I will not know the actual field names of the table until runtime as to what to fields to split it into.  In the example below I have the actual table (t_rec) and each of the fields (pernr, lgart, etc) in the code but each table I
need to load will be different – it will have a different # of fields as well.
FORM read_data_pc.
  LOOP AT indata.
    PERFORM splitdata USING indata.
    APPEND t_rec.
    CLEAR t_rec.
  ENDLOOP.
ENDFORM.
FORM splitdata USING p_infile.
   SPLIT p_infile AT p_delim INTO
        t_rec-pernr                 "Employee #
        t_rec-lgart                 "Wage Type
        t_rec-begda                 "Effective date
        t_rec-endda.                 "End date
  ENDFORM.                       
Once I split the data into the fields then I can just look and insert the record.
Does anyone have any ideas?  Specific code examples would be great if you do.  Thx!!

Hi janice,,
Try this sample code where you can upload data from a flat file into the internal table.
REPORT  z_test.
TABLES: mara.
FIELD-SYMBOLS : <fs> .
DATA : fldname(50) TYPE c.
DATA : col TYPE i.
DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
DATA: progname LIKE sy-repid,
dynnum LIKE sy-dynnr.
DATA itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
DATA: BEGIN OF ZUPLOAD1_T OCCURS 0 ,
         matnr like mara-matnr,
         ersda like mara-ersda,
         ernam like mara-ernam,
         laeda like mara-laeda,
      END OF ZUPLOAD1_T.
*DATA: ZUPLOAD1_T LIKE mara OCCURS 0 WITH HEADER LINE.
DATA: wa_data LIKE TABLE OF  ZUPLOAD1_T WITH HEADER LINE.
selection-screen
SELECTION-SCREEN: BEGIN OF BLOCK blk WITH FRAME TITLE text-001.SELECTION-SCREEN : SKIP 1. PARAMETERS : p_file LIKE rlgrap-filename.SELECTION-SCREEN : SKIP 1.SELECTION-SCREEN : END OF BLOCK blk
. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
F4 Value for File
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'   EXPORTING
                      PROGRAM_NAME        = SYST-REPID
                      DYNPRO_NUMBER       = SYST-DYNNR
                      FIELD_NAME          = ' '
     static              = 'X'
                      MASK                = ' '
    CHANGING      file_name           = p_file   EXCEPTIONS     mask_too_long       = 1     OTHERS              = 2 
          .  IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' 
EXPORTING    filename                      = P_FILE   
i_begin_col                   = 1   
i_begin_row                   = 1   
i_end_col                     = 5   
i_end_row                     = 12507 
     tables   
   intern                        = ITAB
EXCEPTIONS  
        INCONSISTENT_PARAMETERS       = 1  
        UPLOAD_OLE                    = 2  
       OTHERS                        = 3.          .
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'GET_COMPONENT_LIST' 
EXPORTING  
    program          = SY-REPID   
    fieldname        = 'ZMARA' 
       tables   
       components       = CMP.
LOOP AT itab.    AT NEW row.     
IF sy-tabix = 1.        APPEND ZUPLOAD1_T.     
ENDIF.   
ENDAT.   
col = itab-col.   
READ TABLE cmp INDEX col.  
CONCATENATE 'ZUPLOAD1_T-' cmp-compname INTO fldname.  
ASSIGN (fldname) TO <fs>.  
<fs> = itab-COL.  
  APPEND ZUPLOAD1_T.  ENDLOOP.
DELETE ZUPLOAD1_T where matnr eq space.
LOOP AT ZUPLOAD1_T INTO wa_data.
insert mara from  wa_data .
    WRITE: / ZUPLOAD1_T-matnr, 20 ZUPLOAD1_T-ersda , 45 ZUPLOAD1_T-ernam, 55 ZUPLOAD1_T-laeda.
*HERE IAM JUST CHECKING I NEED TO UPDATE A ZTABLE
  ENDLOOP.
insert ZMARA FROM table itab ACCEPTING DUPLICATE KEYS.
I have tried it for mara.Please let me know whether it was helful.
Regards,
Kannan

Similar Messages

  • How can we load a flat file with very, very long lines into a table?

    Hello:
    We have to load a flat file with OWB. The problem is that each of the lines in the file might be up to 30.000 characters long (up to 1.000 units of information in each line, 30 characters long each)
    Of course, our mapping should insert these units of information as independent rows in a table (1.000 rows, in our example).
    We do not know how to go about it. We usually load flat files using table functions, but we am not sure that they will be able to cope with these huge lines. And how should we pivot those lines? Will the Pivot operator do the trick? Or maybe we should pivot those lines outside the database before loading them?
    We are a bit lost. Any suggestion would be appreciated.
    Regards
    Edited by: [email protected] on Oct 29, 2008 8:43 AM
    Edited by: [email protected] on Oct 29, 2008 8:44 AM

    Yes, well, we could define a 1.000 column external table, and then map those 1.000 columns to the Pivot operator… perhaps it would work. But we have been investigating a little bit, and we think that we have found a better solution: there is a unix utility called “fold”. This utility can split our 30.000 character lines in 1.000 lines, 30 characters long each: just what we needed. Then we can load the resulting file using an external table.
    We think this is a much better solution that handling 1.000 columns in the external table and in the Pivot operator.
    Thanks for your help.
    Regards
    Edited by: [email protected] on Oct 29, 2008 10:35 AM

  • How can I load a pdf-file into a byte[]?

    Hello,
    I would like to load a PDF-File into a byte-Array. How can I do this? The standard Streams shouldn't work because this can't be converted into characters. Can it? So, what does work?
    Any idea?
    Bye,
    Wolfang

    Why would someone not do:
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream is = new FileInputStream("foo.pdf");
    byte[] buf = new byte[4096];
    for(int len=-1;(len=is.read(buf))!=-1;)
            baos.write(buf,0,len);
    is.close();
    baos.flush();
    baos.close();
    buf = baos.toByteArray();  // Here are you bytes!You don't need to know the exact size, let ByteArrayOutputStream do it for you. Streams are generally for bytes, Readers/Writers generally for characters. Why exactly did you say: ``The standard Streams shouldn't work because this can't be converted into characters?''

  • How can I load a .TXT file into a dynamic text box?

    I am sure that many people know how to load a .txt file into
    a dynamic text box. But I do not. I want to be able to reference a
    txt file from the server into the text box. So that when I change
    the text file it changes in the flash movie without even editing
    the flash file itself. Thank you.

    http://www.oman3d.com/tutorials/flash/loading_external_text_bc/
    I think this is the simplest way to go :)

  • How can I load a .xlsx File into a SQL Server Table using a Foreach Loop Container in SSIS?

    I know I've REALLY struggled with this before. I just don't understand why this has to be soooooo difficult.
    I can very easily do a straight Data Pump of a .xlsX File into a SQL Server Table using a normal Excel Connection and a normal Excel Source...simply converting Unicode to DT_STR and then using an OLE DB Destination of the SQL Server Table.
    If I want to make the SSIS Package a little more flexible by allowing multiple .xlsX spreadsheets to be pumped in by using a Foreach Loop Container, the whole SSIS Package seems to go to hell in a hand basket. I simply do the following...
    Put the Data Flow Task within the Foreach Loop Container
    Add the Variable Mapping Variable User::FilePath that I defined as a Variable and a string within the FOreach Loop Container
    I change the Excel Connection and its Expression to be ExcelFilePath ==> @[User::FilePath]
    I then try and change the Excel Source and its Data Access Mode to Table Name or view name variable and provide the Variable Name User::FilePath
    And that's when I run into trouble...
    Exception from HRESULT: 0xC02020E8
    Error at Data Flow Task [Excel Source [56]]:SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occured. Error code: 0x80004005.
    Error at Data Flow Task [Excel Source [56]]: Opening a rowset for "...(the EXACT Path and .xlsx File Name)...". Check that the object exists in the database. (And I know it's there!!!)
    I don't understand by adding a Foreach Loop Container to try and make this as efficient as possible has caused such an error unless I'm overlooking something. I have even tried delaying my validations and that doesn't seem to help.
    I have looked hard in Google and even YouTube to try and find a solution for this but for the life of me I cannot seem to find anything on pumping a .xlsX file into SQL Server using a Foreach Loop Container.
    Can ANYONE please help me out here? I'm at the end of my rope trying to get this to work. I think the last time I was in this quandry, trying to pump a .xlsX File into a SQL Server Table using a Foreach Loop Container in SSIS, I actually wrote a C# Script
    to write the contents of the .xlsX File into a .csv File and then Actually used the .csv File to pump the data into a SQL Server Table.
    Thanks for your review and am hoping and praying for a reply and solution.

    Hi ITBobbyP,
    If I understand correctly, you want to load data from multiple sheets in an .xlsx file into a SQL Server table.
    If in this scenario, please refer to the following tips:
    The Foreach Loop container should be configured as shown below:
    Enumerator: Foreach ADO.NET Schema Rowset Enumerator
    Connection String: The OLE DB Connection String for the excel file.
    Schema: Tables.
    In the Variable Mapping, map the variable to Sheet_Name, and change the Index from 0 to 2.
    The connection string for Excel Connection Manager is the original one, we needn’t make any change.
    Change Table Name or View name to the variable Sheet_Name.
    If you want to load data from multiple sheets in multiple .xlsx files into a SQL Server table, please refer to following thread:
    http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How can I load a flat file using a different Work Station

    Hi Gurus,
    I'm having problems with loading Flat file in our Production Server when it comes to loading a file from another work station. The scenario is all the Info Packages needed are created in oour Dev Server. So the location of the flatfile is already define which is the developer's workstation. Now when the package is transported to the production server any changes to the package is not allowed inlcuding the location of the flatfile needed to be uploaded. Now my question is. is there a way that the location be changed in the production server without adding the package Z_BI because that will mean we can do changes in the production server. Thanks in Advance
    - Kit

    Directly you can not change the info package settings. You need do   change the status of Info package to changeable mode and then do necessary changes.
    RSA1 => Click on truck symbol (Object changeability) => select info package => right click => click on Switch changeability.
    Now do the changes to your Info Package.
    With Regards,
    Kishore.

  • Load a flat file into BW-BPS using SAP GUI

    Hi,
    We are using BW BPS 3.5 version, i implemented how to guide  " How to load a flat file into BW-BPS using SAP GUI" successfully without any errors.
    I inlcuded three infoobjects in the text file   costelemt, Posting period and amount. the same three infoobjects i inlcuded the file structure in the global data as specified in the how to document
    The flat file format is like this
    Costelmnt      Postingperiod         Amount   
    XXXXX             #      
    XXXXX             1                          100
    XXXXX             2                           800
    XXXXX             3                           700
    XXXXX             4                           500
    XXXXX             5                           300
    XXXXX             6                           200
    XXXXX             7                           270
    XXXXX             8                           120
    XXXXX             9                           145 
    XXXXX            10                           340
    XXXXX            11                           147
    XXXXX            12                           900 
    I successfully loaded above flat file in to BPS cube and it dispalyed in the layout also.
    But users are requesting to load  flatfile in the below format
    Costelmnt        Annual(PP=#)   Jan(PP=1)   Feb(PP=2) ........................................Dec(PP=12)  
    XXXXX              Blank                       100           800                                                   900
    Is it possible to load a flat file like this
    They wants load a single row instead of 13 rows for each costelement
    How to do this. Please suggest me if anybody accorss this requirment.
    In the infocube we have got only one Info object 0FISCPER3(Posting period) and one 0AMOUNT(Amount)
    do we need 13 Infobjects for each posting period and amount.
    Is there any possiblity we can implement any user exit which we use in BEX Quer's
    Please share your ideas on this.
    Thanks in advance
    Best regards
    SS

    Hi,
    There are 2 ways to do this.
    One is to change the structure of the cube to have 12 key figures for the 12 posting periods.
    Another way is to write an ABAP Function Module to fetch the values from each record based on the posting period and store it in the cube for the corresponding characteristic. This way, you dont have to change the structure of the cube.
    If this particular cube is not used anywhere else, I would suggest to change the structure itself.
    Hope this helps.

  • Parallel loading of flat files into BPC 7.0 NW - Help required

    Hi All
    Can I load multiple flat files in parallel into BPC using IMPORT process chain.
    If yes , How ?
    Regards
    AK

    Please import SAP Note [1507226|https://service.sap.com/sap/support/notes/1507226] titled "FileService should support running DM package simultaneously" which is contained in BPC 7.0 NW SP10 and BPC 7.5 NW SP05.
    Best regards,
    [Jeffrey Holdeman|http://wiki.sdn.sap.com/wiki/display/profile/Jeffrey+Holdeman]
    SAP Labs, LLC
    BusinessObjects Division
    Americas Applications Regional Implementation Group (RIG)

  • How can I load an external SWF into a movie clip that's inside other movie clip?

    Hi.
    I creating my first flash (actionscript 3.0) website but I'm
    stuck with a visual effect I want to create.
    I have a window on my website called contentWindow. Every
    time you click a button this window is supposed to leave the stage,
    load the requested content and return to the stage.
    The sliding window is a movie clip with 83 frames, 21 to
    enter the stage, 21 to leave the stage again, 20 for nothing (its
    just to simulate the loading time) and 21 to return to the stage.
    Now my goal is, when the user clicks on a navigation button,
    the window exits the stage, loads an external SWF with the content,
    and then returns to the stage.
    I've the "window" movie clip with an instance name of
    "contentWindow". Inside there is another movie clip with an
    instance name of "contentLoader". The content that the user
    requested should appear inside the "contentLoader".
    Now, when the contentWindow leaves the stage, I get this
    error message:
    quote:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference.
    at rwd_fla::MainTimeline/trigger()
    If I switch
    "contentWindow.contentLoader.addChild(navLoader);" for
    "contentWindow.addChild(navLoader);" it works fine, but the
    external SWF doesn't move with the window.
    How can I load an external SWF into a movie clip that's
    inside other movie clip?

    Hi,
    Recently, I have been putting together a flash presentation.
    And I am just wondering if the following might help you, in your
    communication with the said swf file:
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    onComplete);
    function onComplete(event:Event):void
    event.target.content.thinggy_mc.y -= 100;
    Not the best example, but this allows you to target a mc
    within an external swf file. I think if you look up this code, you
    will have an answer ;)
    Kind Regards,
    Boxing Boom

  • How do you load exs. format files into EXS 24 sampler?

    How do you load EXS24 format files into the EXS24 sampler? the only format I can load directly is aiff and wav. can't find any posts addressing this question? please help

    You don't load them in, you need to put them in:
    *System/users/your user name/library/application support/logic/Sampler instruments*
    Restart Logic if it's running, they will then appear in the EXS library.

  • How can I turn garage band files into mp3s?

    On my older Macbook i have always been able to easily turn my .band files into mp3s under the Advanced heading in itunes, but with my Macbook Pro, that is not an option. The option has become "Create AAC version". How can I turn my .band files into mp3s so that I can load them onto my web page and my students can pick them up as mp3s and put them on their devices?

    The option has become "Create AAC version".
    Your iTunes importing preferences are currently set to AAC. If you change your Importing preferences to mp3, the option should then become "Create mp3 version". See the following document for some more details:
    iTunes: How to convert a song to a different file format

  • How can i turn a photoshop file into a website with knowing code? can i upload Muse or DreamWeaver?

    How can i turn a photoshop file into a website with knowing code? can i upload Muse or DreamWeaver?
    I created a few images (pages for a site) on photoshop and want to turn them into HTML code for a website- Can i Just upload the file into one of these programs and make a file with the correct code imediatly?
    I was reading about using EDGE Reform but i did not understand if i can create the code with it, in the end it says it still needs to be sent to website developer after?

    You need to look at Dreamweaver as a code editor. You need to learn to create good, clean HTML code with style sheets to make websites with Dreamweaver.
    There are tutorials that will take you from a layered .PSD file to HTML. Here's a good one:
    http://net.tutsplus.com/tutorials/site-builds/from-psd-to-html-building-a-set-of-website-d esigns-step-by-step/
    Adobe's Muse is a semi-WYSIWYG website layout creator for small websites (1-5 pages). But there is no way you can go from a .PDS file to Muse, you have to start the site in Muse.
    I have seen a few Muse sites and they're OK, but there is some code that Muse creates that is kind of odd. If you want a good, clean website that will work for you or your business, Dreamweaver is the best choice. Alternatively, you could hire a pro.
    -Mark

  • How can I convert a pdf file into a usable xcel file

    how can I convert a pdf file into a xcel file. the pdf file file is layed out in colums, justified and separated in various types - i need to be able to set colum limits manualy,  thanks for your input/

    Without further information, I would suggest using either Acrobat or the Export PDF service.

  • How can i read local excel file into internal table in webdynpro for abap a

    Could someone tell me how How can i read local excel file into an internal table in webdynpro for abap application.
    thank u for your reply

    Deep,
    File manuplations...............................
    1. At the presentation level:
    ->GUI_UPLOAD
    ->GUI_DOWNLOAD
    ->CL_GUI_FRONTEND
    2. At the application server level:
    ->OPEN DATASET : open a file in the application server for reading or writing.
    ->READ DATASET : used to read from a file on the application server that has been opened for reading
    -> TRANSFER DATASET : writing data to a file.
    -> CLOSE DATASET : closes the file
    -> DELETE DATASET : delete file
    If file is on the local PC,use the function module GUI_UPLOAD to upload it into an internal table by passing the given parameters......
    call function 'GUI_UPLOAD'
    exporting
    filename = p_file
    filetype = 'ASC'
    has_field_separator = '#'
    tables
    data_tab = t_data
    p_file : excel file path.
    t_data : internal table
    <b>reward points if useful.</b>
    regards,
    Vinod Samuel.

  • How can I embed a pdf file into the body of an email?

    How can I embed a pdf file into the body of an email?

    The problem is defining what it even means to “embed” a PDF file in the body of an e-mail, especially if you are dealing with a multiple page PDF file.
    E-mail is either pure text, rich text (something akin to RTF in Word), or HTML. PDF is not compatible with any of these. Thus, to embed a PDF file, something has to be converted and that means the PDF would be converted to a less graphically rich raster format. But is that what you would really want?
    I think that the MacOS and iOS e-mail clients do under some circumstances place an attached PDF file within HTML segments and by clicking on same, you get the equivalent of extracting the full PDF file, but I have no real experience with that.
    Another alternative is HTML with a proxy image with a hyperlink to an external PDF file that is invoked when you click on the hyperlink.
    Perhaps you can explain what you are really trying to accomplish and what the recipient of such an e-mail's actual experience would be?
              - Dov

Maybe you are looking for

  • Poor Audio in project, when sent from imovie, using itunes

    Help! I have my music video all done. I clicked on "create idvd project". When I view my video in iDvd the audio sounds horrible. I am using a song I had in my iTunes library (straight from a cd). This happened for the first time the other day. I jus

  • Regarding BAPI Return Parameter.

    Hi All,           I want to create Bapi Return Message with Variable values like : ' Sales Order 1876738267 is not created, please try again.' and want to create a log of this after BAPI calling in Calling FM. How can I do this. Please guide me. Than

  • No audio from clips

    I just downloaded the Trial version of Adobe Premiere Pro CS5 and when I import a clip, i'm not getting any audio, not even anything showing up in the 'Audio Master Meter' I do get audio when I import a .mp3 file HELP pleeease, this is very irritatin

  • Removing Adobe Gamma on an eMac computer

    I have a Spyder2express and an eMac computer. I have read that before I profile my monitor using any monitor calibrator, I must first remove Adobe Gamma alias from start up folder. That this file must be deleted before using the monitor profiling sys

  • Won't Burn a Playlist!

    For some odd reason when I try to burn a playlist iTunes won't burn it. I get two errors one in the iTunes LCD window and a dialog box. Here are the links or images to what I am talking about. /___sbsstatic___/migration-images/170/1705916-1.jpg /___s