Question in ABAP syntax, read & insert data from internal table, while loop

Hi, SDN Fellow.
I am from Java background and learnt ABAP, I don't usually write much ABAP code.
I am trying to implement the following logic in a RFC now.
I have one z-custom database table, the structure as the following:
It has two columns, with these sample data.
Says datable table is ZEMPMGRTAB.
EmployeeID,ManagerID
user10,user1
user9,user1
user8,user1
user7,user2
user6,user2
user5,user2
user4,user2
user2,user1
The logic is this:
I have a input parameter, userid. I am using this parameter to have a select statement to query the record into export table,EXPTAB 'LIKE' table ZEMPMGRTAB.
SELECT * FROM  ZEMPMGRTAB
  into table EXPTAB
   WHERE  EMPLOYEEID  = USERID.
Say, my parameter value, USERID ='USER4'.
Referring to the sample data above, I can get the record of this in my EXPTAB,
EmployeeID,ManagerID
user4,user2
Now, I want to iterately use the EXPTABLE-ManagerID
as the USERID input in SELECT statement, until it has no return result. Then, insert the new records in
EXPTAB.
In above new loop case, we will get this table content in EXPTAB,
EmployeeID,ManagerID
user4,user2
user2,user1
I kind of think of the pseudocode logic as below:
(These may not be a valid ABAP code, so I need help to convert/correct them)
DATA:
IWA TYEP ZZEMPMGRTAB,
ITAB
HASHED TABLE OF ZZEMPMGRTAB
WITH UNIQUE KEY EMPLOYEEID.
SELECT * FROM  ZEMPMGRTAB
  into table ITAB
   WHERE  EMPLOYEEID  = USERID.
*Question 1: I cannot insert a internal table to export table, it is *incompatible type, what is the alternative way fo this?
*Question 2: How can I access thedata of the internal table like this,ITAB-MANAGERID? As if I can, I would do this:
* IWA-EMPLOYEEE = ITAB-EMPLOYEEID. IWA-MANAGERID = IWA-MANAGERID. INSERT IWA INTO TABLE EXPTAB.
* Question 3: Is the 'NE NULL' - 'not equal to NULL' is right syntax?
IF ITAB NE NULL.
INSERT ITAB INTO EXPTAB.
ENDIF
* Question 4: Is my WHILE loop setup right here? And are the syntax right?
WHILE ITAB NE NULL.
SELECT * FROM  ZEMPMGRTAB
  into table ITAB
   WHERE  EMPLOYEEID  = ITAB-MANAGERID.
IF ITAB NE NULL.
INSERT ITAB INTO EXPTAB.
ENDIF
REFRESH ITAB.
ENDWHILE.
Assume all the syntax and logic are right, I should get this result:
EmployeeID,ManagerID
user4,user2
user2,user1
If I have a new entry in datable table,ZEMPMGRTAB like this:
user1,user0
My pseudocode logic will get this result:
EmployeeID,ManagerID
user4,user2
user2,user1
user1,user0
I truly appreciate if you can help me to validate the above syntax and pseudocode logic.
Thanks in advance.
KC

Hi,
FUNCTION ZGETSOMEINFO3.
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(USERID) TYPE  AWTXT
*"     VALUE(FMTYPEID) TYPE  AWTXT
*"  EXPORTING
*"     VALUE(RETURN) TYPE  BAPIRETURN
*"  TABLES
*"      APPROVERT STRUCTURE  ZTAB_FMAPPROVER
*"      ACTOWNERT STRUCTURE  ZTAB_FMACTOWNER
DATA: T_RESULT TYPE STANDARD TABLE OF ZTAB_FMAPPROVER.
**Question 1: For this line, I got an error says "Program ''USERID" *not found. Is the syntax right, as the USERID is a parameter for the function.
perform add_line(USERID).
  ENDFUNCTION.
form add_line using i_user type ZTAB_FMAPPROVER.EMPLOYEEID
                    changing T_RESULT TYPE ZTAB_FMAPPROVER.
data: ls_row type ZTAB_FMAPPROVER.
* Get record for i_user
select single * into ls_row from ZTAB_FMAPPROVER
where EmployeeID = i_user.
if sy-subrc NE 0.
* Do nothing, there is not manager for this employee
else.
* Store result
QUESTION 2: I am still got stuck on this line of code. It still *says that "T_RESULT" is not an internal table "OCCURS n" *specification is missing. I thought the line: "T_RESULT TYPE *ZTAB_FMAPPROVER" means declare internal table, T_RESULT as type of ZTAB_FMAPPROVER". Am I understand it wrongly?
append ls_row to t_result.
* Call recursion
perform add_line using ls_row-ManagerID
                          changing t_result.
