Skip to Content
0
Former Member
Oct 20, 2006 at 03:48 PM

Code snippet in a ALV report

38 Views

hello experts

I would like to calclute the invoice value and display in the output (invoice value = VBEP-NETWR/VBEP-FKIMG) , where should i add the code? In the select stament? code help is higly appreciated.

Thanks

mohan

follows the program

  • Global structure of list

type-pools: slis.

tables: likp,

lips,

vbfa,

kssk,

klah,

ausp,

cabn,

vbak,

mara,

vbrk,

ser01,

vbpa,

nast,

zseri,

ltap,

pa0001,

kna1,

objk,

viqmel,

viqmma.

types: begin of i_delivery,

vbeln like likp-vbeln,

posnr like lips-posnr,

kunnr like likp-kunnr,

kunag like likp-kunag,

vkorg like vbak-vkorg,

matnr like lips-matnr,

lfart like likp-lfart,

arktx like vbap-arktx,

vgbel like lips-vgbel,

vgpos like lips-vgpos,

pstyv like lips-pstyv,

wadat type likp-wadat,

lfdat type likp-lfdat,

prodh type lips-prodh,

lfimg type lips-lfimg,

vkbur type lips-vkbur,

werks type lips-werks,

vkgrp type lips-vkgrp,

mvgr1 type lips-mvgr1,

sernr like equi-sernr,

sernp like equi-sernr,

equnr like equi-equnr,

kttxt like qpct-kurztext,

bstnk like vbak-bstnk,

vbelv like lips-vgbel,

posnv like lips-posnv,

uecha like lips-uecha,

ernam like vbak-ernam,

erdat like vbak-erdat,

serail like lips-serail,

anzsn like lips-anzsn,

auart like vbak-auart ,

netwr like vbap-netwr,

fstno like vbpa-pernr,

fstnm like pa0001-ename,

ename like pa0001-ename,

qname like ltap-qname,

name1 like kna1-name1,

name3 like kna1-name2,

pernr like vbpa-pernr,

aufnr like viqmel-aufnr,

qmnum like viqmel-qmnum,

mngrp like viqmma-mngrp,

qmcod like viqmel-qmcod,

qmcol like viqmma-mncod,

cotxt(20),

end of i_delivery.

  • Global structure of list

*/ Selection and Input Parameters

selection-screen begin of block block2 with frame title text-003.

select-options: s_vkorg for likp-vkorg no intervals.

select-options: s_vbeln for likp-vbeln,

s_lfart for likp-lfart,

s_kunnr for likp-kunnr,

s_erdat for likp-erdat,

s_wadat for likp-wadat,

s_werks for lips-werks,

s_matnr for lips-matnr,

s_prodh for lips-prodh,

s_qmnum for viqmel-qmnum.

selection-screen end of block block2.

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

select-options: s_vbelv for vbak-vbeln,

s_auart for vbak-auart.

selection-screen end of block block4.

parameters: p_vari like disvariant-variant.

ranges: r_vbeln for likp-vbeln.

data: gt_fieldcat type slis_t_fieldcat_alv.

data: gt_outtab type i_delivery occurs 0 with header line,

rt_outtab1 type i_delivery occurs 0 with header line,

i_nast type nast occurs 0 with header line,

gt_list_top_of_page type slis_t_listheader,

gt_events type slis_t_event,

gc_formname_top_of_page type slis_formname value 'TOP_OF_PAGE'.

data: g_repid like sy-repid,

g_count like sy-tabix.

data: begin of i_serial occurs 0,

obknr type ser01-obknr,

lief_nr type ser01-lief_nr,

posnr type ser01-posnr,

anzsn type ser01-anzsn,

end of i_serial.

data: begin of i_object_numbers occurs 0,

obknr type objk-obknr,

obzae type objk-obzae,

sernr type objk-sernr,

equnr type objk-equnr,

matnr type objk-matnr,

taser type objk-taser,

end of i_object_numbers.

data: g_save(1) type c,

  • g_default(1) TYPE c,

g_exit(1) type c,

gx_variant like disvariant,

g_variant like disvariant.

data: g_mnkat like viqmma-mnkat,

g_mngrp like viqmma-mngrp,

g_atinn like ausp-atinn.

  • Initialization fieldcatalog

initialization.

g_repid = sy-repid.

perform fieldcat_init using gt_fieldcat[].

move: 'I' to s_vkorg-sign,

'EQ' to s_vkorg-option,

'5090' to s_vkorg-low.

append s_vkorg.

move: 'I' to s_lfart-sign,

'EQ' to s_lfart-option,

'LF' to s_lfart-low.

append s_lfart.

g_save = 'A'.

perform variant_init.

  • Get default variant

gx_variant = g_variant.

call function 'REUSE_ALV_VARIANT_DEFAULT_GET'

