TABLE에서 RANDOM하게 DATA를 가져오는방법

제품 : SQL*PLUS
작성날짜 : 2004-05-20
TABLE에서 RANDOM하게 DATA를 가져오는방법
======================================
PURPOSE
아래의 내용은 Sample table scan을 통해서 table의 data를 가져올 때 마다
result set에서 Random하게 가져오는 방법을 기술하고 있습니다.
8i의 새로운 기능입니다.
Explanation
기본적으로 오라클은 data를 access할 때는
1)Full table scan
2) Sample table scan.
의 두 가지 방법이 있습니다.
1. Full Table Scan
이 방법은 table의 모든 행을 scan한 후 가져오는 방법입니다.
Full table scan을 위해서 Oracle은 table의 모든 row들을 읽고
각각의 행이 where 조건에 만족하는지는 확인합니다. Oracle은
table에 관련된 모든 block을 차례로 읽기 때문에 full table scan은
multiblock 읽기를 통해서 효율적으로 이루어 집니다.
2. Sample Table Scan
Sample table scan 은 table의 data중 무작위적으로 sample을
가져옵니다. 이러한 방법은 SQL문장의 FROM 절에 SAMPLE
option 이나 SAMPLE BLOCK option을 기술 해 줌으로써
사용되어 집니다.
SAMPLE option
Sample table scan은 row 단위로 sample data를 가져올 때
사용하는 option 입니다. (SAMPLE option),
Oracle 은 특정 비율(%)의 row를 테이블에서 읽은 후 각각의
Row가 WHERE 절의 조건에 만족하는지 확인 합니다.
SAMPLE BLOCK option
Sample table scan은 block 단위로 sample data를 가져올 때
사용하는 option 입니다. (SAMPLE BLOCK option),
Oracle 은 특정 비율(%)의 테이블 block을 읽은 후 각각의 row가
WHERE 절에 만족하는지 확인 합니다.
Sample_Percent
Sample_percent 은 전체 row 또는 sample이 포함된 block중에서
가져올 비율(%)를 지정해 줍니다. Sample value 은 반드시
0.000001 와 99.999999 사이에 존재 하여야 합니다.
Example
SQL> SELECT * FROM emp SAMPLE (30);
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
SQL> SELECT * FROM emp SAMPLE BLOCK (10);
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7934 MILLER CLERK 7782 23-JAN-82
1300 10
제약사항
1. 하나의 테이블에서 select할 경우만 사용하실 수 있습니다.
Join이나 remote table은 지원하지 않습니다.
2. SAMPLE option은 사용하실 때, Oracle은 자동적으로 cost-based
optimizer를
사용하게 됩니다. Rule-based optimizer 은 지원되지 않습니다.
3. View는 지원하지 않습니다.
SQL> CREATE VIEW sample_view AS SELECT * FROM emp SAMPLE (30);
CREATE VIEW sample_view AS SELECT * FROM emp SAMPLE (30)
ERROR at line 1:
ORA-00933: SQL command not properly ended
4. 8.1.6 이하에서는 PL/SQL 에서 SAMPLE BLOCK을 지원하지 않습니다.
8.1.5 에서는 아래와 같은 error가 발생합니다.
SQL> ed sample.sql
DECLARE
CURSOR C1 IS
SELECT * FROM emp SAMPLE (10);
C1_rec c1%ROWTYPE;
temp number := 0;
BEGIN
OPEN C1;
WHILE temp = 1 LOOP
FETCH c1 INTO c1_rec;
IF c1%NOTFOUND THEN
temp := 0;
ELSE
DBMS_OUTPUT.PUT_LINE(TO_CHAR(c1_rec.empno));
END IF ;
end LOOP;
CLOSE c1;
END;
SQL> @sample.sql
SELECT * FROM emp SAMPLE (10);
ERROR at line 3:
ORA-06550: line 3, column 34:
PLS-00103: Encountered the symbol "(" when expecting one of the
following:
, ; for group having intersect minus order start union where
connect
The symbol "having" was substituted for "(" to continue.
5. 작은 수의 row를 가진 table에서 sample이나 sample block option을
사용 시에는 일정 비율(%)의 sample data가 return되지 않을 수도
있습니다.
Reference Documents
1. Note:95455.1
2. ORACLE 8i, SQL Reference, Volume 2, Release 8.1.5 (PartA67795-01),
Chapter 7: SQL Statements, Pages 7-542 to 7-546.
3. ORACLE 8i, Concepts, Volume 2, Release 8.1.5 (Part A67783-01),
Chapter 23: Optimizer Operations, Page 23-34.