endif.
endform.
Thanks,
KC

Similar Messages

  • [ECC6] Inserting data from internal table (deep structure) into db table

    Hi experts,
    I have a problem when inserting data from IT using deep structure into a database table. Please help:
    I have one database table with 2 columns ZTest (col1, col2). Col1 is key.
    In my program I have a deep structure t_screen using table type lvc_t_scol:
    In 4.6c systems, the INSERT statement works well but it does not work in ECC6 systems.
    DATA: BEGIN OF t_screen OCCURS 0,
            rec_count(3) TYPE n,
            col1 LIKE ZTest-col1,
            col2 LIKE ZTest-col2.
    DATA: ct TYPE lvc_t_scol.
    DATA: END   OF t_screen.
    t_screen-col1 = 'test1'.
    t_screen-col2 = 'test1'.
    APPEND t_screen.
    t_screen-col1 = 'test2'.
    t_screen-col2 = 'test2'.
    APPEND t_screen.
    INSERT ZTest FROM TABLE t_screen ACCEPTING DUPLICATE KEYS.
    Currently I have an idea using a temporary internal table with the same structure as ZTest. Use MOVE-CORRESPONDING statement to move data from t_screen table to temporary table before inserting --> It worked. But do you have any ideas without using temporary table?

    Hi
    There are a large number of stataments couldn't be supported in unicode system and so it doesn't allow to do it in ECC 6.
    U need to delete the deep structure from your defination:
    DATA: BEGIN OF t_screen OCCURS 0,
            rec_count(3) TYPE n,
            col1 LIKE ZTest-col1,
            col2 LIKE ZTest-col2.
    DATA: ct TYPE lvc_t_scol. "<-------- Error is here
    DATA: END   OF t_screen.
    So u need to use a structure like this to update your table:
    DATA: BEGIN OF T_ZTEST OCCURS 0,
            rec_count(3) TYPE n,
            col1 LIKE ZTest-col1,
            col2 LIKE ZTest-col2.
    DATA: END   OFT_ZTEST.
    Max

  • Insert data from internal table to ztable.

    Hello Expert,
    I have a ztable with a primary key, now i want to pass my data from the internal table to the ztable . I am using modify option to
    pass the data to the ztable but the problem is if the primary key value is same then its update the first record rather add one row in the zrable .But i want to push all the data what are available in the internal table though all the data are same. I even tried with Insert statement but its seems it doesnot work.
    Can you please advice me the right approach.
    Thanks.
    Satya

    Hi,
    It is all about the primary key fields of the database table.
    Example:
    You have a db table with following fields
    MANDT (primary key field)
    BUKRS (primary key field)
    BELNR (primary key field)
    GJAHR
    VBELN
    and it with same fields.
    MANDT BUKRS BELNR GJAHR VBELN
    120 0010 160000 2008 450000
    120 0010 160000 2007 450003
    120 0020 160000 2008 450000
    200 0010 160001 2008 450001
    200 0010 160001 2007 450001
    If you use INSERT statement, only 3 of these will be inserted into the database table, why?
    Because: Each database table must include one or a very small group of key fields that uniquely identify each table line by its value. These fields are known as the primary keys of the table.
    And as lines 1 and 2 / 4 and 5 have the same MANDT BUKRS and BELNR only one will be inserted into the table.
    If the database table is your own one, you will need to modify it so that it would work.
    Thankyou.
    Regards,
    Dhanalakshmi L

  • How to send data from internal table to the shared folder in ABAP

    Hi experts,
             My requirement is to transfer data from a file to shared folder. i just did reading data from a file to a internal table. Now i want to send this internal table data into a shared folder which is  "
    xxx\y\z....".
    I do not have any idea on how to send data from internal table to the shared folder path.
    can anybody please help me out how to do this?
    Thanks & Regards
    Sireesha.

    Where that folder is located, its on presentation server i.e. desktop or application server.
    If its on presentation server, use FM GUI_UPLOAD.
    If its on application server, then use DATASET functions. Have a look at below link.
    [File Handling in ABAP|http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3ca6358411d1829f0000e829fbfe/frameset.htm]
    I hope it helps.
    Thanks,
    Vibha
    Please mark all the useful answers

  • Reading Data from Internal Table

    Hi,
    Can anyone please tell me how to read data from Internal Tables in the Event Handler without using the Select statement OnInitialization?
    Thanks,
    Gaurav

    Hi Siddhartha,
    Can you tell me the problem in my code. I tried to work on the way you suggested. Though I have not finished with the coding, I just wanted to know whether I am going in the direction or not.
    I have declared the the structure in Type Defination as
    TYPES: BEGIN OF TEST_STRUC,
             BEGDA TYPE BEGDA,
             ENDDA TYPE ENDDA,
           END OF TEST_STRUC.
    TYPES: TEST_TAB_TYPE TYPE TABLE OF TEST_STRUC.
    In the Event Handler, I have added the following code on OnInputProcessing:
    event handler for checking and processing user input and
    for defining navigation
    DATA TEST_INFO LIKE LINE OF TEST_TAB.
    DATA: MYTAB6 TYPE TABLE OF PA0006,
          MYTAB6_WA LIKE LINE OF MYTAB6.
    REFRESH TEST_TAB.
    CLEAR TEST_INFO.
    MYTAB6_WA-BEGDA = REQUEST->GET_FORM_FIELD( STARTDATE ).
    MYTAB6_WA-ENDDA = REQUEST->GET_FORM_FIELD( ENDDATE ).
    IF EVENT->NAME EQ 'button'
       AND EVENT->SERVER_EVENT EQ 'click'.
      LOOP AT MYTAB6 INTO MYTAB6_WA.
        TEST_INFO-BEGDA = MYTAB6_WA-BEGDA.
        TEST_INFO-ENDDA = MYTAB6_WA-ENDDA.
      ENDLOOP.
      APPEND TEST_INFO TO TEST_TAB.
      CLEAR TEST_INFO.
      NAVIGATION->SET_PARAMETER( NAME = 'test_tab'
      VALUE = 'begda' ).
      NAVIGATION->SET_PARAMETER( NAME = 'test_tab'
      VALUE = 'endda' ).
      NAVIGATION->GOTO_PAGE( 'MyBSP2.htm').
    ENDIF.
    P.S. MyBSP2.htm is my next page.
    Thanks,
    Gaurav

  • Craete a simple abap object to select data from a table and display

    Hi,
    I know the concept of abap objects but i never worked on it,
    can any one give me simple example of how to create an abap object to display data from mara table.also please send me documents or info regd ABAP OBJECTS.
    I want to write a simple report in terms of abap object
    Regards,
    Sowjanya

    hi,
    Here is hte sample program in se38.
    REPORT ZFGLI00003
    *-- Include for data declarations and performs
    include ZFGLI00003_f01.
    *--Include for Classes and their Implementation
    include ZFGLI00003_cl.
    *                selection-screen                                      *
    *-- Selection Values : Block1
    selection-screen begin of block b1 with frame title text-001.
    *--         Ledger
    parameters: p_rldnr  like zzprodnt-rldnr default 'NP'.
    *--         Fiscal year
    parameters: p_ryear  like zzprodnt-ryear.
    *--         Period(month)
    parameters: p_rpmax  like zzprodnt-rpmax.
    selection-screen end of block b1.
    *-- Selection Values : Block2
    selection-screen begin of block b2 with frame title text-002.
    *--              Company ID's
    select-options : s_glcomp  for ZZPRODNT-ROBUKRS .
    *--              Profit Center
    select-options : s_prctr   for ZZPRODNT-RPRCTR .
    *--              Product Assignment
    select-options : s_prasn   for ZZPRODNT-RZZWWZ01 .
    *--              Corporate Brand
    select-options : s_crpbd   for ZZPRODNT-RZZWWZ05 .
    selection-screen end of block b2.
    *-- Selection Values : Block3  Download Options
    selection-screen begin of block b3 with frame title text-003.
    parameters : p_local radiobutton group 1,
                 p_unix  radiobutton group 1,
                 p_path  like rlgrap-filename obligatory
                         default 'C:P20Z_Formatted.txt'(009).
    selection-screen end of block b3.
    *            At Selection-Selection on value-request  for file path    *
    at selection-screen on value-request for p_path.
      if p_unix <> 'X'.
    *-- Getting F4 help for output file
        perform get_filename changing p_path.
      else.
        message i999(zi) with
              'Sorry !! Function not available for UNIX file.'(i01).
      endif.
    *-- At selection screen validations
    at selection-screen on p_path.
      if p_unix <> 'X'.
    *-- Validate local file
        if p_path+1(2) <> ':'.
          message e999(zi) with 'Invalid file path'(006).
        endif.
      else.
    *-- Validate unix file
        if p_path+0(1) <> '/'.
          message e999(zi) with 'Invalid file path'(006).
        endif.
      endif.
    *                   Initialization                                    *
    initialization.
    *-- Initialize the period
      perform init_period changing p_rpmax p_ryear.
    *                    start-of-selection                               *
    start-of-selection.
      data : o_tm1_intf type ref to lcl_tm1_intf.
      create object o_tm1_intf.
    *-- Extract the data from ZZPRODNT
      call method o_tm1_intf->get_data exporting e_rldnr  = p_rldnr
                                                 e_ryear  = p_ryear
                                                 e_rpmax  = p_rpmax
                                                 e_glcomp = s_glcomp[]
                                                 e_prctr  = s_prctr[]
                                                 e_prasn  = s_prasn[]
                                                 e_crpbd  = s_crpbd[]
                                       importing i_subrc  = v_subrc.
    *   INCLUDE ZFGLI00003_CL                                              *
    *       CLASS lcl_tm1_intf IMPLEMENTATION
    class lcl_tm1_intf definition.
      public section.
    *-- Data Declaration
        data  : lv_date     type sy-datum,       "Date
                lv_time     type sy-uzeit,       "Time
                lv_count    type i,              "Count for total records
                lv_acsline  type zfgl014-acsline,"ACS line code
                lv_amt_curr type zzprodnt-kslvt, "current month amount
                lv_amt_ytd  type zzprodnt-kslvt, "YTD Amount
                lv_check,                        "check if any record is
                                                 "downloaded
                lv_msg(100),                     "message
                lv_count_s(5)  ,                 "Count for total(char)
                lv_amt_curr_s(23),               "Current month amount(char)
                lv_amt_ytd_s(23),                "YTD Amount(char)
                lv_ksl_pd(17),                   "KSLxx
                lv_period(2) type n.             "month(period)
    *-- Types Declaration
        types : ty_rldnr type zzprodnt-rldnr,    "Type for Ledger
                ty_ryear type zzprodnt-ryear,    "Type for Fiscal Year
                ty_rpmax type zzprodnt-rpmax,    "Type for Period
                ty_glcomp type range of char4,   "Type for company selection
                ty_prctr type range of char10,   "Type for profit center sel
                ty_prasn type range of char6,    "Type for prod assignmt sel
                ty_crpbd type range of char4,    "Type for Corp Brand sel
                begin of ty_file,                "Type for File
                  line(150),
                end of ty_file,
                begin of ty_ZZPRODNT,            "Type-ledger summary table
                  company       type OBUKR,      "Company
                  gl_acct       type RACCT,      "GL Account
                  cst_ctr       type KOSTL,      "Cost Center
                  prt_ctr       type PRCTR,      "Profit Center
                  rfarea        type FKBER,      "Functional Area
                  wbs_ele       type PS_POSID,   "WBS Element
                  prd_***       type RKEG_WWZ01, "Product Assignment
                  corp_bd       type RKEG_WWZ05, "Corporate Brand
                  ksl01         type KSLXX9,     "Total of transactions - 01
                  ksl02         type KSLXX9,     "Total of transactions - 02
                  ksl03         type KSLXX9,     "Total of transactions - 03
                  ksl04         type KSLXX9,     "Total of transactions - 04
                  ksl05         type KSLXX9,     "Total of transactions - 05
                  ksl06         type KSLXX9,     "Total of transactions - 06
                  ksl07         type KSLXX9,     "Total of transactions - 07
                  ksl08         type KSLXX9,     "Total of transactions - 08
                  ksl09         type KSLXX9,     "Total of transactions - 09
                  ksl10         type KSLXX9,     "Total of transactions - 10
                  ksl11         type KSLXX9,     "Total of transactions - 11
                  ksl12         type KSLXX9,     "Total of transactions - 12
                  ksl13         type KSLXX9,     "Total of transactions - 13
                  ksl14         type KSLXX9,     "Total of transactions - 14
                  ksl15         type KSLXX9,     "Total of transactions - 15
                  ksl16         type KSLXX9,     "Total of transactions - 16
                end of ty_ZZPRODNT.
    *-- Structure Declaration
    *           Structure for final file
        data  : x_file         type ty_file,
    *           Structure for Product Ledger Summary table
                x_ZZPRODNT     type ty_ZZPRODNT,
    *           Structure for Functional Area to ACS line mapping
                x_zfgl014      type zfgl014.
    *-- Internal Table Declaration
    *           Table for records of Product Ledger Summary table
        data  : it_ZZPRODNT     type table of ty_ZZPRODNT,
    *           Table for final file
                it_file         type table of ty_file,
    *           Table for Functional Area to ACS line mapping
                it_zfgl014      type table of zfgl014.
    *-- Method Declaration.
        methods : get_data      importing e_rldnr  type ty_rldnr
                                          e_ryear  type ty_ryear
                                          e_rpmax  type ty_rpmax
                                          e_glcomp type ty_glcomp
                                          e_prctr  type ty_prctr
                                          e_prasn  type ty_prasn
                                          e_crpbd  type ty_crpbd
                                exporting i_subrc type sy-subrc.
    endclass.                    "lcl_tm1_intf DEFINITION
    *       CLASS lcl_tm1_intf IMPLEMENTATION
    class lcl_tm1_intf implementation.
    *-- Method get_data selects the North American Product Ledger Summary
    *   table data and then maps the Functional Area to ACS line to get
    *   the ACS line code
      method get_data.
    *-- Local Variable
        DATA: L_ZZPRODNT TYPE TY_ZZPRODNT.
    *-- Get the data from North American Product Ledger Summary table
        select robukrs
               racct
               rcntr
               rprctr
               rfarea
               rzzwbs_el
               rzzwwz01
               rzzwwz05
               ksl01
               ksl02
               ksl03
               ksl04
               ksl05
               ksl06
               ksl07
               ksl08
               ksl09
               ksl10
               ksl11
               ksl12
               ksl13
               ksl14
               ksl15
               ksl16
          from zzprodnt
          into table it_ZZPRODNT
         where rldnr    = e_rldnr
           and ryear    = e_ryear
           and rpmax    = e_rpmax
           and ROBUKRS  in e_glcomp
           and RPRCTR   in e_prctr
           and RZZWWZ01 in e_prasn
           and RZZWWZ05 in e_crpbd.
        if sy-subrc = 0.
          loop at it_ZZPRODNT into l_zzprodnt.
            condense l_ZZPRODNT-rfarea no-gaps.
            if l_ZZPRODNT-rfarea is initial.
              delete it_ZZPRODNT.
            endif.
          endloop.
    *-- Get the Functional Area to ACS line code mapping data
          select *
            from zfgl014
            into table it_zfgl014
             for all entries in it_ZZPRODNT
           where fkber = it_ZZPRODNT-rfarea .
          if sy-subrc = 0.
          endif.
        endif.
        i_subrc = sy-subrc.
      endmethod.                    "get_data
    endclass.                    "lcl_tm1_intf IMPLEMENTATION
    *   INCLUDE ZFGLI00003_F01                                             *
    *                             Table
    tables : zzprodnt.
    *                          Data Declaration
    data : v_subrc type sy-subrc.
    *&      Form  get_filename
    *  Description : This subroutine is used for F4 Prompting
    form get_filename changing p_path like rlgrap-filename.
    *-- Local variables
      data : lv_file  like ibipparms-path, "Local file for upload/download
             lv_repid like syst-cprog,     "ABAP program, caller in external
                                           "procedures
             lv_dynnr type syst-dynnr.     "Current screen No
      lv_repid = syst-cprog.
      lv_dynnr = syst-dynnr.
    *-- Function module used for F4 help
      call function 'F4_FILENAME'
           exporting
                program_name  = lv_repid
                dynpro_number = lv_dynnr
           importing
                file_name     = lv_file.
      move lv_file to p_path.
    endform.                    " get_filename
    *&      Form  init_period
    FORM init_period changing p_rpmax p_ryear.
      if sy-datum+4(2) = 01.
        p_rpmax = 12.
        p_ryear = sy-datum+0(4) - 1.
      else.
        p_rpmax = sy-datum+4(2) - 1.
        p_ryear = sy-datum+0(4).
      endif.
    ENDFORM.                    " init_period
    Hope this helps.
    Regards,
    Richa

  • Downloading data from internal table to xls file leading zeros are not disp

    Hai abap gurus,
    when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
    Ex:
    <b>ECC Code.</b>
    045234
      88567
    098456 
    but output is giving like this:
    45234
    88567
    98456
    how to get the actual values.....
    plz help me in this matter.

    Dear Kiran,
    Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
    Then use the function module to download the content of the internal table to the excel file.
    Regards,
    Abir
    Don't forget to Reward Points  *

  • Convert data from internal table to XML file.

    Hi All,
    I am selecting data from database into one internal table.
    Now I want to convert data from internal table to xml file format and save in to my desktop. Please suggest me how I can achieve my requirement.
    Kindly reply me ASAP.

    Use this FM. SAP_CONVERT_TO_XML_FORMAT
    Check this link too -
    Re: Data Export in XML format
    XML files from ABAP programs

  • Inserting records from internal table to database table

    Hi all,
    i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
    1) insert one by one record from internal table
    loop at itab.
    insert ztable from wa.
    endloop.
    2) insert total records at a time
    INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or let me know if any other statement is there with high performance.
    i internal table contains nearly 40000 records.
    thanks.

    Hi,
    Insert the entire table at atime rather than a record so as to increase the performance.
    you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or
    MODIFY ZPRODUCT FROM TABLE GI_AFPO.
    Regards,
    Raj.

  • Hash lookup or Binary search to fetch data from internal table

    Hi All,
    I want to know Which is faster, Hash lookup or Binary search to fetch data from internal tables?
    Thanks,
    Mahesh
    Moderator Message: Duplicate post
    Edited by: kishan P on Oct 14, 2010 4:22 PM

    type mod* .the the sign would change to pattern.try and see.i checked.reward if works.

  • Gui_download for transferring the data from internal table to excel sheet.

    hi all,
    i am using gui_download for transferring the data from internal table to excel sheet.
    I have a internal table with 3 columns col1,col2,col3 and I am getting the file at the specified path,but my problem is that,in the excel sheet(path specified) all the 3 columns values are printed in one column.Please help me.
    Thanks in advance.

    Hi Venkata,
    plz use FM 'SAP_CONVERT_TO_XLS_FORMAT' :
      call function 'SAP_CONVERT_TO_XLS_FORMAT'
        exporting
    *   I_FIELD_SEPERATOR          =
    *   I_LINE_HEADER              =
          i_filename                 = p_file
    *   I_APPL_KEEP                = ' '
        tables
          i_tab_sap_data             = t_mbew
    * CHANGING
    *   I_TAB_CONVERTED_DATA       =
    * EXCEPTIONS
    *   CONVERSION_FAILED          = 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.
    Hope this helps,
    Erwan

  • Download data from internal table to flat file.

    I need to download the data from Internal table to Flat file. can any one suggest how to do it? i suppose WS_Download OR GUI_DOWNLOAD.
    but if it is please guide me how to use this.
    is thre any other F.M. please provide the information.
    Thanks in advance

    Hi,
    Try this,
    * File download, uses older techniques but achieves a perfectly
    * acceptable solution which also allows the user to append data to
    * an existing file.
      PARAMETERS: p_file like rlgrap-filename.
    * Internal table to store export data  
      DATA: begin of it_excelfile occurs 0,
       row(500) type c,
       end of it_excelfile.
      DATA: rc TYPE sy-ucomm,
            ld_answer TYPE c.
      CALL FUNCTION 'WS_QUERY'
           EXPORTING
                query    = 'FE'  "File Exist?
                filename = p_file
           IMPORTING
                return   = rc.
      IF rc NE 0.                       "If File alread exists
        CALL FUNCTION 'POPUP_TO_CONFIRM'
          EXPORTING
    *          TITLEBAR              = ' '
    *          DIAGNOSE_OBJECT       = ' '
               text_question         = 'File Already exists!!'
               text_button_1         = 'Replace'
    *          ICON_BUTTON_1         = ' '
               text_button_2         = 'New name'
    *          ICON_BUTTON_2         = ' '
    *          DEFAULT_BUTTON        = '1'
    *          DISPLAY_CANCEL_BUTTON = 'X'
    *          USERDEFINED_F1_HELP   = ' '
    *          START_COLUMN          = 25
    *          START_ROW             = 6
    *          POPUP_TYPE            =
          IMPORTING
               answer                = ld_answer
    *     TABLES
    *         PARAMETER              =
          EXCEPTIONS
              text_not_found         = 1
              OTHERS                 = 2.
    * Option 1: Overwrite
        IF ld_answer EQ '1'.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
    *            BIN_FILESIZE            =
                 filename                = p_file        "File Name
                 filetype                = 'ASC'
    *       IMPORTING
    *            FILELENGTH              =
            TABLES
                data_tab                = it_excelfile   "Data table
            EXCEPTIONS
                file_write_error        = 1
                no_batch                = 2
                gui_refuse_filetransfer = 3
                invalid_type            = 4
                OTHERS                  = 5.
          IF sy-subrc <> 0.
            MESSAGE i003(zp) WITH
                     'There was an error during Excel file creation'(200).
            exit. "Causes short dump if removed and excel document was open 
          ENDIF.
    * Option 2: New name.
        ELSEIF ld_answer EQ '2'.
          CALL FUNCTION 'DOWNLOAD'
            EXPORTING
                 filename            = p_file          "File name
                 filetype            = 'ASC'           "File type
    *             col_select          = 'X'            "COL_SELECT
    *             col_selectmask      = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
    *                                                   "COL_SELECTMASK
                 filetype_no_show    = 'X'     "Show file type selection?
    *       IMPORTING
    *             act_filename        = filename_dat
            TABLES
                 data_tab            = it_excelfile    "Data table
    *            fieldnames          =
            EXCEPTIONS
                 file_open_error     = 01
                 file_write_error    = 02
                 invalid_filesize    = 03
                 invalid_table_width = 04
                 invalid_type        = 05
                 no_batch            = 06
                 unknown_error       = 07.
        ENDIF.
      ELSE.                               "File does not alread exist.
        CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
    *          BIN_FILESIZE            =
               filename                = p_file         "File name
               filetype                = 'ASC'          "File type
    *     IMPORTING
    *          FILELENGTH              =
          TABLES
               data_tab                = it_excelfile   "Data table
          EXCEPTIONS
               file_write_error        = 1
               no_batch                = 2
               gui_refuse_filetransfer = 3
               invalid_type            = 4
               OTHERS                  = 5.
        IF sy-subrc <> 0.
          MESSAGE i003(zp) WITH
                   'There was an error during Excel file creation'(200).
          exit. "Causes short dump if removed and excel document was open 
        ENDIF.
      ENDIF.
    Regards,
    Raghav

  • Upload data from Internal table to text file with  '~' separator

    can anyone help me to download data from internal table to flat file with  ''  separator. GUI_DOWNLOAD is not working in my case ....like for ''  separator

    Here it is
    REPORT  zkb_test1.
    TYPE-POOLS: truxs.
    DATA: i_scarr TYPE TABLE OF scarr,
    i_conv_data TYPE truxs_t_text_data.
    SELECT * FROM scarr INTO TABLE i_scarr.
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
      EXPORTING
        i_field_seperator    = '~'
      TABLES
        i_tab_sap_data       = i_scarr
      CHANGING
        i_tab_converted_data = i_conv_data
      EXCEPTIONS
        conversion_failed    = 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.
    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                = 'C:\Test1.txt'
        filetype                = 'ASC'
      CHANGING
        data_tab                = i_conv_data
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        not_supported_by_gui    = 22
        error_no_gui            = 23
        OTHERS                  = 24.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Regards
    Kathirvel

  • Insert data from one table to another.

    I have two tables - T1 & T2.
    T1 has columns A1,A2,A3,A4 (A1 & A2 are the primary keys)
    T2 has columns B1,B2,B3,B4 (B1 & B2 are the primary keys)
    I need to insert records from T1 to T2 with the conditions,
    - A1,A2,A3 will have the same record for the multiple records of A4.
    This is what I tried and got the error:-
    SQL> INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
    2 SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
    3 FROM tender_opening_supp, cs_rate
    4 WHERE tos_enq_no = '7211233E' AND
    5 tos_supp_code = csr_scd AND
    6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
    7 csr_set_rank IS NOT NULL;
    INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
    ERROR at line 1:
    ORA-00001: unique constraint (DPURC.NEGO_PROP_SUPP_PK) violated
    You could understand that T1 consists (data from 'tender_opening_supp' & cs_rate), while T2 is nego_prop_supp.
    Pls. get me the soution for thi problem!!

    then this query
    SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
    3 FROM tender_opening_supp, cs_rate
    4 WHERE tos_enq_no = '7211233E' AND
    5 tos_supp_code = csr_scd AND
    6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
    7 csr_set_rank IS NOT NULL
    8 and not exists (select nps_supp_cd from nego_prop_supp,tender_opening_supp where tos_supp_code
    = nps_supp_cd) ;
    have more than one tos_supp_code (the same any times) with any different value from tos_enq_no, tos_bid_seal_condn, csr_set_rank
    then anything is wrong or your key(on nego_prop_supp ) or the query retrieve rows that you not want
    the join is ok?
    why this join retrieve more than one value with the key of the other table? Do you need to filter any more? are you missing a filter?

  • Insert data from a table

    <p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">Hi,</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">I would
    like to insert data in a table. The data are selected by a query. I wrote this
    code but there is an error :</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <font SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New">
    <font SIZE="2" COLOR="#0000f0">PROCEDURE</font><font SIZE="2"> </font>
    <font SIZE="2" COLOR="#808000">GLMASTER_SAVE</font><font SIZE="2"> </font>
    </font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">IS</font></p>
    </font><font SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font SIZE="2" COLOR="#0000f0" face="Courier New">BEGIN</p>
    </font>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
    <font SIZE="2" COLOR="#0000f0">  INSERT</font><font SIZE="2"> </font>
    <font SIZE="2" COLOR="#0000f0">INTO</font><font SIZE="2"> </font></font>
    <font SIZE="2" COLOR="#808000"><font face="Courier New">GLMASTER_SAVE</font></p>
    </font>
    <p style="margin-top: 0; margin-bottom: 0">
    <font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2">COMPANY</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    ACCT_UNIT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2"> ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    SUB_ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    ACTIVE_STATUS</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">)</font></p>
    </font><font SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    VALUES</p>
    </font><font SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">(SELECT</font><font SIZE="2">
    </font><font SIZE="2">COMPANY</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    </font><font SIZE="2">ACCT_UNIT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    </font><font SIZE="2">ACCOUNT</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">,</font></font><font SIZE="2"><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font></font><font face="Courier New"><font SIZE="2">SUB_ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    </font></font><font SIZE="2"><font face="Courier New">ACTIVE_STATUS</font></p>
    <p style="margin-top: 0; margin-bottom: 0">
    <font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">FROM</font><font SIZE="2">
    </font></font><font SIZE="2"><font face="Courier New">GLMASTER</font></p>
    <p style="margin-top: 0; margin-bottom: 0">
    <font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font><font SIZE="2" COLOR="#0000f0" face="Courier New"> </font></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">ORDER</font><font SIZE="2">
    </font><font SIZE="2" COLOR="#0000f0">BY</font><font SIZE="2"> </font>
    <font SIZE="2">COMPANY</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    </font><font SIZE="2">ACCT_UNIT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    </font><font SIZE="2">ACCOUNT</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2">
    </font><font SIZE="2">SUB_ACCOUNT</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">);</font></p>
    </font><font SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0">
    <font SIZE="2" COLOR="#0000f0" face="Courier New"> </font><font SIZE="2" COLOR="#0000f0" face="Courier New">
    </font></font><font SIZE="2" COLOR="#0000f0" face="Courier New">COMMIT;</p>
    </font><font SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font SIZE="2" COLOR="#0000f0" face="Courier New">END;</p>
    </font>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">Do you
    know why ?</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Arial" size="2">Thank you
    for your help.</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0">
    <font color="#008080" face="Arial" size="2"><i><b>Patrick</b></i></font></p>

    try this:
      INSERT INTO GLMASTER_SAVE
        (COMPANY, ACCT_UNIT, ACCOUNT, SUB_ACCOUNT, ACTIVE_STATUS)
      SELECT COMPANY, ACCT_UNIT, ACCOUNT, SUB_ACCOUNT, ACTIVE_STATUS
           FROM GLMASTER
       ORDER BY COMPANY, ACCT_UNIT, ACCOUNT, SUB_ACCOUNT;you need not to include the VALUES
    Message was edited by:
    Warren Tolentino
    sorry ps while posting this you had already posted your solution.

