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: 

Hi All

Former Member
0 Kudos

I have developed an alv report to get sales orders using the search options-customer and material and also provided f4 help.When the o/p is checked in runtime analysis, the load on database is fine if the record is selected from f4 help.However, when the record is directly entered to search the load on DB is high and this is effecting performance.(Checked the select statements and loops).Please help me with the best solution.

KK

1 ACCEPTED SOLUTION

Former Member
0 Kudos

KK,

In VBAP matnr is not the primary key.You are trying to extract the from table which is not mandatory.

If your requirement permits try to extract from

table MARA.

Don't forget to reward if useful...

3 REPLIES 3

Former Member
0 Kudos

Can you post your code?

Rob

Former Member
0 Kudos

Hi Rob,

I have few more issues with the same code along with the old one which i raised.When u execute the code, when there are no changed sales orders b/w the given dates its displaying the message in the next screen but i want it in the selection screen as an error.Here i'm pasting the code.Please send the modifications and suggestion to - lkalpana369@gmail.com.

ZSALES_ORDER_CHANGE_HISTORY *

report zsales_order_change_history line-size 132 no standard page heading

line-count 40(3)

message-id zgems.

type-pools: slis.

tables: vbak,

vbpa,

cdhdr,

cdpos,

tpart,

vbuk.

types: begin of ty_kunnr,

kunnr type kunnr,

end of ty_kunnr,

begin of ty_matnr,

matnr type matnr,

end of ty_matnr,

begin of ty_vbak,

vbeln type vbeln,

kunnr type kunnr,

end of ty_vbak,

begin of ty_vbak_initial,

vbeln type vbeln,

end of ty_vbak_initial,

begin of ty_vbap,

vbeln type vbeln,

matnr type mara-matnr,

end of ty_vbap,

begin of ty_cdhdr,

username type username,

tcode type tcode,

udate type udate,

utime type utime,

end of ty_cdhdr,

begin of ty_ernam,

ernam type ernam,

end of ty_ernam,

begin of ty_kna1,

kunnr type kna1-kunnr,

end of ty_kna1,

begin of ty_mara,

matnr type mara-matnr,

end of ty_mara.

data: begin of itab occurs 10.

include structure cdshw.

data: username type cdusername, "cdhdr-username,

changenr type cdchangenr, "cdhdr-changenr,

tcode type cdtcode, "cdhdr-tcode,

udate type cddatum, "cdhdr-udate,

utime type cduzeit, "cdhdr-utime,

vbeln(10),

posnr(6),

etenr(4),

indtext(200),

end of itab.

data: begin of icdshw occurs 50.

include structure cdshw.

data: end of icdshw.

data: begin of icdhdr occurs 50.

include structure cdhdr.

data: end of icdhdr.

data: i_vbak type table of ty_vbak,

i_vbak_initial type table of ty_vbak_initial,

i_vbap type table of ty_vbap,

i_kunnr type table of ty_kunnr,

i_vbak1 type table of ty_vbak,

i_matnr type table of ty_matnr,

i_mara type table of ty_mara,

i_kna1 type table of ty_kna1,

w_vbak1 type ty_vbak,

w_vbak type ty_vbak,

w_vbak_initial type ty_vbak_initial,

w_vbap type ty_vbap,

v_fval(10) type n,

v_x type c,

k_utext(16) value 'has been changed',

k_itext(16) value 'has been created',

k_dtext(16) value 'has been deleted',

i_fieldcat1 type slis_t_fieldcat_alv,

w_fieldcat1 type slis_fieldcat_alv.

DATA: it_header1 TYPE slis_t_listheader.

DATA: it_header2 TYPE slis_t_listheader.

DATA: wa_header1 TYPE slis_listheader,

wa_header2 TYPE slis_listheader.

DATA: it_eve1 TYPE slis_t_event,

it_eve2 TYPE slis_t_event,

wa_eve1 TYPE slis_alv_event,

wa_eve2 TYPE slis_alv_event.

selection-screen begin of block b1 with frame title text-001.

parameters: kunnr1 radiobutton group rad1 default 'X' user-command uc,

p_kunnr type kna1-kunnr modif id one, "obligatory,

matnr1 radiobutton group rad1,

p_matnr type vbap-matnr modif id two. "obligatory.

selection-screen end of block b1.

selection-screen:skip 2.

selection-screen: begin of block b2 with frame title text-002.

