cancel
Showing results for 
Search instead for 
Did you mean: 

Help on code

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

You get non-zero return codes either because the table isn't sorted or contains no entries. See my other answer.

Rob

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

former_member927251
Active Contributor
0 Kudos

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