Maybe you are looking for

  • CUP 5.3: risk analysis in workflow impossible due to web service performance?

    Hello experts, We are facing a huge challenge within a AC 5.3 implementation. Here, AC has been used successfully with CUP and RAR for quite some time now. However, the RAR analysis has not yet been integrated into the CUP workflow. We would like to

  • Is there any way to log in to a windows domain from iPad?

    My school has both a windows network and iPads.  Until recently all worked fine except there has now been a county-wide internet policy change.  To connect from the school network to the internet there is now a lightspeed gateway.  Now this is fine o

  • Users are unable to see their own profile photo although everyone else can see it in Lync 2013 client

    We have Lync 2013, Exchange 2010 and several AD servers in mixed mode 2003/2008. All user are unable to see their own profile photo either in the main Lync window, in the settings or in a chat although other user can see that their photo is there and

  • Disk size problem

    Hi all; I have wierd problem, and i dont know why its behave like that. Df -h gives me: Filesystem Size Used Avail Use% Mounted on /dev/cciss/c0d0p2 15G 8.5G 5.3G 62% / /dev/cciss/c0d0p1 99M 12M 82M 13% /boot none 4.0G 0 4.0G 0% /dev/shm /dev/cciss/c

  • Change subject on BIP Email

    Hi all, did anyone of you know how to change the subject of the Email which is send by BIP? The default is similar to "FW: EnterpriseOne Report Definition Output". I also want to know if it will be possible to add a note to the Email. Many thanks Ber