Performance syntax loop at and read table
in the routine , for reading one line in a internal table , the syntaxe
loop at xxx where and read tabl exxx with key XXXX
has a great difference on performance or not?
Loop at statement is used only for processing multiple records.Read table is used for reading a particluar record of an internal table.If you just need to check whether record exists in internal table, use can sort and use binary search with TRANSPORTING NO FIELDS addition. Also, try to use field symbols so that performance is increased.
Similar Messages
-
Sy-tabix in relation to LOOP AT and READ TABLE
Hi All,
As per SAP documentation,
1) While looping through an internal table (LOOP AT), sy-tabix contains the index number of current row(for standard and sorted tables)
2)When successfully reading from an internal table(READ TABLE), sy-tabix is set to the index of the result row.
But what happens when READ TABLE is used while looping through another internal table?
i.e. Loop at TAB1...
write sy-tabix.
READ TABLE TAB2...
write sy-tabix.
endloop.
If we are looping through 1st row of TAB1 and the result of read statement is found in 3rd row of TAB2, I expected that sy-tabix before READ would be 1 and after the READ be 3.
But, I found that sy-tabix remains unchanged at 1. Can someone expalin why?
Thanks,
JaganHi
If after reading the table TAB2 the system variable SY-TABIX has still the previous value, that menas the READ TABLE fails or it was read the first record of TAB2.
After READ TABLE TAB2 try to check the SY-SUBRC:
LOOP AT TAB1.
WRITE: / 'TAB1 index:', SY-TABIX.
READ TABLE TAB2 .........
IF SY-SUBRC = 0.
WRITE: 'TAB2 index:', SY-TABIX.
Try this:
DATA: BEGIN OF ITAB OCCURS 0,
FIELD1,
END OF ITAB.
DATA: BEGIN OF ITAB2 OCCURS 0,
FIELD1,
END OF ITAB2.
DATA: INDEX TYPE I.
DO 10 TIMES.
APPEND ITAB.
ENDDO.
DO 10 TIMES.
APPEND ITAB2.
ENDDO.
LOOP AT ITAB.
WRITE: / 'ITAB:', SY-TABIX.
INDEX = SY-TABIX + 2.
READ TABLE ITAB2 INDEX INDEX.
IF SY-SUBRC = 0.
WRITE: 'ITAB2:', SY-TABIX.
ENDIF.
ENDLOOP.
Max -
Field symbols and READ TABLE with system code 4
Hi,
I have a hashed table and I am using field symbols to point to it to retrieve the field content. I then use it in the READ TABLE statement in the following way:
Loop at x_data assign <fs>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c1>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c2>.
READ TABLE ZZZZ assign <fs> with table key a1 = <c1>
a2 = <c2>.
If sy-subrc = 0.
endif.
I ran the debugger and I keep getting a 4. I am not able to get the value from a1 and a2 to see what it is and why it is causing a 4 sy-subrc. I know the value from the hashed table and the values c1 and c2 are the same, so the sy-subrc should be 0.
How would I read a hashed table using field symbols? I know that usig a standard table, I have to sort the table on the key fields() before I actually can do the READ TABLE using the binary search.
Please advise. Thanks
RTHai Rob
Go through the following Code
Field-Symbols are place holders for existing fields.
A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.
Field-Symbols are like Pointers in Programming language C .
Syntax check is not effective.
Syntax :
Data : v1(4) value abcd.
Field-symbols <fs>.
Assign v1 to <fs>.
Write:/ <fs>.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.
The output is:
1 1
2 100
4 16
Thanks & regards
Sreenivasulu P -
RFC and read table in another destination
HI
I search a complete code to read a table using the function 'RFC_GET_TABLE_ENTRIES '
I can acess to another server using RFC without problem.
I need to read table 'tmsbuftxt ' and data ' TRKORR '.
my program looks like
TABLES:
tmsbuftxt.
DATA:
i_tab512 TYPE tab512 OCCURS 0 WITH HEADER LINE,
i_tmsbuftxt TYPE table of tmsbuftxt,
st_tmsbuftxt type tmsbuftxt.
PARAMETERS p_dest LIKE rfcdes-rfcdest OBLIGATORY.
START-OF-SELECTION.
CLEAR i_tab512. REFRESH i_tab512.
CALL FUNCTION 'RFC_GET_TABLE_ENTRIES'
DESTINATION
p_dest
EXPORTING
" BYPASS_BUFFER = ' '
" FROM_KEY = ' '
" GEN_KEY = ' '
" MAX_ENTRIES = 0
table_name = 'tmsbuftxt'
" TO_KEY = ' '
" IMPORTING
"* NUMBER_OF_ENTRIES =
TABLES
entries = i_tab512
EXCEPTIONS
OTHERS = 1.
i_tmsbuftxt[] = i_tab512[].
LOOP AT i_tmsbuftxt INTO st_tmsbuftxt.
Write : st_tmsbuftxt-TRKORR.
ENDLOOP.
The problem is I dont know how to use the function correctly , I can choose the RFC I want but my programm return nothing.
Anyone can corect this?
I just start develop abap since 1 month.
I just want write st_tmsbuftxt-TRKORR. who is in another environnement using RFC.Hello Guillaume,
welcome in this forum.
I try RFC_GET_TABLE_ENTRIES, but I think it is better to use RFC_READ_TABLE. Try this to get the numbers of the transports from another system:
"-Begin-----------------------------------------------------------------
Program Z_TEST.
Data Fields Type Standard Table Of RFC_DB_FLD.
Data Field Type RFC_DB_FLD.
Data Data Type Standard Table Of TAB512.
Data Line Type TAB512.
Field-FIELDNAME = 'TRKORR'.
Append Field To Fields.
Call Function 'RFC_READ_TABLE' Destination 'NONE'
Exporting
QUERY_TABLE = 'TMSBUFTXT'
Tables
FIELDS = Fields
DATA = Data
Exceptions
TABLE_NOT_AVAILABLE = 1
TABLE_WITHOUT_DATA = 2
OPTION_NOT_VALID = 3
FIELD_NOT_VALID = 4
NOT_AUTHORIZED = 5
DATA_BUFFER_EXCEEDED = 6
Others = 7.
If sy-subrc <> 0.
Else.
Loop At Data Into Line.
Write: / Line.
EndLoop.
EndIf.
"-End-------------------------------------------------------------------
Let us know your results.
Cheers
Stefan -
I need to loop through 1 table and read another until a value changes
i need to read a table and sum the quantity field until a reason code changes. how do I go about doing this?
sort itab by reasoncode.
Loop at itab.
quantiy = quanity + itab-quantity.
at end of reasoncode.
jtab-reasoncode = itab-reasoncodee.
jtab-sum = quantity.
append jtab.
clear quantity.
endat
endloop.
or
sort itab by reasoncode.
loop at itab.
at end of reasoncode.
sum.
jtab = itab.
append jtab.
endat.
endloop.
or
let us say itab and jtab are two tables and you want to loop through itab and read jtab for reasoncodes.
if jtab has only one entry for each entry in itab then use read else use loop.
loop at itab.
loop at jtab where reasoncode = itab-reasoncode.
quantiy = quantiy + jtab-quanity.
endloop.
endloop.
or
loop at itab.
read table jtab with key reasoncode = itab-reasoncode.
if sy-subrc eq 0.
endif
endloop. -
Dear All,
Please let me know which one of the two should I use to improve the performance, for tables containing a lot of data ?
Regards,
Thanks in anticipation.
Alok.Hi,
Follow below steps.
In se30 transaction you can look for
Tip&TRicks button on application toolbar
apart from below conventions
Follow below steps
1) Remove corresponding from select satement
2) Remove * from select
3) Select field in sequence as defined in database
4) Avoid unnecessary selects
i.e check for internal table not initial
5) Use all entries and sort table by key fields
6) Remove selects ferom loop and use binary search
7) Try to use secondary index when you don't have
full key.
8) Modify internal table use transporting option
9) Avoid nested loop . Use read table and loop at itab
from sy-tabix statement.
10) free intrenal table memory wnen table is not
required for further processing.
11)
Follow below logic.
FORM SUB_SELECTION_AUFKTAB.
if not it_plant[] is initial.
it_plant1[] = it_plant[].
sort it_plant1 by werks.
delete adjacent duplicates from it_plant1 comparing werks
SELECT AUFNR KTEXT USER4 OBJNR INTO CORRESPONDING FIELDS OF TABLE I_AUFKTAB
FROM AUFK
FOR ALL ENTRIES IN it_plant1
WHERE AUFNR IN S_AUFNR AND
KTEXT IN S_KTEXT AND
WERKS IN S_WERKS AND
AUART IN S_AUART AND
USER4 IN S_USER4 AND
werks eq it_plant1-werks.
free it_plant1.
Endif.
ENDFORM. "SUB_SELECTION_AUFKTAB
Regards
Amole -
What is the difference between READ TABLE ITAB WITH KEY and TABLE KEY
Hi Experts,
what is the difference between
READ TABLE <ITAB> WITH KEY <K1> = <C1>
<Kn> = <Cn> .
and
READ TABLE <ITAB> WITH TABLE KEY <K1> = <C1>
<Kn> = <Cn> .
Thanks
Akash.Hi akashdeep,
Nice question. I also tried to find out, but no much success. My opinion is that for practical purposes there is no difference.
It may have difference in case of searching, especially sorted tables. (binary search or normal linear search).
Case1: If our table is sorted table with defined key fields, and we give WITH TABLE KEY, then faster binary search is used.
Case2 : If our table is sorted table with defined key fields, and we give WITH KEY, (and no field contained in the keys), then normal linear search is used.
regards,
amit m. -
Hello experts read table statement is not working properly
Hello Experts.
my code is like this.
sort it_matnr by matnr.
loop at itab_result.
read table it_matnr with key matnr = itab_result-matnr binary search.
endloop.
there are nearly 2000 records in it_matnr . The records which satisfy the above condition is there here in this internal table. But it is unable to read the record which matches the condition. One thing is that , there are more than one record with the same material. ie mblnr is different but material is the same. In it_matnr table i have only 1 field ie matnr ,so i need to compare only with the matnr.I also tried by sorting it_result by matnr but of no use. Then finally I used loop at where matnr = it_result-matnr , it is working fine. But due to performance reasons we should not use this. so please tell me what to do and correct the code.1. Make sure that the table IT_MATNR is not getting updated inside the loop. Because it will then destroy the sorting.
2. Secondly, if there are multiple records in IT_MATNR for the same material then it will search for the first record encountered in binary algo. So it is advisable that you may provide further filter criteria if possible. check if ITAB_RESULT & IT_MATNR have any other matching field that can be put in filter criteria.
3.Thirdly, check if your requirement can be achieved by STABLE SORT.
<b>SORT <itab> ... STABLE BY <f1>[ASCENDING/DESCENDING].</b>
It will allows you to perform a stable sort, that is, the relative sequence of lines that are unchanged by the sort is not changed. If you do not use the STABLE option, the sort sequence is not preserved. If you sort a table several times by the same key, the sequence of the table entries will change in each sort. However, a stable sort takes longer than an unstable sort.
4. Lastly, you can use parallel cursor technique of multiple loops which is given below:
LOOP AT itab_result.
READ TABLE it_matnr
WITH KEY matnr = itab_result-matnr
BINARY SEARCH.
Process record
LOOP AT it_matnr FROM sy-tabix.
IF it_matnr <> itab_result-matnr.
EXIT.
ENDIF.
Process record based on yuor condition
ENDLOOP.
ENDLOOP. -
Performace Which is better ? : Bapi inside a loop OR Select from Tables
Hi Gurus,
I have a report which displays purchase info records.
If I am selecting from tables i need to use EINA, EINE, EORD and some other tables.
There is a BAPI which gets all purchase info records specific to a vendor , material , purchasing organisation.
QUESTION: Performace wise which is the better Approach, either selecting from tables or BAPI for Purchase info records
Regards
Avi.Whether it using BAPI or select. you need to check the performance. If you have full key for these tables EINA, EINE, EORD then mak a select outside of the loop and within loop use READ TABLE statement with binary search. of if you want multiple records within loop then use loop insdie loop.
Your final objective is to minimise the database hits . If you use bapi inside loop then your database hits will be more
select from EINA
select from EINE
select from EORD
loop at itab,
read table EINA
read table EINE
read table EORD
endloop
a® -
Can I use read table instead of multiple select & loop statements.
Any one please give me the sample code ..how to do it.
Thanks in advanceHi,
Yes you can use read instead of nested loops and select which will affect the performance.
REPORT zkeerthi_ITABLE9 .
tables:vbap,vbak,vbkd.
data:begin of it_vbap occurs 0,
vbeln like vbap-vbeln,
matnr like vbap-matnr,
end of it_vbap.
data:begin of it_vbak occurs 0,
erdat like vbak-erdat,
ernam like vbak-ernam,
vbeln like vbak-vbeln,
end of it_vbak.
data:begin of it_vbkd occurs 0,
konda like vbkd-konda,
kdgrp like vbkd-kdgrp,
vbeln like vbkd-vbeln,
end of it_vbkd.
data:begin of it_final occurs 0,
vbeln like vbap-vbeln,
matnr like vbap-matnr,
erdat like vbak-erdat,
ernam like vbak-ernam,
konda like vbkd-konda,
kdgrp like vbkd-kdgrp,
end of it_final.
parameters:v_matnr type vbap-matnr.
select vbeln
matnr
from vbap
into table it_vbap
where matnr = v_matnr.
select erdat
ernam
vbeln
from vbak
into table it_vbak
for all entries in it_vbap
where vbeln = it_vbap-vbeln.
select konda
kdgrp
vbeln
from vbkd
into table it_vbkd
for all entries in it_vbap
where vbeln = it_vbap-vbeln.
loop at it_vbap.
read table it_vbak with key vbeln = it_vbap-vbeln.
move :it_vbak-erdat to it_final-erdat,
it_vbak-ernam to it_final-ernam,
it_vbap-vbeln to it_final-vbeln,
it_vbap-matnr to it_final-matnr.
append it_final.
read table it_vbkd with key vbeln = it_vbap-vbeln.
move:it_vbkd-konda to it_final-konda,
it_vbkd-kdgrp to it_final-kdgrp.
append it_final.
endloop .
sort it_final by matnr.
loop at it_final.
write:/ it_final-vbeln,
it_final-matnr,
it_final-erdat,
it_final-ernam,
it_final-konda,
it_final-kdgrp.
endloop. -
FBL5N t code and BSEG table is showing wrong contract number
Hi,
The proces flow is contract number>sales order>DMR-->Invoice
Now when I am checking the VBFA table it's showing correct contract number against invoices but FBL5N t code and BSEG table are showing wrong contract numbers.
Why FBL5N and BSEG table is showing wrong contract number?
Currently we are using one enhancement and user exit is used to incorporate one customized field as identifier for bill type.
1. During the billing document release to accounting VFX3, The user exit triggering and it is update the customized fields and Net settlement indicator.
2. Using the Invoice number, get the fields VGBEL(Document number of the reference document) and VGPOS (Item number of the reference item) from VBRP and read table VBAP with VBELN and POSNR, to get DMR number (Sales Document) that created for the Invoice.
3. Use fields VGBEL and VGPOS on table VBAP to get the sale order number.
4. By using the Sales order number, get the Distribution channel to update Net indicator field
In accounting table BSEG-UZAWE = JF must be updated on the customer line.
5. Retrieve the sale order number and item level to get customized field from table VBAP
Any pointers.
Thanks
AshuHi Reazuddin,
Thanks for your reply,
I am concercerned about BSEG table and using user exit EXIT_SAPLV60B_008 to post the document in FI.
Now in we have enhanced this user exit for contracts and included in this way.
SELECT SINGLE ZZ_CONTRACT FROM VBAK INTO (LC_CONTRACT) WHERE VBELN EQ cvbrp-vgbel.
Endloop.
*Moving the values to final accounting table
loop at xaccit.
xaccit-vertn = lc_contract.
xaccit-VBEL2 = xaccit-AUBEL.
xaccit-xref3 = lc_vbel2.
MODIFY xaccit .
ENDLOOP.
Clear: lc_contract,lc_vgbel,lc_vgpos,lc_vbel2.
But I am getting correct data when checked other clients( development and quality), this problem I am getting in production.
Do I need to ask the ABAP'er to debug this enhancement in production?
Thanks
Ashutosh -
i have to fetch belnr from bkpf table, and tax amount(fwste) from bset table.
if for a particular belnr suppose if this belnr 1700000000 has 5 line items in bset table than i need tax amount for all those 5 line items it means i need addition of that tax amount in output
for eg in bset table
belnr fwste lifnr curr
17000000000 0.00 0002300000 usd
2.00
0.00
4.00
in ouput i should get only subtotal has
1700000000 6.00 00023000000 usd
please help how to do its urgent
below is the code
SELECT bukrs
belnr
gjahr
xblnr
waers
budat
usnam
tcode
awkey
FROM bkpf
INTO TABLE gt_bkpf
WHERE bukrs IN s_bukrs
AND gjahr IN s_gjahr
AND tcode EQ 'MIRO'.
SELECT bukrs
belnr
gjahr
buzei
koart
lifnr
zlspr
FROM bseg
INTO TABLE gt_bseg
FOR ALL ENTRIES IN gt_bkpf
WHERE bukrs EQ gt_bkpf-bukrs
AND belnr EQ gt_bkpf-belnr
AND gjahr EQ gt_bkpf-gjahr
AND lifnr IN s_lifnr
AND zlspr IN s_zlspr
and koart eq 'K'.
AND bschl EQ '31'.
gt_bseg1[] = gt_bseg[].
SORT gt_bseg1[] BY lifnr.
DELETE ADJACENT DUPLICATES FROM gt_bseg1[] COMPARING lifnr.
IF gt_bseg1[] IS NOT INITIAL.
SELECT lifnr
name1
FROM lfa1
INTO TABLE gt_lfa1
FOR ALL ENTRIES IN gt_bseg1
WHERE lifnr EQ gt_bseg1-lifnr.
and lifnr eq s_lifnr.
ENDIF.
IF gt_bkpf[] IS NOT INITIAL.
SELECT belnr
gjahr
tcode
WAERS
zuonr
FROM rbkp
INTO TABLE gt_rbkp
FOR ALL ENTRIES IN gt_bkpf
WHERE gjahr EQ gt_bkpf-gjahr
AND tcode EQ gt_bkpf-tcode
AND belnr EQ gt_bkpf-awkey+0(10).
tax amount
SELECT bukrs
belnr
gjahr
buzei
fwste
FROM bset
INTO TABLE gt_bset
FOR ALL ENTRIES IN gt_bkpf
WHERE bukrs EQ gt_bkpf-bukrs
AND belnr EQ gt_bkpf-belnr
AND gjahr EQ gt_bkpf-gjahr.
and fwste ne 0 .
ENDIF.
IF gt_rbkp[] IS NOT INITIAL.
SELECT belnr
gjahr
buzei
cobl_nr
wrbtr
menge
mwskz
meins
FROM rbco
INTO TABLE gt_rbco
FOR ALL ENTRIES IN gt_rbkp
WHERE belnr EQ gt_rbkp-belnr.
ENDIF.
SELECT ebeln
ernam
FROM ekko
INTO TABLE gt_ekko
FOR ALL ENTRIES IN gt_rbkp
WHERE ebeln EQ gt_rbkp-zuonr+0(10).
IF gt_ekko[] IS NOT INITIAL.
SELECT banfn
bnfpo
ernam
ebeln
FROM eban
INTO TABLE gt_eban
FOR ALL ENTRIES IN gt_ekko
WHERE ebeln EQ gt_ekko-ebeln.
ENDIF.
ENDFORM. " RETRIEVE_DATA
*& Form MODIFY_DATA
text
--> p1 text
<-- p2 text
FORM modify_data .
*Sorting all Internal Tables .
SORT gt_bseg BY bukrs belnr gjahr.
SORT gt_bkpf BY bukrs belnr gjahr.
SORT gt_lfa1 BY lifnr.
SORT gt_rbkp BY belnr.
SORT gt_rbco BY belnr.
SORT gt_ekko BY ebeln.
SORT gt_bset BY belnr.
SORT gt_bset
SORT gt_eban BY ebeln.
SORT gt_bkpf .
SORT gt_bseg .
SORT gt_lfa1 .
SORT gt_rbkp .
SORT gt_rbco .
SORT gt_ekko .
SORT gt_bset.
SORT gt_eban .
LOOP AT GT_BSEG WHERE BELNR NE ' '.
MOVE gt_bseg-pswsl TO gt_final-pswsl.
MOVE gt_bseg-lifnr TO gt_final-lifnr.
MOVE gt_bseg-zlspr TO gt_final-zlspr.
READ TABLE GT_BKPF WITH KEY BELNR = GT_BSEG-BELNR BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE gt_bkpf-bukrs TO gt_final-bukrs.
MOVE gt_bkpf-belnr TO gt_final-belnr.
MOVE gt_bkpf-xblnr TO gt_final-xblnr.
MOVE gt_bkpf-budat TO gt_final-budat.
MOVE gt_bkpf-usnam TO gt_final-usnam.
ENDIF.
READ TABLE gt_lfa1 WITH KEY lifnr = gt_bseg-lifnr BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_lfa1-name1 TO gt_final-name1.
ENDIF.
READ TABLE gt_rbkp WITH KEY belnr = gt_bkpf-awkey+0(10)
gjahr = gt_bkpf-gjahr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_rbkp-belnr TO gt_final-rbelnr.
MOVE gt_rbkp-waers TO gt_final-waers.
MOVE gt_rbkp-zuonr TO gt_final-zuonr.
endif.
READ TABLE gt_rbco WITH KEY belnr = gt_rbkp-belnr BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_rbco-buzei TO gt_final-buzei.
MOVE gt_rbco-wrbtr TO gt_final-wrbtr.
MOVE gt_rbco-menge TO gt_final-menge.
MOVE gt_rbco-meins TO gt_final-meins.
MOVE gt_rbco-mwskz TO gt_final-mwskz.
endif.
READ TABLE gt_ekko WITH KEY ebeln = gt_rbkp-zuonr+0(10) BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_ekko-ernam TO gt_final-ernam.
endif.
READ TABLE gt_eban WITH KEY ebeln = gt_ekko-ebeln BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_eban-ernam TO gt_final-ernam.
ENDIF.
READ TABLE GT_BSET WITH KEY BELNR = GT_BKPF-BELNR BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE GT_BSET-FWSTE TO GT_FINAL-FWSTE.
ENDIF.
APPEND gt_final.
endloop.
please help where to add code and how to write
thanks in advancedeclare itab with fields belnr and fwste.... and write code as below...!!!
SELECT bukrs
belnr
gjahr
xblnr
waers
budat
usnam
tcode
awkey
FROM bkpf
INTO TABLE gt_bkpf
WHERE bukrs IN s_bukrs
AND gjahr IN s_gjahr
AND tcode EQ 'MIRO'.
SELECT bukrs
belnr
gjahr
buzei
koart
lifnr
zlspr
FROM bseg
INTO TABLE gt_bseg
FOR ALL ENTRIES IN gt_bkpf
WHERE bukrs EQ gt_bkpf-bukrs
AND belnr EQ gt_bkpf-belnr
AND gjahr EQ gt_bkpf-gjahr
AND lifnr IN s_lifnr
AND zlspr IN s_zlspr
and koart eq 'K'.
AND bschl EQ '31'.
gt_bseg1[] = gt_bseg[].
SORT gt_bseg1[] BY lifnr.
DELETE ADJACENT DUPLICATES FROM gt_bseg1[] COMPARING lifnr.
IF gt_bseg1[] IS NOT INITIAL.
SELECT lifnr
name1
FROM lfa1
INTO TABLE gt_lfa1
FOR ALL ENTRIES IN gt_bseg1
WHERE lifnr EQ gt_bseg1-lifnr.
and lifnr eq s_lifnr.
ENDIF.
IF gt_bkpf[] IS NOT INITIAL.
SELECT belnr
gjahr
tcode
WAERS
zuonr
FROM rbkp
INTO TABLE gt_rbkp
FOR ALL ENTRIES IN gt_bkpf
WHERE gjahr EQ gt_bkpf-gjahr
AND tcode EQ gt_bkpf-tcode
AND belnr EQ gt_bkpf-awkey+0(10).
tax amount
SELECT bukrs
belnr
gjahr
buzei
fwste
FROM bset
INTO TABLE gt_bset
FOR ALL ENTRIES IN gt_bkpf
WHERE bukrs EQ gt_bkpf-bukrs
AND belnr EQ gt_bkpf-belnr
AND gjahr EQ gt_bkpf-gjahr.
and fwste ne 0 .
ENDIF.
IF gt_rbkp[] IS NOT INITIAL.
SELECT belnr
gjahr
buzei
cobl_nr
wrbtr
menge
mwskz
meins
FROM rbco
INTO TABLE gt_rbco
FOR ALL ENTRIES IN gt_rbkp
WHERE belnr EQ gt_rbkp-belnr.
ENDIF.
SELECT ebeln
ernam
FROM ekko
INTO TABLE gt_ekko
FOR ALL ENTRIES IN gt_rbkp
WHERE ebeln EQ gt_rbkp-zuonr+0(10).
IF gt_ekko[] IS NOT INITIAL.
SELECT banfn
bnfpo
ernam
ebeln
FROM eban
INTO TABLE gt_eban
FOR ALL ENTRIES IN gt_ekko
WHERE ebeln EQ gt_ekko-ebeln.
ENDIF.
ENDFORM. " RETRIEVE_DATA
*& Form MODIFY_DATA
text
--> p1 text
<-- p2 text
FORM modify_data .
*Sorting all Internal Tables .
SORT gt_bseg BY bukrs belnr gjahr.
SORT gt_bkpf BY bukrs belnr gjahr.
SORT gt_lfa1 BY lifnr.
SORT gt_rbkp BY belnr.
SORT gt_rbco BY belnr.
SORT gt_ekko BY ebeln.
SORT gt_bset BY belnr.
SORT gt_bset
SORT gt_eban BY ebeln.
SORT gt_bkpf .
SORT gt_bseg .
SORT gt_lfa1 .
SORT gt_rbkp .
SORT gt_rbco .
SORT gt_ekko .
SORT gt_bset.
SORT gt_eban .
<b>sort gt_bset by belnr.
loop at gt_bset.
at end of belnr.
itab-belnr = gt_bset-belnr.
sum.
itab-fwste = gt_bset-fwste.
append itab.
clear itab.
endat.
endloop.
delete adjacent duplicates from gt_bset comparing belnr.
loop at gt_bset.
read table itab with key belnr = gt_bset-belnr.
if sy-subrc = 0.
gt_bset-fwste = itab-fwste.
modify gt_bset index sy-tabix.
endif.
endloop.</b>
LOOP AT GT_BSEG WHERE BELNR NE ' '.
MOVE gt_bseg-pswsl TO gt_final-pswsl.
MOVE gt_bseg-lifnr TO gt_final-lifnr.
MOVE gt_bseg-zlspr TO gt_final-zlspr.
READ TABLE GT_BKPF WITH KEY BELNR = GT_BSEG-BELNR BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE gt_bkpf-bukrs TO gt_final-bukrs.
MOVE gt_bkpf-belnr TO gt_final-belnr.
MOVE gt_bkpf-xblnr TO gt_final-xblnr.
MOVE gt_bkpf-budat TO gt_final-budat.
MOVE gt_bkpf-usnam TO gt_final-usnam.
ENDIF.
READ TABLE gt_lfa1 WITH KEY lifnr = gt_bseg-lifnr BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_lfa1-name1 TO gt_final-name1.
ENDIF.
READ TABLE gt_rbkp WITH KEY belnr = gt_bkpf-awkey+0(10)
gjahr = gt_bkpf-gjahr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_rbkp-belnr TO gt_final-rbelnr.
MOVE gt_rbkp-waers TO gt_final-waers.
MOVE gt_rbkp-zuonr TO gt_final-zuonr.
endif.
READ TABLE gt_rbco WITH KEY belnr = gt_rbkp-belnr BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_rbco-buzei TO gt_final-buzei.
MOVE gt_rbco-wrbtr TO gt_final-wrbtr.
MOVE gt_rbco-menge TO gt_final-menge.
MOVE gt_rbco-meins TO gt_final-meins.
MOVE gt_rbco-mwskz TO gt_final-mwskz.
endif.
READ TABLE gt_ekko WITH KEY ebeln = gt_rbkp-zuonr+0(10) BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_ekko-ernam TO gt_final-ernam.
endif.
READ TABLE gt_eban WITH KEY ebeln = gt_ekko-ebeln BINARY SEARCH.
IF sy-subrc = 0.
MOVE gt_eban-ernam TO gt_final-ernam.
ENDIF.
READ TABLE GT_BSET WITH KEY BELNR = GT_BKPF-BELNR BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE GT_BSET-FWSTE TO GT_FINAL-FWSTE.
ENDIF.
APPEND gt_final.
endloop. -
Deep Structure - Append and Reading
Hi.....
1) I need Deep Structure Syntax for Appending and Reading..
2) I want append data following Deep Structure...
DATA : BEGIN OF itab1 OCCURS 0,
v1 TYPE i,
v2 TYPE i,
END OF itab1.
TYPES : BEGIN OF stru1,
v1 TYPE i,
v2 TYPE i,
END OF stru1.
DATA itab2 TYPE SORTED TABLE OF stru1 WITH HEADER LINE WITH UNIQUE KEY v1.
DATA : BEGIN OF stru2,
v1 TYPE i,
v2 LIKE TABLE OF itab2,
END OF stru2.
DATA itab3 LIKE STANDARD TABLE OF stru2 WITH HEADER LINE.
DATA : BEGIN OF main,
v1 TYPE i,
v2 TYPE stru1,
v3 LIKE TABLE OF itab1,
v4 LIKE STANDARD TABLE OF itab2, "------> *Here CAN WE SPECIFIES AS SORTED TABLE ..IS IT POSSIBLE?
v4 LIKE SORTED TABLE OF itab2*
v5 LIKE STANDARD TABLE OF itab3,
END OF main.
"main-v1 = 11.
"main-v2-v2 = 21.
thanx....
Edited by: B C Ganesh on Mar 16, 2010 9:44 AMHi,
you do READ, APPEND (and other operations on internat table) in the same way on simple internal table like and on internal table which is part of some (deep) structure. You only have to respect names, so instead of
APPEND itab.
you have to do:
APPEND stru1-stru2-stru3-itab.
Regards,
Przemysław -
.<b>
Hello every body ,
In my report ,Before populating the fieldcatalog i am first fetching the details of g/l account into my internal table .There are two line items with same posting date .Now wen i use read table to populate my final table looping through the internal table i am getting only one LIne item record .But wen i give my specific line item number in the sel-screen i am getting all the details.if i don't give it tat is to fetch all the data ,then i am able to get only one line item details that is coming first in the order but the second one is not getting displayed.</b>
Wat could be the reason .
is it bcoz of only using the read statement?My friend :
before looping for read table concept
you have to sort the both tables and the internal table fields should in the same order what ever fields are common in the bot internal table ,.
then the line item table should be the loop and the header table should be the read table .
" example .
sort bseg by burks belnr .
sort bkpf by burks belnr .
loop at bseg .
read table bkpf with key bukrs = bseg-bukrs belnr = bseg-belnr .
you query for modify /inserting into new internal table .....etc
endloop .
but what you are doing is BKPF is looped and BSEG is used in the read concept so it will take only one line item ..and the remainining line item will be skiped .
and remember to sort also ..
reward points if it is usefulll.....
Girish -
Read Table : Error Stating mandt field is not filled.
Dear members,
I am get syntax error when using Read table statement saying mandt field is not filled, however if I remove the KEY field. it is working fine.
please let me know, where I am doing mistake. thank you.
Data : spfli_tab like STANDARD TABLE OF spfli with HEADER LINE.
SELECT *
FROM spfli
INTO TABLE spfli_tab
WHERE carrid = 'LH'.
READ TABLE spfli_tab
WITH TABLE KEY carrid = 'LH'
connid = '2402'.
IF sy-subrc = 0.
ENDIF.Hi...
As Eric Said there are two ways...
For your case use WITH KEY...
SELECT *
FROM spfli
INTO TABLE spfli_tab
WHERE carrid = 'LH'.
READ TABLE spfli_tab
WITH KEY carrid = 'LH'
connid = '2402'.
IF sy-subrc = 0.
WRITE : 'DONE'.
ENDIF.
If u specify WITH TABLE KEY then u will hv to pass all key fields mentioned in DDIC...
Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
Maybe you are looking for
-
I've got a wireless network with one iMac and a Vista PC, on the Vista PC is through USB a printer connected. How can i print from my iMac to that particular printer ?
-
So im just starting java, about 12 weeks in. So in my class we are getting started with objects. What i want to do is create a class called car, and have it create a new car and draw images loaded, and then have the tires rotate, there are 2 images,
-
I've done all the suggestions, STILL NO WiFi !!
I have the 3G 16Gb, and my husband has an original that he upgraded with the 2.0 software. Neither of us can get on WiFi anywhere (at home or in public places), sometimes it asks if we want to connect then drops it, sometimes it says network error, s
-
Ora:processXSLT xpath function and absolute paths
It looks like ora:processXSLT xpath function does not honor absolute paths when specifying the location of the xslt to use in the first parameter. For example, if I call it like this: <copy> <from expression="ora:processXSLT('/u01/transforms/mytransf
-
Have 11.7 flash but no sound---is shockwave not part of adobe flash?? I have taken acobat off pc and was told this was not necessary