select-options: date for vbak-audat. "obligatory.

selection-screen: end of block b2.

at selection-screen output.

perform screen.

at selection-screen on value-request for p_kunnr.

select kunnr

from vbak

into table i_kunnr.

call function 'F4IF_INT_TABLE_VALUE_REQUEST'

exporting

retfield = 'SOLD-TO-PARTY'

dynpprog = sy-repid

dynpnr = sy-dynnr

dynprofield = 'P_KUNNR'

value_org = 'S'

tables

value_tab = i_kunnr

exceptions

parameter_error = 1

no_values_found = 2

others = 3.

if sy-subrc <> 0.

endif.

at selection-screen on value-request for p_matnr.

select matnr

from vbap

into table i_matnr.

call function 'F4IF_INT_TABLE_VALUE_REQUEST'

exporting

retfield = 'MATERIAL'

dynpprog = sy-repid

dynpnr = sy-dynnr

dynprofield = 'P_MATNR'

value_org = 'S'

tables

value_tab = i_matnr

exceptions

parameter_error = 1

no_values_found = 2

others = 3.

if sy-subrc <> 0.

endif.

at selection-screen.

perform screen.

if kunnr1 = 'X' and p_kunnr IS INITIAL.

message e001.

elseif p_kunnr is not initial.

select kunnr

from kna1 into table i_kna1

where kunnr = p_kunnr.

if sy-subrc ne 0.

message e002(zgems) with p_kunnr .

endif.

elseif matnr1 = 'X' and p_matnr IS INITIAL.

message e004.

elseif p_matnr is not initial.

select matnr

from mara into table i_mara

where matnr = p_matnr.

if sy-subrc ne 0.

message e005(zgems) with p_matnr.

endif.

if sy-subrc = 0.

message e003.

endif.

refresh i_mara.

endif.

start-of-selection.

if kunnr1 = 'X' and p_kunnr is not initial.

free:i_vbak,i_vbak1.

select vbeln kunnr

from vbak into table i_vbak

where audat in date and kunnr = p_kunnr.

if sy-subrc = 0.

loop at i_vbak into w_vbak.

clear cdhdr.

clear cdpos.

cdhdr-objectclas = 'VERKBELEG'.

cdhdr-objectid = w_vbak-vbeln.

perform readheader.

if v_x ne 'X'.

w_vbak1-vbeln = w_vbak-vbeln.

append w_vbak1 to i_vbak1.

endif.

clear : w_vbak,v_x.

endloop.

if i_vbak1 is initial.

message E003.

exit.

endif.

else.

message E003.

exit.

endif.

endif.

if matnr1 = 'X' and p_matnr is not initial.

free:i_vbak,i_vbak1.

select vbeln matnr from vbap into table i_vbap

where matnr = p_matnr.

if i_vbap is not initial.

select vbeln from vbak into table i_vbak for all entries

in i_vbap where vbeln = i_vbap-vbeln

and audat in date.

if sy-subrc eq 0.

loop at i_vbak into w_vbak.

clear cdhdr.

clear cdpos.

cdhdr-objectclas = 'VERKBELEG'.

cdhdr-objectid = w_vbak-vbeln.

perform readheader.

if v_x ne 'X'.

w_vbak1-vbeln = w_vbak-vbeln.

append w_vbak1 to i_vbak1.

endif.

clear : w_vbak,v_x.

endloop.

if i_vbak1 is initial.

message e003.

exit.

endif.

else.

message e003.

exit.

endif.

endif.

endif.

at line-selection.

refresh itab.

get cursor value v_fval.

perform interactive1.

top-of-page.

if kunnr1 = 'X'.

write: / 'CHANGED SALES DOCUMENT NUMBERS FOR SOLD-TO-PARTY',p_kunnr.

skip 1.

else.

write: / 'CHANGED SALES DOCUMENT NUMBERS FOR MATERIAL',p_matnr.

skip 1.

endif.

end-of-selection.

write:1(15) sy-uline.

format color 1.

write:/1 sy-vline,3 'DOC NUMBERS' , 15 sy-vline.

write:/1(15) sy-uline.

loop at i_vbak1 into w_vbak1.

format color 2.

write:/1 sy-vline,3 w_vbak1-vbeln , 15 sy-vline.

endloop.

write:/1(15) sy-uline.

perform header1.

form interactive1.

clear cdhdr.

clear cdpos.

cdhdr-objectclas = 'VERKBELEG'.

