Create cursor with data from multiple tables
Hi,
I need to create a cursor that contains fields from different tables.
For example:
Table 1 Table 2 Table 3 Table 4
Col 1 (PK) Col 2 (Pk) Col 4 (Pk) Col 9 (PK)
Col 2 Col 3 (Pk) Col 5 (PK) Col 11
Col 3 Col 6 Col 8 Col 12
Col 4 Col 7 Col 9
Col 5 Col 10
Col 13
Col 14I've created the following:
CURSOR c_test IS
SELECT a.col 1,
a.col 13,
a.col 14
b.col 6
b.col 7
c.col 8
c.col 10
d.col 9
d.col 11
FROM table1 a, table2, b, table3 c, table4 d
WHERE (b.col 2, b.col 3, c.col 4, c.col 5) =
SELECT a.col 1
a.col 2
a.col 3
a.col 4
FROM table1 a
WHERE a.col 1 = '123456');But how can I get also the correct data (col 9 and col 11) of table d?
What's missing in my where clause?
Hope this is a bit clear.
Regards,
Ken
Something like this:
CURSOR c_test IS
SELECT a.col1,
a.col13,
a.col14,
b.col6,
b.col7,
c.col8,
c.col10,
d.col9,
d.col11
FROM table1 a
JOIN table2 b
ON a.col1 = b.col2
AND a.col2 = b.col3
AND a.col1 = '123456'
JOIN table3 c
ON a.col3 = c.col4
AND a.col4 = c.col5
JOIN table4 d
ON a.col1 = d.col9;Check on a.col1 = d.col9, don't whether that's right.
Similar Messages
-
Generic datasource by function module to fetch data from multiple tables?
I'm writing a function module to fetch price, for generic datasource.
At first, extract test is OK. But InfoPackage never stop when loading data to PSA in BW.
And I find the example codes:
OPEN CURSOR WITH HOLD S_CURSOR FOR
SELECT (S_S_IF-T_FIELDS) FROM SFLIGHT
WHERE CARRID IN L_R_CARRID AND
CONNID IN L_R_CONNID.
ENDIF. "First data package ?
* Fetch records into interface table.
* named E_T_'Name of extract structure'.
FETCH NEXT CURSOR S_CURSOR
APPENDING CORRESPONDING FIELDS
OF TABLE E_T_DATA
PACKAGE SIZE S_S_IF-MAXSIZE.
IF SY-SUBRC <> 0.
CLOSE CURSOR S_CURSOR.
RAISE NO_MORE_DATA.
ENDIF.
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF.
There using Cursor to fetch data package by package, and raise exception NO_MORE_DATA to stop the loading process.
Now I fetch data from multiple tables, I don't think I can use Cursor.
Then How can I handle this?
Thanks a lot.Thanks
IF IT_999[] IS INITIAL.
SELECT A~KNUMH A~MATNR A~KSCHL VKORG VTWEG A~DATBI A~DATAB KBETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A999 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_999
WHERE
* A~KNUMH = IT_999-KNUMH AND
( ( A~KSCHL = 'ZPRC' AND VKORG = 'Z000' AND VTWEG = 'Z1' ) OR
( A~KSCHL = 'ZPRD' AND VKORG = 'A000' AND VTWEG = 'Y3' ) ) AND
* A~DATBI >= SY-DATUM AND
LOEVM_KO = ''.
SELECT A~KNUMH A~MATNR A~KSCHL VKORG VTWEG A~DATBI A~DATAB KBETR AS KHETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A999 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_999
WHERE
* A~KNUMH = IT_999-KNUMH AND
A~KSCHL = 'ZPR3' AND A~VKORG = 'I000' AND
* DATBI >= SY-DATUM AND
LOEVM_KO = ''.
ENDIF.
IF IT_997[] IS INITIAL.
SELECT A~KNUMH A~MATNR A~KSCHL VTWEG A~DATBI A~DATAB KBETR AS KHETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A997 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_997
WHERE
* A~KNUMH = IT_997-KNUMH AND
A~KSCHL = 'ZPRA' AND VTWEG = 'Y1' AND
* DATBI >= SY-DATUM AND
LOEVM_KO = ''.
ENDIF.
IF IT_996[] IS INITIAL.
SELECT A~KNUMH A~MATNR A~KSCHL A~DATBI A~DATAB KBETR AS KHETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A996 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_996
WHERE
* A~KNUMH = IT_996-KNUMH AND
A~KSCHL = 'ZPRB' AND
* DATBI >= SY-DATUM AND
LOEVM_KO = ''.
ENDIF.
SELECT MATNR "u7269u6599u53F7u7801
MEINH "u4ED3u50A8u5355u4F4Du7684u5907u7528u8BA1u91CFu5355u4F4D
UMREZ "u57FAu672Cu8BA1u91CFu5355u4F4Du8F6Cu6362u5206u5B50
UMREN "u8F6Cu6362u4E3Au57FAu672Cu8BA1u91CFu5355u4F4Du7684u5206u6BCD
FROM MARM
INTO CORRESPONDING FIELDS OF TABLE IT_MARM
FOR ALL ENTRIES IN TP_DATA
WHERE MATNR = TP_DATA-MATNR AND MEINH = TP_DATA-KMEIN.
LOOP AT TP_DATA.
IF TP_DATA-KPEIN NE 0.
TP_DATA-KBETR = TP_DATA-KBETR / TP_DATA-KPEIN.
TP_DATA-KHETR = TP_DATA-KHETR / TP_DATA-KPEIN.
ENDIF.
IF TP_DATA-KSCHL = 'ZPRA'.
* TP_DATA-MEINH = 'ZI'.
* TP_DATA-KSCHL = 'B4'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'CT'.
TP_DATA-KHETR = TP_DATA-KHETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ENDIF.
ELSEIF TP_DATA-KSCHL = 'ZPRB'.
* TP_DATA-KSCHL = 'L0'.
* TP_DATA-MEINH = 'ZI'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'BAG'.
TP_DATA-KHETR = TP_DATA-KHETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ENDIF.
ELSEIF TP_DATA-KSCHL = 'ZPRC' OR TP_DATA-KSCHL = 'ZPRD'.
* TP_DATA-MEINH = 'ZI'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KHETR = TP_DATA-KBETR * '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'WZI'.
TP_DATA-KBETR = TP_DATA-KBETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KHETR = TP_DATA-KBETR * '1.17'.
ENDIF.
ELSEIF TP_DATA-KSCHL = 'ZPR3'.
* TP_DATA-KSCHL = 'B2'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'BAG'.
TP_DATA-KHETR = TP_DATA-KHETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ENDIF.
ENDIF.
TP_DATA-MEINH = '01'.
MODIFY TP_DATA.
E_T_DATA-MATNR = TP_DATA-MATNR.
E_T_DATA-KSCHL = TP_DATA-KSCHL.
E_T_DATA-KHETR = TP_DATA-KHETR.
E_T_DATA-KBETR = TP_DATA-KBETR.
E_T_DATA-KMEIN = TP_DATA-KMEIN.
E_T_DATA-DATAB = TP_DATA-DATAB.
E_T_DATA-DATBI = TP_DATA-DATBI.
APPEND E_T_DATA.
CLEAR WA_MARM1.
CLEAR WA_MARM2.
ENDLOOP.
Edited by: Shen Peng on Oct 20, 2010 10:09 AM -
Can a block in Oracle contain rows/data from multiple tables?
Hi during my discussion with one of the DBAs, a point came up i.e. A block shouldn't have rows from multiple tables...
Is that true? I read in one of the OTN thread (i don't exactly remember the thread name) that a block can have data from multiple tables. If it doesn't have, what's the table directory in block signifies?
Please share your views.
Thanks,
CSMCSM.DBA wrote:
Hi,
As per the above link,
Table directory
For a heap-organized table, this directory contains metadata about tables whose rows are stored in this block. Multiple tables can store rows in the same block. (Logical Storage Structures)
And by default Oracle creates heap organized tables only.(heap-organized table: A table in which the data rows are stored in no particular order on disk. By default, CREATE TABLE creates a heap-organized table.) (Glossary)
So I can say a block can contain rows from multiple tables. Isn't it?
CSM
See Logical Storage Structures
Given: A segment is a set of extents allocated for a specific database object, such as a table.
Given: An extent is a set of logically contiguous data blocks -
Move data from multiple Tables to a Single Table & Convert the list to ALV.
Hi,
My aim is to get the list of Materials with their descriptions, with MRP Controller, with Unrestriced Qty. & the Reorder Qty. So, I have to fetch the data from different tables. But finally I am not able to copy or move the fetched data from multiple tables into the single final table.
Also tell me how to convert this list into ALV.
Below is the program code.
*& Report Y_REORDER_REPORT
REPORT Y_REORDER_REPORT.
tables : marc,makt, mard.
DATA: Begin of i_final occurs 0,
matnr type marc-matnr,
maktx type makt-maktx,
DISPO type marc-DISPO,
MINBE type marc-MINBE,
LABST type mard-LABST,
end of i_final.
DATA: Begin of i_marc occurs 0,
matnr type marc-matnr,
DISPO type marc-DISPO,
MINBE type marc-MINBE,
end of i_marc.
DATA: Begin of i_makt occurs 0,
matnr type makt-matnr,
maktx type makt-maktx,
end of i_makt.
DATA: Begin of i_mard occurs 0,
matnr type mard-matnr,
LABST type mard-LABST,
LGORT TYPE MARD-LGORT,
end of i_mard.
SELECT matnr
dispo
minbe from marc
into corresponding fields of table i_marc
where dispo EQ 'STR'.
SORT I_MARC by MATNR.
WRITE: /10 'Material',
75 'MRP',
80 'Reorder Qty.'.
LOOP at i_marc.
Write: /10 i_marc-matnr,
75 i_marc-dispo,
80 i_marc-minbe.
ENDLOOP.
write: /.
SELECT matnr
MAKTX from makt
into corresponding fields of table i_makt
for all entries in i_marc
where matnr = i_marc-matnr.
LOOP at i_makt.
Write: /10 i_makt-matnr,
30 i_makt-maktx.
ENDLOOP.
SELECT matnr
LGORT
LABST from mard
into corresponding fields of table i_mard
for all entries in i_marc
where matnr = i_marc-matnr.
LOOP at i_mard.
Write: /10 i_mard-matnr,
30 I_MARD-LGORT,
40 i_mard-labst.
ENDLOOP.
move i_mard-matnr to i_final-matnr.
move i_marc-dispo to i_final-dispo.
move i_marc-minbe to i_final-minbe.
move i_makt-maktx to i_final-maktx.
move i_mard-labst to i_final-labst.
WRITE: /10 'Material',
30 'Material Desc.',
75 'MRP',
80 'Reorder Qty.',
105 'Current Stock'.
LOOP at i_final.
Write: /10 i_final-matnr,
30 i_final-maktx,
75 i_final-dispo,
80 i_final-minbe,
105 i_final-labst.
ENDLOOP.
*LOOP at i_mard.
*Write: /10 i_mard-matnr,
30 i_makt-maktx,
75 i_marc-dispo,
80 i_marc-minbe,
105 i_mard-labst.
*ENDLOOP.
Regards,
VishalChange like this,
SELECT matnr
lgort
labst FROM mard
INTO CORRESPONDING FIELDS OF TABLE i_mard
FOR ALL ENTRIES IN i_marc
WHERE matnr = i_marc-matnr.
LOOP AT i_mard.
WRITE: /10 i_mard-matnr,
30 i_mard-lgort,
40 i_mard-labst.
ENDLOOP.
LOOP AT i_marc.
READ TABLE i_mard WITH KEY matnr = i_marc-matnr.
READ TABLE i_makt WITH KEY matnr = i_marc-matnr.
MOVE i_mard-matnr TO i_final-matnr.
MOVE i_marc-dispo TO i_final-dispo.
MOVE i_marc-minbe TO i_final-minbe.
MOVE i_makt-maktx TO i_final-maktx.
MOVE i_mard-labst TO i_final-labst.
APPEND i_final.
ENDLOOP.
WRITE: /10 'Material',
30 'Material Desc.',
75 'MRP',
80 'Reorder Qty.',
105 'Current Stock'. -
How to extract data from multiple tables (always got errors)
Dear Experts,
I have a simple mapping to extract data from multiple tables as a source (A, B, C) to a target table (X). Below is the picture:
(Sources)....(Target)
A----------------***
B----------------X
C----------------***
Sample Source Data:
Table A:
ColA1
100
200
etc
Table B:
ColB1 ColB2 ColB3
10 Y Ten
20 Y Twenty
30 Y Thirty
etc
Table C:
ColC1 ColC2
11
12
13
etc
Target table (X) should be (just has 1 group INGRP1):
ColA1 ColB1 ColB3 ColC1
100 10 Ten 11
100 10 Ten 12
100 20 Twenty 21
etc
Scenarios:
1. Directly map from A, B, C to X. Unable to map with error message: "API8003: Connection target attribute group is already connected to an incompatible data source. Use a Joiner or Set operator to join the upstream data first before connecting it into this operator."
2. Map each source to Expression Operator and then map from each Expression to target table. I am able to map all attributes successfully but got error when validating it with message: "VLD-1104: Attributes flowing into TEST.EXPR_SRC.INGRP1 have different data sources."
How can I achieve the correct mapping for this purpose?
Use Joiner? I have no key to join the sources
Use Set? The sources have different number of columns
Thanks in advance
PratThanks Nico,
I think it will results data like this:
100 10 Ten 11
200 20 Twenty 12
300 30 Thirty 13
etc
and not the expected:
100 10 Ten 11
100 10 Ten 12
100 20 Twenty 21
etc
But it inspired me to solve this by adding key expression in each source table (B & C) to be joined to table A with this formula:
100+TRUNC(INGRP1.COLB1,-2)
Regards
Prat -
JDBC-XI-FILE scenario. How to extract data from multiple tables
Hi,
At this moment I didn't have the access for XI system. So here I have some silly question. Could you please clarify the same ??
If I got to extract data from single table using JDBC adapter I can put the below query in communication channel
SELECT *FROM orders WHERE new='true'.
But if I got to extract data from multiple tables, logic to be used should be like as shown below. ( from previous thread------prabhu).
SELECT <Table_2>.EID, <Table_2>.FName, <Table_2>.LName, <Table_1>.REC_DAT, <Table_1>.DESCRP
FROM <Table_1> INNER JOIN <Table_2> on
<Table_1>.CARDNO = <Table_2>.CARD
where REC_DAT = <condition>
union
SELECT <Table_2>.EID, <Table_2>.FName, <Table_2>.LName, <Table_1>.REC_DAT, <Table_1>.DESCRP
FROM <Table_1> INNER JOIN <Table_2> on
<Table_1>.CARDNO = <Table_2>.CARD
where REC_DAT = <condition>
But my query is ........how to put the above entire code in one line. (i.e in Qery place of communication channel ) ??
Thanks
KumarHi Palnati,
You either use a select query with join or a stored procedure which will contain the logic to extract the data from multiple tables. But, the limitation in case of stored procedure is u can hv only one selct query in it.
You write ur actual query provided in the parameter 'Query SQL Statement". u can also wrt a stored procedure in it. Also, u can provide a update statement in it which will update a certain flag so tht u don selct the data again.
Check the following link
<a href="http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm</a>
Regards,
Akshay
Message was edited by:
Akshay Salunke -
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 -
Update On data from multiple Tables
How can i update data from multiple tables(Using a Join)
using a single update statement.Hii
Suppose i have following tables
create table emp_mas(empno number primary key,name varchar2(30));
create table emp_grad(empno number primary key,grade varchar2(1));
SQL> select * from emp_grad;
EMPNO G
100 A
101 A
102 B
SQL> select * from emp_mas;
EMPNO NAME
100 GREG
101 THOMAS
102 SAM
I would like to update information of employee 'GREG' Using a single update statement as
UPDATE (SELECT E.EMPNO,E.NAME,G.GRADE FROM EMP_MAS E,EMP_GRAD G WHERE E.EMPNO=G.EMPNO) J
SET J.NAME='GREG THOMAS',J.GRADE='B' WHERE EMPNO=100
Then i am getting Error message like this.
ERROR at line 2:
ORA-01776: cannot modify more than one base table through a join view
How can i achieve the result -
POWL accessing data from multiple tables/objects
Hello,
I have a query on the POWL applications.
If the powl application has to access data from multiple tables/objects, then the solution would be creating a data structure of those tables/objects and referring to that structure in GET_OBJECT_DEF methods.
Is there any other soln? or I am right here?
The queries which are saved for a particular user are transportable? if not, how can they be made transportable?
Thanks & regards,
Ravishyou are right, you can do in get_objects method.
POWL_QUERIES are transportab;e, you can save them in POWL_QUERY transaction.
Best regards,
Rohit
http://wiki.sdn.sap.com/wiki/display/WDABAP/POWL -
Work with data from a table of another SAP R/3 system
Hi,
I want to work with data from a table of another system. I know there's a function called 'RFC_READ_TABLE' but I don't know really how it works. What I want to do is to get data from that system and pass it to the one where I'm working in order I can continue working with this data in the report.
Besides, I'd like to select only the records that have some conditions.
I'd appreciate if someone could tell how to do it, whether with FM 'RFC_READ_TABLE' or in another way.
Thanks in advance,
Gerard
P.S: The systems are already connected in SM59Yes, you can use RFC_read_table .You can pass the number of columns but I recommend you to bring all results in your internal table after that you can filter the records. Most of the time I have notice when you make RFC call with this FM to another system it works but it may also happen that other system controlling authorization and then it might give you nothing. As I face this problem on my last Project.
Hope thisll give you idea!!
<b>P.S award the points.</b>
Good luck
Thanks
Saquib Khan
"Some are wise and some are otherwise" -
Displaying data from multiple table/column
hello ..
anybody can help me how to diplaying data from multiple table/ column in PHP. TQFollow the "How do I SELECT, INSERT, UPDATE and DELETE data from PHP?" example from http://wiki.oracle.com/page/PHP+Oracle+FAQ and change the "select ..." query to your favourite join, e.g.
select country_name, region_name from countries, regions where countries.region_id = regions.region_id; -
Jdbc getting data from multiple tables
hi guys
how can i get data from multiple tables in MSAccess
please help>
here is code thata i want to do
i have 3 tables in my MSAccess databace
Stud_O which consist name,surname fields
Stud_I consist address,tel
Stud_E department,faculty fields
Based on this I would guess that you are missing a key field. There is no way to connect the tables.
I make the class to insert data to the tables. But
cant do getting datas from this tables.
can anybody help me in making query
and method that displays reultset strings to the
textBoxes
A select ...
select name,surname from Stud_O. Use the executeQuery() method. -
Creating table data from multiple tables
I want to be able to create a extract file of the data in the BKPF and BSEG tables. I need to create one line that contains a combination of fields from each table. I am thinking that I have to select the data that I need from the BKPF table into a work table and select the data that I need from the BSEG using the document number field from the BKPF as part of the selection into another work table. after I get the two work tables, I am going to have to read the BKPF table and move the fileds that I want to a third table and then read every entry in the bseg work table that matches the document number and move those field to the third work table. after that is completed, I will a one table that has data from both tables. is this the correct way to handle this. if there is a easier way to perform this operation, could someone please let me know
thanks in advance for the help.Hi Timothy,
this would suffice.
data: itab like bkpf occurs 0 with header line.
data: itab1 like bseg occurs o with header line.
SELECT * FROM BKPF INTO TABLE itab
WHERE BUKRS EQ P_BUKRS AND
BELNR IN S_BELNR AND
GJAHR IN S_GJAHR.
SELECT * FROM BSEG INTO TABLE ITAB1
FOR ALL ENTRIES IN ITAB
WHERE BUKRS eq ITAB-BUKRS
AND BELNR eq ITAB-BELNR
AND GJAHR eq ITAB-GJAHR.
Regards,
Vivek -
To populate dynamically created int table with data from other table
Hi everybody,
I have already created an internal table dynamically, but now want to populate it with data from another IT depending on the plant name.
My dynamic int table contains fields with plant name like '8001' ,'8002' and so on.
no I want to read data from the other table and depending on bwkey which contains similar data like plant name , want to append to this new dynamic int table through read key statement.
I cannot reference the field name hard coded as it does not allow field symbol reference to be hard coded.
Pls help.Hi,
Check the code below:
REPORT ztestdyn.
TYPE-POOLS : slis.
TABLES: yyle0003.
DATA:
g_exit TYPE c,
g_save VALUE 'A', "For parameter I_SAVE
g_repid LIKE sy-repid, "For program name
g_variant TYPE disvariant. "For parameter IS_VARIANT
*Tables
DATA: d_ref TYPE REF TO data,
d_ref1 TYPE REF TO data,
i_alv_cat1 TYPE TABLE OF lvc_s_fcat,
ls_alv_cat1 LIKE LINE OF i_alv_cat1.
DATA: BEGIN OF total_tab OCCURS 0 ,
tknum TYPE yyle0003-tknum,
quantity TYPE p, "yyle0003-QUANTITY,
END OF total_tab.
DATA: BEGIN OF g_scandata_tab OCCURS 0.
INCLUDE STRUCTURE yyle0003.
DATA: END OF g_scandata_tab.
DATA: g_yyle0003_tab LIKE yyle0003 OCCURS 0 WITH HEADER LINE.
DATA: g_itab1 TYPE TABLE OF yyle0003.
DATA: wa_itab1 LIKE g_scandata_tab.
TYPES: BEGIN OF itab2,
tknum TYPE yyle0003-tknum,
vhilm TYPE yyle0003-vhilm,
quantity TYPE p,
END OF itab2.
DATA: g_itab3 TYPE TABLE OF itab2.
DATA: wa_itab3 TYPE itab2.
DATA: g_itab5 TYPE TABLE OF itab2.
DATA: wa_itab5 TYPE itab2.
DATA: g_itab4 TYPE TABLE OF itab2.
DATA: wa_itab4 TYPE itab2.
DATA: gv_wa TYPE REF TO data.
DATA : wa_tab TYPE itab2.
DATA: BEGIN OF itab6 OCCURS 0,
vhilm TYPE yyle0003-vhilm,
quantity TYPE p,
END OF itab6.
******************Start of Internal Table Definition *******************
DATA:
g_custom_container_0100 TYPE REF TO cl_gui_custom_container,
g_alv_grid_0100 TYPE REF TO cl_gui_alv_grid,
g_container_0100 TYPE scrfname VALUE 'LIST',
g_mylayout TYPE lvc_s_layo,
ok_code LIKE sy-ucomm.
FIELD-SYMBOLS :<f_fs> TYPE table,
<f_fs11> TYPE table,
<f_fs1> TYPE table,
<f_fs3> TYPE ANY,
<f_fs4> TYPE ANY,
<f_field> TYPE ANY,
<f_fs5> TYPE ANY.
FIELD-SYMBOLS: <fs_wa> TYPE ANY.
DATA: l_var TYPE i,
l_i TYPE i.
DATA: l_var1 TYPE char20,
l_var2 TYPE char20.
DATA: l_TOTAL TYPE I,
L_FILL TYPE i,
L_TOT TYPE I.
DATA: l_int TYPE i,
l_sum TYPE i.
FIELD-SYMBOLS: <f_fs2> TYPE itab2, "
<f_fs6> TYPE ANY,
<f_fs7> TYPE ANY.
DATA: l_var3 TYPE char15.
DATA: l_quant TYPE p.
FIELD-SYMBOLS: <f_fs8> LIKE itab6, "
<f_fs9> TYPE ANY,
<f_fs10> TYPE ANY.
FIELD-SYMBOLS : <f_fs12> TYPE ANY,
<f_fs13> TYPE ANY.
SORT g_scandata_tab BY tknum vhilm.
LOOP AT g_scandata_tab INTO wa_itab1.
MOVE-CORRESPONDING wa_itab1 TO wa_itab3.
APPEND wa_itab3 TO g_itab3.
ENDLOOP.
LOOP AT g_itab3 INTO wa_itab3.
COLLECT wa_itab3 INTO g_itab4.
ENDLOOP.
LOOP AT g_itab4 INTO wa_itab4.
MOVE-CORRESPONDING wa_itab4 TO wa_itab5.
MOVE-CORRESPONDING wa_itab4 TO itab6.
APPEND wa_itab5 TO g_itab5.
COLLECT itab6.
ENDLOOP.
CLEAR wa_itab3.
SORT g_itab4 BY tknum vhilm.
DELETE ADJACENT DUPLICATES FROM g_itab4 COMPARING vhilm.
DESCRIBE TABLE g_itab4 LINES l_var.
l_i = '2'.
ls_alv_cat1-fieldname = 'TKNUM'.
ls_alv_cat1-col_pos = 1.
ls_alv_cat1-coltext ='ShipmentNo.'.
APPEND ls_alv_cat1 TO i_alv_cat1.
DATA: l_var4(10) TYPE c,
l_var5(10) TYPE c,
l_fieldname(20) TYPE c..
LOOP AT g_itab4 INTO wa_itab4.
IF l_var >= 1.
CONDENSE wa_itab4-vhilm NO-GAPS.
ls_alv_cat1-fieldname = wa_itab4-vhilm. "l_fieldname.
ls_alv_cat1-col_pos = l_i.
ls_alv_cat1-coltext = wa_itab4-vhilm.
ls_alv_cat1-do_sum ='X'.
APPEND ls_alv_cat1 TO i_alv_cat1.
CLEAR : ls_alv_cat1, l_fieldname.
l_i = l_i + 1.
ENDIF.
AT LAST.
ls_alv_cat1-fieldname = 'TOTAL'. "l_fieldname.
ls_alv_cat1-col_pos = l_i.
ls_alv_cat1-coltext = 'TOTAL'.
ls_alv_cat1-do_sum ='X'.
APPEND ls_alv_cat1 TO i_alv_cat1.
CLEAR : ls_alv_cat1, l_fieldname.
ENDAT.
SORT i_alv_cat1 BY fieldname.
DELETE ADJACENT DUPLICATES FROM i_alv_cat1.
ENDLOOP.
SORT i_alv_cat1 BY col_pos.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat1
IMPORTING
ep_table = d_ref.
ASSIGN d_ref->* TO <f_fs>.
CREATE DATA gv_wa LIKE LINE OF <f_fs>.
ASSIGN gv_wa->* TO <fs_wa>.
DELETE ADJACENT DUPLICATES FROM <f_fs> COMPARING ALL FIELDS.
LOOP AT itab6.
CLEAR wa_itab5.
wa_itab5-tknum = 'Total'.
MOVE-CORRESPONDING itab6 TO wa_itab5.
APPEND wa_itab5 TO g_itab5.
CLEAR wa_itab5.
ENDLOOP.
DESCRIBE TABLE g_itab5 LINES L_TOT.
LOOP AT TOTAL_TAB.
L_TOTAL = L_TOTAL + total_tab-quantity.
ENDLOOP.
LOOP AT g_final ASSIGNING <f_fs2>.
ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <f_fs2> TO <f_fs6>.
ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <fs_wa> TO <f_fs7>.
<f_fs7> = <f_fs6>.
CONDENSE <f_fs2>-vhilm NO-GAPS.
ASSIGN COMPONENT 'VHILM' OF STRUCTURE <f_fs2> TO <f_fs3>.
ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.
MOVE <f_fs3> TO l_var1.
ASSIGN COMPONENT l_var1 OF STRUCTURE <fs_wa> TO <f_fs5>.
<f_fs5> = <f_fs4>.
CLEAR total_tab-quantity.
READ TABLE total_tab WITH KEY tknum = <f_fs6>.
IF sy-subrc = 0.
ASSIGN total_tab-quantity TO <f_fs12>.
ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.
<f_fs13> = <f_fs12>.
ENDIF.
L_FILL = L_FILL + 1.
IF L_FILL = L_TOT.
ASSIGN L_TOTAL TO <f_fs12>.
ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.
<f_fs13> = <f_fs12>.
ENDIF.
AT END OF <f_fs2>-tknum.
APPEND <fs_wa> TO <f_fs>.
CLEAR <fs_wa>.
ENDAT.
ENDLOOP.
CLEAR: <f_fs6>,
<f_fs7>.
CLEAR <fs_wa>.
CALL SCREEN 0100.
*& Module STATUS_0100 OUTPUT
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ZVKS'.
SET TITLEBAR 'ZVKS'.
CHECK sy-ucomm IS INITIAL.
SORT g_scandata_tab BY tknum vhilm.
CREATE OBJECT g_custom_container_0100
EXPORTING container_name = g_container_0100
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
CREATE OBJECT g_alv_grid_0100
EXPORTING i_parent = g_custom_container_0100.
g_mylayout-grid_title = 'Display Scanning data'.
CALL METHOD g_alv_grid_0100->set_table_for_first_display
CHANGING
it_outtab = <f_fs>
it_fieldcatalog = i_alv_cat1
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
Regards
Kannaiah -
Reading data from multiple tables on Apex
Hi All,
My apologies if the below question has been answered already, just that I could not find the relevant discussion.
I have an interactive report that I would like to use to display data from 2 tables:
Table 1 has about 10 columns but I just want to display 3 of those columns, field1, field2 & field3.
Table 2 has about 5 columns and I only want to display 2 of these columns(Column1 & Column2) on the same report with the above columns from table 1.
I need my report to look like this: field1 field2 field3 Column1 Column2
from table1, table2
I tried the above example and it seems not to be working, may I please get some assistance on how to achieve this.
Thanks in advance.Hi There,
Thanks for your response, I've actually found and answer the question.
I wanted to display data from 2 separate tables(views) that did not have joints, and so hence I could not join them with a join condition.
What I did was to created a dummy field on both tables with similar values and joined the tables using those dummy fields and it works perfect.
Thanks.
Maybe you are looking for
-
Add AAA Client Errors,Shared Secret value must not be blank.
hello, When i add the AAA client to the ACS 4.2 90 eveluation software installed on win2003 std OS with SPk 1 gives the below error when entered the shared secret value then submitting it. "Shared Secret value must not be blank" what could br the cau
-
I have a java program to select the data from the db for every 15 secs, however after running for 1-2 days, it throws the following exception: java.sql.SQLException: ORA-02068: following severe error from TECH02 ORA-00600: internal error code, argume
-
In any of my order type i cant see actual start and actual finish date and it remains blank though order gets completed. Wat can be a possible reason or is there any specific settings for that ???
-
First Question, is this forum only in english?
I use Adobe Creative Design Web Premium Suite CS 6.0 on my computer here. I have the second license installed om my Notebook at home. Now I become a new very fast WIN 7 Computer and I would install CS 6 before I work with this computer in 1..2 Weeks
-
I am using 6i builder and runtime. I can successfully compile forms in builder, but when I use runtime I get GetRegString = -304500. This happens at other machines as well and to forms that I know are working. What have I done wrong? I suspect that I