Application Development and Automation 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: 
Read only

How to write a code without affecting database

Former Member
0 Likes
880

hi experts,

Please tell me how to write ABAP coding which will hit database ..for ex..

REPORT ZRUNTIME.

TABLES : BSEG.

DATA : BEGIN OF FINAL OCCURS 0,

BELNR LIKE BSEG-BELNR,

WRBTR LIKE BSEG-WRBTR,

AUGDT LIKE BSEG-AUGDT,

END OF FINAL.

SELECT-OPTIONS: DATE1 FOR BSEG-AUGDT.

SELECT BELNR WRBTR AUGDT FROM BSEG INTO CORRESPONDING FIELDS OF TABLE FINAL WHERE AUGDT IN DATE1.

LOOP AT FINAL.

WRITE:/ FINAL-BELNR,FINAL-WRBTR,FINAL-AUGDT.

ENDLOOP.

this is a simple progarm which affects database 100% in runtime analysis.how shall i re write the code in another way ..???

regards,

mani

7 REPLIES 7
Read only

Former Member
0 Likes
852

REPORT ZRUNTIME.

TABLES : BSEG.

types : BEGIN OF ty_FINAL ,

BELNR LIKE BSEG-BELNR,

WRBTR LIKE BSEG-WRBTR,

AUGDT LIKE BSEG-AUGDT,

END OF ty_FINAL.

data: itab type standard table of itab with header line.

SELECT-OPTIONS: DATE1 FOR BSEG-AUGDT.

SELECT BELNR WRBTR AUGDT

FROM BSEG

INTO TABLE itab

WHERE AUGDT IN DATE1.

LOOP AT itab.

WRITE:/ FINAL-BELNR,FINAL-WRBTR,FINAL-AUGDT.

ENDLOOP.

Read only

0 Likes
852

it also crosses 100% in database.

Read only

Former Member
0 Likes
852

hi.

try to code like this:

TYPES : BEGIN OF S_FINAL ,

BELNR LIKE BSEG-BELNR,

WRBTR LIKE BSEG-WRBTR,

AUGDT LIKE BSEG-AUGDT,

END OF S_FINAL.

data: final type standard table of s_final,

wa_final type s_final.

data: l_date type 'data element of field Augdt'.

SELECT-OPTIONS: DATE1 FOR l_date.

try to avoid corresponding keyword by writing fields in internal table in the same order that the fields in dtabase table

SELECT BELNR WRBTR AUGDT FROM BSEG INTO CORRESPONDING FIELDS OF TABLE FINAL WHERE AUGDT IN l_date.

LOOP AT FINAL into wa_final.

WRITE:/ wa_FINAL-BELNR,wa_FINAL-WRBTR,wa_FINAL-AUGDT.

ENDLOOP.

hope this will help u.

Read only

matt
Active Contributor
0 Likes
852

If you don't want to affect the database, then don't select any data! It doesn't matter what you do, if you write a program where most of the processing is involved in getting the data, it will spend most of its time getting the data.

If you really want to get that 100% down, I suggest you add this at the end.

DATA: l_x TYPE f,
      l_y TYPE f,
      l_z TYPE f.
l_x = '-0.5'.
l_y = '0.5'.
DO 10000000 TIMES.
  l_z = l_x.
  l_x = ( l_x * l_x ) - ( l_y * l_y ).
  l_y = 2 * l_z * l_y + l_z + l_y.
ENDDO.

The program will take a lot longer, but you'll get the percentage of time in the database down.

matt

Read only

0 Likes
852

Hi Matthew,

this looks a little bit like a mandelbrot computation. Do you have a graphical output as well?

Read only

ThomasZloch
Active Contributor
0 Likes
852

That would probably add to the ABAP percentage, so we'd have to introduce another huge SELECT to maintain the 50/50 balance.

In the end we should have a nice and fully emancipated little program.

Thomas

Read only

Former Member
0 Likes
852

DATA : BEGIN OF FINAL OCCURS 0,

BELNR LIKE BSEG-BELNR,

WRBTR LIKE BSEG-WRBTR,

AUGDT LIKE BSEG-AUGDT,

END OF FINAL.

field-symbols : <fs_final> like line of final.

data: final_1 like table of final with header line.

select BELNR

WRBTR

AUGDT

into final from <tablename>

where AUGDT IN DATE1.

loop at final assigning <fs_final>.

final_1-belnr = <fs_final>-belnr.

final_1-wrbtr = <fs_final>-wrbtr.

final_1-augdt = <fs_final>-augdt.

append <fs_final> to final_1.

endloop.

hope this helps