on 05-14-2006 7:02 AM
Hello All,
Here is some code and need to verify if its the right way for coding and how to better improve it.
The logic is based on DATA_PACKAGE-/BIC/ZCM_CUST get all the /BIC/ZBU_CUST . This will give the relation between these 2 elements. Now for each zcm_cust get the 4 attributes of zbu_cust and output the data. Can you help me with this code.
data: begin of itab occurs 100,
a type /BIC/OIZBU_CUST,
b type /BIC/OIZCM_CUST,
end of itab.
data : begin of itab2 occurs 100,
c type /BIC/OIZBU_NLVL,
d type /BIC/OIZBU_ISTAT,
e type /BIC/OIZBU_FDATE,
f type /BIC/OIZBU_NEWIN,
g type /BIC/OIZBU_CUST,
end of itab2.
break-point.
select /BIC/ZBU_CUST /BIC/ZCM_CUST from /BIC/QZBU_CUST into itab
for all entries in DATA_PACKAGE
where /BIC/ZCM_CUST = DATA_PACKAGE-/BIC/ZCM_CUST
and DATETO = '20050822'.
endselect.
select /BIC/ZBU_NLVL /BIC/ZBU_ISTAT /BIC/ZBU_FDATE /BIC/ZBU_NEWIN
/BIC/ZBU_CUST
from /BIC/PZBU_CUST
into itab2
for all entries in itab
where /BIC/ZBU_CUST = itab-a.
endselect.
Loop at DATA_PACKAGE.
read table itab with key b = DATA_PACKAGE-/BIC/ZCM_CUST
binary Search.
if sy-subrc = 0.
read table itab2 with key g = itab-a
binary search.
if sy-subrc = 0.
DATA_PACKAGE-/BIC/ZBU_NLVL = itab2-c.
DATA_PACKAGE-/BIC/ZBU_ISTAT = itab2-d.
DATA_PACKAGE-/BIC/ZBU_FDATE = itab2-e.
DATA_PACKAGE-/BIC/ZBU_NEWIN = itab2-f.
endif.
endif.
endloop.
thanks
amit
Hi,
check whether internal tables DATA_PACKAGE, itab
is initial before using For all entries.
sort the internal tables before using binary search.
rgds,
latheesh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I tried incorporating this code. What i am observing is that in the first read i get value of sy-subrc = 4 and in the next read when the values are the same between b and data_package its taking the value of sy-subrc = 8 . Not sure what is wrong. Any help will be much appreciated.
thanks
amit
Try:
DATA: BEGIN OF itab OCCURS <b>0</b>,
a TYPE /bic/oizbu_cust,
b TYPE /bic/oizcm_cust,
END OF itab.
DATA : BEGIN OF itab2 OCCURS <b>0</b>,
c TYPE /bic/oizbu_nlvl,
d TYPE /bic/oizbu_istat,
e TYPE /bic/oizbu_fdate,
f TYPE /bic/oizbu_newin,
g TYPE /bic/oizbu_cust,
END OF itab2.
<b>DATA: wk_index LIKE sy-index.</b>
BREAK-POINT.
<b>SORT data_package BY /bic/zcm_cust.</b>
SELECT /bic/zbu_cust /bic/zcm_cust FROM /bic/qzbu_cust
<b> INTO TABLE itab</b>
FOR ALL ENTRIES IN data_package
WHERE /bic/zcm_cust = data_package-/bic/zcm_cust
AND dateto = '20050822'.
<b>SORT itab BY a.</b>
SELECT /bic/zbu_nlvl /bic/zbu_istat /bic/zbu_fdate /bic/zbu_newin
/bic/zbu_cust
FROM /bic/pzbu_cust
<b> INTO TABLE itab2</b>
FOR ALL ENTRIES IN itab
WHERE /bic/zbu_cust = itab-a.
LOOP AT data_package.
<b> wk_index = sy-index.</b>
READ TABLE itab WITH KEY b = data_package-/bic/zcm_cust
BINARY SEARCH.
IF sy-subrc = 0.
READ TABLE itab2 WITH KEY g = itab-a
BINARY SEARCH.
IF sy-subrc = 0.
data_package-/bic/zbu_nlvl = itab2-c.
data_package-/bic/zbu_istat = itab2-d.
data_package-/bic/zbu_fdate = itab2-e.
data_package-/bic/zbu_newin = itab2-f.
<b> MODIFY data_package INDEX wk_index.</b>
ENDIF.
ENDIF.
ENDLOOP.
I've tried to highlight my changes. The main problem was that you were selecting into the table work area and not appending the table.
Rob
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
As far code is concern ; it fine.
just remove the endselect since it maintains contniues connection with the database till the select query data is transfered .
endselect is not appropriate from performance point of view.
When ever u use binary search ;u should sort the table with key on which the search is performed.
Use select query lik this
SELECT field1 fileds2
FROM Table_Name
INTO TABLE Internal_Table_Name
WHERE <Condition>
Regards
Manoj
Message was edited by: Manoj Gupta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Whenever you are using FOR ALL ENTRIES option in the select statement always ensure the table specified with the FOR ALL ENTRIES is not initial. Otherwise the Select will go into an infinite loop.
Use this.
IF NOT itab1[] is initial.
Select Query with for all entries option.
ENDIF.
<b>Please reward points if it helps.</b>
Regards,
Amit Mishra
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.