Compare data from a table
Hello, I am trying to compare data from one and the same table. In short I have:
NAME DTM CHARGE
Atanas 8/18/2012 9:33:23 AM 100
Atanas 8/18/2012 9:33:23 AM 101
Niki 8/18/2012 9:33:43 AM 200
Niki 8/17/2012 9:34:10 AM 100
Niki 8/18/2012 9:33:43 AM 201
Niki 8/17/2012 9:34:10 AM 101
Atanas 8/17/2012 9:34:29 AM 50
Atanas 8/17/2012 9:34:29 AM 51
Joro 8/18/2012 12:10:12 PM 400
Joro 8/17/2012 12:10:21 PM 300
Joro 8/18/2012 12:10:12 PM 401
Joro 8/17/2012 12:10:21 PM 301
And I want to sum CHARGE for each DTM for each NAME and present the difference in an additional column, the output should be like that:
NAME DTM CHARGE DTM CHARGE DIFFERENCE
Atanas 8/17/2012 9:33:23 AM 101 8/18/2012 9:33:23 AM 201 - 100
Niki 8/17/2012 9:33:23 AM 201 8/18/2012 9:33:23 AM 401 - 200
Joro 8/17/2012 9:33:23 AM 601 8/18/2012 9:33:23 AM 801 200
the DTM will be always /sysdate - 2/ and /sysdate - 1/,
Thanks in advance!
It is not clear what you are trying to do, but it looks like:
with sample_table as (
select 'Atanas' name,to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am') dtm,100 charge from dual union all
select 'Atanas',to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),200 from dual union all
select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),100 from dual union all
select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),201 from dual union all
select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),50 from dual union all
select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),51 from dual union all
select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),400 from dual union all
select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),300 from dual union all
select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),401 from dual union all
select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),301 from dual
select nvl(s1.name,s2.name) name,
s1.dtm,
s1.charge,
s2.dtm,
s2.charge,
s2.charge - s1.charge diff
from (
select name,
dtm,
sum(charge) charge
from sample_table
where dtm >= trunc(sysdate) - 1
and dtm < trunc(sysdate)
group by name,
dtm
) s1
full join
select name,
dtm,
sum(charge) charge
from sample_table
where dtm >= trunc(sysdate)
and dtm < trunc(sysdate) + 1
group by name,
dtm
) s2
on s1.name = s2.name
NAME DTM CHARGE DTM CHARGE DIFF
Atanas 17-AUG-12 101 18-AUG-12 201 100
Niki 17-AUG-12 201 18-AUG-12 401 200
Joro 17-AUG-12 601 18-AUG-12 801 200
SQL> SY.
Similar Messages
-
Comparing data from two tables
My PL/SQL is very limited, however, I need to write some code that compares data stored in two different Oracle tables and then writes the differences to a third table. Both tables have primary keys that I will use to ensure I am comparing like for like. These tables could be large.
Any help on the best way to do this, or any code examples would be very appreciated.One fairly efficient way of doing this is with set operators. The following code is untested - but looks right ;). It also assumes you want to know the provenance of the rows; if not, just zap the literal from each SELECT statement.
INSERT INTO diff_tab SELECT * FROM
( (SELECT 'tab1nottab2' AS provenance, t1.col1, t1.col2 FROM tab1 t1
MINUS
SELECT 'tab1nottab2', t2.col_a, t2.col_b FROM tab2 t2)
UNION ALL
(SELECT 'tab2nottab1', t2.col_a, t2.col_b FROM tab2 t2
MINUS
SELECT 'tab2nottab1', t1.col1, t1.col2 FROM tab1 t1)
/Cheers, APC -
Compare date from snapshot tables
I have mothly snapshot tables in oracle database 10gR2 that I loaded in discoverer 10gR2 as it as business users want to query monthly data. Fine.
Now business users want to compare two months data something like:
'snap_date jan-2009' 'site_id for jan-2009' 'site_status for jan-2009' 'snap_date feb-2009' 'site_id for feb-2009' 'site_status for feb-2009'
01/31/2009 a0001P active 02/28/2009 a0001P inactive
01/31/2009 b0001P active 02/28/2009 deleted -
01/31/2009 c0001L active 02/28/2009 c0001L active
01/31/2009 - - 02/28/2009 z0001P active
They want to see it like:
'site_id' 'site_status for jan-2009' 'site_status for feb-2009'
a0001P active inactive
b0001P active site deleted
c0001L active active
z0001P no site found active
Please suggest, how can I achieve this in discoverer?
Two snap_dates can be any dates from last five years on which already snap_shot has been taken and added to the snapshot table.
Thanks.
Edited by: vkumar on Mar 17, 2009 2:17 PMHi Rod,
Actually this is just one table having snapshot data for different months like:
'snap_date' 'site_id' 'site_status'
01/31/2009 a0001P active
01/31/2009 b0001P active
01/31/2009 c0001L active
02/28/2009 a0001P inactive
02/28/2009 c0001L active
02/28/2009 z0001P active
From this table I want to compare data for different dates with respect to site_id?
Thanks.
Edited by: vkumar on Mar 19, 2009 10:44 AM
Edited by: vkumar on Mar 19, 2009 10:44 AM -
Hi All,
This is a JDBC-Prooxy scenario. I used a JDBC sender adapter to pick records from the table and used a proxy to to pass the data to R/3 and called a fuction module in R/3. The scenario worked fine as expected.
Now the problem is there is another table in the database which contains the history. Now I need to compare the records in 2 tables and pass the data to R/3 if a record does not exist in second table(This can be done by a select querry), but if a record exists I need to check for "amount" field again. If the amount in history file is lesser, the record has to be passed with the amount(difference between the first table and history table). If the amount is also same, I should not send the record to R/3.
How can I achieve this? Where can I do these comparisons and pass the data to R/3?
Thanks in Advance.
Regards,
Jai Shankar.Jai,
The solution would like this,
1. Receive -- To select data from Table 1
2. Send Synch -- To select data from table 2 ( refer my blog )
3. Transforamtion ( n:1 ) -- combine the data from step 1 and step 2 and do the mappinng . Set some field to determine if the IDOC should be sent or not.
4. Switch -- Check for the data and then send the IDOC if needed else terminate the BPM anbd process flow.
Regards,
Bhavesh -
Procedure to check data from different tables
Hi
I am trying to write a procedure to compare data from a table with another.
Table 1
ID Name Dept
1 ABC Y
2 DEF Z
Table 2
ID Dept
1 Y
2 Z
Table 3
Name ID
1 ABC
2 DEF
I would like to compare each record data in Table 1 with data from different tables table2,table3 by matching ID,name.... Please help me with how I could start writing a procedure and also spool data that does not match from the table1 with other tables
thanks
Edited by: 890563 on Apr 30, 2012 10:34 AMHope below helps you.
CREATE TABLE TABLE1
( ID VARCHAR2(10),
FIRST_NAME VARCHAR2(30),
LAST_NAME VARCHAR2(30),
MIDDLE_NAME VARCHAR2(30)
INSERT INTO TABLE1 VALUES('123456','testfirst','testlast','testmiddle');
INSERT INTO TABLE1 VALUES('123457','testfirst1','testlast1','testmiddle1');
CREATE TABLE TABLE1
( ID VARCHAR2(10),
FIRST_NAME VARCHAR2(30),
LAST_NAME VARCHAR2(30),
MIDDLE_NAME VARCHAR2(30)
INSERT INTO TABLE2 VALUES('123456','testfirst','testlas','testmidd');
INSERT INTO TABLE2 VALUES('123457','testfirst2','testlast1','testmiddle1');
SELECT TABLE1.ID,
-- Match First Name
CASE WHEN TABLE1.FIRST_NAME != TABLE2.FIRST_NAME THEN TABLE1.FIRST_NAME ELSE NULL END TABLE1_FIRST_NAME,
CASE WHEN TABLE1.FIRST_NAME != TABLE2.FIRST_NAME THEN TABLE2.FIRST_NAME ELSE NULL END TABLE2_FIRST_NAME,
-- Match Middle Name
CASE WHEN TABLE1.MIDDLE_NAME != TABLE2.MIDDLE_NAME THEN TABLE1.MIDDLE_NAME ELSE NULL END TABLE1_MIDDLE_NAME,
CASE WHEN TABLE1.MIDDLE_NAME != TABLE2.MIDDLE_NAME THEN TABLE2.MIDDLE_NAME ELSE NULL END TABLE2_MIDDLE_NAME,
-- Match Last Name
CASE WHEN TABLE1.LAST_NAME != TABLE2.LAST_NAME THEN TABLE1.LAST_NAME ELSE NULL END TABLE1_LAST_NAME,
CASE WHEN TABLE1.LAST_NAME != TABLE2.LAST_NAME THEN TABLE2.LAST_NAME ELSE NULL END TABLE2_LAST_NAME
FROM TABLE1, TABLE2
WHERE TABLE1.ID = TABLE2.ID
ID TABLE1_FIRST_NAME TABLE2_FIRST_NAME TABLE1_MIDDLE_NAME TABLE2_MIDDLE_NAME TABLE1_LAST_NAME TABLE2_LAST_NAME
123456 NULL NULL testmiddle testmidd testlast testlas
123457 testfirst1 testfirst2 NULL NULL NULL NULL
{code} -
Performance Issue - Fetching latest date from a507 table
Hi All,
I am fetching data from A507 table for material and batch combination. I want to fetch the latest record based on the value of field DATBI. I have written the code as follows. But in the select query its taking more time. I dont want to write any condition in where claue for DATBI field because I have already tried with that option.
SELECT kschl
matnr
charg
datbi
knumh
FROM a507
INTO TABLE it_a507
FOR ALL ENTRIES IN lit_mch1
WHERE kschl = 'ZMRP'
AND matnr = lit_mch1-matnr
AND charg = lit_mch1-charg.
SORT it_a507 BY kschl matnr charg datbi DESCENDING.
DELETE ADJACENT DUPLICATES FROM it_a507 COMPARING kschl matnr charg.Hi,
These kind of tables will be storing large volumes of data. Thus while making a select on it, its important to use as many primary key fields as possible in the where condition. Here you can try mentioning KAPPL since its specific to a requirement. If its for purchasing use 'M' and try.
if not lit_mch1[] is initial.
SELECT kschl
matnr
charg
datbi
knumh
FROM a507
INTO TABLE it_a507
FOR ALL ENTRIES IN lit_mch1
WHERE kappl = 'M'
AND kschl = 'ZMRP'
AND matnr = lit_mch1-matnr
AND charg = lit_mch1-charg.
endif.
SORT it_a507 BY kschl matnr charg datbi DESCENDING.
DELETE ADJACENT DUPLICATES FROM it_a507 COMPARING kschl matnr charg.
This should considerably increase the performance
Regards,
Vik -
How to fetch data from 2 tables
Hi Experts,
I am using 2 Ztables.Let us assume that there are 2 fields in Table1 as a and b and 2nd Table contain c as field.I want to retrive data from these tables by combining the fields of Table1 with that of 2.
Eg: I want to compare a+b with c and fetch records.
Is there any logic to combine 2 fields and compare with 3rd field using a single select statement?
Regds,
Sam.Hi Sam,
if the tables have one or more common key fields, you can use a JOIN condition for the tables, i.e.
data:
begin of ls_target,
a like ztable1-a,
b like ztable1-b,
c like ztable2-c,
end of ls_target,
lt_target like table of ls_target.
select ztable1~a ztable1~b ztable2~c
into corresponding fields of table lt_target
from ztable1
join ztable2 ON ztable2~key = ztable1~key
where <your condition>.
Note ahead:
1) some people say select into corresponding fields is not good for performance. I think it is good to avoid errors and nobody ever gave a perfomance proof.
2) Most developers always use an alias such as ztable1AS a, ztable2 AS b. This is due to the fact that after table joins were introduced with release 3.1, the ABAP sample programs an documentation always used the ALIAS clause although it is not necessary nor does it establish transparency.
Kind regards
Clemens -
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 -
Does ODI has ability to extract data from multiple tables
We have requirement using ODI to extract data from multiple tables depending on certain logic and spool 100+ files.
How efficient ODI is in data extraction from several multiple tables especially when the extraction is dependent on certain business logic conditions ? Also, if anyone used Peoplesoft Application Engine process to extract volumes of data, how efficient Peoplesoft Applicaiton Engine process is as compared to ODI ? I will really appreciate if someone throws some light on this ? Thanks in advance.
RamOne more option
Create two Integration Interfaces and launch them sequentially:
1st Interface : select a IKM ... Append and activate the Distinct rows check box.
2nd Interface : select an IKM ... Incremental Update and set the UPDATE option to No.
Be aware that the update key in this Integration Interface should be composed of all the target columns mapped. Also activate the Distinct rows check box.
Thanks,
Sutirtha
Edited by: Sutirtha Roy on Jul 21, 2009 10:08 AM -
Best way to compare data of 2 tables present on 2 different servers
Hi,
We are doing data migration and I wil like to compare data between 2 tables which are present on 2 different server. I know to find the difference i can go for minus or full outer join and by creating the database link.
But my problem is the volume of the data. The tables under consideration has approximately 40-60 columns and number of rows in each tables are around 60-70 million. Also both the tables are on 2 diffferent servers.
I would like to know
1] What will be the best way to compare the data and print the difference from performance perepective? I know that if I am going for DB links then its will definitely impact the performance as the tables are across 2 different servers.
2] Is it advisable to go for using SQL - PL/SQL for this kind of senario or dump the data in flat files and use C or C++ code to find the difference.
Regards,
AmolCheck this at asktom.oracle.com. Search for "Marco Stefanetti" and follow the few posts between Marco and Tom. As far as your tables being on separate servers, you could consider dumping the data to file and using external table or using CTAS ( create table as select ) to get both tables locally.
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2151582681236 -
Retrive data from 4 tables without using joins
hi ,
i have to retrive data from 4 tables........but i donot want to use joins because of performance issues.
please guide me how to proceed further ?
thankshi manish,
CONSTANTS: c_act_plan(2) TYPE c VALUE 'U1' ,
c_person(1) TYPE c VALUE 'P' ,
p1_betid(8) TYPE c VALUE '50005316',
c_topdown(1) TYPE c VALUE 'A' ,
c_admnby(3) TYPE c VALUE '032' ,
c_bet_type(1) TYPE c VALUE 'Q' ,
c_firmed(1) TYPE c VALUE '1' ,
c_subtyp_mail(4) TYPE c VALUE '0001' .
TYPES: BEGIN OF ty_hrp1001,
objid TYPE hrp1001-objid,
END OF ty_hrp1001,
BEGIN OF ty_pa0001,
pernr TYPE pa0001-pernr,
subty TYPE pa0001-subty,
objps TYPE pa0001-objps,
sprps TYPE pa0001-sprps,
endda TYPE pa0001-endda,
begda TYPE pa0001-begda,
seqnr TYPE pa0001-seqnr,
werks TYPE pa0001-werks,
gsber TYPE pa0001-gsber,
btrtl TYPE pa0001-btrtl,
END OF ty_pa0001,
BEGIN OF ty_t500p,
persa TYPE t500p-persa,
name1 TYPE t500p-name1,
END OF ty_t500p,
BEGIN OF ty_t001p,
werks TYPE t001p-werks,
btrtl TYPE t001p-btrtl,
btext TYPE t001p-btext,
END OF ty_t001p,
BEGIN OF ty_pa0002,
pernr TYPE pa0002-pernr,
subty TYPE pa0002-subty,
objps TYPE pa0002-objps,
sprps TYPE pa0002-sprps,
endda TYPE pa0002-endda,
begda TYPE pa0002-begda,
seqnr TYPE pa0002-seqnr,
nachn TYPE pa0002-nachn,
vorna TYPE pa0002-vorna,
END OF ty_pa0002,
BEGIN OF ty_pa0105,
pernr TYPE pa0105-pernr ,
subty TYPE pa0105-subty ,
objps TYPE pa0105-objps ,
sprps TYPE pa0105-sprps ,
endda TYPE pa0105-endda ,
begda TYPE pa0105-begda ,
seqnr TYPE pa0105-seqnr ,
usrid_long TYPE pa0105-usrid_long,
END OF ty_pa0105,
BEGIN OF ty_output,
pernr TYPE pa0002-pernr ,
werks TYPE pa0001-werks ,
gsber TYPE pa0001-gsber ,
btrtl TYPE pa0001-btrtl ,
name1 TYPE t500p-name1 ,
btext TYPE t001p-btext ,
nachn TYPE pa0002-nachn ,
vorna TYPE pa0002-vorna ,
usrid_long TYPE pa0105-usrid_long,
END OF ty_output.
DATA: w_hrp1001 TYPE ty_hrp1001,
t_hrp1001 TYPE TABLE OF ty_hrp1001,
t_hrp1001_tmp TYPE TABLE OF ty_hrp1001,
w_pa0001 TYPE ty_pa0001 ,
t_pa0001 TYPE SORTED TABLE OF ty_pa0001
WITH NON-UNIQUE KEY pernr ,
t_pa0001_tmp TYPE TABLE OF ty_pa0001 ,
w_t500p TYPE ty_t500p ,
t_t500p TYPE HASHED TABLE OF ty_t500p
WITH UNIQUE KEY persa ,
w_t001p TYPE ty_t001p ,
t_t001p TYPE HASHED TABLE OF ty_t001p
WITH UNIQUE KEY werks btrtl ,
w_pa0002 TYPE ty_pa0002 ,
t_pa0002 TYPE SORTED TABLE OF ty_pa0002
WITH NON-UNIQUE KEY pernr ,
t_pa0002_tmp TYPE TABLE OF ty_pa0002 ,
w_pa0105 TYPE ty_pa0105 ,
t_pa0105 TYPE SORTED TABLE OF ty_pa0105
WITH NON-UNIQUE KEY pernr ,
w_output TYPE ty_output ,
t_output TYPE TABLE OF ty_output .
SELECT objid
FROM hrp1001
INTO TABLE t_hrp1001
WHERE otype EQ c_person
AND plvar EQ c_act_plan
AND rsign EQ c_topdown
AND relat EQ c_admnby
AND istat EQ c_firmed
AND begda LE sy-datum
AND endda GT sy-datum
AND sclas EQ c_bet_type
AND sobid EQ p1_betid.
IF sy-subrc EQ 0.
SORT t_hrp1001 BY objid.
ENDIF.
IF NOT t_hrp1001[] IS INITIAL.
t_hrp1001_tmp[] = t_hrp1001[].
DELETE ADJACENT DUPLICATES FROM t_hrp1001_tmp
COMPARING objid.
SELECT pernr
subty
objps
sprps
endda
begda
seqnr
werks
gsber
btrtl
FROM pa0001
INTO TABLE t_pa0001
FOR ALL ENTRIES IN t_hrp1001_tmp
WHERE pernr EQ t_hrp1001_tmp-objid
AND endda GT sy-datum
AND begda LE sy-datum.
SELECT pernr
subty
objps
sprps
endda
begda
seqnr
nachn
vorna
FROM pa0002
INTO TABLE t_pa0002
FOR ALL ENTRIES IN t_hrp1001_tmp
WHERE pernr EQ t_hrp1001_tmp-objid
AND endda GT sy-datum
AND begda LE sy-datum.
ENDIF.
IF NOT t_pa0001[] IS INITIAL.
t_pa0001_tmp[] = t_pa0001[].
SORT t_pa0001_tmp BY werks btrtl.
DELETE ADJACENT DUPLICATES FROM t_pa0001_tmp COMPARING werks btrtl.
SELECT werks
btrtl
btext
FROM t001p
INTO TABLE t_t001p
FOR ALL ENTRIES IN t_pa0001_tmp
WHERE werks EQ t_pa0001_tmp-werks
AND btrtl EQ t_pa0001_tmp-btrtl.
DELETE ADJACENT DUPLICATES FROM t_pa0001_tmp COMPARING werks.
SELECT persa
name1
FROM t500p
INTO TABLE t_t500p
FOR ALL ENTRIES IN t_pa0001_tmp
WHERE persa EQ t_pa0001_tmp-werks.
ENDIF.
IF NOT t_pa0002[] IS INITIAL.
t_pa0002_tmp[] = t_pa0002[].
DELETE ADJACENT DUPLICATES FROM t_pa0002_tmp COMPARING pernr.
SELECT pernr
subty
objps
sprps
endda
begda
seqnr
usrid_long
FROM pa0105
INTO TABLE t_pa0105
FOR ALL ENTRIES IN t_pa0002_tmp
WHERE pernr EQ t_pa0002_tmp-pernr
AND subty EQ c_subtyp_mail
AND endda GT sy-datum
AND begda LE sy-datum
AND usrty EQ c_subtyp_mail.
ENDIF.
REFRESH t_output.
LOOP AT t_hrp1001 INTO w_hrp1001.
LOOP AT t_pa0001 INTO w_pa0001
WHERE pernr EQ w_hrp1001-objid.
READ TABLE t_t500p INTO w_t500p WITH KEY persa = w_pa0001-werks
TRANSPORTING
name1.
CHECK sy-subrc EQ 0.
READ TABLE t_t001p INTO w_t001p WITH KEY werks = w_pa0001-werks
btrtl = w_pa0001-btrtl
TRANSPORTING
btext.
LOOP AT t_pa0002 INTO w_pa0002
WHERE pernr EQ w_hrp1001-objid.
LOOP AT t_pa0105 INTO w_pa0105
WHERE pernr EQ w_pa0002-pernr.
w_output-pernr = w_pa0002-pernr .
w_output-werks = w_pa0001-werks .
w_output-gsber = w_pa0001-gsber .
w_output-btrtl = w_pa0001-btrtl .
w_output-name1 = w_t500p-name1 .
w_output-btext = w_t001p-btext .
w_output-nachn = w_pa0002-nachn .
w_output-vorna = w_pa0002-vorna .
w_output-usrid_long = w_pa0105-usrid_long.
APPEND w_output TO t_output.
CLEAR w_output.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
Reward if usful,
Thanks,
Srikanth.A -
Compare data between two tables of same schema
Folks,
I have one very intresting query which i would like to share with you all and looking forward for the solution asap.
Scenario
I have two table say TableA and TableB, both having same structre say as below
TableA
Col1 Var(10)
Col2 INT
TableB
Col1 Var(10)
Col2 INT
I want to compare data between these two tables and store compared data into third table, let me expalin the whole scenario.
TableA
ColA ColB
INDIA 1
PAKistan 2
TableB
ColA ColB
INDIA 1
PAK 3
I want result like
Difference
ColA ColB
True 0
False -1
I want to store this difference in thrid table.
i.e. when comparing text, i need TRUE when compare 100% else False, Caption is not considered.
When comparing numeric value, simple sub is requried , TableA-TableB
Note - I dont want to use any external tool to compare the table data, i required sql query to do the same.
Thanks
Amit Srivastava
Amit
Please mark as answer if helpful
http://fascinatingsql.wordpress.com/Whereas the abbreviation of countries that exist in Table2 table are the first three letters of the name of the country*, here's a suggestion:
-- code #1 v2
INSERT into [Difference] (Col1, Col2, ACol1, BCol1)
SELECT case when A.Col1 = B.Col1 then 'true' else 'false' end,
(IsNull(A.Col2, 0) - IsNull(B.Col2, 0)), A.Col1, B.Col1
from TableA as A full outer join
TableB as B on (A.Col1 = B.Col1
or Left(A.Col1, 3) = B.Col1);
Is the COLLATE database case insensitive? If not, the code #1 above will have to be modified, using the upper () function or using COLLATE case insensitive in A.Col1 and B.Col1 columns.
But if the abbreviation of the country follow the
ISO 3166-1 alpha-3 standard, will require a fourth table containing the symbol and name of countries.
-- code #2 v2
;with
TableB_2 as (
SELECT case when Len(Col1) = 3
then (SELECT Country_name from [ISO 3166-1 a3] where Cod = Col1)
else Col1 end as Col1, Col2
from TableB
INSERT into [Difference] (Col1, Col2, ACol1, BCol1)
SELECT case when A.Col1 = B.Col1 then 'true' else 'false' end,
(IsNull(A.Col2, 0) - IsNull(B.Col2, 0)), A.Col1, B.Col1
from TableA as A full outer join
TableB_2 as B on A.Col1 = B.Col1;
Structure and data to test:
use tempdb;
CREATE TABLE TableA (Col1 varchar(10), Col2 int);
CREATE TABLE TableB (Col1 varchar(10), Col2 int);
CREATE TABLE [Difference] (Col1 varchar(10), Col2 int, ACol1 varchar(10), BCol1 varchar(10));
INSERT into TableA values ('INDIA', 1), ('PAKistan', 2), ('China', 12);
INSERT into TableB values ('INDIA', 1), ('PAK', 3), ('Bhutan', 3);
go
CREATE TABLE [ISO 3166-1 a3] (Cod char(3) primary key, [Country_name] varchar(30));
INSERT into [ISO 3166-1 a3] values
('IND', 'India'), ('PAK', 'Pakistan'), ('CHN', 'China'), ('BGD', 'Bangladesh'),
('BTN', 'Bhutan'), ('MMR', 'Myanmar'), ('NPL', 'Nepal');
go
(*) If the short form of the country name using the first three letters of the country name,
false positives can occur. For example,
Mali and Malta or
Angola and Anguilla.
José Diz Belo Horizonte, MG - Brasil -
Adding Data From One Table to Another
Now, this doesn't strike me as a particularly complex problem, but I've either strayed outside the domain of Numbers or I'm just not looking at the problem from the right angle. In any case, I'm sure you guys can offer some insight.
What I'm trying to do is, essentially, move data from one table to another. One table is a calendar, a simple two column 'date/task to be completed' affair, the other is a schedule of jogging workouts, i.e, times, distances. Basically, I'm trying to create a formula that copies data from the second table onto the first but only for odd days of the week, excepting Sundays (and assuming Monday as the start of the week). Now, this isn't the hard part, I can do that. The problem comes when I replicate the formula down the calendar. Even on the days when the 'if' statement identifies it as an 'even day', the cell reference to the appropriate workout on the second table is incremented, so when it comes to the next 'odd day', it has skipped a workout.
I can't seem to see any way of getting it to specifically copy the NEXT line in the second table, and not the corresponding line.
This began as a distraction to try and organise my running so I could see at a glance what I had to do that day and track my progress, but now it's turned into an obsession. SURELY there's a solution?
Cheers.Hi Sealatron,
Welcome to Apple Discussions and the Numbers '09 forum.
Several possible ways to move the data occur to me, but the devil's in the details of how the data is currently arranged.
Is it
• a list of three workouts, one for each of Monday, Wednesday and Friday, then the same three repeated the following week?
• an open-ended list that does not repeat?
• something else?
Regards,
Barry -
Error while selecting date from external table
Hello all,
I am getting the follwing error while selecting data from external table. Any idea why?
SQL> CREATE TABLE SE2_EXT (SE_REF_NO VARCHAR2(255),
2 SE_CUST_ID NUMBER(38),
3 SE_TRAN_AMT_LCY FLOAT(126),
4 SE_REVERSAL_MARKER VARCHAR2(255))
5 ORGANIZATION EXTERNAL (
6 TYPE ORACLE_LOADER
7 DEFAULT DIRECTORY ext_tables
8 ACCESS PARAMETERS (
9 RECORDS DELIMITED BY NEWLINE
10 FIELDS TERMINATED BY ','
11 MISSING FIELD VALUES ARE NULL
12 (
13 country_code CHAR(5),
14 country_name CHAR(50),
15 country_language CHAR(50)
16 )
17 )
18 LOCATION ('SE2.csv')
19 )
20 PARALLEL 5
21 REJECT LIMIT UNLIMITED;
Table created.
SQL> select * from se2_ext;
SQL> select count(*) from se2_ext;
select count(*) from se2_ext
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04043: table column not found in external source: SE_REF_NO
ORA-06512: at "SYS.ORACLE_LOADER", line 19It would appear that you external table definition and the external data file data do not match up. Post a few input records so someone can duplicate the problem and determine the fix.
HTH -- Mark D Powell -- -
Can we export DATA from all tables in a schema?
Hi,
I have a question; Can we export all the DATA from all the tables present in the schema to any source (eigther CSV, TXT, DAt, etc..)?
Or
Can I have a PL/SQL procedure to display DATA from all Tables in a schema?
With Best Regards,
- NaveedHi,
This is pretty much what you need.
DECLARE
V_COUNT NUMBER;
v_sql varchar2(1000);
IN_OWNER_NAME VARCHAR2(100) := 'AP' ; -- SCHEMA NAME
TYPE T_COL_NAME is table of varchar2(1000) index by binary_integer;
v_col_tbl t_col_name;
BEGIN
FOR i in
(SELECT object_name
FROM dba_objects
WHERE owner = IN_OWNER_NAME
AND object_type ='TABLE'
and rownum < 2)
LOOP
v_sql := 'SELECT COUNT(*) FROM ' || i.object_name ;
EXECUTE IMMEDIATE v_sql INTO V_COUNT;
if v_count > 0 then
v_sql := 'SELECT * FROM ' || i.object_name ;
select column_name
bulk collect
into v_col_tbl
from DBA_TAB_COLUMNS
WHERE TABLE_NAME = I.OBJECT_NAME
AND OWNER = IN_OWNER_NAME;
-- start selecting the column and exporting using the column names selected.
end if;
if v_col_tbl.count > 0 then
for i in v_col_tbl.first .. v_col_tbl.last
loop
DBMS_OUTPUT.PUT_lINE(v_col_tbl(i));
end loop;
end if;
DBMS_OUTPUT.PUT_lINE( i.object_name || '-' || v_count);
END LOOP;
END;
- Ronel
Maybe you are looking for
-
Displaying Image on Image: Urgent
Hello All, In my jsp page, I need to display an Image and on that image I need to display another image. How do I achieve this? My requirement is there is a standard image. Depending on the language selected, I need to put another image on this in a
-
I Have a small problem, that I need some help on ... I need to find the rgb value for the default background colors of Panels. I used new Color color = JPanel().getBackground(); int red = color.getRed(); int green = color.getGreen(); int blue = color
-
Why is Professional Quality occupying less memory space than Best Perforrmance ?
Hi there, I am confused about Best Performance (BP) and Professional Quality (PQ) and not sure if I understand what I am reading correctly about the Encoding ( iDVD > Preference > Projects > Encoding ) If I understand correctly, if we set the encodin
-
How can I reduce the amount of storage my iPhone uses for messages?
Is there any way to reduce the amount of storage space my iPhone uses for Messages? Can I limit the storage to the last year or some other limit (specific date, specific amount of storage etc.)? Thank you
-
Switch Off Automatic Spellcheck ?
Having to work in several languages on my iPhone, I was expecting the promised option of switching off the automatic spellcheck with 2.2. update ? Can't find it ?