How to insert data in the table without  join and using mapped rule value

1.Table SOL_K
A B C D – Columns Name
C D A B –Coulmns Values Defined (Rule --- Defined)
2.SECOND table SIC_K
SIC_ K
A B C D
Kamal Micky NULL MANOJ
3 Table SIC_Mapping
Same Columns A B C D based On Table SOL_K defined rule
I want to insert values(from table SIC K) into table SICMapping Table with the help of first table(SOL_K)(mapped rule)
Required Result SIC_Mapping Table
The output will be come like this.
A B C D — Columns Name
NULL MANOJ Kamal Micky ---- Came based on defined Mapping Rule

What's your database version?
That's a funny requirement.
How about :
select case sol.a
          when 'A' then sic.a
          when 'B' then sic.b
          when 'C' then sic.c
          when 'D' then sic.d
       end as a
     , case sol.b
          when 'A' then sic.a
          when 'B' then sic.b
          when 'C' then sic.c
          when 'D' then sic.d
       end as b
     , case sol.c
          when 'A' then sic.a
          when 'B' then sic.b
          when 'C' then sic.c
          when 'D' then sic.d
       end as c
     , case sol.d
          when 'A' then sic.a
          when 'B' then sic.b
          when 'C' then sic.c
          when 'D' then sic.d
       end as d
from sol_k sol, sic_k sic
;XQuery can do the trick too :
SQL> SELECT *
  2  FROM XMLTable(
  3   'for $i in ora:view("SIC_K")/ROW
  4    return element r {
  5     for $j in ora:view("SOL_K")/ROW/child::*
  6     return element {name($j)} {$i/child::*[name()=$j]/text()}
  7    }'
  8   columns
  9     a varchar2(30) path 'A'
10   , b varchar2(30) path 'B'
11   , c varchar2(30) path 'C'
12   , d varchar2(30) path 'D'
13  );
A          B          C          D
           MANOJ      Kamal      Micky
Edited by: odie_63 on 29 juin 2011 22:07