exporting

i_save = g_save

changing

cs_variant = gx_variant

exceptions

not_found = 2.

if sy-subrc = 0.

p_vari = gx_variant-variant.

endif.

at selection-screen on value-request for p_vari.

perform f4_for_variant.

at selection-screen.

perform pai_of_selection_screen.

  • Start of Selection

start-of-selection.

perform e03_eventtab_build using gt_events[].

perform select_data tables gt_outtab.

  • Display list

end-of-selection.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_background_id = 'ALV_BACKGROUND'

i_callback_user_command = 'USER_COMMAND'

is_variant = g_variant

i_save = g_save

i_callback_program = g_repid

it_fieldcat = gt_fieldcat[]

tables

t_outtab = gt_outtab.

*----


  • Forms

*----


  • Initialization fieldcatalog

form fieldcat_init

using rt_fieldcat type slis_t_fieldcat_alv.

data: ls_fieldcat type slis_fieldcat_alv.

data: pos type i value 1.

clear ls_fieldcat.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'VBELN'.

ls_fieldcat-seltext_s = 'Delivery'.

ls_fieldcat-seltext_m = 'Delivery'.

ls_fieldcat-key = 'X'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'POSNR'.

ls_fieldcat-key = 'X'.

ls_fieldcat-seltext_s = 'Item'.

ls_fieldcat-seltext_m = 'Item'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'LFART'.

ls_fieldcat-seltext_s = 'Del Type'.

ls_fieldcat-seltext_m = 'Delivery Type'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'VGBEL'.

ls_fieldcat-seltext_s = 'Source Doc'.

ls_fieldcat-seltext_m = 'Source Doc'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'AUART'.

ls_fieldcat-seltext_s = 'Type'.

ls_fieldcat-seltext_m = 'Type'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'KUNNR'.

ls_fieldcat-seltext_s = 'Customer'.

ls_fieldcat-seltext_m = 'Customer'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'NAME1'.

ls_fieldcat-seltext_s = 'Name'.

ls_fieldcat-seltext_m = 'Name1'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'WERKS'.

ls_fieldcat-seltext_s = 'Plant'.

ls_fieldcat-seltext_m = 'Plant'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'MATNR'.

ls_fieldcat-seltext_s = 'Material'.

ls_fieldcat-seltext_m = 'Material'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'MVGR1'.

ls_fieldcat-seltext_s = 'Speciality'.

ls_fieldcat-seltext_m = 'Speciality'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'PRODH'.

ls_fieldcat-seltext_s = 'Hierarchy'.

ls_fieldcat-seltext_m = 'Prod Hierarchy'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'ARKTX'.

ls_fieldcat-seltext_s = 'Description'.

ls_fieldcat-seltext_m = 'Description'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'ERNAM'.

ls_fieldcat-seltext_s = 'Created By'.

ls_fieldcat-seltext_m = 'Created By'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'ERDAT'.

ls_fieldcat-seltext_s = 'Created On'.

ls_fieldcat-seltext_m = 'Created On'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'WADAT'.

ls_fieldcat-seltext_s = 'GoodsMvt.Date'.

ls_fieldcat-seltext_m = 'Goods Mvt Date'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'SERNR'.

ls_fieldcat-seltext_s = 'Serial Shipped'.

ls_fieldcat-seltext_m = 'Serial Shipped'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'SERNP'.

ls_fieldcat-seltext_s = 'Old Serial'.

ls_fieldcat-seltext_m = 'Old Serial'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'VBELV'.

ls_fieldcat-seltext_s = 'Invoice'.

ls_fieldcat-seltext_m = 'Invoice'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'NETWR'.

ls_fieldcat-seltext_s = 'Invoice Amt'.

ls_fieldcat-seltext_m = 'Invoice Value'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'QMNUM'.

ls_fieldcat-seltext_s = 'Notification'.

ls_fieldcat-seltext_m = 'Notification'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'QMCOD'.

ls_fieldcat-seltext_s = 'Rep LevKST'.

ls_fieldcat-seltext_m = 'Repair Level KST'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'COTXT'.

ls_fieldcat-seltext_s = 'CdTXT KST'.

ls_fieldcat-seltext_m = 'Repair Level Text KST'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'QMCOL'.

ls_fieldcat-seltext_s = 'Rep LevKSE'.

ls_fieldcat-seltext_m = 'Repair Level KSE'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

pos = pos + 1.

ls_fieldcat-col_pos = pos.

ls_fieldcat-fieldname = 'KTTXT'.

ls_fieldcat-seltext_s = 'CdTXT KSE'.

ls_fieldcat-seltext_m = 'Repair Level Text KSE'.

append ls_fieldcat to rt_fieldcat.

clear ls_fieldcat.

