Require sum value of one table to be inserted into another table column

Hi
I have a table which contains a list of parts and their prices required for an assembly.
I am trying to calculate the total from this part lists and put into the total price column for the assembly (another table column).
My method was to calculate the total in a page process ( eg, once all parts in the assembly have been entered the page process calculates the total price (the sum of the part prices at that time) and puts the result (total) in the assembly total column)
In the process I capture the total using either
SELECT SUM(TOTAL_COST) Total INTO B from CC_REQ_BOM WHERE RID = :P5_RID;
or
SELECT SUM(TOTAL_COST) INTO B from CC_REQ_BOM WHERE RID = :P5_RID;
Both the above sql statements are allowed ( one with alias and one without alais) by the page process but they dont seem to be working as no total is returned to the table when the page process is run.
to insert the calculation(variable B) into the required table I have used
INSERT INTO CC_REQ(TOTAL_COST)
VALUES(B);
I have used this method a few times with no problems for standard sql statements but this is the first time I have used it with the sum SQL function. For some reason it doesn't seem to like the SUM function even though the code below works in SQL Command window.
SELECT SUM(TOTAL_COST) from CC_REQ_BOM WHERE RID = :P5_RID;
Any help welcome.
PGJ

Hi
In that case, I would do something like this then...
CREATE TABLE crt_crates
(ccr_id   INTEGER        CONSTRAINT ccr_pk PRIMARY KEY,
ccr_name VARCHAR2(4000) CONSTRAINT ccr_nam_nn NOT NULL);
CREATE TABLE crt_requests
(cre_id        INTEGER        CONSTRAINT cre_pk PRIMARY KEY,
cre_reference VARCHAR2(4000) CONSTRAINT cre_ref_nn NOT NULL,
--I've skipped the requester as this would probably refernce a different table
--I've skipped request details as it's not necessary for this example
cre_ccr_id    INTEGER        CONSTRAINT cre_ccr_fk REFERENCES crt_crates);
CREATE TABLE crt_materials
(cma_id   INTEGER        CONSTRAINT cma_pk PRIMARY KEY,
cma_name VARCHAR2(4000) CONSTRAINT cma_nam_nn NOT NULL,
cma_cost NUMBER(12,2)   CONSTRAINT cma_cos_nn NOT NULL);
CREATE TABLE crt_crate_bom
(ccb_id       INTEGER CONSTRAINT ccb_pk PRIMARY KEY,
ccb_ccr_id   INTEGER CONSTRAINT ccb_ccr_fk REFERENCES crt_crates,
ccb_cma_id   INTEGER CONSTRAINT ccb_cma_fk REFERENCES crt_materials,
ccb_quantity INTEGER DEFAULT 1 CONSTRAINT ccb_qua_nn NOT NULL);
INSERT INTO crt_crates
VALUES(1, 'Crate 1');
INSERT INTO crt_requests
VALUES(1,'Request 1',1);
INSERT INTO crt_materials
VALUES(1,'Material 1', 1000);
INSERT INTO crt_materials
VALUES(2,'Material 2', 500);
INSERT INTO crt_crate_bom
VALUES(1,1,1,5);
INSERT INTO crt_crate_bom
VALUES(2,1,2,3);
COMMIT;
--So crate cost totals would be...
SELECT cre_reference              request,
       ccr_name                   crate,
       SUM(cma_cost*ccb_quantity) crate_cost
FROM   crt_requests,
       crt_crates,
       crt_materials,
       crt_crate_bom
WHERE  cre_ccr_id = ccr_id
AND    ccb_ccr_id = ccr_id
AND    ccb_cma_id = cma_id
GROUP BY cre_reference,
         ccr_name;
--And request cost totals would be...
SELECT cre_reference              request,
       SUM(cma_cost*ccb_quantity) crate_cost
FROM   crt_requests,
       crt_crates,
       crt_materials,
       crt_crate_bom
WHERE  cre_ccr_id = ccr_id
AND    ccb_ccr_id = ccr_id
AND    ccb_cma_id = cma_id
GROUP BY cre_reference; Do you see what I mean - you don't store the derived values as they could get out of sync with the component parts that make then up. You derive them from the underlying data instead.
Hope this makes sense.
Cheers
Ben