Similar Messages

  • Arranging Random Data Pieces From SLX/Smart Catalogue Into Table Format

    Hi,
    We have a performance data grid that needs to appear on our quotation report.  The data is organized currently into rows in a 2-table linked format and manually entered as plain txt by the user.  We are now migrating towards designing a report in Crystal Reports to try to recreate this table layout but still needing to mine data for other purposes.  Therefore, the data pieces need to be distinct and separate.  Further, the data pieces required for the table can vary and can be organized in up to 9 different ways depending upon the given situation.  Is there an effective way to aesthetically arrange random data pieces in a table format?  The data pieces are coming from SalesLogix / SmartCatalog.  Has any other user of Crystal Reports attempted to do this - i.e. create a data table on a Crystal report?
    Sincerely,
    Sarah Imig
    International Sales Administrator/Database Administrator
    HayssenSandiacre

    Hi,
    We have a performance data grid that needs to appear on our quotation report.  The data is organized currently into rows in a 2-table linked format and manually entered as plain txt by the user.  We are now migrating towards designing a report in Crystal Reports to try to recreate this table layout but still needing to mine data for other purposes.  Therefore, the data pieces need to be distinct and separate.  Further, the data pieces required for the table can vary and can be organized in up to 9 different ways depending upon the given situation.  Is there an effective way to aesthetically arrange random data pieces in a table format?  The data pieces are coming from SalesLogix / SmartCatalog.  Has any other user of Crystal Reports attempted to do this - i.e. create a data table on a Crystal report?
    Sincerely,
    Sarah Imig
    International Sales Administrator/Database Administrator
    HayssenSandiacre

  • Use SQL to roll a schedule forward to a random date

    Hi,
    oracle 10.2.0.4  Linux
    We have two largeish  tables ( 10^5 rows in each) that track our workforces scheduled hours.  The first table creates generic schedules that show working days, each schedule must have 1-n rows in it, one for each day in the cycle.  The majority of our workforce are on a rolling 8 day cycle.  In the example below I have two shifts
    Sched_4d that is a four day cycle of day-on day-off pairs.
    Sched_3d this is a staggered full day, half day, day-off cycle.
    From the information below you can see that in 1990 the sched_4d went from an 8 hour day to a 9 hour day.  There is no guarantee that SCHED_4D will not suddenly gain 2 extra days as part of this years union talks.
    The second table is a simple assigment table showing when a person goes onto a schedule.
    To work out a given day's schedule, you look at the EMP_SHIFT table to work out which schedule is "current", then you look at the date that the person was assigned to the schedule and assume that is SHIFT_ID 1, the next day is SHIFT_ID 2 until you complete the cycle and start again.
    CREATE TABLE SCHED_DATA
      SCHED_ID     VARCHAR2(8 CHAR)             NOT NULL,
      ASOFDATE           DATE                          NOT NULL,
      SHIFT_ID        NUMBER(3)           NOT NULL,
      SCHED_HRS       NUMBER(4,2)                   NOT NULL
    CREATE UNIQUE INDEX SCHED_DATA on SCHED_DATA (SCHED_ID, ASOFDATE, SHIFT_ID)
    CREATE TABLE EMP_SHIFT
    EMPID VARCHAR2(15 CHAR) NOT NULL,
    ASOFDATE DATE NOT NULL,
    SCHED_ID VARCHAR2(8 CHAR) NOT NULL
    CREATE UNIQUE INDEX EMP_SHIFT on EMP_SHIFT ( EMPID, ASOFDATE, SCHED_ID)
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1980',1,8);
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1980',2,0);
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1980',3,8);
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1980',4,0);
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1990',1,9);
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1990',2,0);
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1990',3,9);
    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', '01-JAN-1990',4,0);
    INSERT INTO SCHED_DATA VALUES ('SCHED_3D', '01-JAN-1990',1,8);
    INSERT INTO SCHED_DATA VALUES ('SCHED_3D', '01-JAN-1990',2,4);
    INSERT INTO SCHED_DATA VALUES ('SCHED_3D', '01-JAN-1990',3,0);
    INSERT INTO EMP_SHIFT VALUES ('001', '20-DEC-1989', 'SCHED_4D');
    INSERT INTO EMP_SHIFT VALUES ('001', '01-JAN-1990', 'SCHED_4D');
    INSERT INTO EMP_SHIFT VALUES ('001', '03-JAN-1990', 'SCHED_3D');
    Given the above information, I need to write a select that receives 2 dates ( :FROM and :TO) and for all employees in EMP_SHIFT returns a row for each day and the relevant scheduled hours for that day. 
    Thus the above data  with a from and to of '21-DEC-1989' : '05-JAN-1990' should return
    EMPID, DATE, SCHED_HOURS
    001, 21-DEC, 0
    001, 22-DEC, 8
    001, 23-DEC, 0
    001, 24-DEC, 8
    001, 25-DEC, 0
    001, 26-DEC, 8
    001, 27-DEC, 0
    001, 28-DEC, 8
    001, 29-DEC, 0
    001, 30-DEC, 8
    001, 31-DEC, 0
    001, 01-JAN, 9
    001, 02-JAN, 0
    001, 03-JAN, 8
    001, 04-JAN, 4
    001, 05-JAN, 0
    The employee started thir assignment to sched_4d on 20-DEC, so that would be SHIFT_ID 1.  Thus 21-DEC is SHIFT ID 2 which is 0 hours.  Cycle until the next event which is 01-JAN, when they are assigned to the new sched_4d which has them working 9 hours on day 1.  On 03-JAN they switch to the new cycle and go on the 8:4:0 rotation.
    I can see how I could
    SELECT EMPID, DAY_OF_INTEREST, SCHED_ID
    FROM EMP_SHIFT A, (SELECT '01-JAN-1979' + rownum "DAY_OF_INTEREST" from dual connect by level <=10000)
    WHERE A.ASOFDATE = (SELECT MAX(A1.ASOFDATE) FROM EMP_SHIFT A1 WHERE A1.EMPID = A.EMPID AND A1.ASOFDATE <= DAY_OF_INTEREST)
    AND DAY_OF_INTEREST BETWEEN :FROM_DT AND :TO_DT
    And I imagine I need to use some kind of MOD( (DAY_OF_INTEREST - EMP_SHIFT.ASOFDATE), (#number of days in shift) ) to work out which shift_id applies for a given Day_of_interest
    But I am struggling to do this in a way that would scale to more than one employee,
    Do any of the analytic functions achieve this in a neat way ?

    Hi,
    There are several analytic functions that might help here.  Both tables include starting dates only; we need to know ending dates for employee assignments as well as for schedules.  I used the analytic MIN and LEAD functions to get these in the query below.  Also, the query below needs to know how many days are in each schedule.  I used the analytic COUNT function for that.
    WITH    params   AS
       SELECT  TO_DATE ('21-DEC-1989', 'DD_MON-YYYY')  AS start_date
       ,       TO_DATE ('05-JAN-1990', 'DD_MON-YYYY')  AS end_date
       FROM    dual
    ,       all_dates   AS
        SELECT  start_date + LEVEL - 1    AS a_date
        FROM    params
        CONNECT BY  LEVEL <= (end_date + 1) - start_date
    ,       sched_data_plus AS
        SELECT  sched_id, asofdate, shift_id, sched_hrs
        ,       NVL ( MIN (asofdate) OVER ( PARTITION BY  sched_id
                                            ORDER BY      asofdate
                                            RANGE BETWEEN 1         FOLLOWING
                                                  AND     UNBOUNDED FOLLOWING
                                          ) - 1
                    , TO_DATE ('31-DEC-9999', 'DD-MON-YYYY')
                    )          AS uptodate
        ,       COUNT (*) OVER ( PARTITION BY  sched_id
                                 ,             asofdate
                               )  AS days_in_sched
        FROM    sched_data
    ,       emp_shift_plus AS
        SELECT  empid, asofdate, sched_id
        ,       NVL ( LEAD (asofdate) OVER ( PARTITION BY  empid
                                             ORDER BY      asofdate
                                           ) - 1
                    , TO_DATE ('31-DEC-9999', 'DD-MON-YYYY')
                    )    AS uptodate
        FROM    emp_shift
    SELECT    e.empid
    ,         d.a_date
    ,         s.sched_hrs
    FROM      all_dates        d
    JOIN      sched_data_plus  s  ON   d.a_date    BETWEEN s.asofdate
                                                   AND     s.uptodate
    JOIN      emp_shift_plus   e  ON   d.a_date    BETWEEN e.asofdate
                                                   AND     e.uptodate
                                  AND  e.sched_id  = s.sched_id
                                  AND  MOD ( d.a_date - e.asofdate
                                           , s.days_in_sched
                                           ) + 1   = s.shift_id
    ORDER BY  e.empid
    ,         d.a_date
    This query starts by getting all the days of interest, that is, all the days between the given start- and end dates.  (When you said "random date", I assume you meant "given date", which may not involve any random element.)
    Once we have a list of all the dates of interest, getting the results you want is just a matter of inner-joining to get which schedules were in effect on those dates, and which employees were assigned to those schedules on those dates.
    If you're concerned about having more than 1 employee, maybe you should post sample data that involves more than 1 employee.
    How do you handle employee terminations?  For example, what if employee 001 had quit on January 4, 1990?  I assume you'd want the output for that employee to stop on January 4, rather than continue to the end of the period of interest.
    If you have termination dates in an employee table not shown here, then you can use that termination date instead of December 31, 9999 as the default end date for assignments.  If you have a special schedule for terminations (or leaves of absence, for that matter) you'll probably want to include a WHERE clause in the main query not to display dates after the employee left (or while the employee was on leave).

  • For a few months now my ical keeps jumping back and forth.  It's very hard to use my calendar as it doesn't open on today, it may stay a few seconds and then it goes backwards to random dates and forwards.  It doesn't sit still so I can see what I have on

    My iCal is driving me nuts.
    It won't sit still when I am looking at my calender.  I try holding it still with one finger, two fingers and it just moves.  It jumps to random dates and I have no confidence in it any longer.   I use my calendar all the time and this just isn't good enough.
    I have gone into the apple store and they said they hadn't seen that before.  It did it while I was there.  They restored the phone and it didn't make any difference.
    I have turned the calendar off in settings - mail - icloud - deleted and then turned back on again.  It didn't help.
    I put the Google Calendar app on in the hopes I would have a calendar that wouldn't frustrate me and it is so slow in responding, I have deleted it.
    I see online that many others are having the same problem with their iCal. 
    It would be great to know the solution.
    Please help

    Hey everyone in Apple world!
    I figured out how to fix the flashing yellow screen problem that I've been having on my MBP!  Yessssss!!!
    I found this super handy website with the golden answer: http://support.apple.com/kb/HT1379
    I followed the instructions on this page and here's what I did:
    Resetting NVRAM / PRAM
    Shut down your Mac.
    Locate the following keys on the keyboard: Command (⌘), Option, P, and R. You will need to hold these keys down simultaneously in step 4.
    Turn on the computer.
    Press and hold the Command-Option-P-R keys before the gray screen appears.
    Hold the keys down until the computer restarts and you hear the startup sound for the second time.
    Release the keys.
    I went through the 6 steps above twice, just to make sure I got rid of whatever stuff was holding up my bootup process.  Since I did that, my MBP boots up just like normal.  No flashing yellow screen anymore!!   
    (Note that I arrived at this solution when I first saw this page: http://support.apple.com/kb/TS2570?viewlocale=en_US)
    Let me know if this works for you!
    Elaine

  • How to modify changes of table control data in PAI

    I have a table control where the columns are brought by dict fields.I am able to bring data into table control through an itab.
    Now what i want is whenever user edits data in table control and clicks on save button the corresponding changes should be made in database.
    For this according to my understanding we need to (in PAI) modify the changes in itab from the table control and then in SY-UCOMM of SAVE button we need to update in database table using itab.
    For this , I am not able to write code for modifying the changes in itab from table control. Here is my code below.Please tell me how to do this.
    PROCESS BEFORE OUTPUT.
    MODULE FILL_DATA.
    LOOP AT ITAB INTO ZEMPLOYEE_MASTER WITH CONTROL EMPTABLE CURSOR
    EMPTABLE-CURRENT_LINE.
    ENDLOOP.
    MODULE STATUS_0001.
    PROCESS AFTER INPUT.
    LOOP AT ITAB.
       MODULE MODIFY_ITAB.
    ENDLOOP.
    MODULE USER_COMMAND_0001.
    REPORT  ZDATA_FORM1.
    TABLES: ZEMPLOYEE_MASTER.
    CONTROLS EMPTABLE TYPE TABLEVIEW USING SCREEN 0001.
    data: begin of itab occurs 0,
           emp_no like zemployee_master-emp_no,
           name like zemployee_master-name,
           city like zemployee_master-city,
          end of itab,
          rowno TYPE I VALUE 1.
    *&      Module  STATUS_0001  OUTPUT
    *       text
    MODULE STATUS_0001 OUTPUT.
    *  SET PF-STATUS 'xxxxxxxx'.
    *  SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0001  OUTPUT
    *&      Module  USER_COMMAND_0001  INPUT
    *       text
    MODULE USER_COMMAND_0001 INPUT.
      MESSAGE 'Inside INPUT' TYPE 'I'.
    CASE SY-UCOMM.
       WHEN 'SAVE'.
         UPDATE zemployee_master.
       WHEN 'EXIT'.
         LEAVE PROGRAM.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0001  INPUT
    *&      Module  fill_data  OUTPUT
    *       text
    MODULE fill_data OUTPUT.
      select emp_no name city from zemployee_master into TABLE itab ORDER BY emp_no.
      Describe table itab lines EMPTABLE-LINES.
    ENDMODULE.                 " fill_data  OUTPUT
    *&      Module  modify_itab  INPUT
    *       text
    MODULE modify_itab INPUT.
    * MODIFY itab from zemployee_master index
    * MESSAGE 'Inside modify_itab' TYPE 'I'.
    ENDMODULE.                 " modify_itab  INPUT

    Hi
    In the following module of your code
    MODULE modify_itab INPUT.
    MODIFY itab from zemployee_master index tc-current_line " Where TC is the name of the Table control on the Screen
    ENDMODULE.
    Table control data gets refreshed on *enter*
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/2165e990-0201-0010-5cbb-b5c2ad436140
    Cheerz
    Ramchander Rao.K

  • Loading MS Access Table and Data into Oracle

    Hi,
    I have few tables in MS Access. I want to create same layout of tables in Oracle and want to populate data from MS Access tables to Oracle tables.
    Please let me know if there is a way by which I can create tables and load data automatically (thru some option or script)?
    I have Oracle 10g database and its clients.
    Thanks in advance,
    Rajeev.

    You can use Oracle migration workbench
    Loading MS Access Table and Data into Oracle
    It´s very easy to use and good to import
    regards,
    Felipe

  • Excel Table with Data Connection Manual Text Entry Misaligned After Refresh

    Greetings!
    I have an Excel 2010 workbook that includes a table linked to my SharePoint 2013 site by a data connection. The SharePoint list feeds the table standard information that's managed on the SharePoint site, but I need the user of the Excel workbook to be able
    to enter text manually in the workbook to associate local information with the line-items coming from the SharePoint list. To do this, I've added extra columns to the end of the table.
    The user can enter information in the appropriate cells in the "extra" columns at the end of the table, but when I refresh the data connection, the addition of a new list item on the SharePoint side results in the user's manually entered text getting
    out of alignment with the row it's supposed to be associated with.
    Example
    Column 1(SP)
    Column 2(Extra)
    Row 1
    Item 1
    Row 2
    Item 2
    Text entered for Item 2
    Row 3
    Item 3
    Then, if I add a new item to the list in SharePoint, for example, something that would appear between the original items 1 & 2, after refreshing the table, I get the following:
    Column 1(SP)
    Column 2(Extra)
    Row 1
    Item 1
    Row 2
    New Item 1.5
    Text entered for Item 2
    Row 3
    Item 2
    Row 4
    Item 3
    The table's data connection is set to insert rows for new items, and I could swear I had this working properly once upon a time...but I can't seem to make it work now.
    Any thoughts on what would cause this?
    Thanks in advance!

    Yes, it is. I realized after posting the first time, that I'd assigned the question to the Visio forum. I wasn't sure how to reassign to the correct (Excel) forum, so I re-posted over there:
    http://social.msdn.microsoft.com/Forums/en-US/b3bbe00c-94c0-48d4-bed9-fbd08d707b1d/excel-table-with-sharepoint-data-connection-manual-text-entry-misaligned-after-refresh?forum=exceldev

  • Help on export sybase iq tables with data and import in another database ?

    Help on export Sybase iq 16 tables with data and import into another database ?

    Hi Nilesh,
    If you have table/index create commands (DDLs), you can create them in Developper and import data using one of methods below
    Extract/ Load table
    Insert location method : require IQ servers to be entered in interfaces file
    Backup/Restore : copy entire database content
    If you have not the DDLs, you can generate them using IQ cockpit or SCC.
    http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01773.1604/doc/html/san1288042631955.html
    http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01840.1604/doc/html/san1281564927196.html
    Regards,
    Tayeb.

  • R/3 tables and data sources

    hi guys,
                         i am trying to find r/3 tables for plant maintainance data sources
    and project system data sources
    i am trying it out in help.sap.com
    i am able to find r/3 tables information for 60% of data sources only
    how can i find the exact information of r/3 tables with respect to data sources
    i have seen help link for this application components throughly
    please suggest me
    i will assign points

    Hi Selva,
    I typically try this:
    Goto ROOSOURCE -> Give the datasource name  and find out what type of datasource it is. If it is based on view/table then use the table/view. If it is based on function module then you would need to look at the code and find out from which tables the data is extracted.
    For fn module:Goto se37 -> Give the fn module name -> Click the "find" button -> give the text as "select". Select the radio button "Main program". It would list all the select statements in the fn module. In teh select statement you can find the name of the table.
    Hope this helps.
    Bye
    Dinesh

  • How to update the data base table with data

    i have two ztables, one is zfm_kfz and other one is zfm_kmvrg
    zfm_kfz is maintained by using table maintenance generator as well as alv grid control for list display.
    zfm_kfz the field r like this KFZR, GERAET, KOSTENTRAEGER, BEZEICHNUNG, TUVDATUMMMYYYY, ASUDATUMMMYYYY, KMSTAND, HISTO AND REIFEN.
    PROBLEM: all the data in grid control r updated except KMSTAND
    fields in zfm_kmvrg are kostentraeger, kfznr and kmstand i m creating table control for this screen here what ever enter the last km stand is updated in the list.for one kfznr many kostentraegers and kmstand, the last km stand is updated here , go through this code plz hepl me
    CONTROLS tabctrl TYPE TABLEVIEW USING SCREEN 100.
    DATA: cols LIKE LINE OF tabctrl-cols,
          lines TYPE i.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF zfm_kmvrg,
          fs_itab LIKE LINE OF itab,
          fl_change TYPE c,
          fl_error  TYPE c.
    *TABLES fs_itab.
    LOOP AT tabctrl-cols INTO cols.
      cols-screen-input = '0'.
      MODIFY tabctrl-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    *SELECT * FROM spfli INTO TABLE itab.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_101'.
      DESCRIBE TABLE itab LINES lines.
      tabctrl-lines = lines.
    ENDMODULE.                    "status_0100 OUTPUT
    MODULE cancel INPUT
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.                    "cancel INPUT
    MODULE read_table_control INPUT
    MODULE read_table_control INPUT.
      MODIFY itab FROM fs_itab INDEX tabctrl-current_line.
    ENDMODULE.                    "read_table_control INPUT
    MODULE user_command_0100 INPUT
    MODULE user_command_0100 INPUT.
      DATA:
        lw_index TYPE i.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'ADD'.
          LOOP AT tabctrl-cols INTO cols.
            cols-screen-input = '1'.
            MODIFY tabctrl-cols FROM cols INDEX sy-tabix.
          ENDLOOP.
          CLEAR fs_itab.
          APPEND fs_itab TO itab.
        WHEN 'SAVE'.
          IF NOT itab[] IS INITIAL.
            LOOP AT itab[] into FS_ITAB.
              lw_index = sy-tabix.
              IF NOT fs_itab IS INITIAL.
                MODIFY ZFM_KMVRG FROM fs_itab.
                IF sy-subrc EQ 0.
                  UPDATE ZFM_KFZ set kmstand = fs_itab-kmstand
                                        WHERE kfznr = fs_itab-kfznr.
                ELSE.
                  fl_error = 'X'.
                  WRITE:/ 'The record number', lw_index,
                          'has not been updated'.
                ENDIF.
              ENDIF.
            ENDLOOP.
          ELSE.
            MESSAGE s000(0) WITH 'No data is present to update'.
          ENDIF.
      ENDCASE.
      IF fl_error = 'X'.
        LEAVE TO LIST-PROCESSING.
      ELSE.
        MESSAGE s000(0) WITH
              'All the records have been updated successfully'.
      ENDIF.
    ENDMODULE.                    "user_command_0100 INPUT
    IN SE51
    PROCESS BEFORE OUTPUT.
      MODULE STATUS_0100.
      LOOP AT ITAB INTO fs_itab WITH CONTROL tabctrl.
      ENDLOOP.
    PROCESS AFTER INPUT.
      MODULE CANCEL AT EXIT-COMMAND.
      LOOP AT ITAB.
        module read_table_control.
      ENDLOOP.
      module user_command_0100.
    i m trying many times i m not getting proper output, plz help me on this

    Hi,
    I am hereby givng the similar sample code.Check this with your requirement.
    In the flow logic of the screen 9000, write the following code.
    PROCESS BEFORE OUTPUT.
      MODULE set_status.
      MODULE get_t_ctrl_lines.
      LOOP AT i_makt WITH CONTROL t_ctrl CURSOR t_ctrl-current_line.
    * Dynamic screen modifications
        MODULE set_screen_fields.
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP AT i_makt.
        FIELD i_makt-pick MODULE check.
        FIELD i_makt-zmatnr MODULE zmatnr .
      ENDLOOP.
      MODULE user_command_9000.
    In the program, write the following code.
    PROGRAM SAPMZTC MESSAGE-ID zz.
    * Tables Declaration
    TABLES: zzz_makt.
    * Internal table Declaration
    DATA : i_makt TYPE STANDARD TABLE OF zzz_makt WITH HEADER LINE.
    * Table control Declaration
    CONTROLS: t_ctrl TYPE TABLEVIEW USING SCREEN '9000'.
    * Variable Declaration
    DATA : flg,           "Flag to set the change mode
           ln TYPE i.     "No. of records
    *&      Module  get_T_CTRL_lines  OUTPUT
    *  Populating data
    MODULE get_t_ctrl_lines OUTPUT.
      SELECT zmatnr zmaktx
             INTO CORRESPONDING FIELDS OF TABLE i_makt
             FROM zzz_makt.
      DESCRIBE TABLE i_makt LINES ln.
    * To make the vertical scroll bar to come on runtime
      t_ctrl-lines = ln + 100.
    ENDMODULE.                 " get_T_CTRL_lines  OUTPUT
    *&      Module  USER_COMMAND_9000  INPUT
    * Triggering event according to the user command
    MODULE user_command_9000 INPUT.
      DATA :lv_fcode LIKE sy-ucomm,    "Function Code
            lv_answer(1) type c.       "Storing the answer
      lv_fcode = sy-ucomm.
      CASE lv_fcode.
        WHEN 'CHANGE'.
    * Setting the flag to make the table control in editable mode[excluding
    * primary key].
          flg = 'Y'.
        WHEN 'DELETE'.
    * Setting the flag to make the table control in editable mode after
    * deleting the selected line
          flg = 'Y'.
    * Confirmation of delete
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
             TITLEBAR       = 'Confirm'
             text_question  = 'Are you sure to delete from database?'
             TEXT_BUTTON_1  = 'Yes'(001)
             TEXT_BUTTON_2  = 'No'(002)
            IMPORTING
             ANSWER         =  lv_answer.
          if lv_answer eq '1'.
    * Updating the database table from the internal table
            UPDATE zzz_makt FROM TABLE i_makt.
    * Deleting the selected row from the internal table
            DELETE i_makt WHERE pick = 'X'.
    * Deleting the selected row from the database table
            DELETE FROM zzz_makt WHERE pick = 'X'.
            MESSAGE s005 WITH 'Deleted Successfully'.
          ENDIF.
        WHEN 'SAVE'.
    * Inserting new record or updating existing record in database table
    * from the internal table
          MODIFY zzz_makt FROM TABLE i_makt.
          MESSAGE s005 WITH 'Saved Successfully'.
        WHEN 'BACK'.
          SET SCREEN '0'.
        WHEN 'EXIT' OR 'CANCEL'.
    * Leaving the program
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_9000  INPUT
    *&      Module  set_screen_fields  OUTPUT
    * Setting the screen fields
    MODULE set_screen_fields OUTPUT.
      LOOP AT SCREEN.
        IF flg IS INITIAL.
          screen-input = 0.
        ELSEIF ( flg EQ 'Y' ).
          IF ( ( screen-name = 'I_MAKT-ZMAKTX'
                 OR screen-name = 'I_MAKT-CHECK1' )
                AND t_ctrl-current_line LE ln ) .
    * Making the screen fields as editable
            screen-input = 1.
          ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )
                     AND t_ctrl-current_line LE ln ).
    * Making the screen field as uneditable
            screen-input = 0.
          ENDIF.
        ENDIF.
    * Modifying the screen after making changes
        MODIFY SCREEN.
      ENDLOOP.
    ENDMODULE.                 " set_screen_fields  OUTPUT
    *&      Module  zmatnr  INPUT
    * Appending records to the internal table
    MODULE zmatnr INPUT.
      MODIFY i_makt INDEX t_ctrl-current_line.
      IF t_ctrl-current_line GT ln.
        READ TABLE i_makt WITH KEY zmatnr = i_makt-zmatnr.
        IF sy-subrc NE 0.
    * Inserting record if it does not exist in database
          APPEND i_makt.
        ELSE.
         MESSAGE i005 WITH 'Material Number' i_makt-zmatnr 'already exists'.
        ENDIF.
      ENDIF.
    ENDMODULE.                 " zmatnr  INPUT
    *&      Module  set_status  OUTPUT
    * Setting the GUI status
    MODULE set_status OUTPUT.
      SET PF-STATUS 'ZSTATUS'.
      SET TITLEBAR  'ZTITLE'.
    ENDMODULE.                 " set_status  OUTPUT
    *&      Module  CHECK  INPUT
    * Modify the internal table using the current line in table control
    MODULE check INPUT.
      MODIFY i_makt INDEX t_ctrl-current_line.
    ENDMODULE.                 " CHECK  INPUT

  • Best way to set up a custom table using dates ytd, quarters, months

    Hello-
    I did post this on the crystal forum however it really involves setting up a good structured table in order to get the data to report on which I think we need to change which is why I'm posting here.
    I am not a dba but I work with crystal reports and we are working together to get data in tables that we can report on.  We are in the process of creating a data warehouse, which will mainly be summarized data we are exporting out of our legacy system and importing into a mysql database.  Most of this data will be summarized by month, quarter and year.  We will have multiple years of data.  A lot of the reports we will be creating will be in a comparison manner such as 2009 vs 2008 or Jan this year compared to Jan last year or list out sales by month Jan-Dec 2009.  I would like this data to be easily displayed on a report in a side by side manner.  To get this result, what is the best way to structure the data in the tables on a monthly, quarterly and yearly basis?  Right now weu2019ve got one field in the table called date (which is a string) which is listed like:
    Date
    2008YTD
    2009YTD
    2009Jan
    2008Jan
    Is it best to break out the date information so that on the report side it will be easier to work with?  Also should this be set up in the table as a date instead of a string?  If so how do you account for a YTD date?  Are we going to need 2 dates, a start and end date to achieve ytd or qtd information?  Do you recommend creating just a date table and if so how would that be structured?
    So for reporting purposes, using crystal reports, I would like to display comparison data on a report side by side, for this example this year goals compared to last years goals by goal code A-Z (which is a credit code, goals are for the # of credits by code for the year).  The end result I would like is to look like this:
    code   2009 goal   2008 goal
    A        25              20
    B        50              60
    C        10              15
    However the data looks like this (displaying all of the 2009 data first then the 2008 data, not side by side which is how it is in the table):
    code   2009 goal   2008 goal
    A        25
    B        50
    C        10
    etc to Z
    A                          20
    B                          60
    C                          15
    Right now the data is structured in the table like:
    Code  Goal  Date (this is currently a string in the db)
    A        25     YTD 2009
    B        50     YTD 2009
    etc. A-Z for 2009 then:
    A        20      YTD 2008
    B        60      YTD 2008
    Any thoughts on strucuting a table would be appreciated.  thanks.

    Jennifer,
    Most of the DW examples I've seen use a dimDateTime table in the database. That table has multiple columns related to the specific time... For example, here are the columns that are in the, SQL Server sample database, "AdventureWorkdDW"... "DimTime" table
    COLUMN_NAME             COLUMN_INFO
    TimeKey               (int, not null)
    FullDateAlternateKey     (datetime, null)
    DayNumberOfWeek          (tinyint, null)
    EnglishDayNameOfWeek     (nvarchar(10), null)
    SpanishDayNameOfWeek    (nvarchar(10), null)
    FrenchDayNameOfWeek     (nvarchar(10), null)
    DayNumberOfMonth     (tinyint, null)
    DayNumberOfYear          (smallint, null)
    WeekNumberOfYear     (tinyint, null)
    EnglishMonthName     (nvarchar(10), null)
    SpanishMonthName     (nvarchar(10), null)
    FrenchMonthName          (nvarchar(10), null)
    MonthNumberOfYear     (tinyint, null)
    CalendarQuarter          (tinyint, null)
    CalendarYear          (char(4), null)
    CalendarSemester     (tinyint, null)
    FiscalQuarter          tinyint, null)
    FiscalYear          (char(4), null)
    FiscalSemester          (tinyint, null)
    Then all of the fact table receive their date stamps by linking back to this table, using the TimeKey as a foreign key.
    HTH,
    Jason

  • How-To "Refresh a table of data after inserting or deleting"

    I'd like to say a word on the how-to article "How to refresh a table of data after inserting or deleting a row using ADF".
    (http://www.oracle.com/technology/products/jdev/howtos/1013/updtable/index.html?_template=/ocom/technology/content/print)
    I spent a lot of time on it because I needed help in implementing simple CRUD functionality on a table, using JSF-ADF-TopLink technologies.
    While the the article does provide correct steps, it is in one important place not specific enough, so the reader may easily get stuck. In section "Refresh the data table", point 1: when you double click on the removeEntity() button, in Structure window, then you do not get the required dialog. You get CommandButton Properties dialog.
    You must click on the removeEntity() button in Editor's Design view. But even there you may get the CommandButton Properties dialog, not managed beans dialog.
    You may resolve that by going to JSF configuration file, faces-config.xml, and switch to Overview view. This will show you the managed beans that you have.
    Then, you may already have a backing bean for the page. You can use that and avoid creating a new managed bean.
    I could understand what the operations mean only after very careful reading of "Creating More Complex Pages", section "Overriding Declarative Methods" in JDeveloper Help (or in ADF Developer's Guide PDF document).
    In general: I believe that "ADF bindings" need more conceptual explanation, maybe in form of an article. Grammatical form "bindings" may create a false understanding that "bindings" are just references. But they are not -- ADF bindings are active objects that handle traffic between UI components and Data Controls. It seems that "bindings" even communicate among themselves. Maybe it would be more understandable to differentiate strictly between "binding objects" (or "binders"?), binding object definitions and binding object references.
    It would be very helpful to have a diagram showing grahically what specific binder objects are created in a small apllication (2-3 pages using 1-2 tables), with whom they communicate and what type of data is passed on.
    Priit

    Hi
    Thanks for your infos.
    Yes exactly I use almost the same code you have post here.
    Could You answer to my next questions?
    First - >what do you mean by saying that "it's not good idea using refreshing in IE?" Of course I use refreshing in backing_bean for my button "remove" that removes row, commit changes to database and refresh table, almost the same as You said in your post:
    Code in backing_bean is and comments on difference to Your code is below:
    public commandButton2_action1(){
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding =
    bindings.getOperationBinding("removeEntity");
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty()) {
    return null;
    //above remove entity, but I dont now if it do commit to database? So i do it below
    OperationBinding commit1 = bindings.getOperationBinding("Commit");
    commit1.execute();
    //and at the end I refresh my table, "findAllRezerwacja1 - it is an id of the methodAction, not the iterator -> is it ok? or should I change to Iterator id?
    OperationBinding requery = bindings.getOperationBinding("findAllRezerwacja1");
    requery.execute();
    return null;
    Page Definition code for this:
    <methodAction id="findAllRezerwacja1"
    InstanceName="SessionEJBLocal.dataProvider"
    DataControl="SessionEJBLocal" MethodName="findAllRezerwacja"
    RequiresUpdateModel="true" Action="999"
    ReturnName="SessionEJBLocal.methodResults.SessionEJBLocal_dataProvider_findAllRezerwacja_result"/>
    <table id="findAllRezerwacja2" IterBinding="findAllRezerwacja1Iter">
    <AttrNames>
    <Item Value="dataDo"/>
    <Item Value="dataOd"/>
    <Item Value="idRezerwacja"/>
    <Item Value="liczbaUczestnikow"/>
    <Item Value="prowadzacy"/>
    <Item Value="uwagi"/>
    </AttrNames>
    </table>
    <methodAction id="removeEntity" InstanceName="SessionEJBLocal.dataProvider"
    DataControl="SessionEJBLocal" MethodName="removeEntity"
    RequiresUpdateModel="true" Action="999">
    <NamedData NDName="entity"
    NDValue="${bindings.findAllRezerwacja2.currentRow.dataProvider}"
    NDType="java.lang.Object"/>
    </methodAction>
    <action id="Commit" IterBinding="findAllRezerwacja1Iter"
    InstanceName="SessionEJBLocal.dataProvider"
    DataControl="SessionEJBLocal" RequiresUpdateModel="true"
    Action="2"/>
    </bindings>
    //and rest of code for Iterator etc
    My second question is, why when you use refresh button in IE (I know is not recommended as You said, but sometimes user do it, so I want prevent situations that I will describe here) so when I press refresh button in IE exactly after removing one row by clicking my button, refreshing by pressing IE button is doing the same --> is deleting next row. How to stop deleting row, when for example user would press IE refresh button after pressing remove button for table. If I change selection in table after deleting row, and press refresh button in IE, instead of deleting row, I got error message: JBO-29000: JBO-35007: and
    JBO-35007. So where Im doing wrong. Maybe I should do sth with postback ? Could You help me? Thanks in advance
    Last one question: what is the difference between using delete and removeEntity from operations node? Im now reading carefully ADF Dev Guide, so I hope I can find infos there? But if You know, please answer to this question.
    Thanks

  • The "More Everything Plan" is ruining my life!  (and adding random data charges to my bill)

    Hello,
    I recently changed my data plan a few months ago to the 6 GB Data plan with 2 phones tied to my service when I upgraded my phone to the Samsung Galaxy 5.  For the most part my wife and I have been doing pretty good at keeping the our monthly data usage down to the 6 GB.  On Nov 4th was I upgraded to the new 10 GB my everything plan and ever since that change, my account has been making RANDOM data charges at all hours of the night!  I pulled both my wife's Data Usage report and my own and compared them. 
    Looking at my wife's data usage below, you can clearly see that there are automated data spikes that her phone went through on the same exact time on different days!  Looking at the dates, these spikes did not start to automatically occur until we upgraded our plan on Nov 4th.  The same goes for my data usage below.  There are multiple days that my phone surged on the same exact time with large spikes of data!  These reports were organized by largest "Unbilled Data Usage" spikes.
    These spikes SHOULD NOT be occurring and have nothing to do with what apps we have installed our phones.  We have both filtered our usage by apps on our phones and they do not add up.  What's the point of having a larger data plan, if that data plan just steals MG randomly off your phone for no reason???  Because of these spikes, I have add to pay over $100 in overage fees and in November, I have already had to buy MORE DATA ($20 for 5 GB more) because I was already at 90% of my usage with 2 weeks still to go in the billing cycle!  I need actions and not suggestions.  I'm not the only one with these problems and this needs to be addressed.
    Please help!!!!!
    (Wife's Data Usage)
    (My Data Usage)

    You're right, data usage can be confusion...especially when your response above doesn't make sense.
    If data usage is counted in 6 hour blocks, then how in the world did Nov. 5th last 138 hours???  Data was calculated 23 times on 11/5/14 and 14 times on on 11/4.  These are just 2 examples of when the data was pulled in in "6 hour blocks of time". Nearly every day in my pulled report this month shows 2 dozen or more times the data was recorded and billed each day. (see below)
    Further more, if data usage actually was counted in 6 hour intervals, that still doesn't explain why my phone randomly surged 1.27 GB of data at 5:36 AM in the morning on 11/12/14.  Even if this counted data since 11:36 PM the night before on 11/11/14 night, there's no way I would have used this much data!  Since I work during the weekdays 9-5, I am already in bed at this time and not using my phone.  And it can't be recorded data usage after 5:36 AM, because then what would be the point of having a time stamp in the report?  Where was this data coming from???  (see below)
    The timing of my spike in data is just way too coincidental of when I upgraded my data to 10 GB earlier this month.  If you compare our data usage against other months (when I had 6 GB) we didn't have random spikes like we are seeing now.  There is something wrong with the new data plan on our phones, and I really wish someone could clearly point out where these additional charges are coming from.  Please have a representative contact me at your earlier convenience.
    6 Hour Blocks of Time?
    Data pulled at 5:36 AM
    Data Spike in the Past Months

  • What are the tables storing data of tcode FB60

    Hi Friends
    Can anybody tell me in which tables transaction data for transaction code FB60 are stored.
    Thanks for your support.
    Regards
    KTK

    Hi,
    Tables are probably :
    BKFP ( Accounting Document Header )
    BSEG ( Accounting Document Segment )
    <b>!</b> both contains a lots of data !
    Hope this helps,
    Erwan

  • How to move tables with data from one client to another

    Hello friends
    I have 2 clients 001 and 002.
    I have created a table with lots of data on client 001.
    I have to get the same table on 002 also with the same data.
    Is there an easier way of transfering this data from one table to another?
    I would appreciate any feedback on this.
    I know that mappings etc., can be done using the export and import of tpz file. So I want to know if there is any similar thing to transfer a table with data.
    THanks
    Ram

    hi
    thanks for the response
    We are working on a sandbox system for demo purpose.
    Actually we have two different group of people using two different clients created on the same server.
    Our group is using client 001 and another group is using client 002.
    We don't want the changes that one group does to the table to affect the other.
    Our group has created a z-table and have entered considerable amount of data.
    However, the other group also need to create the same table with the same data.
    So to avoid double work, we were trying to see if there is a way to copy the table with data created on 001 to 002.
    Any suggestions / feedback will be greatly appreciated.
    Thanks
    Ram

Maybe you are looking for