endform. "fieldcat_init

  • Data selection

form select_data tables rt_outtab like gt_outtab[].

clear: r_vbeln[].

  • Read all Invoices for the Selection

select distinct h~vbeln h~kunnr h~kunag

d~posnr d~matnr d~anzsn

d~serail d~vgbel d~vgpos

d~posnv d~lfimg d~arktx

d~uecha h~lfart h~erdat

h~ernam h~lfdat d~prodh

h~vkorg d~vkbur d~vkgrp

d~mvgr1 h~wadat_ist d~pstyv

d~werks

into (rt_outtab-vbeln, rt_outtab-kunnr,

rt_outtab-kunag, rt_outtab-posnr,

rt_outtab-matnr, rt_outtab-anzsn,

rt_outtab-serail, rt_outtab-vgbel,

rt_outtab-vgpos, rt_outtab-posnv,

rt_outtab-lfimg, rt_outtab-arktx,

rt_outtab-uecha, rt_outtab-lfart,

rt_outtab-erdat, rt_outtab-ernam,

rt_outtab-lfdat, rt_outtab-prodh,

rt_outtab-vkorg, rt_outtab-vkbur,

rt_outtab-vkgrp, rt_outtab-mvgr1,

rt_outtab-wadat, rt_outtab-pstyv,

rt_outtab-werks)

from likp as h inner join lips as d

on h~vbeln = d~vbeln

where h~vbeln in s_vbeln

and h~vkorg in s_vkorg

and h~lfart in s_lfart

and h~kunnr in s_kunnr

and h~erdat in s_erdat

and d~matnr in s_matnr

and d~werks in s_werks

and d~prodh in s_prodh

and d~vgbel in s_vbelv

and d~matnr like 'S%'.

select single * from vbak where vbeln = rt_outtab-vgbel.

if: sy-subrc eq 0.

move vbak-vbeln to rt_outtab-vgbel.

move vbak-auart to rt_outtab-auart.

endif.

select single * from mara where matnr = rt_outtab-matnr

and mtart eq 'FERT'.

check sy-subrc eq 0.

if not rt_outtab-posnv is initial.

rt_outtab-vgpos = rt_outtab-posnv.

endif.

clear: vbfa.

select single vbeln rfwrt into (rt_outtab-vbelv, rt_outtab-netwr)

from vbfa where vbelv eq rt_outtab-vbeln

and posnv eq rt_outtab-posnr

and vbtyp_n eq 'M'.

append rt_outtab.

if not r_vbeln-low is initial.

if r_vbeln-low gt rt_outtab-vbeln.

r_vbeln-low = rt_outtab-vbeln.

endif.

if r_vbeln-high lt rt_outtab-vbeln.

r_vbeln-high = rt_outtab-vbeln.

endif.

else.

r_vbeln-low = rt_outtab-vbeln.

r_vbeln-high = rt_outtab-vbeln.

endif.

clear: rt_outtab.

endselect.

if not r_vbeln is initial.

move: 'I' to r_vbeln-sign,

'BT' to r_vbeln-option.

append r_vbeln.

select * into corresponding fields of table i_serial

from ser01 where lief_nr in r_vbeln.

endif.

sort i_serial.

if not i_serial[] is initial.

select * into corresponding fields of table i_object_numbers

from objk

for all entries in i_serial

where obknr eq i_serial-obknr

and taser eq 'SER01'.

endif.

sort i_object_numbers by obknr obzae.

loop at rt_outtab.

  • Read the Sold To Name

select single name1 into rt_outtab-name1

from kna1 where kunnr eq rt_outtab-kunnr.

  • Read Ship-to Customer

clear: objk.

if not rt_outtab-serail is initial.

read table i_serial with key lief_nr = rt_outtab-vbeln

posnr = rt_outtab-posnr.

if sy-subrc eq 0.

do i_serial-anzsn times.

read table i_object_numbers with key obknr = i_serial-obknr

matnr = rt_outtab-matnr

binary search.

if sy-subrc eq 0.

rt_outtab-sernr = i_object_numbers-sernr.

delete i_object_numbers index sy-tabix.

move '1' to rt_outtab-lfimg.

clear: rt_outtab-aufnr, rt_outtab-qmnum,

rt_outtab-equnr, rt_outtab-qmcod, g_mngrp, g_mnkat.

select single aufnr qmnum equnr qmcod qmgrp qmkat

into (rt_outtab-aufnr, rt_outtab-qmnum,

rt_outtab-equnr, rt_outtab-qmcod, g_mngrp, g_mnkat)

from viqmel where matnr = rt_outtab-matnr

and serialnr = rt_outtab-sernr

and qmart eq 'S4'

and qmnum in s_qmnum.

clear: rt_outtab-cotxt.

select single kurztext into rt_outtab-cotxt

