Professional Documents
Culture Documents
Docslide - Us - Sap Exercise On Alv Report
Docslide - Us - Sap Exercise On Alv Report
Functional Description:
The purpose of this development is to display sales order flow information like
sales orders, delivery orders and billing documents. User can download or send
email this report.
1. Report need to contain sales order information, delivery information and
billing information and need to display totals and sub-totals of the amount
based on the sales order no delivery document number and billing
document number.
2. User can display or download or send mail based on selection of check
boxes.
A.
B.
C.
D.
E.
F.
G.
H.
I.
J.
K.
L.
M.
N.
O.
P.
Q.
R.
S.
T.
U.
V.
W.
8. Calculate subtotals and totals for net amount fields (VBRP-NETWR) based
on billing document number and company code.
9. Highlight sales document number delivery document number and billing
document number.
10.To download file use function module GUI_DOWNLOAD.
11.To send mail use FM (function module)
SO_NEW_DOCUMENT_ATT_SEND_API1.
PROGRAM CODE:
Report
ZSR_427.
tables:vbak,vbap,lips,likp,vbrp,vbrk,makt,kna1,somlreci1.
type-pools:slis.
select-options:
types:begin of ty_vbak,
vbeln type vbeln_va,
audat type audat,
vkorg type vkorg,
vkgrp type vkgrp,
vkbur type vkbur,
end of ty_vbak.
types:begin
vbeln
posnr
matnr
matkl
of ty_vbap,
type vbeln_va,
type posnr_va,
type matnr,
type matkl,
end of ty_vbap.
types:begin of ty_lips,
vbeln type vbeln_vl,
vgbel type vgbel,
vgpos type vgpos,
posnr type posnr_vl,
werks type werks_d,
lgort type lgort_d,
end of ty_lips.
types:begin of ty_likp,
vbeln type vbeln_vl,
vstel type vstel,
lfdat type lfdat_v,
kunnr type kunwe,
end of ty_likp.
*********************************************************************
******************************************
data
data
data
data
doc_data
object_id
objcont
receiver
like
like
like
like
sodocchgi1.
soodk.
soli occurs 10 with header line.
somlreci1 occurs 1 with header line.
*********************************************************************
******************************************
at selection-screen output.
loop at screen.
case 'X'.
when p_saldoc.
case screen-group1.
when 'AA1'.
screen-input = '1'.
when 'AA2'.
*
screen-input = '0'.
screen-output = '0'.
*
when 'AA3'.
screen-input = '0'.
screen-output = '0'.
endcase.
modify screen.
when p_deldoc.
case screen-group1.
when 'AA2'.
screen-input = '1'.
when 'AA1'.
screen-input = '0'.
screen-output = '0'.
when 'AA3'.
screen-input = '0'.
screen-output = '0'.
endcase.
modify screen.
when p_bildoc.
case screen-group1.
when 'AA3'.
screen-input = '1'.
when 'AA1'.
screen-input = '0'.
screen-output = '0'.
when 'AA2'.
screen-input = '0'.
screen-output = '0'.
endcase.
modify screen.
endcase.
endloop.
start-of-selection.
if p_saldoc = 'X'.
select vbeln audat vkorg
whERE vbeln IN s_sdno.
select vbeln vgbel vgpos posnr werks lgort from lips into table
i_lips FOR ALL ENTRIES IN i_vbap WHERE vgbel = i_vbap-vbeln AND vgpos
= i_vbap-posnr.
endif.
if sy-subrc = 0 and i_lips is not initial.
select vbeln vstel lfdat kunnr from likp into table i_likp for
all ENTRIES IN i_lips WHERE vbeln = i_lips-vbeln.
endif.
if sy-subrc = 0 and i_lips is not initial.
select vbeln posnr vgbel vgpos from vbrp into table i_vbrp for
all ENTRIES IN i_lips WHERE vgbel = i_lips-vbeln AND vgpos = i_lipsposnr.
endif.
if sy-subrc = 0 and i_vbrp is not initial.
select vbeln fkdat bukrs netwr from vbrk into table i_vbrk for
all ENTRIES IN i_vbrp WHERE vbeln = i_vbrp-vbeln.
endif.
if sy-subrc = 0 and i_vbap is not initial.
select matnr maktx spras from makt into table i_makt for all e
ntrIES IN i_vbap WHERE matnr = i_vbap-matnr AND spras = sy-langu.
endif.
if sy-subrc = 0 and i_likp is not initial.
select name1 ort01 kunnr from kna1 into table i_kna1 for all e
ntrIES IN i_likp WHERE kunnr = i_likp-kunnr.
else.
message e398(00) with 'no entries found'.
endif.
if sy-subrc = 0.
read table i_vbrk with key vbeln = wa_vbrp-vbeln into w
a_vbrk.
if sy-subrc = 0.
read table i_makt with key matnr = wa_vbap-matnr spra
s = sy-langu INTO wa_makt.
if sy-subrc = 0.
read table i_kna1 with key kunnr = wa_likp-kunnr in
to wa_kna1.
wa_final-vbeln_vbak = wa_vbak-vbeln.
wa_final-posnr_vbap = wa_vbap-posnr.
wa_final-audat = wa_vbak-audat.
wa_final-vkorg = wa_vbak-vkorg.
wa_final-vkgrp = wa_vbak-vkgrp.
wa_final-vkbur = wa_vbak-vkbur.
wa_final-matnr = wa_vbap-matnr.
wa_final-maktx = wa_makt-maktx.
wa_final-matkl = wa_vbap-matkl.
wa_final-vbeln_likp = wa_likp-vbeln.
wa_final-posnr_lips = wa_lips-posnr.
wa_final-vstel = wa_likp-vstel.
wa_final-lfdat = wa_likp-lfdat.
wa_final-werks = wa_lips-werks.
wa_final-lgort = wa_lips-lgort.
wa_final-kunnr = wa_likp-kunnr.
wa_final-name1 = wa_kna1-name1.
wa_final-ort01 = wa_kna1-ort01.
wa_final-vbeln_vbrk = wa_vbrk-vbeln.
wa_final-posnr_vbrp = wa_vbrp-posnr.
wa_final-fkdat = wa_vbrk-fkdat.
wa_final-bukrs = wa_vbrk-bukrs.
wa_final-netwr = wa_vbrk-netwr.
append wa_final to i_final.
endif.
endif.
endif.
endif.
endif.
endif.
endloop.
if p_down = 'X'.
perform download.
endif.
if p_mail = 'X'.
perform mail .
endif.
if p_dis = 'X'.
perform build_fieldcatalog.
perform alvdisplay.
else.
perform normal_display.
endif.
where
endif.
if sy-subrc = 0 and i_vbap is not initial.
select matnr maktx spras from makt into table i_makt for all e
ntrIES IN i_vbap WHERE matnr = i_vbap-matnr AND spras = sy-langu.
endif.
if sy-subrc = 0 and i_likp is not initial.
select name1 ort01 kunnr from kna1 into table i_kna1 for all e
ntrIES IN i_likp WHERE kunnr = i_likp-kunnr.
else.
message e398(00) with 'no entries found'.
endif.
wa_final-werks = wa_lips-werks.
wa_final-lgort = wa_lips-lgort.
wa_final-kunnr = wa_likp-kunnr.
wa_final-name1 = wa_kna1-name1.
wa_final-ort01 = wa_kna1-ort01.
wa_final-vbeln_vbrk = wa_vbrk-vbeln.
wa_final-posnr_vbrp = wa_vbrp-posnr.
wa_final-fkdat = wa_vbrk-fkdat.
wa_final-bukrs = wa_vbrk-bukrs.
wa_final-netwr = wa_vbrk-netwr.
append wa_final to i_final.
endif.
endif.
endif.
endif.
endif.
endif.
*
endloop.
if p_down = 'X'.
perform download.
endif.
if p_mail = 'X'.
perform mail .
endif.
if p_dis = 'X'.
perform build_fieldcatalog.
perform alvdisplay.
else.
perform normal_display.
endif.
where
endif.
if sy-subrc = 0 and i_vbrp is not initial.
select vbeln vgbel vgpos posnr werks lgort from lips into table
i_lips FOR ALL ENTRIES IN i_vbrp WHERE vbeln = i_vbrp-vgbel AND posnr
= i_vbrp-vgpos.
endif.
if sy-subrc = 0 and i_lips is not initial.
select vbeln vstel lfdat kunnr from likp into table i_likp for
all ENTRIES IN i_lips WHERE vbeln = i_lips-vbeln.
endif.
if sy-subrc = 0 and i_lips is not initial.
select vbeln posnr matnr matkl from vbap into table i_vbap for
alL ENTRIES IN i_lips WHERE vbeln = i_lips-vgbel AND posnr = i_lipsvgpos.
endif.
if sy-subrc = 0 and i_vbap is not initial.
select vbeln audat vkorg vkgrp vkbur from vbak into table i_vb
ak FOR ALL ENTRIES IN i_vbap WHERE vbeln = i_vbap-vbeln.
endif.
if sy-subrc = 0 and i_vbak is not initial.
select vbeln posnr matnr matkl from vbap into table i_vbap for
alL ENTRIES IN i_vbak WHERE vbeln = i_vbak-vbeln.
endif.
if sy-subrc = 0 and i_vbap is not initial.
select matnr maktx spras from makt into table i_makt for all e
ntrIES IN i_vbap WHERE matnr = i_vbap-matnr AND spras = sy-langu.
endif.
if sy-subrc = 0 and i_likp is not initial.
select name1 ort01 kunnr from kna1 into table i_kna1 for all e
ntrIES IN i_likp WHERE kunnr = i_likp-kunnr.
else.
message e398(00) with 'no entries found'.
endif.
if sy-subrc = 0.
read table i_lips with key vbeln = wa_vbrp-vgbel posnr = wa_
vbrp-vgpos INTO wa_lips.
if sy-subrc = 0.
read table i_likp with key vbeln = wa_lips-vbeln into wa_li
kp.
if sy-subrc = 0.
read table i_vbap with key vbeln = wa_lips-vgbel posnr =
wa_lips-vgpos INTO wa_vbap.
if sy-subrc = 0.
read table i_vbak with key vbeln = wa_vbap-vbeln into w
a_vbak.
if sy-subrc = 0.
read table i_makt with key matnr = wa_vbap-matnr spra
s = sy-langu INTO wa_makt.
if sy-subrc = 0.
read table i_kna1 with key kunnr = wa_likp-kunnr in
to wa_kna1.
wa_final-vbeln_vbak = wa_vbak-vbeln.
wa_final-posnr_vbap = wa_vbap-posnr.
wa_final-audat = wa_vbak-audat.
wa_final-vkorg = wa_vbak-vkorg.
wa_final-vkgrp = wa_vbak-vkgrp.
wa_final-vkbur = wa_vbak-vkbur.
wa_final-matnr = wa_vbap-matnr.
wa_final-maktx = wa_makt-maktx.
wa_final-matkl = wa_vbap-matkl.
wa_final-vbeln_likp = wa_likp-vbeln.
wa_final-posnr_lips = wa_lips-posnr.
wa_final-vstel = wa_likp-vstel.
wa_final-lfdat = wa_likp-lfdat.
wa_final-werks = wa_lips-werks.
wa_final-lgort = wa_lips-lgort.
wa_final-kunnr = wa_likp-kunnr.
wa_final-name1 = wa_kna1-name1.
wa_final-ort01 = wa_kna1-ort01.
wa_final-vbeln_vbrk = wa_vbrk-vbeln.
wa_final-posnr_vbrp = wa_vbrp-posnr.
wa_final-fkdat = wa_vbrk-fkdat.
wa_final-bukrs = wa_vbrk-bukrs.
wa_final-netwr = wa_vbrk-netwr.
append wa_final to i_final.
endif.
endif.
endif.
endif.
endif.
endif.
endloop.
if p_down = 'X'.
perform download.
endif.
if p_mail = 'X'.
perform mail .
endif.
if p_dis = 'X'.
perform build_fieldcatalog.
perform alvdisplay.
else.
perform normal_display.
endif.
endif.
*&--------------------------------------------------------------------*
*&
Form BUILD_FIELDCATALOG
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
form download.
if p_down = 'X'.
type-pools:abap.
data : fullpath
filename
path
user_action
encoding
type
type
type
TYPE
type
string,
string,
string,
i,
abap_encoding.
if p_file is initial.
call method cl_gui_frontend_services=>file_save_dialog
exporting
window_title
= 'Gui_Download Demo'
with_encoding
= 'X'
initial_directory
= 'D:\'
changing
filename
= filename
path
= path
fullpath
= fullpath
" user_action
= user_action
file_encoding
= encoding
exceptions
cntl_error
= 1
error_no_gui
= 2
not_supported_by_gui = 3
others
= 4.
if sy-subrc <> 0.
exit.
endif.
*
*
*
* "FORM f_get_file_name .
* CALL FUNCTION 'F4_FILENAME'
* EXPORTING
*
program_name
= syst-cprog
**
DYNPRO_NUMBER
= SYST-DYNNR
*
field_name
= 'P_FILE'
* IMPORTING
*
file_name
= p_file.
endif.
p_string = fullpath.
*
*
*
*
*
*
*
=
= p_string
= 'DAT'
= ' '
= ' '
= '00'
= ' '
= 'X'
= ' '
= ' '
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
DAT_MODE
= ' '
CONFIRM_OVERWRITE
= ' '
NO_AUTH_CHECK
= ' '
CODEPAGE
= ' '
IGNORE_CERR
= ABAP_TRUE
REPLACEMENT
= '#'
WRITE_BOM
= ' '
TRUNC_TRAILING_BLANKS_EOL
= 'X'
WK1_N_FORMAT
= ' '
WK1_N_SIZE
= ' '
WK1_T_FORMAT
= ' '
WK1_T_SIZE
= ' '
WRITE_LF_AFTER_LAST_LINE
= ABAP_TRUE
SHOW_TRANSFER_STATUS
= ABAP_TRUE
IMPORTING
FILELENGTH
=
tables
data_tab
= i_final
*
FIELDNAMES
=
exceptions
file_write_error
= 1
no_batch
= 2
gui_refuse_filetransfer
= 3
invalid_type
= 4
no_authority
= 5
unknown_error
= 6
header_not_allowed
= 7
separator_not_allowed
= 8
filesize_not_allowed
= 9
header_too_long
= 10
dp_error_create
= 11
dp_error_send
= 12
dp_error_write
= 13
unknown_dp_error
= 14
access_denied
= 15
dp_out_of_memory
= 16
disk_full
= 17
dp_timeout
= 18
file_not_found
= 19
dataprovider_exception
= 20
control_flush_error
= 21
others
= 22
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
"DOWNLOAD
*&-------------------------------------------------------------------
--*
*&
Form build_fieldcatalog
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
form build_fieldcatalog .
fieldcatalog-fieldname = 'VBELN_VBAK'.
fieldcatalog-seltext_m = 'sales document no'.
fieldcatalog-col_pos = 1.
fieldcatalog-emphasize = 'X'.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'POSNR_VBAP'.
fieldcatalog-seltext_m = 'sales document item'.
fieldcatalog-col_pos = 2.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'AUDAT'.
fieldcatalog-seltext_m = 'SD creation Date'.
fieldcatalog-col_pos = 3.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'VKORG'.
fieldcatalog-seltext_m = 'sales organisation'.
fieldcatalog-col_pos = 4.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'VKGRP'.
fieldcatalog-seltext_m = 'sales group'.
fieldcatalog-col_pos = 5.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'VKBUR'.
fieldcatalog-seltext_m = 'sales office'.
fieldcatalog-col_pos = 6.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'material'.
fieldcatalog-col_pos = 7.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'MAKTX'.
fieldcatalog-seltext_m = 'material description'.
fieldcatalog-col_pos = 8.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'MATKL'.
fieldcatalog-seltext_m = 'material group'.
fieldcatalog-col_pos = 9.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname
fieldcatalog-seltext_m
fieldcatalog-col_pos =
fieldcatalog-emphasize
append fieldcatalog .
clear fieldcatalog.
= 'VBELN_LIKP'.
= 'delivery document no'.
10.
= 'X'.
fieldcatalog-fieldname = 'POSNR_LIPS'.
fieldcatalog-seltext_m = 'delivery document item'.
fieldcatalog-col_pos = 11.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'VSTEL'.
fieldcatalog-seltext_m = 'shipping point'.
fieldcatalog-col_pos = 12.
append fieldcatalog .
clear fieldcatalog.
*
fieldcatalog-fieldname = 'LFDAT'.
fieldcatalog-seltext_m = 'delivery date'.
fieldcatalog-col_pos = 13.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'WERKS'.
fieldcatalog-seltext_m = 'plant'.
fieldcatalog-col_pos = 14.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'LGORT'.
fieldcatalog-seltext_m = 'storage location'.
fieldcatalog-col_pos = 15.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'KUNNR'.
fieldcatalog-seltext_m = 'ship to party'.
fieldcatalog-col_pos = 16.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'NAME1'.
fieldcatalog-seltext_m = 'ship to party name'.
fieldcatalog-col_pos = 17.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'ORT01'.
fieldcatalog-seltext_m = 'ship to party city'.
fieldcatalog-col_pos = 18.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname
fieldcatalog-seltext_m
fieldcatalog-col_pos =
fieldcatalog-emphasize
append fieldcatalog .
clear fieldcatalog.
= 'VBELN_VBRK'.
= 'billing document no'.
19.
= 'X'.
fieldcatalog-fieldname = 'POSNR_VBRP'.
fieldcatalog-seltext_m = 'billing document item'.
fieldcatalog-col_pos = 20.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'FKDAT'.
fieldcatalog-seltext_m = 'billing date'.
fieldcatalog-col_pos = 21.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'BUKRS'.
fieldcatalog-seltext_m = 'company code'.
fieldcatalog-col_pos = 22.
append fieldcatalog .
clear fieldcatalog.
fieldcatalog-fieldname = 'NETWR'.
fieldcatalog-seltext_m = 'net value'.
fieldcatalog-col_pos = 23.
fieldcatalog-do_sum = 'X'.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog .
clear fieldcatalog.
* CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
*
EXPORTING
*
I_PROGRAM_NAME
= 'ZSR_427000'
*
I_INTERNAL_TABNAME
= i_final[]
*
I_STRUCTURE_NAME
= i_final
**
I_CLIENT_NEVER_DISPLAY
= 'X'
**
I_INCLNAME
=
**
I_BYPASSING_BUFFER
=
**
I_BUFFER_ACTIVE
=
*
CHANGING
*
ct_fieldcat
= fieldcatalog
*
EXCEPTIONS
*
INCONSISTENT_INTERFACE
= 1
*
PROGRAM_ERROR
= 2
*
OTHERS
= 3
*
.
* IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.
endform.
" BUILD_FIELDCATALOG
*&--------------------------------------------------------------------*
*&
Form ALVDISPLAY
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
form alvdisplay .
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
IS_SEL_HIDE
*
I_DEFAULT
*
*
i_save
*
IS_VARIANT
*
IT_EVENTS
*
IT_EVENT_EXIT
*
IS_PRINT
*
IS_REPREP_ID
*
I_SCREEN_START_COLUMN
*
I_SCREEN_START_LINE
*
I_SCREEN_END_COLUMN
*
I_SCREEN_END_LINE
*
I_HTML_HEIGHT_TOP
*
I_HTML_HEIGHT_END
*
IT_ALV_GRAPHICS
*
IT_HYPERLINK
*
IT_ADD_FIELDCAT
*
IT_EXCEPT_QINFO
*
IR_SALV_FULLSCREEN_ADAPTER
* IMPORTING
*
E_EXIT_CAUSED_BY_CALLER
*
ES_EXIT_CAUSED_BY_USER
tables
t_outtab
exceptions
program_error
others
=
= 'X'
= 'X'
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
0
0
0
0
0
0
=
=
= i_final
= 1
= 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
" ALVDISPLAY
*&--------------------------------------------------------------------*
*&
Form DOWNLOAD
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
form mail .
concatenate wa_final-vbeln_vbak
wa_final-posnr_vbap
wa_final-audat
wa_final-vkorg
wa_final-vkgrp
wa_final-vkbur
wa_final-matnr
wa_final-maktx
wa_final-matkl
wa_final-vbeln_likp
wa_final-posnr_lips
wa_final-vstel
wa_final-lfdat
wa_final-werks
wa_final-lgort
wa_final-kunnr
wa_final-name1
wa_final-ort01
wa_final-vbeln_vbrk
wa_final-posnr_vbrp
wa_final-fkdat
wa_final-bukrs
into objcont-line separated by space.
append objcont.
endloop.
* insert receiver (sap name)
refresh receiver.
clear receiver.
move: sy-uname to receiver-receiver,
'X'
to receiver-express,
'B'
to receiver-rec_type.
append receiver.
* insert mail description
write 'Sending a mail through abap'
to doc_data-obj_descr.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data
= doc_data
importing
new_object_id
= object_id
tables
object_content
= objcont
receivers
= receiver
exceptions
too_many_receivers
= 1
document_not_sent
= 2
document_type_not_exist
= 3
operation_no_authorization = 4
parameter_error
x_error
enqueue_error
others
=
=
=
=
5
6
7
8.
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
"mail
*&--------------------------------------------------------------------*
*&
Form NORMAL_DISPLAY
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
form normal_display .
endform.
" NORMAL_DISPLAY