Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Read statement

Former Member
0 Kudos

Hi All,

I have the following code and I am not getting data properly with the Read statement.

This report has thousands of lines of output data. If I have the read stmt with binary search it is not able to find some records from IKONv and I am getting KBETR and KWERT values as 0.00 in the output.

READ TABLE ikonv WITH KEY knumv = iORD-knumv

KPOSN = IORD-POSNR. " binary search.

If I give the Read stmt with out binary search it is finding all the data properly but taking long time(approx 7min) for execution.

Can someone please guide me to resolve this problem.

Thanks,

Veni.

FORM get_data.

SELECT AVBELN AERDAT AAUART AKNUMV ABSTNK AKUNNR

BPOSNR BMATNR BARKTX BNETWR B~NETPR

CVBELN CERDAT C~RFMNG

INTO TABLE IORD

FROM VBAK AS A

INNER JOIN VBAP AS B

ON AVBELN = BVBELN

INNER JOIN VBFA AS C

ON Bvbeln = Cvbelv

AND BPOSNR = CPOSNV

WHERE A~ERDAT IN S_ERDAT

AND A~AUART IN S_AUART

AND A~KUNNR IN S_KUNNR

AND C~VBTYP_N NE 'J'

AND C~VBTYP_N NE 'R'.

IF sy-subrc = 0.

SELECT knumv kposn KBETR kschl kwert

FROM konv

INTO TABLE ikonv

FOR ALL ENTRIES IN iORD

WHERE knumv = iORD-knumv

AND kschl = 'PR00'.

ENDIF.

ENDFORM. " get_data

&----


*& Form process_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process_data.

DATA: lv_name1 LIKE kna1-name1.

loop at iORD.

  • if sy-subrc = 0.

MOVE IORD-vbeln TO iout-vbeln.

MOVE IORD-ERDAT TO iout-ERDAT.

MOVE IORD-AUART TO iout-AUART.

MOVE IORD-NETWR TO iout-NETWR.

MOVE IORD-BSTNK TO iout-BSTNK.

MOVE IORD-KUNNR TO iout-KUNNR.

MOVE IORD-POSNR TO iout-POSNR.

MOVE IORD-MATNR TO iout-MATNR.

MOVE IORD-ARKTX TO IOUT-ARKTX.

  • MOVE IORD-ZMENG TO IOUT-ZMENG.

MOVE IORD-NETPR TO iout-NETPR.

MOVE IORD-INVNO TO iout-INVNO.

MOVE IORD-INVDT TO IOUT-INVDT.

MOVE IORD-RFMNG TO iout-RFMNG.

SELECT SINGLE name1

FROM kna1 INTO lv_name1 WHERE kunnr = iORD-kunnr.

IF sy-subrc = 0.

MOVE lv_name1 TO iout-name1.

ENDIF.

READ TABLE ikonv WITH KEY knumv = iORD-knumv

KPOSN = IORD-POSNR. " binary search.

IF sy-subrc = 0.

MOVE IKONV-KBETR TO IOUT-KBETR.

Move IKONV-KWERT to iout-kwert.

ENDIF.

  • endif.

APPEND IOUT.

CLEAR iout.

ENDLOOP.

CLEAR iORD.

clear ikonv.

CLEAR lv_name1.

ENDFORM. " process_data

1 ACCEPTED SOLUTION

shafiq_rehman3
Active Contributor
0 Kudos

Before doing the binary search you have to sort the table based on those two fields which you are using in comparison of read statement.

5 REPLIES 5

shafiq_rehman3
Active Contributor
0 Kudos

Before doing the binary search you have to sort the table based on those two fields which you are using in comparison of read statement.

0 Kudos

Hi,

I wrote the following stmt before Read, but now it is taking even longer time to execute and actually it is timing out.

Sort ikonv ascending by knumv kposn.

Thanks,

Veni.

0 Kudos

Do your have your process data routine in a loop? In that case try the sort statement out of that loop and right after the select statement of that internal table. Here is how,


FORM get_data.

SELECT A~VBELN A~ERDAT A~AUART A~KNUMV A~BSTNK A~KUNNR
B~POSNR B~MATNR B~ARKTX B~NETWR B~NETPR
C~VBELN C~ERDAT C~RFMNG
INTO TABLE IORD
FROM VBAK AS A
INNER JOIN VBAP AS B
ON A~VBELN = B~VBELN
INNER JOIN VBFA AS C
ON B~vbeln = C~vbelv
AND B~POSNR = C~POSNV
WHERE A~ERDAT IN S_ERDAT
AND A~AUART IN S_AUART
AND A~KUNNR IN S_KUNNR
AND C~VBTYP_N NE 'J'
AND C~VBTYP_N NE 'R'.

IF sy-subrc = 0.
  SELECT knumv kposn KBETR kschl kwert
  FROM konv
  INTO TABLE ikonv
  FOR ALL ENTRIES IN iORD
  WHERE knumv = iORD-knumv
  AND kschl = 'PR00'.
  Sort ikonv ascending by knumv kposn. "Put your sort statement here
ENDIF.

ENDFORM. " get_data

Former Member
0 Kudos

hi,

just sort your internal table content before your searching, that would improve your performance

Former Member
0 Kudos

Hi,

If you put the sort statement in the loop, then each loop, the ikonv will be sorted. It must effect the performance. So you can put it before the loop . Try it...

Regards,

Chris Gu