cdhdr-objectid = v_fval.

perform readheader.

perform readpos.

loop at itab.

case itab-tabname.

when 'VBPA'.

if itab-fname = 'KUNNR' or

itab-fname is initial.

move itab-tabkey to vbpa.

select single * from tpart where spras = sy-langu

and parvw = vbpa-parvw.

if sy-subrc = 0.

replace '&' with tpart-vtext into itab-indtext.

concatenate tpart-vtext itab-indtext into itab-indtext.

endif.

endif.

when 'VBAP'.

if itab-fname is initial.

replace '&' with text-111 into itab-indtext.

endif.

endcase.

if itab-indtext(1) eq '&'.

replace '&' with itab-ftext(40) into itab-indtext.

endif.

if itab-chngind = 'I'.

replace '%' with k_itext into itab-indtext.

elseif itab-chngind = 'U'.

replace '%' with k_utext into itab-indtext.

else.

replace '%' with k_dtext into itab-indtext.

endif.

condense itab-indtext.

modify itab.

endloop.

sort itab by utime descending.

delete adjacent duplicates from itab comparing all fields.

refresh i_fieldcat1.

clear w_fieldcat1.

w_fieldcat1-fieldname = 'UDATE'.

w_fieldcat1-tabname = 'ITAB'.

w_fieldcat1-seltext_m = 'DATE'.

w_fieldcat1-outputlen = '000010'.

append w_fieldcat1 to i_fieldcat1.

clear w_fieldcat1.

w_fieldcat1-fieldname = 'POSNR'.

w_fieldcat1-tabname = 'ITAB'.

w_fieldcat1-seltext_m = 'ITEM NUMBER'.

w_fieldcat1-outputlen = '000011'.

append w_fieldcat1 to i_fieldcat1.

clear w_fieldcat1.

w_fieldcat1-fieldname = 'ETENR'.

w_fieldcat1-tabname = 'ITAB'.

w_fieldcat1-seltext_m = 'SCHEDULED LINE NUMBER'.

w_fieldcat1-outputlen = '000015'.

append w_fieldcat1 to i_fieldcat1.

clear w_fieldcat1.

w_fieldcat1-fieldname = 'INDTEXT'.

w_fieldcat1-tabname = 'ITAB'.

w_fieldcat1-seltext_m = 'ACTION'.

w_fieldcat1-outputlen = '000070'.

append w_fieldcat1 to i_fieldcat1.

clear w_fieldcat1.

w_fieldcat1-fieldname = 'USERNAME'.

w_fieldcat1-tabname = 'ITAB'.

w_fieldcat1-seltext_m = 'USERNAME'.

w_fieldcat1-outputlen = '000010'.

append w_fieldcat1 to i_fieldcat1.

clear w_fieldcat1.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_callback_program = sy-repid

i_callback_user_command = 'SUB_COMMAND1'

it_fieldcat = i_fieldcat1

it_events = it_eve1[]

tables

t_outtab = itab.

endform. " INTERACTIVE1

*events

FORM header1.

CLEAR wa_eve1.

wa_eve1-name = 'TOP_OF_PAGE'.

wa_eve1-form = 'TOP-OF-PAGE1'.

APPEND wa_eve1 TO it_eve1.

ENDFORM. "HEADER1

&----


*& Form TOP-OF-PAGE1

&----


FORM top-of-page1. "#EC CALLED

wa_header1-typ = 'H'.

wa_header1-info = 'CHANGED SALES DOCUMENT DETAILS:'.

APPEND wa_header1 TO it_header1.

CLEAR wa_header1.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = it_header1[]

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

REFRESH it_header1.

ENDFORM. "TOP-OF-PAGE1

&----


*& Form SUB_COMMAND1

&----


form sub_command1 using r_ucomm type sy-ucomm r_selfield type slis_selfield.

data: w_fieldcat2 type slis_fieldcat_alv,

i_fieldcat2 type slis_t_fieldcat_alv.

refresh i_fieldcat2.

clear w_fieldcat2.

w_fieldcat2-fieldname = 'TABNAME'.

w_fieldcat2-tabname = 'ITAB'.

w_fieldcat2-seltext_m = 'TABLENAME'.

w_fieldcat2-outputlen = '000010'.

append w_fieldcat2 to i_fieldcat2.

clear w_fieldcat2.

w_fieldcat2-fieldname = 'FNAME'.