Similar Messages

  • How can I get a count at the same time I am inserting into another table

    I have a requirement where I have to find out the count(number of records inserted into another table) at the same time I insert into the table:
    Like
    I am copying records from table B to A, while doing this I have to find out how many records I've inserted since I need this count in subsequent steps
    INSERT INTO A
    SELECT * FROM B
    how can I store the count into any variable while doing above statement
    Please advice

    No, Warren that doesn't work!
    SQL> set serveroutput on
    SQL> declare
      2     vCtr  number := 0;
      3  begin
      4     insert into emp2
      5     select * from emp;
      6
      7     select count(*)
      8       into vCtr
      9       from emp2;
    10
    11     dbms_output.put_line('rows created '||to_char(vCtr));
    12  end;
    13  /
    rows created 15
    PL/SQL procedure successfully completed.
    SQL> declare
      2     vCtr  number := 0;
      3  begin
      4     insert into emp2
      5     select * from emp;
      6
      7     select count(*)
      8       into vCtr
      9       from emp2;
    10
    11     dbms_output.put_line('rows created '||to_char(vCtr));
    12  end;
    13  /
    rows created 30
    PL/SQL procedure successfully completed.
    SQL>

  • Insert values to one table based on a value inserted into another table

    Hi,
    I've got a form based off a report which creates a new project. I've added an additional process to this form to insert four new values into another table as soon as the new project is created and the PK for that project is generated. This was working last week (of course!) and now seems to not work at all. It's complaining that the PK I was getting from my first insert was null. Here is one the the statements in my process I'm trying to run:
    insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER);
    The complaint I get that it's getting null where :P45_PROJECT_SEQ should be.
    Thoughts?
    Thanks,
    Jon

    Hi Andy,
    Thanks for the tip. Those two values didn't match and I updated them so they do and I'm still getting a "cannot insert NULL..." error.
    When I turn on debug I see that I'm getting the PK and I see the value. Here's my debug output:
    0.24: ...Process "Get PK": PLSQL (AFTER_SUBMIT) declare function get_pk return varchar2 is begin for c1 in (select PROJECT_SEQ.nextval next_val from dual) loop return c1.next_val; end loop; end; begin :P45_PROJECT_SEQ := get_pk; end;
    0.25: ...Session State: Saved Item "P45_PROJECT_SEQ" New Value="252"
    0.25: ...Process "Process Row of PROJECT": DML_PROCESS_ROW (AFTER_SUBMIT) #OWNER#:PROJECT:P45_PROJECT_SEQ:PROJECT_SEQ|IUD
    0.26: ...Session State: Save "P45_PROJECT_SEQ" - saving same value: "252"
    0.26: ...Process "reset page": CLEAR_CACHE_FOR_PAGES (AFTER_SUBMIT) 45
    0.27: Nulling cache for application "120" page: 45
    0.27: ...Process "Add Week Groups": PLSQL (AFTER_SUBMIT) insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER); insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY') +
    0.28: Encountered unhandled exception in process type PLSQL
    0.28: Show ERROR page...
    0.28: Performing rollback...
    I notice that when it runs my process "Add Week Groups" it's not displaying all of the SQL. But the SQL is fine, it's right here:
    insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER);
    Hmmm....what about the "reset page" action in the last of the 0.26 lines?
    Thanks,
    Jon

  • How to get the data from one table and insert into another table

    Hi,
    We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
    For the above requirement what the best way to implement in OAF.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    Thanks

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • Multi-row uipdate with an insert into another table [I think]

    Folks,
    I'm trying to get a multi row region with a checkbox against each row. When a user checks a box I want to insert a corresponding row into another table. So I've tried to simplify the questions and distill the problem down using the EMP table.
    So, here goes:
    I have table EMPS, which looks like this:
    EMPNO     Number     
    FIRSTNAME     Varchar2(9)     
    LASTNAME     Varchar2(10)     
    HIREDATE     Date
    I have table EMP_CANDIDATES, which looks like this:
    EMPNO     Number     
    SELECTION_DATE     Date     
    NOTES Varchar2(53)
    - I want to create a multi-row region based on EMPS, with a checkbox on each employee row.
    - The user should be able to select any number of employees in the region and then press submit.
    - on-submit there needs to be a process, which inserts a record into EMP_CANDIDATES for each checked employee.
    I've tried pre-populating a collection with the EMPS records and using apex_item.checkbox to produce a checkbox, using this code:
    =============
    if apex_collection.collection_exists(p_collection_name=>'EMPS') then
    apex_collection.delete_collection(p_collection_name=>'EMPS');
    end if;
    apex_collection.create_collection_from_query(
    p_collection_name=>'EMPS',
    p_query=>'select
    p.empno,
    p.hiredate,
    p.firstname,
    p.lastname,
    null selection
    from emps p');
    =========
    I can create a report region on this using tthe following SQL:
    select c001 empno
    , c002 hiredate
    , c003 firstname
    , c004 lastname
    ,apex_item.checkbox(1,c005) selection
    from apex_collections
    where collection_name ='EMPS'
    ======
    So how do I now get a MRU that will insert a row into EMP_CANDIDATES for each checked row in my region? Or have I gone about this the wrong way?
    TFH
    Derek

    Hi Derek,
    Firstly, your checkbox should be on the c001 field as this is the one that contains your empno.
    Then, you need a page process that can be triggered by a button. The process should be set to run "On submit (After computations and validations)" and the PL/SQL code would be something like:
    DECLARE
    v_empno NUMBER;
    BEGIN
    IF HTMLDB_APPLICATION.G_F01.COUNT = 0 THEN
    raise_application_error(-20001, 'Please select at least one employee!');
    END IF;
    FOR i IN 1.. HTMLDB_APPLICATION.G_F01.COUNT LOOP
    v_empno := TO_NUMBER(HTMLDB_APPLICATION.G_F01(i));
    INSERT INTO EMP_CANDIDATES VALUES (v_empno, whateverdate, whatevernotes);
    END LOOP;
    END;
    This will firstly count the items that have been ticked - if there aren't any, the user gets an error message. If there is at least one item ticked, the code will loop through these, get the empno relating to the ticked box and insert a record into the emp_candidates table. Please note that no account is taken here of any validation on this second table - if you need to ensure, for example, uniqueness of records in this table, you will have to update the above to perform this validation.
    Regards
    Andy

  • How to read LONG RAW data from one  table and insert into another table

    Hello EVERYBODY
    I have a table called sound with the following attributes. in the music attribute i have stored some messages in the different language like hindi, english etc. i want to concatinate all hindi messages and store in the another table with only one attribute of type LONG RAW.and this attribute is attached with the sound item.
    when i click the play button of sound item the all the messages recorded in hindi will play one by one automatically. for that i'm doing the following.
    i have written the following when button pressed trigger which will concatinate all the messages of any selected language from the sound table, and store in another table called temp.
    and then sound will be played from the temp table.
    declare
         tmp sound.music%type;
         temp1 sound.music%type;
         item_id ITEM;
    cursor c1
    is select music
    from sound
    where lang=:LIST10;
    begin
         open c1;
         loop
              fetch c1 into tmp; //THIS LINE GENERATES THE ERROR
              temp1:=temp1||tmp;
              exit when c1%notfound;
         end loop;
    CLOSE C1;
    insert into temp values(temp1);
    item_id:=Find_Item('Music');
    go_item('music');
    play_sound(item_id);
    end;
    but when i'm clicking the button it generates the following error.
    WHEN-BUTTON-PRESSED TRIGGER RAISED UNHANDLED EXCEPTION ORA-06502.
    ORA-06502: PL/SQL: numeric or value error
    SQL> desc sound;
    Name Null? Type
    SL_NO NUMBER(2)
    MUSIC LONG RAW
    LANG CHAR(10)
    IF MY PROCESS TO SOLVE THE ABOVE PROBLEM IS OK THEN PLESE TELL ME THE SOLUTION FOR THE ERROR. OTHER WISE PLEASE SUGGEST ME,IF ANY OTHER WAY IS THERE TO SOLVE THE ABOVE PROBLEM.
    THANKS IN ADVANCE.
    D. Prasad

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • How can i merge data between two tables and then insert to another table

    Hi ,
    Could pls help me,
    I have two tables i need to merge this tables for a single column then need to insert the records to a third table
    Ex-
    Suppose emp, dept two tables , merge this two tables for empid then insert that value to emp_dept table.
    I am using oracle 10g.
    Thanks

    Hi,
    too many values comes from the select clause. I stated you have to match the columns from the emp_dept table to the columns in the select. In my example I return all the columns of emp and dept, but I think you have only one empid column, the select for example will give 2, one empid from emp and one empid from dept. So best is to match:
    insert into emp_dept
    (column1,column2,column3,empid)
    select emp.column1, emp.column2, dept.column3, emp.empid
    from   emp, dept
    where emp.empid = dept.empidAbove is an example how you can match, so the number of columns in the insert should match with the number of columns coming from the select.
    But better for us to help you is give your definitions of emp, dept and emp_dept.
    Herald ten Dam
    htendam.wordpress.com

  • Insert into another table using record

    Hi all, i am reading from TableA , need to sort the records and insert the sorted order in table B, and need some help with the coding, would appreciate if anyone can help.
    I am using records
    create or replace procedure ZZ AS
    DECLARE
    CURSOR GEN_CUR IS
         select *
         FROM TABLE_A;
            ORDER BY field_1 ASC;
         info_rec GEN_CUR%ROWTYPE;
         BEGIN
              open GEN_CUR;
              LOOP
                   FETCH gen_cur INTO info_rec;
                   EXIT WHEN gen_cur%NOTFOUND;
                   -- i need to insert the record into table_B. table_B's fields are identical to table_A, but am unsure of the code.
              END LOOP;
              CLOSE gen_cur;
         END;Message was edited by:
    learningoracle

    From Oracle 9.2 onwards we can do clever things with records:
    SQL> select * from tab1
      2  /
    K F
    Z X
    A X
    SQL> declare
      2     r tab1%ROWTYPE;
      3  begin
      4     for r in ( select * from tab1 order by key ) loop
      5       insert into tab12 values r;
      6     end loop;
      7  end;
      8  /
    PL/SQL procedure successfully completed.
    SQL> select * from tab12
      2  /
    K F
    A X
    Z X
    SQL> But as K Richards has pointed out you can do this with a straight INSERT ... SELECT statement...
    SQL> roll
    Rollback complete.
    SQL> insert into tab12
      2  select * from tab1 order by key
      3  /
    2 rows created.
    SQL> select * from tab12
      2  /
    K F
    A X
    Z X
    SQL> Note that sort order is only guaranteed when we use an ORDER BY clause.
    Cheers, APC

  • How to Query from table and insert into another table.

    Hi
    I am using the following query in VO and all the columns are attached to EO ( table name emp_temp)
    select a.npw_number, a.person_id,b.assignment_id,a.title,a.last_name,a.first_name,a.date_of_birth,a.sex,
    b.organization_name,b.organization_id,b.job_id,b.job_name,b.position_id,b.position_name,b.supervisor_id,
    b.supervisor_name,b.location_id,b.effective_start_date,b.effective_end_date
    from per_all_people_f a,per_assignments_v b
    where a.person_id=b.person_id
    and a.npw_number=:1
    I can query the data in screen. I need into insert the data into the emp_temp.
    I don't know how to do this . Please help me.
    Thanks
    Subra

    You can create a VO based on EO on emp_temp table.....
    And u have attached a Different VO on the page... Right...
    Now what u can do is....once u click on apply....
    u can set the each attributes of EO based VO explicitly via code, from the values of second VO.... and then commit.....
    Perhaps this might help...

  • Diffrence between backend insert and front end insert into a table.

    I am developing a conversion program for tax exemption. For this program only ZX_EXEMPTIONS table is used to populate the data and we got confirmation from Oracle also regarding this.For inserting the data into this table we are taking the max of tax_exemption_id which is pk for this table and adding one to it and inserting into the table. But problem here is after inserting from back end we are not able to insert from front end.
    It seems backend data is holding the tax_exemption_id which is suppose to reserve by front end data.Please explain the different behavior of populating of tax_exemption_id from front end and back end.

    Hi,
    i think the problem is that you are using max-value + 1 for tax_exemption_id. But as ZX_EXEMPTIONS is using sequence ZX_EXEMPTIONS_S
    for primary key generation, you encounter situation that you are increasing PK Id for this table without increasing sequence value.
    When trying to insert rows from front end - which probably uses sequence value - it tries to use a sequence value already used by your backend
    process (which generated it by Maxvalue + 1) and would then encounter a primary key violation.
    I think you should use sequence mentioned above to generate your PK Ids in backend process as well. And before doing so, check current value
    of ZX_EXEMPTIONS_S, as you might need to rebuild the sequence in order to select nextval sucessfully for both frontend and backend.
    Regards

  • How to dynamic field insert into intenal table?

    hi friends
    this is my urgent requirements .... how to dynamic field insert into internal table if it possible please tell me
    thanks & regards
    pauldharma

    Hi,
    Go through this
    REPORT  yusmm_text1  NO STANDARD PAGE HEADING
                         LINE-SIZE 199.
    T A B L E S
    TABLES: MARA,
            MAKT,
            THEAD.
    GLOBAL TYPE-POOLS
    TYPE-POOLS : SLIS.
       GLOBAL TYPES
    TYPES : BEGIN OF TP_FINAL,
           MATNR TYPE MARA-MATNR,
           BEGRU TYPE MARA-BEGRU,
           MTART TYPE MARA-MTART,
           MAKTX TYPE MAKT-MAKTX,
           SPRAS TYPE MAKT-SPRAS,
           LTXT(2000)  TYPE C ,
           SRNO TYPE N ,
          END OF TP_FINAL.
    TYPES : BEGIN OF TP_T002,
            SPRAS TYPE T002-SPRAS,
            LAISO TYPE T002-LAISO,
            SRNO TYPE N ,
            END OF TP_T002.
    TYPES : BEGIN OF TP_MARA_MAKT,
            MATNR TYPE MARA-MATNR,
            BEGRU TYPE MARA-BEGRU,
            MTART TYPE MARA-MTART,
            SPRAS TYPE MAKT-SPRAS,
            MAKTX TYPE MAKT-MAKTX,
           END OF TP_MARA_MAKT.
    Types: BEGIN OF tp_matnr,
           matnr TYPE mara-matnr,
           END OF tp_matnr.
       GLOBAL ELEMENTARY VARIABLES
    DATA : gv_date TYPE sy-datum.
    DATA : gv_repid TYPE sy-repid.
    DATA : g_var1(10) TYPE C.
    DATA : gv_index TYPE sy-tabix.
    DATA: gv_strg TYPE string,
          gv_strg1(2000) TYPE C.
    DATA : gv_lang TYPE sy-langu.
    DATA : g_v(3) TYPE N .
    DATA : gv_lines(3) TYPE N .
    DATA : gv_var(3) TYPE N .
    DATA : gv_var1(3) TYPE N.
    DATA: gv_str TYPE STRING.
    DATA: gv_str1 TYPE STRING.
    DATA : gv_li TYPE I,
           gv_lit TYPE I,
           gv_lin TYPE I.
    DATA: g_var11(3) TYPE N,
          gv_li1(3) TYPE N,
          g_var2(3) TYPE N.
    DATA : gv_i1 TYPE I.
    DATA : gv_i TYPE I.
    DATA: gl_lenght TYPE I.
       GLOBAL STRUCTURES
    DATA:   T_NEWTABLE TYPE REF TO DATA,
            T_NEWLINE  TYPE REF TO DATA,
            T_FLDCAT1   TYPE SLIS_T_FIELDCAT_ALV,
            T_FLDCAT   TYPE LVC_T_FCAT,
            WA_IT_FLDCAT TYPE LVC_S_FCAT,
            WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV,
            WA_COLNO(2) TYPE N,
            WA_FLNAME(5) TYPE C,
            L_LT TYPE SLIS_LAYOUT_ALV.
       GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
    DATA : IG_MARA_MAKT TYPE STANDARD TABLE OF TP_MARA_MAKT,
           WG_MARA_MAKT TYPE TP_MARA_MAKT.
    DATA : IG_T002 TYPE STANDARD TABLE OF TP_T002,
           WG_T002 TYPE TP_T002.
    DATA : IG_FINAL TYPE STANDARD TABLE OF TP_FINAL,
           WG_FINAL TYPE TP_FINAL.
    data : IG_MATNR TYPE STANDARD TABLE OF TP_MATNR WITH HEADER  LINE,
           WG_MATNR TYPE TP_MATNR.
    DATA:BEGIN OF IG_THEAD OCCURS 0.
            INCLUDE STRUCTURE THEAD .
    DATA: END OF IG_THEAD.
    DATA:BEGIN OF IG_TLINE OCCURS 0.
            INCLUDE STRUCTURE TLINE  .
    DATA:END OF IG_TLINE.
    FIELD-SYMBOLS
    FIELD-SYMBOLS: <T_DYNTABLE> TYPE STANDARD TABLE,"Dynamic internal
                                                            "tablename
                   <FS_DYNTABLE>,  "Field symbol to create work area
                  <FS_FLDVAL> TYPE ANY.   " Field symbol to assign values
    COMPULSORY
    FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
                   <FS_DATA1> TYPE REF TO DATA,
                   <FS_2>    TYPE STANDARD TABLE,
                   <FS_22>   TYPE STANDARD TABLE,
                   <FS_1>,
                   <FS_11>,
                   <F>,
                   <FA>,
                   <LWA_LINE_WA>,
                   <LWA_LINE_WA1>.
    ------- Create Dyn Table From FC
    DATA: LT_DATA        TYPE   REF TO DATA,
          LT_DATA1        TYPE   REF TO DATA,
          LWA_LINE       TYPE   REF TO  DATA,
          LWA_LINE1       TYPE   REF TO  DATA,
          LI_FIELD_CAT   TYPE   LVC_T_FCAT,
          LWA_FIELD_CAT  TYPE   LVC_S_FCAT.
       PARAMETERS & SELECT-OPTIONS
    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_SPRAS FOR MAKT-SPRAS NO INTERVALS  DEFAULT 'EN'
                                                            OBLIGATORY ,
                     S_MATNR FOR MARA-MATNR,
                     S_MTART FOR MARA-MTART.
    PARAMETERS: GP_SIZE TYPE I DEFAULT '200'.
    SELECTION-SCREEN : END OF BLOCK B1.
       INITIALIZATION
    INITIALIZATION.
      gv_repid = sy-repid.
      gv_date = sy-datum.
    AT SELECTION-SCREEN
    AT SELECTION-SCREEN.
      IF GP_SIZE < 0.
       MESSAGE E002(00).
      ENDIF.
      IF GP_SIZE > 50000.
       MESSAGE W130(26) WITH TEXT-004.
        SET CURSOR FIELD 'gp_size'.
      ENDIF.
    START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM FIELDCAT.
      PERFORM LAYOUT.
      PERFORM DATA_FETCH.
      PERFORM READ_DATA_TO_FINAL.
      SORT ig_final BY matnr spras.
      gv_lin = gv_li.
      gv_li = gv_li - 2.
      LOOP AT ig_final INTO wg_final.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Material Number'.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Authorization Group'.
        g_VAR11 = wg_final-srno + 2.
        gv_li1 = gv_li1 + 2.
        MOVE : g_var11 TO gv_i1.
        ASSIGN COMPONENT g_var11 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'MatDesc'.
        g_var2 = g_var11 + gv_lines.
        ASSIGN COMPONENT g_var2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'BasicData'.
        APPEND <LWA_LINE_WA1> TO <FS_22>.
        EXIT.
       ENDLOOP.
      LOOP AT ig_final INTO wg_final.
        AT NEW matnr.
          gv_index = sy-tabix.
          ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
          <F> = wg_final-matnr.
          ENDAT.
        AT NEW MATNR.
        GV_INDEX = SY-TABIX.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-matnr.
         ENDAT.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-begru.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-begru.
        gv_var = wg_final-srno + 2.
        gv_li = gv_li + 2.
        MOVE : gv_var TO gv_i.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-maktx.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-maktx.
        gv_var1 = gv_var + gv_lines  .
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
       <F> = wg_final-ltxt.
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-ltxt.
        AT END OF matnr.
          APPEND <LWA_LINE_WA> TO <FS_2>.
          CLEAR <LWA_LINE_WA>.
        ENDAT.
        AT END OF matnr.
         APPEND <LWA_LINE_WA1> TO <FS_22>.
         CLEAR <LWA_LINE_WA1>.
        ENDAT.
      ENDLOOP.
      PERFORM display..
    *&      Form  data_fetch
          text
    -->  p1        text
    <--  p2        text
    FORM DATA_FETCH .
      SELECT matnr
              from mara up to gp_size rows
             appending corresponding fields of table ig_matnr
             where matnr in s_matnr
             and mtart in s_mtart.
    loop at ig_matnr.
      SELECT  MARA~MATNR
              MARA~BEGRU
              MARA~MTART
              MAKT~SPRAS
              MAKT~MAKTX FROM MARA INNER JOIN MAKT
        ON MARAMATNR = MAKTMATNR
       appending corresponding fields of TABLE ig_mara_makt  UP TO GP_SIZE
    ROWS
        WHERE makt~spras IN s_spras
        AND   mara~matnr IN s_matnr
        AND   mara~mtart IN s_mtart
        AND   mara~matnr EQ ig_matnr-matnr.
        endloop.
      IF sy-subrc = 0.
        SORT ig_mara_makt.
      ENDIF.
    ENDFORM.                    " data_fetch
    *&      Form  read_data_to_final
          text
    -->  p1        text
    <--  p2        text
    FORM READ_DATA_TO_FINAL .
      LOOP AT ig_mara_makt INTO wg_mara_makt .
        wg_final-MATNR = wg_mara_makt-MATNR.
        wg_final-BEGRU = wg_mara_makt-BEGRU.
        wg_final-MTART = wg_mara_makt-MTART.
        wg_final-SPRAS = wg_mara_makt-SPRAS.
        wg_final-MAKTX = wg_mara_makt-MAKTX.
        READ TABLE ig_t002 INTO wg_t002 WITH KEY spras = wg_final-spras.
        IF sy-subrc = 0.
          wg_final-srno = wg_t002-srno.
        ENDIF.
        CLEAR ig_thead[].
        ig_thead-TDOBJECT = 'MATERIAL'.
        ig_thead-TDNAME   = wg_final-matnr.
        ig_thead-TDID     = 'GRUN'.
        ig_thead-TDSPRAS  = wg_final-spras.
        CALL FUNCTION 'TEXT_READ'
          EXPORTING
            I_HEADER   = IG_THEAD
            I_READONLY = 'X'
          IMPORTING
            E_HEADER   = IG_THEAD
          TABLES
            T_LINES    = IG_TLINE[]
          EXCEPTIONS
            NOTFOUND   = 1.
        IF sy-subrc  EQ 0.
          LOOP AT  ig_tline.
            gv_strg = ig_tline-tdline.
            IF gv_strg1 <> ' '.
              CONCATENATE gv_strg1 ';' gv_strg INTO gv_strg1.
            ELSE.
              gv_strg1 = gv_strg.
            ENDIF.
          ENDLOOP.
          wg_final-ltxt = gv_strg1.
          APPEND wg_final TO ig_final.
          CLEAR wg_final.
          gv_strg1 = ' '.
        ELSE.
          APPEND wg_final TO  ig_final.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " read_data_to_final
    " read_data_to_final
    *&      Form  layout
          text
    -->  p1        text
    <--  p2        text
    FORM LAYOUT .
      CLEAR L_LT.
      L_LT-ZEBRA = 'X'.
      L_LT-COLWIDTH_OPTIMIZE = 'X'.
      L_LT-WINDOW_TITLEBAR = 'MATERIAL DETAILS'.
    ENDFORM.                    " layout
    *&      Form  fieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM FIELDCAT .
      SELECT SPRAS
               LAISO FROM t002 INTO  CORRESPONDING FIELDS OF TABLE ig_t002
          WHERE spras IN s_spras.
      DESCRIBE TABLE ig_t002 LINES gv_lines.
      LOOP AT ig_t002 INTO wg_t002.
        g_v = g_v + 1.
        Wg_t002-srno = g_v.
        MODIFY ig_t002 FROM wg_t002 TRANSPORTING SRNO.
      ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'MD-' wg_t002-LAISO
                          WA_COLNO
                         INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'BD-' wg_t002-LAISO
                           WA_COLNO
                        INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      MOVE 'MATNR' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Material No'.
      WA_IT_FLDCAT-INTLEN = 18.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 1.
      MOVE 'BEGRU' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Authorization Group'.
      WA_IT_FLDCAT-INTLEN = 4.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 2.
      DESCRIBE TABLE T_FLDCAT LINES gv_li.
      ASSIGN LT_DATA TO <FS_DATA>.
    Creating the Dynamic Internal Table
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA>   " Dynamic Internal Table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA>->* TO <FS_1>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_1> TO <FS_2>.
    Creating a Workarea
      CREATE DATA LWA_LINE LIKE LINE OF <FS_2> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE->* TO <LWA_LINE_WA>.
      LOOP AT T_FLDCAT INTO WA_IT_FLDCAT.
        WA_IT_FLDCAT1-FIELDNAME = WA_IT_FLDCAT-FIELDNAME.
        WA_IT_FLDCAT1-TABNAME =  WA_IT_FLDCAT-TABNAME.
        WA_IT_FLDCAT1-SELTEXT_L = WA_IT_FLDCAT-SELTEXT.
       WA_IT_FLDCAT1-REF_TABNAME = 'MARC'.
        APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
        CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
      ENDLOOP.
      ASSIGN LT_DATA1 TO <FS_DATA1>.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA1>  " Dynamic Internal table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA1>->* TO <FS_11>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_11> TO <FS_22>.
    Creating a Workarea
      CREATE DATA LWA_LINE1 LIKE LINE OF <FS_22> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE1->* TO <LWA_LINE_WA1>.
    ENDFORM.                    " fieldcat
    *&      Form  show
          text
    -->  p1        text
    <--  p2        text
    FORM Display .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
       I_INTERFACE_CHECK                 = ' '
       I_BYPASSING_BUFFER                = ' '
       I_BUFFER_ACTIVE                   = ' '
         I_CALLBACK_PROGRAM                = GV_REPID
        I_CALLBACK_PF_STATUS_SET          = 'PF_STATUS_SET'
        I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
       I_CALLBACK_TOP_OF_PAGE            = ' '
       I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
       I_CALLBACK_HTML_END_OF_LIST       = ' '
       I_STRUCTURE_NAME                  =
       I_BACKGROUND_ID                   = ' '
       I_GRID_TITLE                      =
       I_GRID_SETTINGS                   =
        IS_LAYOUT                         = L_LT
         IT_FIELDCAT                       = T_FLDCAT1[]
       IT_EXCLUDING                      =
       IT_SPECIAL_GROUPS                 =
       IT_SORT                           =
       IT_FILTER                         =
       IS_SEL_HIDE                       =
       I_DEFAULT                         = 'X'
       I_SAVE                            = ' '
       IS_VARIANT                        =
       IT_EVENTS                         =
       IT_EVENT_EXIT                     =
       IS_PRINT                          =
       IS_REPREP_ID                      =
       I_SCREEN_START_COLUMN             = 0
       I_SCREEN_START_LINE               = 0
       I_SCREEN_END_COLUMN               = 0
       I_SCREEN_END_LINE                 = 0
       I_HTML_HEIGHT_TOP                 = 0
       I_HTML_HEIGHT_END                 = 0
       IT_ALV_GRAPHICS                   =
       IT_HYPERLINK                      =
       IT_ADD_FIELDCAT                   =
       IT_EXCEPT_QINFO                   =
       IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
       E_EXIT_CAUSED_BY_CALLER           =
       ES_EXIT_CAUSED_BY_USER            =
        TABLES
          T_OUTTAB                          = <FS_2>
    EXCEPTIONS
       PROGRAM_ERROR                     = 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.
    ENDFORM.                    " display
    FORM PF_STATUS_SET USING RS_EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'DISPLAY' .
    ENDFORM. "PF_STATUS_SET
    *& Form Name: user_command *
    *& Form Desc: For Handling USER_COMMAND *
    FORM USER_COMMAND USING IF_UCOMM TYPE SY-UCOMM
                         IS_SELFIELD TYPE SLIS_SELFIELD.
      CASE IF_UCOMM.
        WHEN 'DOWNLOAD'.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
      TITLEBAR                    = ' '
      DIAGNOSE_OBJECT             = ' '
              TEXT_QUESTION               = 'Data download to excel'
      TEXT_BUTTON_1               = 'Ja'(001)
      ICON_BUTTON_1               = ' '
      TEXT_BUTTON_2               = 'Nein'(002)
      ICON_BUTTON_2               = ' '
      DEFAULT_BUTTON              = '1'
      DISPLAY_CANCEL_BUTTON       = 'X'
      USERDEFINED_F1_HELP         = ' '
      START_COLUMN                = 25
      START_ROW                   = 6
      POPUP_TYPE                  =
    IMPORTING
      ANSWER                      =
    TABLES
      PARAMETER                   =
    EXCEPTIONS
      TEXT_NOT_FOUND              = 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 FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
        BIN_FILESIZE                  =
              FILENAME                     = 'C:\Material-Text.xls'
             FILETYPE                      = 'ASC'
        APPEND                        = ' '
         WRITE_FIELD_SEPARATOR         = 'X'
        HEADER                        = '00'
         TRUNC_TRAILING_BLANKS         = 'X'
        WRITE_LF                      = 'X'
        COL_SELECT                    = ' '
        COL_SELECT_MASK               = ' '
         DAT_MODE                      = 'X'
       IMPORTING
         FILELENGTH                    = GL_LENGHT
            TABLES
              DATA_TAB                      = <FS_22>
      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
        OTHERS                        = 22
          IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          IF GL_LENGHT NE 0.
            MESSAGE S398(00) WITH 'DATA downloaded to EXCEL'.
          ENDIF.
    Thanks
      ENDCASE.
    ENDFORM.                    "user_command

  • Build a sql query fro different table and insert into a table

    Hi I have a requirement ,
    i have some table 1 table which holds rules which rules i have to apply on the sql query
    2 table will hold table name and column name and transformation
    with these help of 2 tables i want to build a sql quey and the sql query need to be insert into another  table.

    Hi Karthick,
    I am not going to build Dynamic Data Model.
    i already have table 1 contains rules let's say COUNT,
    and another table contain source table name , column name , Target table name, Source Table name like that
    so with the help of these 2 tables i want to build Sql query and going to insert into 3rd table.

  • Insert into two tables with a single query (same ID)

    Hello,
    I want to insert two tables at the same time ( with a single query) provided that both records get inserted with the same id. How do I do this?
    Table Movies
    id
    name
    Table Category
    movie_id
    cat_typea) Insert into first table, retrieve the id (may be by using my_sequence.currval and then insert into another table.
    issue: Makes three query to the db, I am also guessing that when multiple people try to insert there will be an issue, I might be wrong.
    I don't have any other idea.
    Greatly appreciated!

    Why don't use multitable insert ? It's available from 9i.
    A sequence.nextval will return the same value within the whole instruction
    so all records can be inserted with the same id.
    Look at this example:
    DROP TABLE A;
    DROP TABLE B;
    drop sequence a_seq;
    CREATE TABLE A(
      ID NUMBER,
      FIRSTNAME VARCHAR2(50)
    CREATE TABLE B AS
    SELECT id, firstname lastname FROM a;
    CREATE SEQUENCE a_seq
    START WITH 1;
    INSERT ALL
    INTO A(ID, FIRSTNAME) VALUES(A_SEQ.NEXTVAL, FNAME)
    INTO B(ID, LASTNAME) VALUES(A_SEQ.NEXTVAL, LNAME)
    SELECT 'fname ' || LEVEL FNAME, 'lname ' || LEVEL LNAME
    FROM DUAL
    CONNECT BY LEVEL < 10
    COMMIT;
    SELECT * FROM A;
    SELECT * FROM b;
    DROP TABLE A succeeded.
    DROP TABLE B succeeded.
    drop sequence a_seq succeeded.
    CREATE TABLE succeeded.
    CREATE TABLE succeeded.
    CREATE SEQUENCE succeeded.
    18 rows inserted
    commited
    ID                     FIRSTNAME                                         
    3                      fname 1                                           
    4                      fname 2                                           
    5                      fname 3                                           
    6                      fname 4                                           
    7                      fname 5                                           
    8                      fname 6                                           
    9                      fname 7                                           
    10                     fname 8                                           
    11                     fname 9                                           
    9 rows selected
    ID                     LASTNAME                                          
    3                      lname 1                                           
    4                      lname 2                                           
    5                      lname 3                                           
    6                      lname 4                                           
    7                      lname 5                                           
    8                      lname 6                                           
    9                      lname 7                                           
    10                     lname 8                                           
    11                     lname 9                                           
    9 rows selected

  • Need help in SQL Query: Update a row in a table & insert the same row into another table

    I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
    Thanks in Advance.

    Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
    SQL> var v_id number
    update tableA  
    set colB='ABC' 
    where colC='XYZ' 
    returning id into :v_id;
    insert into table A_History (ID, colA, colB, ColC)  
    select id, ColA, ColB, ColC  
    from tableA  
    where id = :v_id;   

  • To replace values of one of the field in the database table

    How to replace values of one of the field in the database table with a new values? Pls help to solve

    Hi
    You can use the UPDATE command to update one of the field value in a table
    see the UPDATE syntax and use it
    but in real time you should not do like this
    Regards
    Anji

Maybe you are looking for

  • SharePoint 2013 SSRS SQL 2012 SP1 and Mac Safari 5.1 or 6.0 report issues

    I have been try to figure out an issue that only seems to be affecting Safari 5.1 or 6.0 on OSX 10.6.8 or 10.7. I can view the same reports as the same user on the same Mac as the same user in Chrome 27.0.1453.116 or Firefox 22.  I have also tested i

  • Can't send even 1-member Mail group to SMTP server

    Using Mail 2.1.3, I can't send a group e-mail via my ISP, smtpauth.earthlink.net. This is true even when the group contains only one address, my own. The message is accepted if I expand the group. Earthlink's SMTP mail server says "message does not c

  • Low resolution Indesign files on Mac Book Pro!

    Why is my new mac book pro retina showing Indesign as low res text and images? Pdf's exported as hi-res print ready files are also low res to look at on screen!

  • Force encryption on SQL Server not working?

    Hello Everyone, I'm running SQL Server 2008 64-bit. I've installed a self-signed cert on the box and set  "Force Encryption"  and restarted SQL server.  I setup a client machine to trust the authority of the cert installed on the server. When I conne

  • Facing Problem in Hierarchies on Multiprovider.

    Hi All, I am new to BW. Issue: I executed a report with selections in BeX, I am getting the output. Selections include 2 infoObjects and One Hierarchy. I got the report in BeX. But, When I executed on the Multiprovider/Cube on which the report is bui