Similar Messages

  • How to Insert data in 3 table without use of join 1table mapped rule define

    1.Table SOL_K
    A B C D – Columns Name
    C D A B –Coulmns Values Defined (Rule --- Defined)
    2.SECOND table SIC_K
    SIC_ K
    A B C D
    Kamal Micky NULL MANOJ
    3 Table SIC_Mapping
    Same Columns A B C D based On Table SOL_K defined rule
    I want to insert values(from table SIC K) into table SICMapping Table with the help of first table(SOL_K)(mapped rule)
    Required Result SIC_Mapping Table
    The output will be come like this.
    A B C D — Columns Name
    NULL MANOJ Kamal Micky ---- Came based on defined Mapping Rule

    This is the forum for issues with the SQL Developer tool. You will get better answers in the SQL and PL/SQL forum.

  • How to insert data into the mysql table by giving as a text file

    Hi,
    Any one know's how to insert data into the mysql table by giving as a text file as the input in JSP.Please respond ASAP.
    Thanks:)

    At least you can try StringTokenizer to parse your text files. Or download a text JDBC driver to parse your files, for instance, HXTT Text(www.hxtt.net) or StelsCSV(www.csv-jdbc.com).

  • Its very urgent:how to insert data into database tables

    Hi All,
    I am very new to oaf.
    I have one requirement data insert into database tables.
    here createPG having data that data insert into one custom table.
    but i dont know how to insert data into database tables.
    i wrote the code in am,co as follows.
    in am i wrote the code:
    public void NewoperationManagerLogic()
    ManagerCustomTableVOImpl vo1=getManagerCustomTableVO1();
    OADBTransaction oadbt=getOADBTransaction();
    if(!vo1.isPreparedForExecution())
    vo1.executeQuery();
    Row row=vo1.createRow();
    vo1.insertRow(row);
    in createPG processrequest co:
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    ManagerInformationAMImpl am=(ManagerInformationAMImpl)pageContext.getApplicationModule(webBean);
    am.NewoperationManagerLogic();
    process form request:
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    if(pageContext.getParameter("Submit")!=null)
    ManagerInformationAMImpl am=(ManagerInformationAMImpl)pageContext.getApplicationModule(webBean);
    am.getOADBTransaction().commit();
    please help with an example(sample code).
    its very urgent.
    thanks in advance
    Seshu
    Edited by: its urgent on Dec 25, 2011 9:31 PM

    Hi ,
    1.)You must have to create a EO based on custom table and then VO based on this EO eventually to save the values in DB
    2.) the row.setNewRowState(Row.STATUS_INITIALIZED); is used to set the the status of row as inialized ,this is must required.
    3.) When u will create the VO based on EO the viewattributes will be created in VO which will be assigned to the fields to take care the db handling .
    You must go thtough the lab excercise shipped with you Jdeveloper ,there is a example of Create Employee page ,that will solve your number of doubts.
    Thanks
    Pratap

  • How to insert data in database table

    Hi experts,
                   How to insert data into database table using internal table from function module.

    Hi,
    As per my understanding are you looking for the complete API feature of data insertion into the database using the Locking Mechanism? If yes, then you need to create a Lock Object using the Primary keys of the Primary Table and Secondary Tables. You need to call the lock object first and then you need to make the entry into the table. This principle is based on  'All or None Concept'.
    For the insert Statement Key word you can have a look at the following link:
    http://help.sap.com/abapdocu/en/ABAPINSERT_SOURCE.htm
    Hope this helps.
    Thanks,
    Samantak.

  • How to insert data to the specified row column of the multi column list box

    Hi All
    How do i insert data into the specified column of the multi cplumn list box?
    I have a table that containsall station nos and name.Then another table contains the data the various stations having at  for 24 hrs.That is 12 am to 11 pm.
    And i want to display each stations details as follows using a multi column list box/table
    My stationinfo table
    stnno   stnname......................
    s1           stn1
    s2            stn2
    s3             stn3
    The other table
    stnno      sysdatetime       data
    s1             12am                   1
    s2              12am                   4
    s1               1  am                 2
    So the station s1,s2.... will have data for 24 hrs.
    And i want to display it as follows using a multicolumn listbox
    stnname        12am   1 am ......................................11pm
    s1                   ...................
    s2                 ........................
    What i have in my  mind is to get all station nos
    and in a for loop get the station's data from 12 am to 11 pm
    or
    select every statios data for each hor.But in this case i have to query the database 24 times.So i dont think its a good way.
    Or any other better query available?
    Can anybody suggest me a good idea?
    One more thing...how to insert data into the specified field row or column of a multi column list box?
    Thanks in advance

    hi
    i want to know,,can u say ur need clearly...and i attached two image u see that one
    Indrajit
    | [email protected] | [email protected] .
    Attachments:
    station.JPG ‏35 KB
    station2.JPG ‏79 KB

  • How to insert date into a table by selecting form sysdate

    Hi
    My Table format is like this
    SQL>desc log;
    Name Null? Type
    EMP_ID VARCHAR2(30)
    LOGIN DATE
    LOGOUT DATE
    now when ever an employee logs in i w'd like to insert date into the table.
    i put up the following query
    SQL> insert into log(emp_id,login)
    2 values
    3 ('Ed_01',
    4 select
    5 sysdate
    6 from dual
    7 );
    select
    ERROR at line 4:
    ORA-00936: missing expression
    I got the above error how can i rectify that plz suggest me very urgently as i have to submit my project very early to my boss.

    try this :
    insert into log(emp_id,login) values ('Ed_01', sysdate);

  • How to insert data into two tables linke with foreign key..

    I have two tables
    1)EMP(emp_ID,username,emp_type_code)
    emp_ID is primary key, emp_type_code is a foreign key references emptype table.
    2)emptype(emp_type_code,emp_type_descripton)
    emp_type_code is primary key
    Could anyone help me ..how to insert data into EMP table. How to insert data into two tables linke with foreign key..

    CREATE TABLE "CATDB"."DWDIMUSER"
    "USER_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_ID" NUMBER(10,0),
    "FULLNAME" VARCHAR2(20 BYTE),
    "FNAME" VARCHAR2(20 BYTE),
    "LNAME" VARCHAR2(20 BYTE),
    "USER_SUBTYPE" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMUSER_PK" PRIMARY KEY ("USER_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE,
    CONSTRAINT "DIMUSER_DIMSPECIALTY_FK" FOREIGN KEY ("SPECIALTY_ID") REFERENCES "CATDB"."DWDIMSPECIALTY" ("SPECIALTY_ID") DISABLE
    CREATE TABLE "CATDB"."DIMSPECIALTY"
    "SPECIALTY_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_NAME" VARCHAR2(100 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("SPECIALTY_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    INSERT INTO DIMUSER (FullName, FNAME, LNAME, USER_TYPE, USER_SUBTYPE)
    SELECT DISTINCT
    Engineer AS FullName,
    regexp_substr(Engineer , '[^,| ]+', 1, 1) as FName,
    regexp_substr(Engineer , '[^,| ]+', 1, 2) as LName ,
    'Engineer'
    FROM EMPLOYEELOOKUP;
    INSERT INTO DIMSPECIALTY (SPECIALTY_NAME)
    SELECT DISTINCT SPECIALITY
    FROM EMPLOYEELOOKUP;
    COMMIT;
    CREATE TABLE employeelookup ...IS A TABLE THAT HAS ALL THE DATA NEDED TO BE FILLED IN BOTHE TABLES...
    CREATE TABLE "CATDB"."EMPLOYEELOOKUP"
    "EMPLOYEELOOKUP_ID" NUMBER(10,0) NOT NULL ENABLE,
    "ENGINEER" VARCHAR2(25 BYTE),
    "SPECIALTY" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("EMPLOYEELOOKUP_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    DATA IN EMPLOYEELOOKUP
    Engineer, Specialty,
    John, Dow, Electronis,
    Dow, Jons, Technician
    Stan Smithers Sales
    Mark, Richards Marketing
    Jenny, Lane Marketing
    John, Lee Sales
    I NEED TO LOAD THE FOREIGN KEY IN DIMUSER FROM THE DIMSPECIALTY TABLE?
    BY USING THE LOOKUP TABLE TO MARCH THE NAMES UNDER THE Engineer COLUMN, SPECIALTY COLUMNE DISTICTIVLY BY JOINING THE DIMSPECILTY TO RISTIVE THE PRIMARY KEY AND FILL IT IN THE DIMUSER TABLE AS A FOREIGNE KEY.

  • Using variables to insert data in the table

    I want to insert datas in the table. I use constants,
    all the constants are stored properly in the table. But,
    when I use variables I get the error message
    "Too few parameters. expected 6".
    (I declared all the fields of the table as text only.)
    My program is "newt.jsp"
    <%@ page language="java" import="java.sql.*" %>
    <html>
    <head>
    <title>storing customer information in the database</title>
    </head>
    <body>
    <%
    String cno1 = request.getParameter("cno");
    String n1 = request.getParameter("n");
    String add11 = request.getParameter("add1");
    String add21 = request.getParameter("add2");
    String phone1 = request.getParameter("phone");
    String email1 = request.getParameter("email");
    Connection con = null;
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:customer"," "," ");
    Statement statement1 = con.createStatement();
    Statement statement2 = con.createStatement();
    statement2.executeUpdate("create table cust1 (cno varchar(20),n varchar(20),add1 varchar(20),add2 varchar(20),phone varchar(20),email varchar(20))");
    statement1.executeUpdate("insert into cust1 (cno,n,add1,add2,phone,email) values(cno1,n1,add11,add21,phone1,email1)");
    catch(SQLException sqle) {
    System.err.println(sqle.getMessage());
    catch(ClassNotFoundException cnfe) {
    System.err.println(cnfe.getMessage());
    catch(Exception e) {
    System.err.println(e.getMessage());
    finally {
         try {
         if(con!=null) {
              con.close();
    catch(SQLException sqle) {
    System.err.println(sqle.getMessage());
    %>
    <br><br>
    Mr./Ms. <%=n1 %> <br>
    Your datas have been stored.<br>
    </body>
    </html>
    Those who know answer please reply.
    My thanks in advance.

    I would expect your insert statement to be this:
    statement1.executeUpdate("insert into cust1 (cno,n,add1,add2,phone,email) values('"+cno1+"','"+n1+"','"+add11+"','"+add21+"','"+phone1+"','"+email1+"')");
    If you just create a string, it's not going to fill in variables into the string by magic.

  • How to insert data from *.dmp file to  oracle 11g using Oracle SQL Develope

    hi
    i backup my database using PL/SQL developer and made *.dmp file
    how to insert data from *.dmp file to oracle 11g using Oracle SQL Developer 2.1.1.64
    and how to make *.dmp file from sql*plus ?
    thanks in advance

    Pl/Sql developer has a config window, there you choose the exec to do the import/export.
    Find it and his home version, it may be exp or expdp, the home version is the version of the client where the exp executable is.
    Then use the same version of imp or impdp to execute the import, you do not need to use Oracle SQL Developer 2.1.1.64. If you want to use it, you must have the same version in the oracle home that exp/imp of sql developer use.

  • How to insert data into a table only when data has changed its value (when compared to the previous inserted value)

    I wish to insert data into a table only when the value of the inserted data has changed. Thus, in a time series, if the value of the data at time, t-1, is 206 then if the data to be inserted at time t is 206, then it is skipped (not entered).
    If the value of the data at time t+1 is 206, it is skipped also; until the value changes, so if the value at t+1 was 205, then that would be inserted, and if at time t+2 the data is 206, it would be inserted too.
    What is the best way to do it without increasing overheads?

    This view works:
    SELECT
    i.IDNO,i.[Date],i.[Level]
    FROM
    mytable i
    INNER
    JOIN mytable
    d
    ON
    d.IDNO
    = i.IDNO-1
    WHERE
    i.[Level]
    <> d.[Level]
    on this mytable below.  A trigger could be quite useful here although I am cautious using them. However I wish to avoid the overhead by not having a temp table (which could be sizable).  mytable below
    should give 3 lines. The IDNO is an identity column.
    IDNO
    Item
    Date
    Level
    1
    X24
    12/23/13 10:41
    22996
    2
    X24
    12/23/13 10:41
    22996
    3
    X24
    12/23/13 9:21
    23256
    4
    X24
    12/23/13 9:21
    23256
    5
    X24
    12/23/13 9:22
    23256
    6
    X24
    12/23/13 9:22
    23256
    7
    X24
    12/23/13 9:22
    22916

  • How to insert data into a table from an xml document

    using the XmlSql Utility, how do I insert data into a table from an xml document, using the sqlplus prompt.
    if i use the xmlgen.insertXML(....)
    requires a CLOB file, which i dont have, only the xml doc.
    Cant i insert directly from the doc to the table?
    the xmlgen examples I have seen first convert a table to a CLOB xmlString and then insert it into another table.
    Isnt there any other way?

    Your question is little perplexing.
    If you're using XML SQL Utility from
    the commandline, just use putXML.
    java OracleXML putXML
    null

  • How to insert data from a table to database

    Hi all,
    My problem statement is that:
    I have jsp page, which has a table with some columns editable for inserting data. I am using MySql database.
    Now when I insert the data in the table and click submit button , the data entered must get stored in the database.
    If its a single data I can do it , but how to do for mulitple rows or columns.
    Please suggest me a solution
    Regards,
    Suraj

    i did one program similar to this requirement. when the rows and columns are fixed then what is the problem.
    use java script and capture all the values into an array and pass this to servlet and there call a method which will set
    the bean objects. or else no need to pick the array directly pass all the parameters and set the beans by retrieving these
    parameters(request.getParameter()).
    Diablo

  • How to move data in the table to different database ?

    I'm currently having some problem with moving some of my data from devlopment db to production db. Currently i'm having 2 dev. db and i would like to combine the data in the table into 1 prod. db. Can anyone pls tell me, is it possible to do so. Please tell me the solution on how this can be done, if you guys know.
    Thanks in advance.

    Hi,
    create a database_link from your
    PROD db to each of the DEV dbs.
    then insert into table (select * from
    table@dev_db1)
    insert into table (select * from table@dev_db2)
    HTH
    Detlev
    null

  • How to dispaly datas from the table, base on the selection screen

    hi there gurus,
    im currently developing a stock aging report,
    i have completed one program but it do not allow me to excutes the program althought the syntax is correct.
    i would to get some ideas from you, regarding how to extract the datas from the tables?
    my selction screen will be, mat number, date, and gl account.
    and the out put datas are, mbew-matnr, makt-maktx, mbew-lbkum, mara_meins, mbew-salk3,and the consumptions for the past 12months and the values for it.
    can u plz guide me with this,
    thank you,.
    this is kind of very urgent program that i need to finish , plz help me.

    here is the total code the i do
    REPORT  ZSTK_AGING_REP2.
    *TABLES
    TABLES: mseg,
            mara,
            makt,
            SKAT,
            SKA1,
            MARV,
            T001,
            T030,
            T149D,
            AM07M,
            MCMSEG,
            T001K,
            T001W,
            T134M,
            vbak,
            mbew,
    mcon, rmcb0, marc, t024w,  mvke, v134w, t438a, propf, maprf, t000, t024e
    , tvko.
    DATA: BEGIN OF ta_material OCCURS 2,
           werks LIKE mard-werks,
           lgort LIKE mard-lgort,
           matnr LIKE mard-matnr,
           labst LIKE mard-labst,
           umlme LIKE mard-umlme,
           insme LIKE mard-insme,
           einme LIKE mard-einme,
           speme LIKE mard-speme,
           retme LIKE mard-retme,
           verpr LIKE mbew-verpr,
           maktx LIKE makt-maktx,
           meins LIKE mara-meins,
          bukrs LIKE t001-bukrs,
          konto LIKE t030-konts,
          butxt LIKE t001-butxt,
          txt50 LIKE skat-txt50,
          MABTR LIKE MCMSEG-DMBTR,
          SKBTR LIKE MCMSEG-DMBTR,
          WAERS LIKE T001-WAERS,
          WAER2 LIKE T001-WAERS,
          BWKEY LIKE MBEW-BWKEY,
          LBKUM LIKE MBEW-LBKUM,
         MEINS LIKE MARA-MEINS,
             SALK3 LIKE MBEW-SALK3,
             WAERS1 LIKE T001-WAERS,
             BUKRS1 LIKE T001-BUKRS,
             KONTO1 LIKE T030-KONTS,
            lbkum LIKE mbew-lbkum,
              erdat LIKE vbak-erdat,
          END OF ta_material.
    DATA: BEGIN OF ta_mseg OCCURS 2,
            mblnr LIKE mseg-mblnr,
    *->Begin of KL02+ -
            mjahr like mseg-mjahr,
            zeile like mseg-zeile,
    *->End of KL02+ -
            meins LIKE mseg-meins,
            menge LIKE mseg-menge,
            werks LIKE mseg-werks,
            lgort LIKE mseg-lgort,
            matnr LIKE mseg-matnr,
            budat LIKE mkpf-budat,
            saknr LIKE SKA1-SAKNR,
          END OF ta_mseg.
    single recs based on MATNR
    DATA: BEGIN OF i_matnr OCCURS 0,
            werks LIKE mard-werks,
            lgort LIKE mard-lgort,
            matnr LIKE mard-matnr,
            maktx LIKE makt-maktx,
            mblnr LIKE mseg-mblnr,
            verpr LIKE mbew-verpr,
            labst LIKE mard-labst,                    "Valuated stock with
    *unrestricted use
            umlme LIKE mard-umlme,                    "Stock in transfer
    *(from one storage location to another)
            insme LIKE mard-insme,                    "Stock in quality
    *inspection
            einme LIKE mard-einme,                    "Total Stock of All
    *Restricted Batches
            speme LIKE mard-speme,                    "Blocked stock
            retme LIKE mard-retme,                    "Blocked Stock Returns
            meins LIKE mara-meins,                    "base unit
          bukrs LIKE t001-bukrs,
          konto LIKE t030-konts,
          butxt LIKE t001-butxt,
          txt50 LIKE skat-txt50,
          MABTR LIKE MCMSEG-DMBTR,
          SKBTR LIKE MCMSEG-DMBTR,
          WAERS LIKE T001-WAERS,
          WAER2 LIKE T001-WAERS,
          BWKEY LIKE MBEW-BWKEY,
          LBKUM LIKE MBEW-LBKUM,
         MEINS LIKE MARA-MEINS,
             SALK3 LIKE MBEW-SALK3,
             WAERS1 LIKE T001-WAERS,
             BUKRS1 LIKE T001-BUKRS,
             KONTO1 LIKE T030-KONTS,
            lbkum LIKE mbew-lbkum,
           END OF i_matnr.
    recs based on MBLNR
    DATA: BEGIN OF i_mblnr OCCURS 0,
            mblnr LIKE mseg-mblnr,
            werks LIKE mseg-werks,
            lgort LIKE mseg-lgort,
            matnr LIKE mseg-matnr,
            menge LIKE mseg-menge,
            meint LIKE mseg-meins,
            budat LIKE mkpf-budat,
         bukrs LIKE t001-bukrs,
         konts LIKE t030-konts,
         butxt LIKE t001-butxt,
         txt50 LIKE skat-txt50,
         MABTR LIKE MCMSEG-DMBTR,
         SKBTR LIKE MCMSEG-DMBTR,
         WAERS LIKE T001-WAERS,
         WAER2 LIKE T001-WAERS,
         BWKEY LIKE MBEW-BWKEY,
          LBKUM LIKE MBEW-LBKUM,
         MEINS LIKE MARA-MEINS,
             SALK3 LIKE MBEW-SALK3,
             WAERS1 LIKE T001-WAERS,
             BUKRS1 LIKE T001-BUKRS,
             KONTO1 LIKE T030-KONTS,
           END OF i_mblnr.
    TYPES: BEGIN OF t_mat,
            lgort LIKE mseg-lgort,
            werks LIKE mseg-werks,
            matnr LIKE mseg-matnr,
            mblnr LIKE mseg-mblnr,
            maktx LIKE makt-maktx,
            meins LIKE mara-meins,
    meng0 LIKE mbew-lbkum,
    value0 LIKE mbew-salk3,
           meng0  LIKE mard-labst,                   "0 to 10 days
           value0 LIKE mseg-dmbtr,
           meng1  LIKE mard-labst,                   "11 to 30 days
           value1 LIKE mseg-dmbtr,
           meng2 LIKE mard-labst,                   "31 to 60 days
           value2 LIKE mseg-dmbtr,
           meng3 LIKE mard-labst,                   "61-90
           value3 LIKE mseg-dmbtr,
           meng4 LIKE mard-labst,                   "90 days onwards
           value4 LIKE mseg-dmbtr,
           END OF t_mat.
    DATA: i_mat2 TYPE t_mat OCCURS 0 WITH HEADER LINE.
    TYPES: BEGIN OF t_mat2,
            lgort LIKE mard-lgort,                    " storage location
            cnt0(5),
            cnt1(5),
            cnt2(5),
            cnt3(5),
            cnt4(5),
       meng0 LIKE mbew-lbkum,
    value0 LIKE mbew-salk3,
           meng0  LIKE mard-labst,                   "0 to 10 days
           value0 LIKE mseg-dmbtr,
           meng1  LIKE mard-labst,                   "11 to 30 days
           value1 LIKE mseg-dmbtr,
           meng2 LIKE mard-labst,                   "31 to 60 days
           value2 LIKE mseg-dmbtr,
           meng3 LIKE mard-labst,                   "61-90
           value3 LIKE mseg-dmbtr,
           meng4 LIKE mard-labst,                   "90 days onwards
           value4 LIKE mseg-dmbtr,
           END OF t_mat2.
    DATA: i_matsum TYPE t_mat2 OCCURS 0 WITH HEADER LINE.
    DATA:  w_mengb TYPE mbew-lbkum,
           w_workqyt TYPE mbew-lbkum,
           w_index TYPE sy-tabix,
    *DATA: w_mengb TYPE mard-labst,     "tmp Balance qty
         w_workqty TYPE mard-labst,   "Work qty
         w_index TYPE sy-tabix,
          w_days(5)  TYPE n,           "duration difference (days)
          w_mths(5)  TYPE n,           "duration difference (mths)
          w_dat1 TYPE sy-datum,        "date
          w_dat2 TYPE sy-datum,        "today's date
          w_detl(1) TYPE c,
          w_summ(1) TYPE c,
          w_denom TYPE i,
          w_numer TYPE i,
          w_conv TYPE i,
          w_ttlcnt TYPE i,
          w_cnt TYPE i,
          v_topofpage(1),
         w_meng LIKE mard-labst,
           w_meng LIKE mbew-lbkum,
    *sapscript values
          w_title(20) TYPE c.              "Summary / Detail Report
    DATA: lv_peinh LIKE mbew-peinh,  "Price Unit
          lv_verpr LIKE mbew-verpr.  "Moving Price
    proram comes here
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_werks FOR mseg-werks,
                    s_lgort FOR mseg-lgort,
                    s_matnr FOR mara-matnr,
                    s_saknr FOR ska1-saknr,
                    S_ERDAT FOR VBAK-ERDAT.
    PARAMETERS: pck_detl RADIOBUTTON GROUP rep1,
                pck_summ RADIOBUTTON GROUP rep1,
                pck_dtsm RADIOBUTTON GROUP rep1 DEFAULT 'X'.
    SELECTION-SCREEN END OF BLOCK blk1.
    top of the page
      TOP-OF-PAGE.
      PERFORM  f_top_of_page.
      FORM f_top_of_page .
      IF v_topofpage = 'D'.
    *-->Report header for detail report
        WRITE:/2 'Printed By :', sy-uname,
               80 'Stock Aging Report - Detail',
               180 'Printed on:', sy-datum, sy-timlo,
               220 'Page:', sy-pagno.
        WRITE:/,/,/.
        WRITE:/2 'Storage',
               10 'Matl ID',
               22 'Matl Description',
               61 'UOM',
               78 '<--=<QTY ON THIS DATE -->',
              78 '<-- =< 10 days -->',
              112 '<--11 to 30 days -->',
              148 '<--31 to 60 days -->',
              181 '<--61 to 90 days -->',
              216 '<-- > 90 days -->',
               /2 'Location',
               76 'Qty',
               92 'Value'.
              112 'Qty',
              128 'Value',
              148 'Qty',
              164 'Value',
              181 'Qty',
              195 'Value',
              216 'Qty',
              231 'Value'.
        WRITE:/2 sy-uline(235).
      ELSE.
    *-->Report header for Summary report
        WRITE:/2 'Printed By :', sy-uname,
               80 'Stock Aging Report - Summary',
               180 'Printed on:', sy-datum, sy-timlo,
               220 'Page:', sy-pagno.
        WRITE:/,/,/.
        WRITE:/2 'Storage',
               10 'Matl ID',
               22 'Matl Description',
               61 'UOM',
               78 '<--< QTY ON THIS DATE -->',
              78 '<-- < 10 days -->',
              112 '<--11 to 30 days -->',
              148 '<--31 to 60 days -->',
              181 '<--61 to 90 days -->',
              216 '<-- > 90 days -->',
               /2 'Location',
               76 'Qty',
               92 'Value'.
              112 'Qty',
              128 'Value',
              148 'Qty',
              164 'Value',
              181 'Qty',
              195 'Value',
              216 'Qty',
              231 'Value'.
        WRITE:/2 sy-uline(235).
      ENDIF.
    ENDFORM.                    " f_top_of_page
    *start-of-selection
    *PERFOM f_data_selection.
    FORM f_data_selection.
      SELECT a~werks
             a~lgort
             a~matnr
            a~saknr
            a~lbkum
            a~erdat
            a~labst
             a~umlme
             a~insme
             a~einme
             a~speme
             a~retme
           b~verpr    "this field no long been used
             c~maktx
             d~meins
             INTO CORRESPONDING FIELDS OF TABLE ta_material
             FROM mard AS a
             INNER JOIN makt AS c ON amatnr = cmatnr
             INNER JOIN mara AS d ON amatnr = dmatnr
             WHERE a~matnr IN s_matnr
               AND a~werks IN s_werks
               AND a~lgort IN s_lgort
              AND a~saknr IN s_saknr
              AND a~erdat IN s_erdat
               AND c~spras = 'EN'.
    *--> SC01 - End  of Insertion **
    *-->Select material documents
      SELECT a~mblnr
            a~mjahr
            a~zeile
            a~meins
            a~menge
            a~werks
            a~lgort
            a~matnr
            b~budat
            INTO CORRESPONDING FIELDS OF TABLE ta_mseg
      FROM mseg AS a INNER JOIN mkpf AS b
      ON amblnr = bmblnr
      AND amjahr = bmjahr
      FOR ALL ENTRIES IN ta_material
      WHERE matnr = ta_material-matnr
      AND a~werks = ta_material-werks
      AND a~lgort = ta_material-lgort
      AND algort NE aumlgo
      AND a~shkzg = 'S'
      AND a~smbln EQ space
      AND a~smblp EQ space.
    *--> SC03 - Start of Insertion **
    If MBLNR exist in MSEG-SMBLN and this
    record's SHKZG = 'H'. Remove it from the table.
    This is becuase this particular record has already been reverse.
      LOOP AT ta_mseg.
        SELECT SINGLE *
                 FROM mseg
                WHERE smbln = ta_mseg-mblnr
    *->Begin of KL02+ -
                  and SMBLP = ta_mseg-zeile.
                 AND shkzg = 'H'.  "return.           " KL02-
    *->End of KL02+ -
        IF sy-subrc = 0.
          DELETE ta_mseg.
        ENDIF.
      ENDLOOP.
    *--> SC03 - Enf   of Insertion **
    ENDFORM.                    " f_data_selection
    *IMPORTANT , NEED TO CHECK LATER
    FORM f_data_preparation.
    *-->Append data for report details
      LOOP AT ta_material.
        DATA: ta_msegtemp LIKE ta_mseg OCCURS 2 WITH HEADER LINE.
    *-->Loop at all material documents into a temp table
        REFRESH ta_msegtemp. CLEAR ta_msegtemp.
        LOOP AT ta_mseg WHERE matnr = ta_material-matnr AND
                              werks = ta_material-werks AND
                              lgort = ta_material-lgort.
          ta_msegtemp = ta_mseg. APPEND ta_msegtemp.
        ENDLOOP.
    *-->Add up all the stock for the material
        CLEAR w_mengb.
        w_mengb = ta_material-labst +
                        ta_material-umlme +
                        ta_material-insme +
                        ta_material-einme +
                        ta_material-speme +
                        ta_material-retme.
        IF w_mengb IS INITIAL.
          CONTINUE.
        ENDIF.
    *-->sort msegtemp by posting date
        SORT ta_msegtemp BY budat DESCENDING.
    *-->get the values from the material documents into the report output
        LOOP AT ta_msegtemp.
    *->Begin of KL02- -
         CALL FUNCTION 'HRCM_TIME_PERIOD_CALCULATE'
           EXPORTING
             begda               = ta_msegtemp-budat
             endda               = sy-datum
           IMPORTING
            NOYRS               =
             nomns               = w_mths
             nodys               = w_days
          EXCEPTIONS
            invalid_dates       = 1
            overflow            = 2
            OTHERS              = 3
    *->End of KL02- -
    *->Begin of KL02+ -
    *-->Get the days difference btw two dates
          clear w_days.
          w_days = sy-datum - ta_msegtemp-budat.
    *--> Include today's date into calculation
          w_days = w_days + 1.
    *->End of KL02+ -
    check base unit, do conversion
          IF ta_material-meins <> ta_msegtemp-meins.
            CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
              EXPORTING
                i_matnr              = ta_material-matnr
                i_in_me              = ta_msegtemp-meins
                i_out_me             = ta_material-meins
                i_menge              = ta_msegtemp-menge
              IMPORTING
                e_menge              = ta_msegtemp-menge
              EXCEPTIONS
                error_in_application = 1
                error                = 2
                OTHERS               = 3.
          ENDIF.
    *--> SC01 - Start of Insertion **
          SELECT SINGLE peinh
                        verpr
                   INTO (lv_peinh,
                         lv_verpr)
                   FROM mbew
                  WHERE matnr = ta_material-matnr
                    AND bwkey = ta_material-werks.
          IF sy-subrc = 0.
            ta_material-verpr = lv_verpr.
          ENDIF.
    *--> SC01 - End   of Insertion **
    *-->check whether the mseg value is LE than the stock value
          IF ta_msegtemp-menge LE w_mengb.
    *-->Days < 10 days
            IF w_days  LE 1 AND w_days EQ 366.
              i_mat2-meng0 = i_mat2-meng0 + ta_msegtemp-menge.
              IF NOT lv_peinh EQ 0.
                i_mat2-value0 = ( i_mat2-meng0 / lv_peinh ) *
    ta_material-verpr."+SC01
              ENDIF.
    **-->Days 11 - 30 days
           ELSEIF w_days >= 11 AND w_days =< 30.
             i_mat2-meng1 = i_mat2-meng1 + ta_msegtemp-menge.
             IF NOT lv_peinh EQ 0.
               i_mat2-value1 = ( i_mat2-meng1 / lv_peinh ) *
    *ta_material-verpr."+SC01
             ENDIF.
    **-->Days 31-60 days
           ELSEIF w_days >= 31 AND w_days =< 60.
             i_mat2-meng2 = i_mat2-meng2 + ta_msegtemp-menge.
             IF NOT lv_peinh EQ 0.
               i_mat2-value2 = ( i_mat2-meng2 / lv_peinh ) *
    *ta_material-verpr."+SC01
             ENDIF.
    **-->Days 61-90 days
           ELSEIF w_days >= 61 AND w_days =< 90.
             i_mat2-meng3 = i_mat2-meng3 + ta_msegtemp-menge.
             IF NOT lv_peinh EQ 0.
               i_mat2-value3 = ( i_mat2-meng3 / lv_peinh ) *
    *ta_material-verpr.
             ENDIF.
    **-->Days > 90 days
           ELSEIF w_days > 90.
             i_mat2-meng4 = i_mat2-meng4 + ta_msegtemp-menge.
             IF NOT lv_peinh EQ 0.
               i_mat2-value4 = ( i_mat2-meng4 / lv_peinh ) *
    *ta_material-verpr.
             ENDIF.
           ENDIF.
    *->End of KL002+
            w_mengb = w_mengb - ta_msegtemp-menge.
          ELSE.
            IF NOT w_mengb LE 0 .
                 IF NOT lv_peinh EQ 0.
    **->End of KL001+
                   i_mat2-value0 = ( i_mat2-meng0 / lv_peinh )
    *ta_material-verpr."+SC01
    **->Begin of KL001+
                 ENDIF.
               ELSEIF w_days GE 22.
                 i_mat2-meng3 = i_mat2-meng3 + w_mengb.
                 IF NOT lv_peinh EQ 0.
                   i_mat2-value3 = ( i_mat2-meng3 / lv_peinh )
    *ta_material-verpr.
                 ENDIF.
    **->End of KL001+
               ENDIF.
    **--> SC02 - End  of Insertioin **
           ENDIF.
    *->End of KL002-
    *->Begin of KL002+
    *--> < 10 days
                     IF w_days EQ 1 AND w_days LE 366.
              i_mat2-meng0 = i_mat2-meng0 + ta_msegtemp-menge.
              IF NOT lv_peinh EQ 0.
                i_mat2-value0 = ( i_mat2-meng0 / lv_peinh ) *
    ta_material-verpr."+SC01
              ENDIF.
             ELSEIF w_days >= 11 AND w_days =< 30.
               i_mat2-meng1 = i_mat2-meng1 + w_mengb.
               IF NOT lv_peinh EQ 0.
                 i_mat2-value1 = ( i_mat2-meng1 / lv_peinh ) *
    *ta_material-verpr.
               ENDIF.
    **--> 31 - 60 days
             ELSEIF w_days >= 31 AND w_days =< 60.
               i_mat2-meng2 = i_mat2-meng2 + w_mengb.
               IF NOT lv_peinh EQ 0.
                 i_mat2-value2 = ( i_mat2-meng2 / lv_peinh ) *
    *ta_material-verpr.
               ENDIF.
    **--> 61 - 90 days
             ELSEIF w_days >= 61 AND w_days =< 90.
               i_mat2-meng3 = i_mat2-meng3 + w_mengb.
               IF NOT lv_peinh EQ 0.
                 i_mat2-value3 = ( i_mat2-meng3 / lv_peinh ) *
    *ta_material-verpr.
               ENDIF.
    **--> > 90 days
             ELSEIF w_days > 90.
               i_mat2-meng4 = i_mat2-meng4 + w_mengb.
               IF NOT lv_peinh EQ 0.
                 i_mat2-value4 = ( i_mat2-meng4 / lv_peinh ) *
    *ta_material-verpr.
               ENDIF.
              ENDIF.
    *->End of KL002+
              w_mengb = 0.
            ENDIF. " check stock value NE zero
          ENDIF.   "check Mat doc amount is LE than the stock value
    ENDIF.
        ENDLOOP. " msegtemp
    *-->append i_mat2 values
        i_mat2-werks = ta_material-werks.
        i_mat2-lgort = ta_material-lgort.
        i_mat2-matnr = ta_material-matnr.
        i_mat2-maktx = ta_material-maktx.
        i_mat2-meins = ta_material-meins.
        APPEND i_mat2. CLEAR i_mat2.
      ENDLOOP. " ta_material
    *-->Append data for summary data
      DATA: i_lgort LIKE i_mat2 OCCURS 2 WITH HEADER LINE.
      i_lgort[] = i_mat2[].
      SORT i_lgort BY werks lgort.
      DELETE ADJACENT DUPLICATES FROM i_lgort COMPARING werks lgort.
      DATA: v_cnt0(5), v_cnt1(5), v_cnt2(5), v_cnt3(5), v_cnt4(5),
            v_value0 LIKE i_matsum-value0.
           v_value1 LIKE i_matsum-value1,
           v_value2 LIKE i_matsum-value2,
           v_value3 LIKE i_matsum-value3,
           v_value4 LIKE i_matsum-value4.
      LOOP AT i_lgort.
        CLEAR v_cnt0. CLEAR v_value0.
      CLEAR v_cnt1. CLEAR v_value1.
       CLEAR v_cnt2. CLEAR v_value2.
       CLEAR v_cnt3. CLEAR v_value3.
       CLEAR v_cnt4. CLEAR v_value4.
        LOOP AT i_mat2 WHERE lgort = i_lgort-lgort AND
                             werks = i_lgort-werks.
          IF NOT i_mat2-meng0 IS INITIAL.
            v_cnt0 = v_cnt0 + 1.
            v_value0 = v_value0 + i_mat2-value0.
          ENDIF.
         IF NOT i_mat2-meng1 IS INITIAL.
           v_cnt1 = v_cnt1 + 1.
           v_value1 = v_value1 + i_mat2-value1.
         ENDIF.
         IF NOT i_mat2-meng2 IS INITIAL.
           v_cnt2 = v_cnt2 + 1.
           v_value2 = v_value2 + i_mat2-value2.
         ENDIF.
         IF NOT i_mat2-meng3 IS INITIAL.
           v_cnt3 = v_cnt3 + 1.
           v_value3 = v_value3 + i_mat2-value3.
         ENDIF.
         IF NOT i_mat2-meng4 IS INITIAL.
           v_cnt4 = v_cnt4 + 1.
           v_value4 = v_value4 + i_mat2-value4.
         ENDIF.
        ENDLOOP.
        CLEAR i_matsum.
        i_matsum-lgort = i_mat2-lgort.
        IF v_cnt0 NE space.
          i_matsum-cnt0 = v_cnt0.
          i_matsum-value0 = v_value0.
          APPEND i_matsum.
        ENDIF.
       CLEAR i_matsum.
       i_matsum-lgort = i_mat2-lgort.
       IF v_cnt1 NE space.
         i_matsum-cnt1 = v_cnt1.
         i_matsum-value1 = v_value1.
         APPEND i_matsum.
       ENDIF.
       CLEAR i_matsum.
       i_matsum-lgort = i_mat2-lgort.
       IF v_cnt2 NE space.
         i_matsum-cnt2 = v_cnt2.
         i_matsum-value2 = v_value2.
         APPEND i_matsum.
       ENDIF.
       CLEAR i_matsum.
       i_matsum-lgort = i_mat2-lgort.
       IF v_cnt3 NE space.
         i_matsum-cnt3 = v_cnt3.
         i_matsum-value3 = v_value3.
         APPEND i_matsum.
       ENDIF.
       CLEAR i_matsum.
       i_matsum-lgort = i_mat2-lgort.
       IF v_cnt4 NE space.
         i_matsum-cnt4 = v_cnt4.
         i_matsum-value4 = v_value4.
         APPEND i_matsum.
       ENDIF.
      ENDLOOP.
    ENDFORM.                    "f_data_preparation
    *IMPORTANT , NEED TO CHECK LATER
    FORM f_display_data .
      IF pck_dtsm = 'X'.
    *-->Display detail
        v_topofpage = 'D'.
        PERFORM f_display_detail.
    *-->display summary
        v_topofpage = 'S'.
        NEW-PAGE.
        PERFORM f_display_summary.
      ELSEIF pck_detl = 'X'.
    *-->Display detail
        v_topofpage = 'D'.
        PERFORM f_display_detail.
      ELSEIF pck_summ = 'X'.
    *-->display summary
        v_topofpage = 'S'.
        PERFORM f_display_summary.
      ENDIF.
    ENDFORM.                    " f_display_data
    FORM f_display_detail .
      v_topofpage = 'D'.
      SORT i_mat2 BY werks lgort.
    *DATA: v_count(5),
    DATA: v_count,
            v_va1 LIKE i_mat2-value0.
           v_va2 LIKE i_mat2-value0,
           v_va3 LIKE i_mat2-value0,
           v_va4 LIKE i_mat2-value0,
           v_va5 LIKE i_mat2-value0.
      LOOP AT i_mat2.
        WRITE:/2 i_mat2-lgort,
              10 i_mat2-matnr,
              22 i_mat2-maktx(38),
              61 i_mat2-meins,
              64 i_mat2-meng0,
              82 i_mat2-value0.
             100 i_mat2-meng1,
             118 i_mat2-value1,
             136 i_mat2-meng2,
             154 i_mat2-value2,
             169 i_mat2-meng3,
             186 i_mat2-value3,
             204 i_mat2-meng4,
             222 i_mat2-value4.
    *-->Set counter and add up all values by lgort
        v_count = v_count + 1.
         v_va1 = v_va1 + i_mat2-value0.
       v_va2 = v_va2 + i_mat2-value1.
       v_va3 = v_va3 + i_mat2-value2.
       v_va4 = v_va4 + i_mat2-value3.
       v_va5 = v_va5 + i_mat2-value4.
        AT END OF lgort.
          WRITE:/10 'Cnt:',
                 15 v_count,
                 55 'Subtotal',
                 82 v_va1.
                118 v_va2,
                154 v_va3,
                186 v_va4,
                222 v_va5.
          CLEAR v_count. CLEAR v_va1.
         CLEAR v_va2. CLEAR v_va3. CLEAR v_va4. clear v_va5.
        ENDAT.
      ENDLOOP.
    ENDFORM.                    " f_display_detail
    FORM f_display_summary .
      v_topofpage = 'S'.
      LOOP AT i_matsum.
        IF NOT i_matsum-cnt0 IS INITIAL.
          WRITE:/2  i_matsum-lgort,
                 10 'Cnt:',15 i_matsum-cnt0,
                 82 i_matsum-value0.
        ENDIF.
       IF NOT i_matsum-cnt1 IS INITIAL.
         WRITE:/2  i_matsum-lgort,
                10 'Cnt:',15 i_matsum-cnt1,
                118 i_matsum-value1.
       ENDIF.
       IF NOT i_matsum-cnt2 IS INITIAL.
         WRITE:/2  i_matsum-lgort,
                10 'Cnt:',15 i_matsum-cnt2,
                154 i_matsum-value2.
       ENDIF.
       IF NOT i_matsum-cnt3 IS INITIAL.
         WRITE:/2  i_matsum-lgort,
                10 'Cnt:', 15 i_matsum-cnt3,
                186 i_matsum-value3.
       ENDIF.
       IF NOT i_matsum-cnt4 IS INITIAL.
         WRITE:/2  i_matsum-lgort,
                10 'Cnt:', 15 i_matsum-cnt4,
                222 i_matsum-value4.
       ENDIF.
      ENDLOOP.
    ENDFORM.                    " f_display_summary

Maybe you are looking for

  • I need to host a website with a SQL database - Azure pricing details are too confusing

    Hello, I need to give a potential client a hosting price for a somewhat simple web application they want me to build. I told them it shouldn't be a problem. After gathering the requirements, I figured I would use the following technology to build and

  • Retaining Tag Colors on Export to PDF

    Hello! I've tried to Export As>Adobe PDF in several ways but all the Tags come out bold/black instead of their specified colors.  If I print a PDF, all colors are correct but the file is ~32x larger. Is there something I'm missing?  Emailing smaller

  • Connecting Ipod Touch to PC

    when i connect my ipod touch to my computer, it does not show up but it charges.

  • Can I add forms I've created to the Templates tab?

    I currently have 44 'base forms' that I then duplicate to create the forms for each event, however because there is no filing structure in My Forms, I now have well over 100 forms in there! We'll soon be using FormsCentral Team and those forms will m

  • Unsupported feature: Faults with Complex types

    I am confused about the statement that WebLogic currently does not support Faults with Complex types. In a pilot project I am working on we did expose custom complex exceptions and it appeared that WebLogic correctly created the WSDL Fault definition