w_fieldcat2-tabname = 'ITAB'.

w_fieldcat2-seltext_m = 'FIELD NAME'.

w_fieldcat2-outputlen = '000015'.

append w_fieldcat2 to i_fieldcat2.

clear w_fieldcat2.

w_fieldcat2-fieldname = 'USERNAME'.

w_fieldcat2-tabname = 'ITAB'.

w_fieldcat2-seltext_m = 'USERNAME'.

w_fieldcat2-outputlen = '000010'.

append w_fieldcat2 to i_fieldcat2.

clear w_fieldcat2.

w_fieldcat2-fieldname = 'TCODE'.

w_fieldcat2-tabname = 'ITAB'.

w_fieldcat2-seltext_m = 'TRANSACTION'.

w_fieldcat2-outputlen = '000015'.

append w_fieldcat2 to i_fieldcat2.

clear w_fieldcat2.

w_fieldcat2-fieldname = 'UDATE'.

w_fieldcat2-tabname = 'ITAB'.

w_fieldcat2-seltext_m = 'DATE'.

w_fieldcat2-outputlen = '000010'.

append w_fieldcat2 to i_fieldcat2.

clear w_fieldcat2.

w_fieldcat2-fieldname = 'UTIME'.

w_fieldcat2-tabname = 'ITAB'.

w_fieldcat2-seltext_m = 'TIME'.

w_fieldcat2-outputlen = '000010'.

append w_fieldcat2 to i_fieldcat2.

clear w_fieldcat2.

call function 'REUSE_ALV_POPUP_TO_SELECT'

exporting

i_title = 'ORDER'

I_ALLOW_NO_SELECTION = 'X'

i_screen_start_column = 5

i_screen_start_line = 5

i_screen_end_column = 80

i_screen_end_line = 25

i_scroll_to_sel_line = 'X'

i_tabname = 'ITAB'

it_fieldcat = i_fieldcat2

tables

t_outtab = itab.

endform. "SUB_COMMAND1

&----


*& Form READPOS

&----


form readpos.

loop at icdhdr.

check icdhdr-udate in date.

call function 'CHANGEDOCUMENT_READ_POSITIONS'

exporting

changenumber = icdhdr-changenr

tablekey = cdpos-tabkey

tablename = cdpos-tabname

importing

header = cdhdr

tables

editpos = icdshw

exceptions

no_position_found = 1

others = 2.

case sy-subrc.

when '0000'.

loop at icdshw.

check icdshw-chngind ne 'E'.

clear itab.

move-corresponding icdhdr to itab.

move-corresponding icdshw to itab.

case itab-tabname.

when 'KONVC'.

move icdhdr-objectid to itab-vbeln.

move icdshw-tabkey(6) to itab-posnr.

when others.

move icdshw-tabkey+3(10) to itab-vbeln.

move icdshw-tabkey+13(6) to itab-posnr.

move icdshw-tabkey+19(4) to itab-etenr.

endcase.

move '& %' to itab-indtext.

append itab.

clear itab.

endloop.

when others.

message e003.

leave.

endcase.

endloop.

endform. "READPOS

&----


*& Form READHEADER

&----


form readheader.

call function 'CHANGEDOCUMENT_READ_HEADERS'

exporting

date_of_change = cdhdr-udate

objectclass = cdhdr-objectclas

objectid = cdhdr-objectid

time_of_change = cdhdr-utime

username = cdhdr-username

tables

i_cdhdr = icdhdr

exceptions

no_position_found = 1

others = 2.

if sy-subrc ne 0.

v_x = 'X'.

endif.

endform. "READHEADER

&----


*& Form l

&----


form screen.

if kunnr1 = 'X'.

p_matnr = ' '.

loop at screen.

if screen-group1 = 'ONE'.

screen-input = '1'.

modify screen.

endif.

if screen-group1 = 'TWO'.

screen-input = '0'.

modify screen.

endif.

endloop.

elseif matnr1 = 'X'.

p_kunnr = ' '.

loop at screen.

if screen-group1 = 'TWO'.

screen-input = '1'.

modify screen.

endif.

if screen-group1 = 'ONE'.

screen-input = '0'.

modify screen.

endif.

endloop.

endif.

endform. "SCREEN

Former Member
0 Kudos

KK,

In VBAP matnr is not the primary key.You are trying to extract the from table which is not mandatory.

If your requirement permits try to extract from

table MARA.

Don't forget to reward if useful...