Use two secondary indexes in a select statement
hi, i want to use two secondary indexes in a select statement.
how can i do it?
Hello,
To do it use the WHERE stm in the same order as the secondary stm is on SE11....To check if the index is used go to tcode ST05.
example
select * from ztable
WHERE BUKRS EQ 'BUK1' AND
ZFIELD EQ 'BOY'.
on se11 on the ZTABLE indexes setion must have a secondary index with
BUKRS and
ZFIELD.
BYE!!
Hope this helps!!
Gabriel
Similar Messages
-
Problems with Hints in abap code to use an index in a Select statement
Hi,
I want to use an especific index in a select statement but I can´t get it. I use de next statement:
SELECT ltaklgnum ltaktanum ltakvbeln ltaptapos ltapnltyp ltappvqui
FROM ltak AS ltak INNER JOIN ltap AS ltap
ON ltaktanum = ltaptanum
AND ltaklgnum = ltaplgnum
INTO TABLE l_t_tanum_silo
WHERE ltap~lgnum EQ ip_lgnum
AND ltap~pquit EQ ' '
AND ltak~lgnum EQ ip_lgnum
AND ltak~kquit EQ ' '
AND ltak~queue EQ ip_queue
%_HINTS DB2 ''.
We have DB2 for Linux Unix and Windows 9.5 as DB system.
How can I fix this?
Thanks a lot.
RegardsThe DB2 for Linux Unix and Windows is coded DB6 for SAP and not DB2
Look at the following OSS notes
- [Note 129385 - Database hints in Open SQL|https://service.sap.com/sap/support/notes/129385]
- [Note 150037 - Database hints in Open SQL for DB6 (DB2 for LUW)|https://service.sap.com/sap/support/notes/150037]
- [Note 1270314 - DB6: DB2 9.5 Perf. degrad. for queries with INLIST clause|https://service.sap.com/sap/support/notes/1270314]
- [Note 868888 - DB6: Optimization Guidelines|https://service.sap.com/sap/support/notes/868888]
You should use a
SELECT ltak~lgnum ltak~tanum ltak~vbeln ltap~tapos ltap~nltyp ltap~pvqui
FROM ltak AS ltak INNER JOIN ltap AS ltap
ON ltak~tanum = ltap~tanum
AND ltak~lgnum = ltap~lgnum
INTO TABLE l_t_tanum_silo
WHERE ltap~lgnum EQ ip_lgnum
AND ltap~pquit EQ ' '
AND ltak~lgnum EQ ip_lgnum
AND ltak~kquit EQ ' '
AND ltak~queue EQ ip_queue
%_HINTS DB6 '<IXSCAN TABLE=''LTAP'' INDEX=''"LTAP~M"'' />'.
In note 868888 there is a sample for a join.
SELECT A~TABSPACE
FROM TADB6 AS A
JOIN IADB6 AS B ON A~TABART = B~TABART
%_HINTS DB6 '<NLJOIN><IXSCAN TABLE=''IADB6'' />'
DB6 '<IXSCAN TABLE=''TADB6'' /></NLJOIN>'.
Regards -
Primary index and secondary index in a select query
Hii,
How to use a primary or secondary index in a select query? How does this indexes actually work?
Moderator message: please search for available information/documentation.
Edited by: Thomas Zloch on Jan 21, 2012 8:38 PMrajan please just google or search SDN. there are large number of post for this..
to give you a head start: for using a particular index in the select query a %_HINTS ORACLE 'INDEX clause is added -
How to use Oracle Table Type values in Select Statement.
Hi,
I am fetching initial set of values into Oracle Table of Records Type and want to use list of values in the Select statement.
For example, try something like the following:
TYPE t_record IS RECORD (
ID TABLEA.ID%type,
NO TABLEA.NO%type,
v_record t_record;
TYPE t_table IS TABLE OF v_record%TYPE;
v_table t_table;
-- Code to populate the values in v_table here.
SELEC ID,NO, BULK COLLECT INTO <some other table variabes here> FROM TABLEA
WHERE ID IN v_table(i).ID;
I want to know how to use the values from Oracle Table Type in the Select Statement.Something like this:
create or replace type t_record as object (
id number,
no number
CREATE or replace type t_table AS TABLE OF t_record;
set serveroutput on
declare
v_table t_table := t_table();
v_t1 t_table := t_table();
begin
v_table.extend(1);
v_table(1).ID := 1;
v_table(1).No := 10;
v_table.extend(1);
v_table(2).ID := 2;
v_table(2).ID := 20;
SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
from TableA
FROM TABLEA
WHERE ID IN (select t.ID from table(v_Table) t);
for i in 1..v_t1.count loop
dbms_output.put_line(v_t1(i).ID);
dbms_output.put_line(v_t1(i).No);
end loop;
end;
/Untested!
P;
Edited by: bluefrog on Mar 5, 2010 5:08 PM -
Using temporary tablespace for sort in select statement without spacifying
how can i use some particular temporary tablespace in select statement for sording without allocating any temporary tablespace to that user
Try to set for the current session the in memory sorting space to 0 before running your query:
SQL> alter session set sort_area_size = 0;The query should use the temporary tablespace.
Message was edited by:
Pierre Forstmann -
What is proper syntax for using PassBack in a Report page select statement
In my select statement I reference the passBack function using:
onClick="javascript:passBack()"
In my Page Header I (Typically) define the passBack function as:
<script language="JavaScript" type="text/javascript">
function passBack(passVal1,passVal2) {
opener.document.getElementById("P2000_CABLE_ID").value = passVal1;
opener.document.getElementById("P2000_CABLE_LABEL").value = passVal2;
window.opener.location.reload(true);
</script>
But I have never used the passBack function from the Select statement before and cannot happen onto the proper syntax.
The Page Items I want to pass are:
1. :P2004_CABLE_ID
2. :P2004_LABEL
I want to pass them to:
1. :P2000_CABLE_ID
2. :P2000_CABLE_LABEL
Can someone please help me out... Again?
Thanks- GaryLet's assume column XYZ has both numbers (1), and letters (any alphabet).
I have a case statement on SQL to turn any value that's not 1 into 0, then I am getting a sum of that column.
I am also grouping by Row A, B etc to get aggregated sum of column XYZ for those group.
Now on Crystal Reports function, I need to sum up values under column XYZ for all the groups.
If I try using sum function like below, I get an error stating:
"A number field or currency amount field is required here"
(sum({Command.XYZ}))
So I thought if I can use a case statement to change the non-numbers to 0 prior to sum that will probably resolve it. But I could not get the below case statement to work either (Error: A string is required).
SELECT {Command.XYZ}
Case 1:
1
Default:
0; -
Two secondary indexes in a where clause
Hi All,
Can any one of you let me know wether DB optimizer will use two indexes if given in where clause........
example : primary index A,B. secondary C,D,E.
select ................ where A in ....
B in ....
C in ....
so iam using all(two) fields of primary index and one field of secondary so will the DB optimizer search for the index blocks or directly the table blocks when it comes to the C field in the where clause......
Thanks in advance.Hello,
To do it use the WHERE stm in the same order as the secondary stm is on SE11....To check if the index is used go to tcode ST05.
example
select * from ztable
WHERE BUKRS EQ 'BUK1' AND
ZFIELD EQ 'BOY'.
on se11 on the ZTABLE indexes setion must have a secondary index with
BUKRS and
ZFIELD.
BYE!!
Hope this helps!!
Gabriel -
Is it possible to use a secondary index in embedded persistent class
Hi,
I'm new to Berkely DB Java Edition and have just started playing with it.
To express a relation between two entities Foo and Bar, I am trying with an assocation class FooBarAssociation that is not an entity but rather a @Persistent-annotated embedded class in Foo (Foo has a collection of FooBarAssociations). Now I'm looking for a way to find all Foos associated with a given Bar id by use of an index. Can this be done? Is the use of the SecondaryKey in the embedded class at all correct? If this is not the way to go, can it be done any other way (except from using three entities)?
@Entity
class Bar {
@PrimaryKey
private int id;
@Persistent
class FooBarAssocication {
@SecondaryKey(relatedEntity=Bar.class, relate=Relationship.ONE_TO_ONE)
private int barId;
@Entity
class Foo {
@PrimaryKey
private int id;
private Set<FooBarAssocication> fooBarAssociations = new HashSet<FooBarAssocication>();
}Any help much appreciated.
/Martin SöderströmMartin,
So could this be done with the embedded persistent class like this, or should I give up and make the FooBarAssociation class an entity of its own?A separate relationship entity class will definitely work, as described in the SecondaryIndex javadoc.
But SecondaryKey fields have to be at the top level of an entity class, so an embedded class that contains the secondary key (and other attributes) won't work.
Logically, you have a one-to-many relationship from Foo-to-Bar, and the relationship has attributes.
If you store the relationship in the Bar entity, then it's pretty easy because there is one Bar instance per relationship and other attributes can easily be stored there. I know you said you want to put it in the Foo class because it logically belongs there, but I'll show this alternative anyway for completeness:
@Entity
class Bar {
@PrimaryKey
private int id;
@SecondaryKey(relatedEntity=Foo.class, relate=Relationship.MANY_TO_ONE)
private int fooId;
private Date createTime;
@Entity
class Foo {
@PrimaryKey
private int id;
}If it's really important to put the relationship fields into the Foo class, then you can do something like the following. It's messy to attach relationship attributes, but it can be done with either a parallel list or map.
Also, be sure to read the "Key Placement with Many-to-Many for Related Entities" section of the SecondaryIndex javadoc page.
@Entity
class Bar {
@PrimaryKey
private int id;
@Entity
class Foo {
@PrimaryKey
private int id;
// Use one of the following, either this:
@SecondaryKey(relatedEntity=Bar.class, relate=Relationship.ONE_TO_MANY)
private List<Integer> barIds = new ArrayList<Integer>;
private List<Date> barCreateTimes = new ArrayList<Date>;
// Or this:
@SecondaryKey(relatedEntity=Bar.class, relate=Relationship.ONE_TO_MANY)
private Set<Integer> barIds = new HashSet<Integer>;
private Map<Integer, Date> barCreateTimes = new HashMap<Integer, Date>;
From reading the documentation I also get the feeling that I could use the Base API and set up a SecondaryDatabase to create a secondary index for a case like this (correct?).Yes, you could do that, but I would hate to see you move to the base API just for this issue. The DPL is much easier to use (and easier for us to support).
Anyway, so far the BDBJE looks very promising to us. It may replace our current Hibernate solution.Great. We'd love to hear more about what you're doing, why JE works well for you, etc, either on the forum or privately if you prefer (mark.hayes at o.com). It helps us a lot to know what people are doing with JE.
--mark -
HOW CAN I USE MULTIPLE INNERJOINS IN A SINGLE SELECT STATEMENT?
HI,
I AM SHABEER AHMED,
I AM GETTING AN ERROR WHILE I ATTEMPT TO EXECUTE A SELECT STATEMENT WITH MULTIPLE INNER JOINS . BECOZ I WANT TO FETCH ITEM DATA, PARTNER DATA BASED ON HEADER DATA .
THEN OF COURSE I HAVE FETCH DATA FROM VBAK VBAP VBKD SO LZ SEND ME THE SOLUTION.
BYEHi,
1.Just see this:
SELECT * INTO CORRESPONDING FIELD OF TABLE itab
FROM t1 INNER JOIN t2 ON t1f4 EQ t2f4
INNER JOIN t3 ON t2f5 EQ t3f5 AND
t2f6 EQ t3f6 AND
t2f7 EQ t3f7.
2.But better to use for all entries.It increases the performance.
FOR ALL ENTRIES
Tabular Conditions
The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
<cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement.
You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.
Example for ALL ENTRIES
DATA: TAB_SPFLI TYPE TABLE OF SPFLI,
TAB_SFLIGHT TYPE SORTED TABLE OF SFLIGHT
WITH UNIQUE KEY TABLE LINE,
WA LIKE LINE OF TAB_SFLIGHT.
SELECT CARRID CONNID
INTO CORRESPONDING FIELDS OF TABLE TAB_SPFLI
FROM SPFLI
WHERE CITYFROM = 'NEW YORK'.
SELECT CARRID CONNID FLDATE
INTO CORRESPONDING FIELDS OF TABLE TAB_SFLIGHT
FROM SFLIGHT
FOR ALL ENTRIES IN TAB_SPFLI
WHERE CARRID = TAB_SPFLI-CARRID AND
CONNID = TAB_SPFLI-CONNID.
LOOP AT TAB_SFLIGHT INTO WA.
AT NEW CONNID.
WRITE: / WA-CARRID, WA-CONNID.
ENDAT.
WRITE: / WA-FLDATE.
ENDLOOP.
INNER JOINS
In a relational database, you normally need to read data simultaneously from more than one database table into an application program. You can read from more than one table in a single SELECT statement, such that the data in the tables all has to meet the same conditions, using the following join expression:
SELECT...
FROM <tab> INNER JOIN <dbtab> AS <alias> ON <cond> <options>
where <dbtab> is a single database table and <tab> is either a table or another join expression. The database tables can be specified statically or dynamically as described above. You may also use aliases. You can enclose each join expression in parentheses. The INNER addition is optional.
A join expression links each line of <tab> with the lines in <dbtab> that meet the condition <cond>. This means that there is always one or more lines from the right-hand table that is linked to each line from the left-hand table by the join. If <dbtab> does not contain any lines that meet the condition <cond>, the line from <tab> is not included in the selection.
The syntax of the <cond> condition is like that of the WHERE clause, although individual comparisons can only be linked using AND. Furthermore, each comparison must contain a column from the right-hand table <dbtab>. It does not matter on which side of the comparison it occurs. For the column names in the comparison, you can use the same names that occur in the SELECT clause, to differentiate columns from different database tables that have the same names.
The comparisons in the condition <cond> can appear in the WHERE clause instead of the ON clause, since both clauses are applied equally to the temporary table containing all of the lines resulting from the join. However, each join must contain at least one comparison in the condition <cond>.
Example for INNER JOINS
REPORT demo_select_inner_join.
DATA: BEGIN OF wa,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
fldate TYPE sflight-fldate,
bookid TYPE sbook-bookid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY carrid connid fldate bookid.
SELECT pcarrid pconnid ffldate bbookid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
INNER JOIN sbook AS b ON bcarrid = fcarrid AND
bconnid = fconnid AND
bfldate = ffldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
fseatsmax > fseatsocc.
LOOP AT itab INTO wa.
AT NEW fldate.
WRITE: / wa-carrid, wa-connid, wa-fldate.
ENDAT.
WRITE / wa-bookid.
ENDLOOP.
Regards,
Shiva Kumar(Reward if helpful). -
How to use a table name in the select statement using a variable?
Hi Everybody,
I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
Regards,
Mallik.Hi all,
Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
for ex : select * from (tab_name) where....?
Can we do inner join on such select statements? If so how?
Thanks & Regards,
Mallik. -
Using a view instead of a select statement
Greetings Abapers
Ive got a problem. Im writing a program and one of the things i do is i use 2 select statements which are as follows:
Read all organisational relationships for all business partneru2019s linked to sales codes for all date ranges
select * from hrp1001 into table lt_hrp1001 " Get all external business partners
where plvar eq '01'
and sclas eq 'BP'
and relat eq '008'
or relat eq 'Z40'.
select * from hrp1001 appending corresponding fields of table lt_hrp1001 "Get all employees
where plvar eq '01'
and sclas eq 'BP'
and relat eq '291'
and otype eq 'S'.
I have however been told that i can use the database view HRVPADIC since the hrp1001 table is giving me duplicats which i dont want. Can anyone tell me how to use this view i.e. syntax and logic. I would really appreciate it.Well, I don't see how using the view would be better. Why don't you just get all of the data at once:
SELECT * FROM hrp1001 INTO TABLE lt_hrp1001
WHERE plvar EQ '01'
AND sclas EQ 'BP'
AND ( ( relat EQ '008'
OR relat EQ 'Z40' )
OR relat EQ '291'
AND otype EQ 'S' ).
(I didn't test this so check it.)
Rob -
How to use column name as variable in select statement
hi,
i want to make a sql query where in select statement using variable as a column name. but its not working plz guide me how can i do this.
select :m1 from table1;
regardsHi,
Is this what you want..
SQL> select &m1 from dept;
Enter value for m1: deptno
old 1: select &m1 from dept
new 1: select deptno from dept
DEPTNO
10
20
30
40
SQL> select &m1 from dept;
Enter value for m1: dname
old 1: select &m1 from dept
new 1: select dname from dept
DNAME
ACCOUNTING
RESEARCH
SALES
OPERATIONS
SQL> select &&m1 from dept;
Enter value for m1: loc
old 1: select &&m1 from dept
new 1: select loc from dept
LOC
NEW YORK
DALLAS
CHICAGO
BOSTON
SQL> select &&m1 from dept;
old 1: select &&m1 from dept
new 1: select loc from dept
LOC
NEW YORK
DALLAS
CHICAGO
BOSTONIf you use single '&' then each time you fire the query, It will ask for the new value..
But if you will use double '&&' the value of m1 will be persistent across the session..
Twinkle -
I can't use my field-symbols in my select statement...
Hello experts,
I am have been having problems with my report for the past days. My problem is,
I declared a dynamic field symbol so that I can use it in my select statement
instead of the standard internal table. But it is giving me a dump. Below is my code:
REPORT zfr_forex_rev_acctg
NO STANDARD PAGE HEADING
LINE-COUNT 0
LINE-SIZE 100.
Data dictionary tables *
TABLES: bsis,
bsas,
tcurr,
t001.
FIELD-SYMBOLS: <fs_dyntable> TYPE STANDARD TABLE,
<fs_dynline> TYPE ANY,
<fs_fld> TYPE ANY,
<fs_data> TYPE REF TO data,
<fs_1> TYPE ANY,
<fs_2> TYPE ANY TABLE.
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
METHODS: build_table,
get_data,
combine_data,
display_header,
display_results.
PRIVATE SECTION.
TYPES: BEGIN OF t_bsis_bsas,
zuonr TYPE bsis-zuonr,
gjahr TYPE bsis-gjahr,
belnr TYPE bsis-belnr,
bldat TYPE bsis-bldat,
waers TYPE bsis-waers,
blart TYPE bsis-blart,
dmbtr TYPE bsis-dmbtr,
wrbtr TYPE bsis-wrbtr,
hkont TYPE bsis-hkont,
amount TYPE bsis-wrbtr,
END OF t_bsis_bsas.
DATA: it_bsis_bsas TYPE STANDARD TABLE OF t_bsis_bsas,
v_counter TYPE i.
data declarations for internal table
DATA: lt TYPE lvc_t_fcat,
ls TYPE lvc_s_fcat,
fldname(50) TYPE c,
it_ddfields TYPE TABLE OF ddfield,
wa_ddfields LIKE LINE OF it_ddfields.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD build_table
METHOD build_table.
DATA: lv_from TYPE bsis-gjahr,
lv_asof TYPE bsis-gjahr,
lv_check TYPE i,
lt_data TYPE REF TO data,
lt TYPE lvc_t_fcat.
FIELD-SYMBOLS: <fs_year> TYPE gjahr.
ASSIGN lv_asof TO <fs_year>.
lv_from = p_year.
lv_asof = p_asof+0(4).
v_counter = lv_asof - lv_from.
wa_ddfields-fieldname = 'ZUONR'.
wa_ddfields-position = '0001'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000018'.
wa_ddfields-decimals = '00000'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'GJAHR'.
wa_ddfields-position = '0002'.
wa_ddfields-datatype = 'NUMC'.
wa_ddfields-leng = '000004'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'BELNR'.
wa_ddfields-position = '0003'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000010'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'BLDAT'.
wa_ddfields-position = '0004'.
wa_ddfields-datatype = 'DATS'.
wa_ddfields-leng = '000008'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'WAERS'.
wa_ddfields-position = '0005'.
wa_ddfields-datatype = 'CUKY'.
wa_ddfields-leng = '000005'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'BLART'.
wa_ddfields-position = '0006'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000002'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'DMBTR'.
wa_ddfields-position = '0007'.
wa_ddfields-datatype = 'CURR'.
wa_ddfields-leng = '000013'.
wa_ddfields-decimals = '000002'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'WRBTR'.
wa_ddfields-position = '0008'.
wa_ddfields-datatype = 'CURR'.
wa_ddfields-leng = '000013'.
wa_ddfields-decimals = '000002'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'HKONT'.
wa_ddfields-position = '0009'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000010'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
wa_ddfields-fieldname = 'AMOUNT'.
wa_ddfields-position = '0010'.
wa_ddfields-datatype = 'CURR'.
wa_ddfields-leng = '000010'.
wa_ddfields-decimals = '000002'.
APPEND wa_ddfields TO it_ddfields.
DATA: lv_position TYPE i.
lv_position = 0011.
WHILE lv_check < v_counter.
<fs_year> = lv_asof.
wa_ddfields-fieldname = <fs_year>.
wa_ddfields-position = lv_position.
wa_ddfields-datatype = 'NUMC'.
wa_ddfields-leng = '000004'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
lv_asof = lv_asof - 1.
ADD 1 TO: lv_check, lv_position.
ENDWHILE.
CLEAR lv_position.
lv_position = 1.
LOOP AT it_ddfields INTO wa_ddfields.
ls-col_pos = lv_position.
ls-row_pos = lv_position.
ls-fieldname = wa_ddfields-fieldname.
APPEND ls TO lt.
ADD 1 TO lv_position.
ENDLOOP.
CLEAR lv_position.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <fs_dyntable>.
ENDMETHOD.
METHOD get_data
METHOD get_data.
*get records from BSIS
SELECT zuonr gjahr belnr bldat waers blart dmbtr wrbtr hkont
FROM bsis
INTO CORRESPONDING FIELDS OF TABLE <fs_dyntable>
WHERE bukrs = p_bukrs
AND hkont IN s_hkont
AND budat <= p_asof.
*get records from BSAS
SELECT zuonr gjahr belnr bldat waers blart dmbtr wrbtr hkont
FROM bsas
APPENDING CORRESPONDING FIELDS OF TABLE <fs_dyntable>
WHERE bukrs = p_bukrs
AND hkont IN s_hkont
AND budat <= p_asof
AND augdt > p_asof.
ENDMETHOD.
START-OF-SELECTION.
DATA: main TYPE REF TO lcl_main.
CREATE OBJECT main.
CALL METHOD main->build_table.
CALL METHOD main->get_data.
Need help on this problem. Thanks a lot guys and take care!Hi guys,
I found out the problem and Andreas is right. Now, I am having problems when including DMBTR, WRBTR in my select statement. All the others are ok. Here is my modified code. Please suggest what I need to add/modify. Thanks a lot!
CLASS lcl_main IMPLEMENTATION.
METHOD build_table
METHOD build_table.
DATA: lv_from TYPE bsis-gjahr,
lv_asof TYPE bsis-gjahr,
lv_check TYPE i,
lt_data TYPE REF TO data,
lt TYPE lvc_t_fcat.
FIELD-SYMBOLS: <fs_year> TYPE gjahr.
ASSIGN lv_asof TO <fs_year>.
lv_from = p_year.
lv_asof = p_asof+0(4).
v_counter = lv_asof - lv_from.
ZUONR
wa_ddfields-fieldname = 'ZUONR'.
wa_ddfields-position = '0001'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000018'.
wa_ddfields-decimals = '00000'.
APPEND wa_ddfields TO it_ddfields.
GJAHR
wa_ddfields-fieldname = 'GJAHR'.
wa_ddfields-position = '0002'.
wa_ddfields-datatype = 'NUMC'.
wa_ddfields-leng = '000004'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
BELNR
wa_ddfields-fieldname = 'BELNR'.
wa_ddfields-position = '0003'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000010'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
BLDAT
wa_ddfields-fieldname = 'BLDAT'.
wa_ddfields-position = '0004'.
wa_ddfields-datatype = 'DATS'.
wa_ddfields-leng = '00008'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
WAERS
wa_ddfields-fieldname = 'WAERS'.
wa_ddfields-position = '0005'.
wa_ddfields-datatype = 'CUKY'.
wa_ddfields-leng = '000005'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
BLART
wa_ddfields-fieldname = 'BLART'.
wa_ddfields-position = '0006'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000002'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
DMBTR
wa_ddfields-fieldname = 'DMBTR'.
wa_ddfields-position = '0007'.
wa_ddfields-datatype = 'CURR'.
wa_ddfields-leng = '000013'.
wa_ddfields-decimals = '000002'.
APPEND wa_ddfields TO it_ddfields.
WRBTR
wa_ddfields-fieldname = 'WRBTR'.
wa_ddfields-position = '0008'.
wa_ddfields-datatype = 'CURR'.
wa_ddfields-leng = '000013'.
wa_ddfields-decimals = '000002'.
APPEND wa_ddfields TO it_ddfields.
HKONT
wa_ddfields-fieldname = 'HKONT'.
wa_ddfields-position = '0009'.
wa_ddfields-datatype = 'CHAR'.
wa_ddfields-leng = '000010'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
AMOUNT
wa_ddfields-fieldname = 'AMOUNT'.
wa_ddfields-position = '0010'.
wa_ddfields-datatype = 'CURR'.
wa_ddfields-leng = '000010'.
wa_ddfields-decimals = '000002'.
APPEND wa_ddfields TO it_ddfields.
DATA: lv_position TYPE i.
lv_position = 0011.
Additional fields for the years
WHILE lv_check < v_counter.
wa_ddfields-fieldname = <fs_year>.
wa_ddfields-position = lv_position.
wa_ddfields-datatype = 'NUMC'.
wa_ddfields-leng = '000004'.
wa_ddfields-decimals = '000000'.
APPEND wa_ddfields TO it_ddfields.
lv_asof = lv_asof - 1.
ADD 1 TO: lv_check, lv_position.
ENDWHILE.
CLEAR lv_position.
lv_position = 1.
LOOP AT it_ddfields INTO wa_ddfields.
CASE wa_ddfields-fieldname.
WHEN 'BLDAT'.
ls-col_pos = lv_position.
ls-row_pos = lv_position.
ls-fieldname = wa_ddfields-fieldname.
ls-inttype = 'D'.
ls-ref_table = 'BSIS'.
ls-ref_field = 'BLDAT'.
WHEN 'WAERS'.
ls-col_pos = lv_position.
ls-row_pos = lv_position.
ls-fieldname = wa_ddfields-fieldname.
ls-ref_table = 'BSIS'.
ls-ref_field = 'WAERS'.
when 'DMBTR'.
ls-col_pos = lv_position.
ls-row_pos = lv_position.
ls-fieldname = wa_ddfields-fieldname.
ls-ref_table = 'BSIS'.
ls-ref_field = 'DMBTR'.
when 'WRBTR'.
ls-col_pos = lv_position.
ls-row_pos = lv_position.
ls-fieldname = wa_ddfields-fieldname.
ls-ref_table = 'BSIS'.
ls-ref_field = 'WRBTR'.
WHEN OTHERS.
ls-col_pos = lv_position.
ls-row_pos = lv_position.
ls-fieldname = wa_ddfields-fieldname.
ENDCASE.
APPEND ls TO lt.
ADD 1 TO lv_position.
ENDLOOP.
CLEAR lv_position.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <fs_dyntable>.
ENDMETHOD. -
What is the use of for all entries in select statement
what is the use of for all entries in select statement
hi,
FOR ALL ENTRIES is an effective way of doing away with using JOIN on two tables.
You can check the below code -
SELECT BUKRS BELNR GJAHR AUGDT
FROM BSEG
INTO TABLE I_BSEG
WHERE BUKRS = ....
SELECT BUKRS BELNR BLART BLDAT
FROM BKPF
INTO TABLE I_BKPF
FOR ALL ENTRIES IN I_BSEG
WHERE BUKRS = I_BSEG-BUKRS
AND BELNR = I_BSEG-BELNR
AND BLDAT IN SO_BLDAT.
*******************************8
look another example
what is the use of FOR ALL ENTRIES
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
Hope this helps!
Regards,
Anver
<i>if hlped pls mark points</i> -
Integrating the two parts of a union select statement...
Hi everybody ,
I have a query such as the one follows...:
SELECT TMHMA , DATES , COUNT(EXETASI)
FROM PARAGG_LAB_TESTS_LOCAL_MS PAR_TESTS_MS , PARAGG_LAB_TESTS_LOCAL PAR_TESTS_DET
WHERE PAR_TESTS_MS.BARCODE=PAR_TESTS_DET.BARCODE
GROUP BY TMHMA , DATES
UNION
SELECT TMHMA , DATES , SUM(NUM_TESTS)
FROM NUM_TESTS_PROFILE ,
PARAGG_LAB_PROFILES_LOCAL_MS PAR_PROFILE_MS , PARAGG_LAB_PROFILES_LOCAL PAR_PROFILE_DET
WHERE PAR_PROFILE_MS.BARCODE=PAR_PROFILE_DET.BARCODE AND
PAR_PROFILE_DET.PROFILE=NUM_TESTS_PROFILE.CODE_PROFILE
GROUP BY TMHMA , DATES
Is this possible to integrate the two parts of the above union sql statement into one (without using union) and compute the result of COUNT(EXETASI)+SUM(NUM_TESTS)..????
Thanks , a lot
SimonHi , Jameel
it is not correct because the columns more than one table has the columns TMHMA and DATES . To indicate this , i rewrite the query...
SELECT PAR_TESTS_MS.TMHMA , PAR_TESTS_MS.DATES , COUNT(EXETASI)
FROM PARAGG_LAB_TESTS_LOCAL_MS PAR_TESTS_MS , PARAGG_LAB_TESTS_LOCAL PAR_TESTS_DET
WHERE PAR_TESTS_MS.BARCODE=PAR_TESTS_DET.BARCODE
GROUP BY TMHMA , DATES
UNION
SELECT PAR_PROFILE_MS.TMHMA , PAR_PROFILE_MS.DATES , SUM(NUM_TESTS)
FROM NUM_TESTS_PROFILE ,
PARAGG_LAB_PROFILES_LOCAL_MS PAR_PROFILE_MS , PARAGG_LAB_PROFILES_LOCAL PAR_PROFILE_DET
WHERE PAR_PROFILE_MS.BARCODE=PAR_PROFILE_DET.BARCODE AND
PAR_PROFILE_DET.PROFILE=NUM_TESTS_PROFILE.CODE_PROFILE
GROUP BY TMHMA , DATES
and the results
TMHMA DATES COUNT(EXETASI)
11 19/8/2005 1
11 15/9/2005 4
11 15/9/2005 57
11 16/9/2005 58
11 10/10/2005 4
11 10/10/2005 72
11 14/10/2005 3
11 14/10/2005 160
11 7/4/2006 2
11 7/4/2006 53
11 8/4/2006 2
11 8/4/2006 61
11 9/4/2006 2
11 9/4/2006 31
209 30/4/2006 3
209 30/4/2006 31
209 8/5/2006 4
209 8/5/2006 31
88 20/10/2005 2
88 20/10/2005 59
and the expected results.....
TMHMA DATES COUNT(EXETASI)
11 19/8/2005 1
11 15/9/2005 61
11 16/9/2005 58
11 10/10/2005 76
11 14/10/2005 163
11 7/4/2006 55
11 8/4/2006 63b]
11 9/4/2006 [b]33
209 30/4/2006 34
209 8/5/2006 35
88 20/10/2005 61
Thanks , a lot
Simon
Maybe you are looking for
-
Is there an app that blocks all communications from a certain Number
Does anybody know an app that blocks all communications from a certain number
-
Start script for Nagios 3.0.4 on Solaris 10 doesn't work.
I compiled Nagios 3.0.4 on a Solaris 10 system using the following configure string: ./configure prefix=/space/nagios with-gd-lib=/usr/local/lib with-gd-inc=/usr/local/include with-nagios-user=na gios with-nagios-group=nagios with-temp-dir=/space/nag
-
There seems to be a discrepancy between Adobe Customization Wizard XI and the actual preferences in Reader after it is installed. I used the Wizard to create an .mst for the Reader installation. In one section I checked OFF for Protected view. When I
-
HI , As per the Business Scenario (Textile Industry ) they will raise the Sales order for XXXXX Material 1000 meters (one line item) while there are raising the Billing Document (order related Billing) they want to raise different line items based o
-
I'm trying to intall Mavericks on my HD but it tells me that I can not install it beause Time Machine uses the this HD. I have turn off the Time Machine and even removed all portions from the drive. What else can I do?