Join on Internal tables
Hello ppl,
I have 2 internal tables.
I want to write a select query to select 2 fields from one internal table and 1 field from another internal table.
These 3 fields will be selected in a third internal table.
Fields to be selected: gt_mast-matnr
gt_mast-werks
gt_afko-aufld
Into internal table gt_csbe.
How to achieve this?
Please help.
Thanks,
David.
Hi,
It can achieved by using Inner Join.
Refer the sample code for using Inner Join:
Inner joins using 3 tables
Try this :-
SELECT stpo~stlnr stpo~idnrk mast~matnr mara~mtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpo~stlnr = mast~stlnr
JOIN mara ON mara~matnr = mast~matnr
WHERE stpo~stlty = 'M' "AND stpo~idnrk IN s_matnr
AND mast~werks = 1000.
Here s_matnr is a select-options on the selection-screen.
Or this.
Select single Vbrk~Bukrs Vbrk~Kunrg Vbrk~Vbeln
Vbrk~Fkdat Vbrk~Bstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
Vbak~Vbeln Vbak~Bstdk
Likp~Vbeln Likp~lfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on Tvzbt~Zterm = Vbrk~Zterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on Vbak~Vbeln = SalesLnk~Vbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on Likp~Vbeln = DeliveryLnk~Vbelv
where vbrk~vbeln = pu_Vbeln.
This code locates sales, delivery and payment terms info from a billing document number.
or
Here, this one also works fine :
select zfpcd~cadivi zfpcd~proforma zfpcd~factura zfpcd~aniofactura
zfpcd~montousd zfpcd~montoap zfpcd~ebeln zfpcd~inco1
zfpcd~lifnr lfa1~name1 zcdvs~status zfpcd~conint
into it_lista
from zfpcd inner join zcdvs
on zfpcd~ebeln = zcdvs~ebeln
and zfpcd~proforma = zcdvs~proforma
and zfpcd~lifnr = zcdvs~lifnr
inner join lfa1
on zfpcd~lifnr = lfa1~lifnr
where zcdvs~status = '04'.
<REMOVED BY MODERATOR>
Cheers,
Chandra Sekhar.
Edited by: Alvaro Tejada Galindo on Feb 26, 2008 12:43 PM
Similar Messages
-
How to join two internal table rows in alternative manner into one internal table?
How to join two internal table rows in alternative manner into one internal table?
two internal tables are suppose itab1 & itab2 & its data
Header 1
Header 2
Header 3
a
b
c
d
e
f
g
h
i
Header 1
Header 2
Header 3
1
2
3
4
5
6
7
8
9
INTO itab3 data
Header 1
Header 2
Header 3
a
b
c
1
2
3
d
e
f
4
5
6
g
h
i
7
8
9Hi Soubhik,
I have added two additional columns for each internal table.
Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)
Row_Count - It represents the Row Count Number, increase the row count value 1 by one..
ITAB1:
Header 1
Header 2
Header 3
Table_Count
Row_Count
a
b
c
1
1
d
e
f
1
2
g
h
i
1
3
ITAB2:
Header 1
Header 2
Header 3
Table_Count
Row_Count
1
2
3
2
1
4
5
6
2
2
7
8
9
2
3
Create the Final Internal table as same as the ITAB1/ITAB2 structure.
"Data Declarations
DATA: IT_FINAL LIKE TABLE OF ITAB1. "Final Internal Table
FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1, "TAB1
<FS_TAB2> TYPE TY_TAB2. "TAB2
"Assign the values for the additional two column for ITAB1
LOOP AT ITAB1 ASSIGNING <FS_TAB1>.
<FS_TAB1>-TABLE_COUNT = 1. "Table value same for all row
<FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Assign the values for the additional two column for ITAB2
LOOP AT ITAB2 ASSIGNING <FS_TAB2>.
<FS_TAB2>-TABLE_COUNT = 2. "Table value same for all row
<FS_TAB2>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Copy the First Internal Table 'ITAB1' to Final Table
IT_FINAL[] = ITAB1[].
"Copy the Second Internal Table 'ITAB2' to Final Table
APPEND IT
LOOP AT ITAB2 INTO WA_TAB2.
APPEND WA_TAB2 TO IT_FINAL.
ENDLOOP.
"Sort the Internal Table based on TABLE_COUNT & ROW_COUNT
SORT IT_FINAL BY ROW_COUNT TABLE_COUNT.
After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.
Regards
Rajkumar Narasimman -
Hello,
i have to join the whole content of a table with the content of a aggregated table. i "moved" the content of the 2 dictionary tables into 2 internal tables and i want to join these 2 internal tables now.
first of all, is it generally possible to join 2 internal tables, for example with a read or loop statement?!
at second, i know how i would solve the problem in oracle 10g, but it looks like that open-sql supports not the same features like orcale. knows anyone of you how i can rebuild the following oracle statement in abap.
select a.id, a.col1, b.col2
from table_a as a, (select id, sum(col2) as col2 from table_c group by id) as b where a.id = b.id order by 1
thxHello Markus
ABAP open sql ahould be something like
select aid acol1 sum( b~col2 )
from table_a as a
join table_c as b
on aid = bid
group by b~id
not sure abour the order by; don't know oracle syntax exactly.
Try!
Regards,
Clemens -
Joining Two Internal Tables - ( Urgent )
Could anybody please give me the whole code for joining two internal tables
and putting the data in a third internal table. Please, very urgent.
Regards,
SAURAVHi,
Refer this code
*& Form SUB_READ_VBRK
text
FORM sub_read_vbrk.
SELECT vbeln
rplnr
bukrs
FROM vbrk
INTO TABLE it_vbrk
WHERE vbeln IN s_vbeln
AND rplnr NE ' '.
IF sy-subrc EQ 0.
SORT it_vbrk BY rplnr.
ENDIF.
ENDFORM. " SUB_READ_VBRK
*& Form SUB_READ_FPLTC
text
FORM sub_read_fpltc.
IF NOT it_vbrk[] IS INITIAL.
SELECT fplnr
fpltr
ccnum
FROM fpltc
INTO TABLE it_fpltc
FOR ALL ENTRIES IN it_vbrk
WHERE fplnr EQ it_vbrk-rplnr
AND ccins EQ 'GIFC'.
IF sy-subrc EQ 0.
SORT it_fpltc BY fplnr.
ENDIF.
ENDIF.
ENDFORM. " SUB_READ_FPLTC
*& Form SUB_COLLECT_DATA
text
FORM sub_collect_data.
*--Local variables
DATA : lv_count(3) TYPE c.
IF NOT it_fpltc[] IS INITIAL.
LOOP AT it_fpltc INTO wa_fpltc.
lv_count = wa_fpltc-fpltr+3(3).
wa_final-ccnum = wa_fpltc-ccnum.
wa_final-rfzei = lv_count.
CLEAR : wa_vbrk.
READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbrk-vbeln.
wa_final-bukrs = wa_vbrk-bukrs.
ENDIF.
APPEND wa_final TO it_final.
CLEAR : wa_vbrk,
wa_fpltc,
lv_count.
ENDLOOP.
ENDIF.
ENDFORM. " SUB_COLLECT_DATA
Regards,
prashant -
How to join several internal tables?
Hi,
I have several internal tables. And there is a very complex LOOP to extract data from these internal tables and many other logic inside it. The LOOP is very time-consuming.
I am thinking to join these internal tables into one big internal table, to save some logic inside the complex LOOP. But as I know there is no "join" function for internal tables.
So is there any workaround method to perform a "join" operation on internal tables?
Thanks a lot!Hi,
I have several internal tables. And there is a very complex LOOP to extract data from these internal tables and many other logic inside it. The LOOP is very time-consuming.
I am thinking to join these internal tables into one big internal table, to save some logic inside the complex LOOP. But as I know there is no "join" function for internal tables.
So is there any workaround method to perform a "join" operation on internal tables?
Thanks a lot! -
hi all
please give a query for joining of three internal tables and store into another table,and we should retrive data from that third table
please take those fields as material number,plant,storage location,stock,unitsHello Raja,
SELECT EKKNEBELN EKKNEBELP EKKNKOSTL EKKNPS_PSP_PNR EKKN~SAKTO
EKETWEMNG EKETETENR EKETBEDAT EKPOKNTTP EKPOLOEKZ EKPOMATNR
EKPOWERKS EKPOMATKL EKPOMENGE EKPOMEINS EKPONETPR EKPOPEINH
EKPONETWR EKPOMTART EKPOEFFWR EKKOBUKRS EKKOBSART EKKOERNAM
EKKOLIFNR EKKOEKORG EKKOEKGRP EKKOWAERS EKKO~BEDAT
EKKO~MEMORY INTO TABLE G_T_OUTTAB
FROM ( EKKN
INNER JOIN EKET
ON EKETEBELN = EKKNEBELN
AND EKETEBELP = EKKNEBELP
INNER JOIN EKPO
ON EKPOEBELN = EKETEBELN
AND EKPOEBELP = EKETEBELP
INNER JOIN EKKO
ON EKKOEBELN = EKPOEBELN )
WHERE EKKN~EBELN IN S_EBELN
AND EKKN~EBELP IN S_EBELP
AND EKKN~KOSTL IN S_KOSTL
AND EKKN~PS_PSP_PNR IN S_WBS
AND EKKN~SAKTO IN S_SAKTO
AND EKPO~KNTTP IN S_KNTTP
AND EKPO~LOEKZ IN S_LOEKZ
AND EKPO~MATKL IN S_MATKL
AND EKPO~MATNR IN S_MATNR
AND EKPO~WERKS IN S_WERKS
AND EKKO~BEDAT IN S_BEDAT
AND EKKO~BSART IN S_BSART
AND EKKO~BUKRS IN S_BUKRS
AND EKKO~EKGRP IN S_EKGRP
AND EKKO~EKORG IN S_EKORG
AND EKKO~ERNAM IN S_ERNAM
AND EKKO~LIFNR IN S_LIFNR
AND EKPO~MTART IN S_MTART
AND EKKO~MEMORY IN S_MEMORY
AND EKET~BEDAT IN S_DAT_ET.
Try with this code.
If useful reward.
Vasanth -
Left ouer join with internal table
Good morning to everybody
I need created a internal table with 2 internal table but 1 is primary.
I tried use "left outer join" but it allows only with table and not with internal tabel
I would to be this result
a a xxx
b
c c zzz
d d sss
e
f f ttt
How can i do it?
Thanks a lot for your support
Beste regatrdsHi,
The following code is for your reference:
data: begin of wa1,
key type c,
end of wa1.
data: begin of wa2,
key type c,
var(3) type c,
end of wa2.
data: begin of wa3,
key1 type c,
key2 type c,
var(3) type c,
end of wa3.
data: itab1 like standard table of wa1,
itab2 like standard table of wa2,
itab3 like standard table of wa3.
wa1-key = 'a'.
append wa1 to itab1.
wa1-key = 'b'.
append wa1 to itab1.
wa1-key = 'c'.
append wa1 to itab1.
wa1-key = 'd'.
append wa1 to itab1.
wa1-key = 'e'.
append wa1 to itab1.
wa1-key = 'f'.
append wa1 to itab1.
clear wa1.
wa2-key = 'a'.
wa2-var = 'zzz'.
append wa2 to itab2.
wa2-key = 'c'.
wa2-var = 'yyy'.
append wa2 to itab2.
wa2-key = 'd'.
wa2-var = 'ttt'.
append wa2 to itab2.
wa2-key = 'f'.
wa2-var = 'sss'.
append wa2 to itab2.
clear wa2.
loop at itab1 into wa1.
read table itab2 into wa2
with key key = wa1-key
binary search.
if sy-subrc = 0.
wa3-key1 = wa1-key.
wa3-key2 = wa2-key.
wa3-var = wa2-var.
append wa3 to itab3.
clear wa3.
else.
append wa1 to itab3.
endif.
endloop.
loop at itab3 into wa3.
write:/ wa3-key1, wa3-key2,wa3-var.
endloop.
Hope it helps.
Regards,
Chris Gu -
Select (join) into internal table with nested structures
Hello Experts,
i wonder about the correct notation of a select statement.
I have an internal table it_zoll including two structures as defined below.
The select is a join on the two tables zollp and zolls. As coded below the select is syntactically correct, but the fields
in the nested structures are not filled ....
Any ideas how to write the select statement ? (The internal table it_zoll must have the nested structures for other reasons ..)
Declaration:
TYPES: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
END OF ty_zollp.
TYPES: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
DATA: zollp type ty_zollp.
DATA: zolls type ty_zolls.
DATA: END OF wa_zoll.
DATA: it_zoll LIKE TABLE OF wa_zoll.
Select:
SELECT
zollp~belnr zollp~werks zollp~gebnr
zolls~grnum zolls~werks zolls~name1
FROM zollp
JOIN zolls ON zolls~werks = zollp~werks
AND zolls~grnum = zollp~grnum
INTO CORRESPONDING FIELDS OF TABLE it_zoll
WHERE zollp~werks = werks
AND zollp~gebnr IN s-gebnr
AND ...
Thank you !DATA: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
END OF ty_zollp.
DATA: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
Include structure ty_zollp.
Include structure ty_zolls.
DATA: END OF wa_zoll.
The above declaration had worked. Please try.
Regards,
Satish Kanteti -
Can we join two internal tables
Hi to all,
i want take data from one database(db) table into internal table from this we want to retrieve data from other db table and put this data into another internal table .provided that two db tables are depends on foreign key relations .You can do this a number of ways. You can use an inner join in your select statement and put the required data into an internal table or you can do two selects from the db and loop at the first itab, then loop at the second where the keys match and put the required data into a third internal table.
Here is an example of using an inner joine to get data from db tables into one internal table.
report zrich_0001.
data: begin of ima occurs 0,
matnr type mara-matnr,
mtart type mara-mtart,
werks type marc-werks,
dispo type marc-werks,
end of ima.
select-options: s_matnr for ima-matnr.
select mara~matnr mara~mtart marc~werks marc~dispo
into table ima
from mara
inner join marc
on mara~matnr = marc~matnr
where mara~matnr in s_matnr.
loop at ima.
write:/ ima-matnr, ima-mtart, ima-werks, ima-dispo.
endloop.
Regards,
Rich Heilman -
Join 2 internal tables into 1 internal table
itab 1
field 1
1
2
3
5
itab2
field 1
1
2
3
4
6
The result require is
itab3
filed 1
1
2
3
4
5
6
how to achieve this if any one can give the exact code for this it will be of great help to me.
thanks
naveenhi ,
create the new internal table with all required fields and select the data from those tables through inner-join query as example follows.
REPORT Z0292_INT_SELECT.
DATA : BEGIN OF WA,
PONO TYPE Z0292_PURITEM-PONO,
ITEM TYPE Z0292_PURITEM-ITEM,
POD TYPE Z0292_PURHEA-POD,
VENID TYPE Z0292_PURHEA-VENID,
END OF WA.
DATA : ITAB LIKE TABLE OF WA WITH HEADER LINE.
SELECT APONO AITEM BPOD BVENID
INTO TABLE ITAB
FROM Z0292_PURITEM AS A INNER JOIN Z0292_PURHEA AS B
ON APONO = BPONO.
LOOP AT ITAB.
WRITE : / ITAB-PONO,ITAB-ITEM,ITAB-POD,ITAB-VENID.
ENDLOOP.
sagun desai
Posts: 51
Questions: 9
Registered: 2/27/06
Forum points: 48
Re: how to get the data in one internal table? with 3 different tables..
Posted: Jul 31, 2007 10:34 AM in response to: rhymmeanne Reply E-mail this post
DATA : BEGIN OF IT_A005 OCCURS 0,
vkorg TYPE a005-vkorg,
vtweg TYPE a005-vtweg,
kschl TYPE a005-kschl,
matnr TYPE a005-matnr,
kunnr TYPE a005-kunnr,
datab TYPE a005-datab,
end of it_a005.
DATA : begin of IT_MVKE OCCURS 0,
matnr TYPE MVKE-matnr,
vkorg TYPE MVKE-vkorg,
vtweg TYPE MVKE-vtweg,
kondm TYPE mvke-kondm,
end of it_mvke.
DATA : begin of IT_KNVV OCCURS 0,
kunnr TYPE KNVV-kunnr,
vkorg TYPE KNVV-vkorg,
vtweg TYPE KNVV-vtweg,
kdgrp TYPE knvv-kdgrp,
konda TYPE knvv-konda,
end of it_knvv.
DATA : BEGIN OF IT_FINAL OCCURS 0,
vkorg TYPE a005-vkorg,
vtweg TYPE a005-vtweg,
kschl TYPE a005-kschl,
kondm TYPE mvke-kondm,
matnr TYPE a005-matnr,
kdgrp TYPE knvv-kdgrp,
konda TYPE knvv-konda,
kunnr TYPE a005-kunnr,
datab TYPE a005-datab,
END OF IT_FINAL.
SELECT * FROM A005 INTO TABLE IT_A005.
SELECT * FROM MVKE INTO CORRESPONDING FIELDS
OF TABLE IT_MVKE
FOR ALL ENTRIES IN IT_A005
WHERE MATNR = IT_A005-MATNR
AND VKORG = IT_A005-VKORG
AND VTWEG = IT_A005-VTWEG.
SELECT * FROM KNVV INTO CORRESPONDING FIELDS
OF TABLE IT_KNVV
FOR ALL ENTRIES IN IT_A005
WHERE KUNNR = IT_A005-KUNNR
AND VKORG = IT_A005-VKORG
AND VTWEG = IT_A005-VTWEG.
LOOP AT IT_A005.
IT_FINAL-vkorg = IT_a005-vkorg.
IT_FINAL-vtweg = IT_a005-vtweg.
IT_FINAL-kschl = IT_a005-kschl.
IT_FINAL-MATNR = IT_a005-matnr.
IT_FINAL-KUNNR = IT_a005-kunnr.
IT_FINAL-DATAB = IT_a005-datab.
READ TABLE IT_MVKE WITH KEY MATNR = IT_A005-MATNR
AND VKORG = IT_A005-VKORG
AND VTWEG = IT_A005-VTWEG.
IT_FINAL-kondm = IT_mvke-kondm.
READ TABLE IT_KNVV WITH KEY KUNNR = IT_A005-KUNNR
AND VKORG = IT_A005-VKORG
AND VTWEG = IT_A005-VTWEG.
IT_FINAL-kdgrp = IT_knvv-kdgrp.
IT_FINAL-konda = IT_knvv-konda.
APPEND IT_FINAL.
CLEAR : IT_FINAL, IT_MVKE, IT_KNVV.
ENDLOOP.
You can try with this code.
It should work.
if it ok for you then you can close this issue.
Cheers,
Sagun Desai. -
Regarding joining two internal tables
Hi All,
Tell me how to use 'UNION' in different ways.
Thank you,
RohitHi,
If its internal table joining then best is to use APPEND LINES.... statement.
You can also append internal tables to index tables using the following statement:
APPEND LINES OF itab1 TO itab2.
This statement appends the whole of ITAB1 to ITAB2. ITAB1 can be any type of table, but its line type must be convertible into the line type of ITAB2.
When you append an index table to another index table, you can specify the lines to be appended as follows:
APPEND LINES OF itab1 [FROM n1] [TO n2] TO itab2.
n1 and n2 specify the indexes of the first and last lines of ITAB1 that you want to append to ITAB2.
This method of appending lines of one table to another is about 3 to 4 times faster than appending them line by line in a loop. After the APPEND statement, the system field SY-TABIX
contains the index of the last line appended. When you append several lines to a sorted table, you must respect the unique key (if defined), and not violate the sort order. Otherwise, a runtime error will occur.
thanx. -
Hi expert,
I'm using 'Reuse_Alv_Hierseq_List_Display' and i wanted to joing the header data(vbak & kna1) and item data (vbap & vbep) seperately.So that i could assign this internal table name in the about funtion module parameters(I_OUTTAB_HEADER & I_OUTTAB_ITEM).Plz help me out!
Regards,
Arshad.Using I Joins decreses the performance.
U can use FOR ALL ENTRIES instead.
1st fetch required data from VBAK
Then fetch data from KNA! for all entries of VBAK
2ndt fetch required data from VBAP
Then fetch data from VBEP for all entries of VBAP
Reward if useful -
Possible to join multiple internal tables ?
Is it possible to join internal tables like this:
itab1:
fields are matnr f1 f2
itab2:
fields are matnr f3 f4
itab3:
fields are matnr f5 f6
required final-itab:
fields are - matnr f1 f2 f3 f4 f5 f6
(which are joined by matnr)
Thanks.Ok, then we need to take all three ITABs and get all of the MATNRs into another internal table, then loop at this internal table and read the records for ITAB1, ITAB2, and ITAB3.
data: begin of imatnr occurs 0,
matnr type mara-matnr,
end of imatnr.
loop at itab1.
imatnr-matnr = itab1-matnr.
collect imatnr.
endloop.
loop at itab2.
imatnr-matnr = itab2-matnr.
collect imatnr.
endloop.
loop at itab3.
imatnr-matnr = itab3-matnr.
collect imatnr.
endloop.
Loop at imatnr.
clear final_itab.
final_itab-matnr = imatnr-matnr.
clear itab1.
read table itab1 with key matnr = imatnr-matnr.
if sy-subrc = 0.
final_itab-f1 = itab1-f1.
final_itab-f2 = itab1-f2.
endif.
clear itab2.
read table itab2 with key matnr = imatnr-matnr.
if sy-subrc = 0.
final_itab-f3 = itab2-f3.
final_itab-f4 = itab2-f4.
endif.
clear itab3.
read table itab3 with key matnr = imatnr-matnr.
if sy-subrc = 0.
final_itab-f5 = itab3-f5.
final_itab-f6 = itab3-f6.
endif.
append final_itab.
endloop.
REgards,
Rich Heilman -
HI all,
How to access data from two internal table using join condition ?
suppose i have tow internal table itab and jtab and i want to access data by using inner join on this tow table.
please tell .
thanx..hi,
You can use PROVIDE ENDPROVIDE statements in ABAP to achive this.
Check the below documenttaion.
PROVIDE
Syntax
PROVIDE FIELDS {*|{comp1 comp2 ...}}
FROM itab1 INTO wa1 VALID flag1
BOUNDS intliml1 AND intlimu1
[WHERE log_exp1]
FIELDS {*|{comp1 comp2 ...}}
FROM itab2 INTO wa2 VALID flag2
BOUNDS intliml2 AND intlimu2
[WHERE log_exp2]
BETWEEN extliml AND extlimu
[INCLUDING GAPS].
ENDPROVIDE.
Effect
The statements PROVIDE and ENDPROVIDE define a loop through a statement block. In this loop, any number of internal tables itab1 itab2 ... are processed together. A single table can appear several times. For every table itab you must specify a FIELDS clause. After FIELDS you must specify the character * for all components or a list comp1 comp2 ... for specific components of the relevant table. The names of the components comp1 comp2 ... can only be specified directly.
To be able to process internal tables using PROVIDE, all tables itab1 itab2 ... must be fully typed index tables and contain two special columns that have the same data type (d, i, n, or t) for all relevant tables. For every table you must specify the names intliml1 intliml2 ... and intlimu1 intlimu2 ... of these columns using the addition BOUNDS.
The columns intliml1 intliml2 ... and intlimu1 intlimu2 ... in every row of the relevant internal tables must contain values that can be interpreted as limits of closed intervals. Within a table, the intervals specified in these columns must not overlap and must be sorted in ascending order. The intervals therefore make up a unique key for every row.
For every table you must specify a work area wa1 wa2 ... compatible with the row type and a variable flag1 flag2 ..., for which a character-type data type with length 1 is expected. In the PROVIDE loop, the components specified after FIELDS are filled with values in the relevant work areas wa1 wa2 ... for every specified internal table. The variables flag1 flag2 ... are also filled. A work area wa1 wa2 ... or a variable flag1 flag2 ... cannot be specified more than once.
With the BETWEEN addition you must specify an interval extliml, extlimu. It must be possible to convert the data objects extliml and extlimu into the data types of the respective columns intliml1 intliml2 ... and intlimu1 intlimu2 ... of the individual tables.
The interval limits intliml1 intliml2 ... and intlimu1 intlim2 for every row of all relevant internal tables itab1 itab2 ... that are within the closed interval made up by extliml and extlimu divide the latter into new intervals and every interval limit closes one interval in the original direction. If, within a relevant table, a lower interval limit follows an upper interval limit with no space or gap between them and the components of the corresponding rows specified after FIELDS have the same content, the two intervals are combined and the corresponding interval limits intliml1 intliml2 ... and intlimu1 intlimu2 ... are ignored for the new intervals.
For every interval that is created in such a way and overlaps with at least one of the intervals of a table involved, the PROVIDE loop is passed once. The components of every work area wa1 wa2 ... specified after FIELDS and the variables flag1 flag2 ... are filled with values as follows:
The components intliml1 intliml2 ... and intlimu1 intlimu2 ... of every work area wa1 wa2 ... are filled with the interval limits of the current interval.
If the current interval overlaps with one of the intervals of an involved table, the remaining components of the corresponding work area are assigned the contents of the relevant components of this table row and the variable flag1 flag2 ... is set to the value "X". Otherwise, the work area components and the variables flag1 flag2 ... are set to their Initial value.
Except for intliml1 intliml2 ... and intlimu1 intlimu2 ..., the components not specified after FIELDS are always set to their initial value. The components intliml1 intliml2 ... and intlimu1 intlimu2 ... are always assigned.
The ABAP runtime environment checks for every table involved, whether the condition of sorted and non-overlapping intervals is met within the interval made up by extliml and extlimu and, if necessary, triggers an exception that can be handled.
If the INCLUDING GAPS addition is specified, the system passes the PROVIDE loop for every interval, that is also when the current interval does not overlap with at least one of the intervals of an involved table. In the latter case, the variable flag is of initial value for every relevant table.
You can use the WHERE addition to specify a condition for every table itab1 itab2 ... involved. After WHERE, you can specify any logical expression log_exp1 log_exp2 ... ; the first operand of every comparison must be a component of the internal table. As such, all logical expressions except for IS ASSIGNED, IS REQUESTED, and IS SUPPLIED are possible. You can only specify components that are in the list after FIELDS. Here it is not possible to specify a component using character-type data objects in brackets. The table entries for which the condition is not met are ignored by the PROVIDE loop. You can leave the PROVIDE loop following the instructions in the section Leaving loops.
System fields
The system fields sy-subrc and sy-tabix are set to the value 0 before every loop pass and at ENDPROVIDE. Only if the loop is not passed once, is sy-subrc set to 4 at ENDPROVIDE.
Notes
The relevant internal tables should not be modified in the PROVIDE loop.
The WHERE condition can be used to remove overlaps between the tables involved or to ensure the sorting of the intervals.
In two tables itab1 and itab2, the respective columns col1 and col2 are interval limits of type i. The filling of the internal tables results in the following intervals (rows two and three):
|01|02|03|04|05|06|07|08|09|10|11|12|13|14|
| Itab1 Int1 | |Itab1 Int2 | |
| | Itab2 Int1 | |
| | ... BETWEEN ... |
| | i1 | i2 | i3 | i4 |i5| |
The interval specified in the BETWEEN addition to the PROVIDE statement is shown in the fourth row. It serves as a basis for the five intervals in the fifth row represented by i1 to i5. These can be processed in the PROVIDE loop.
Because each of the five intervals overlaps with one of the intervals from rows two and three, the PROVIDE loop is passed five times.
Only the component col3 of wa1 is filled in the first pass, only the component col3 of wa2 in the third pass, and the components col3 of both work areas in the second and fourth passes. The fields valid1 and valid2 are set accordingly.
DATA: BEGIN OF wa1,
col1 TYPE i,
col2 TYPE i,
col3 TYPE string,
END OF wa1.
DATA: BEGIN OF wa2,
col1 TYPE i,
col2 TYPE i,
col3 TYPE string,
END OF wa2.
DATA: itab1 LIKE STANDARD TABLE OF wa1,
itab2 LIKE STANDARD TABLE OF wa2.
DATA: flag1(1) TYPE c,
flag2(1) TYPE c.
wa1-col1 = 1.
wa1-col2 = 6.
wa1-col3 = 'Itab1 Int1'.
APPEND wa1 TO itab1.
wa1-col1 = 9.
wa1-col2 = 12.
wa1-col3 = 'Itab1 Int2'.
APPEND wa1 TO itab1.
wa2-col1 = 4.
wa2-col2 = 11.
wa2-col3 = 'Itab2 Int1'.
PROVIDE FIELDS col3 FROM itab1 INTO wa1
VALID flag1
BOUNDS col1 AND col2
FIELDS col3 FROM itab2 INTO wa2
VALID flag2
BOUNDS col1 AND col2
BETWEEN 2 AND 14.
WRITE: / wa1-col1, wa1-col2, wa1-col3, flag1.
WRITE: / wa2-col1, wa2-col2, wa2-col3, flag2.
SKIP.
ENDPROVIDE.
The list output is as follows:
2 3 Itab1 Int1 X
2 3
4 6 Itab1 Int1 X
4 6 Itab2 Int1 X
7 8
7 8 Itab2 Int1 X
9 11 Itab1 Int2 X
9 11 Itab2 Int1 X
12 12 Itab1 Int2 X
12 12
Exceptions
Catchable Exceptions
CX_SY_PROVIDE_INTERVAL_OVERLAP
Cause: In one of the involved tables there are overlapping intervals within extlim1 and extlim2.
Runtime Error: UNCAUGHT_EXCEPTION
CX_SY_PROVIDE_TABLE_NOT_SORTED
Cause: One of the involved tables is not sorted in ascending order by the intervals within extlim1 and extlim2.
Runtime Error: UNCAUGHT_EXCEPTION
Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 28, 2008 1:36 PM -
Join of internal tables for output
Hi,
Thanks for your good answers (I have granted you your points). However, I have a problem with the READ command regarding the key fields. There is only one field in common between the two itabs and that is KNUMA. The compiler keeps telling me that I still need the other fields as seen below. Why ?
START-OF-SELECTION.
SELECT knuma bukrs vkbur
FROM kona
INTO TABLE t_condtab
WHERE knuma IN so_knuma
AND datbi > sy-cdate.
SELECT knuma kschl vkorg kunnr zzprodh4 knumh
FROM kote502
INTO TABLE t_kotetab
FOR ALL ENTRIES IN t_condtab
WHERE knuma = t_condtab-knuma.
LOOP AT t_condtab.
READ TABLE t_kotetab WITH TABLE KEY knuma = t_condtab-knuma
kschl = t_condtab-kschl
vkorg = t_condtab-vkorg
kunnr = t_condtab-kunnr
zzprodh4 = t_condtab-zzprodh4
knumh = t_condtab-knumh.
WRITE t_kotetab-vkorg TO t_condtab-vkorg.
WRITE t_kotetab-kunnr TO t_condtab-kunnr.
WRITE t_kotetab-zzprodh4 TO t_condtab-zzprodh4.
WRITE t_kotetab-knumh TO t_condtab-knumh.
MODIFY t_condtab.
ENDLOOP.Remove TABLE in Read statement.
SORT t_condtab BY knuma.
SORT t_kotetab BY knuma.
LOOP AT t_condtab.
READ TABLE t_kotetab WITH KEY knuma = t_condtab-knuma Binary search.
kschl = t_condtab-kschl
vkorg = t_condtab-vkorg
kunnr = t_condtab-kunnr
zzprodh4 = t_condtab-zzprodh4
knumh = t_condtab-knumh.
WRITE t_kotetab-vkorg TO t_condtab-vkorg.
WRITE t_kotetab-kunnr TO t_condtab-kunnr.
WRITE t_kotetab-zzprodh4 TO t_condtab-zzprodh4.
WRITE t_kotetab-knumh TO t_condtab-knumh.
MODIFY t_condtab.
ENDLOOP.
Maybe you are looking for
-
Hi All, I've read the other threads on this but not found one exactly like it. We are running Exchange 2010 SP3 Update 1. We recently sent out an internal email to a distribution that had a couple of dynamic DL's in it and a few regular DL's. A lot
-
Why does cs5 stop working when printing
At my wits end...CS6 continually Stops working when I attempt to print to a Ricoh printer...all ok before upgrade from XP...drivers appear ok and have been reloaded.
-
IDES ECC 5.0, BW, FI, HR
Hi, I am new to SAP world and looking for IDES ECC 5 so I can learn SAP better. Please share your IDES ECC 5 with installation documentation. I am willing to pay a price via paypal. Please email me at [email protected] Please help. Thank you so much.
-
XML Escaping in ABAP via CL_IXML Library?
Hello Partners: I was going through some work of XML integration of SAP with a third-party. But came across an issue: The text descriptions we are sending within an XML tag has certain special characters like '&'. But the XML parser is <i>not escapin
-
Problem using a decision making operation (if - than, if not - then)
I have a signal comming in. based on this signal the program has to make a desicion. I was trying this with the true-fase feature, but something wrong. Could you help me with this.