from qpct where katalogart eq g_mnkat

and codegruppe eq g_mngrp

and code eq rt_outtab-qmcod

and sprache eq sy-langu.

  • Read Serial Number from Name Plate Data.

clear: klah, kssk, ausp, cabn, g_atinn.

select single atinn into (g_atinn) from cabn

where atnam = 'SBANK_SERIAL_NUMBER'.

select single atwrt

into (rt_outtab-sernp)

from ( klah as a inner join kssk as k

on aclint = kclint )

join ausp as p

on kobjek = pobjek

and p~atinn = g_atinn

and pklart = aklart

where a~klart = '002'

and a~class = 'KSE_SN_ENDOSCOPES'

and k~objek = rt_outtab-equnr.

*KSE Repair level (activity code text from KSE-SM07 code group)

clear: rt_outtab-qmcol, g_mngrp, g_mnkat.

clear: rt_outtab-qmcol.

clear: g_mnkat, g_mngrp.

select single mnkat mngrp mncod into

(g_mnkat, g_mngrp, rt_outtab-qmcol)

from viqmma where qmnum = rt_outtab-qmnum

and mngrp eq 'KSE-SM07'

and kzloesch eq space.

clear: rt_outtab-kttxt.

select single kurztext into rt_outtab-kttxt

from qpct where katalogart eq g_mnkat

and codegruppe eq g_mngrp

and code eq rt_outtab-qmcol

and sprache eq sy-langu.

rt_outtab1 = rt_outtab.

append rt_outtab1.

endif.

enddo.

endif.

endif.

endloop.

clear: rt_outtab[].

rt_outtab[] = rt_outtab1[].

sort rt_outtab by vbeln posnr.

endform.

----


  • FORM get_repname *

----


  • ........ *

----


  • --> P_VBELN *

  • --> P_POSNR *

  • --> P_PERNR *

  • --> P_ENAME *

----


form get_repname using p_vbeln

p_posnr

changing p_pernr

p_ename. "

data: i_vbpa like vbpa occurs 0 with header line.

clear: i_vbpa[].

call function 'Z_DETERMINE_ACTIVE_SALES_REP'

exporting

g_salesdocument = p_vbeln

g_sales_item = p_posnr

tables

st_vbpa = i_vbpa.

read table i_vbpa index 1.

if sy-subrc = 0.

p_pernr = i_vbpa-pernr.

select single ename into p_ename

from pa0001

where pernr = i_vbpa-pernr.

endif.

endform. " get_repname

----


  • FORM E03_EVENTTAB_BUILD *

----


  • ........ *

----


  • --> E03_LT_EVENTS *

----


form e03_eventtab_build using e03_lt_events type slis_t_event.

data: ls_event type slis_alv_event.

*

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = e03_lt_events.

read table e03_lt_events with key name = slis_ev_top_of_page

into ls_event.

if sy-subrc = 0.

move gc_formname_top_of_page to ls_event-form.

append ls_event to e03_lt_events.

endif.

endform.

----


  • FORM TOP_OF_PAGE *

----


  • ........ *

----


form top_of_page.

*

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = gt_list_top_of_page.

endform.

*&----


*& Form USER_COMMAND

*&----


form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case r_ucomm.

when '&IC1'.

perform display_delivery using r_ucomm

rs_selfield.

endcase.

endform.

&----


*& Form display_delivery

&----


form display_delivery

using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case rs_selfield-sel_tab_field.

when '1-VBELN'.

set parameter id 'VL' field rs_selfield-value.

call transaction 'VL03N' and skip first screen.

when '1-VBELV'.

set parameter id 'VF' field rs_selfield-value.

call transaction 'VF03N' and skip first screen.

endcase.

endform.

&----


*& Form VARIANT_INIT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form variant_init.

*

clear g_variant.

g_variant-report = g_repid.

endform. " VARIANT_INIT

&----


*& Form F4_FOR_VARIANT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form f4_for_variant.

*

call function 'REUSE_ALV_VARIANT_F4'

exporting

is_variant = g_variant

i_save = g_save

  • it_default_fieldcat =

importing

e_exit = g_exit

es_variant = gx_variant

exceptions

not_found = 2.

if sy-subrc = 2.

message id sy-msgid type 'S' number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

else.

if g_exit = space.

p_vari = gx_variant-variant.

endif.

endif.

endform.

&----


*& Form PAI_OF_SELECTION_SCREEN

&----


  • text

----


form pai_of_selection_screen.

*

if not p_vari is initial.

move g_variant to gx_variant.

move p_vari to gx_variant-variant.

call function 'REUSE_ALV_VARIANT_EXISTENCE'

exporting

i_save = g_save

changing

cs_variant = gx_variant.

g_variant = gx_variant.

else.

perform variant_init.

endif.

endform.