Sunteți pe pagina 1din 28

CASESTUDY1:

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.

Detailed Functional Requirements:

1. Create a report with following in selection screen. All are optional.

A. Selection screen block 1.

i) Radiobutton (Based on sales documents)

ii) Radiobutton (Based on Delivery documents)

iii) Radiobutton( Based on Billing Documents)

iv) Sales Document Number (VBAK-VBELN)- Select option

v) Delivery Document Number(LIKP-VBELN)- Select option

vi) Billing Document Number(VBRK-VBELN)- Select option

B. Selection screen block 2.

i) Display on screen (Check Box)

ii) Send mail (Check Box)

iii) User ID (Select option with no interval)

iv) Download (Check Box)

v) File name(Parameter)
2. Enable and disable select options based on radio button selection.

3. Get sales order flow data from VBAK, VBAP, LIKP, LIPS, VBRK, and VBRP.

4. Get material text from MAKT using MATNR = VBAP-MATNR and SPRAS = SY-
LANGU.

5. Get customer information from KNA1 using KUNNR = LIKP-KUNNR.

6. According to user selection display report or download report in excel format and
send e-mail to SAP inbox with excel attachment.

7. Report need to contain the following fields:

A. Sales document number (VBAK-VBELN)

B. Sales document item (VBAP-POSNR)

C. SD creation date (VBAK-AUDAT)

D. Sales Organization (VBAK-VKORG)

E. Sales group( VBAK-VBGRP)

F. Sales office(VBAK-VKBUR)

G. Material(VBAP-MATNR)

H. Material Description(MAKT-MAKTX)

I. Material Group(VBAP-MATKL)

J. Delivery Document Number(LIKP-VBELN)

K. Delivery Documents Item(LIPS-POSNR)

L. Shipping Point(LIKP-PATEL)

M. Delivery Date(LIKP-LFDAT)

N. Plant(LIPS-WERKS)

O. Storage location( LIPS-LGORT)


P. Ship to party(LIKP-KUNNR)

Q. Ship-to-party name(KNA1-NAME1)

R. Ship-to-party city(KNA1-ORT01)

S. Billing document number(VBRK-VBELN)

T. Billing document item(VBRP-POSNR)

U. Billing date (VBRK-FKDAT)

V. Company Code(VBRK-BULRS)

W. Net value(VBRK-NETWR)

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.

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

parameters: p_saldoc radiobutton group g1 user-command a1 default 'X


',
p_deldoc radiobutton group g1 ,
p_bildoc radiobutton group g1.

select-options: s_sdno for vbak-vbeln modif id aa1,


s_ddocno for likp-vbeln modif id aa2,
s_bdocno for vbrk-vbeln modif id aa3.

selection-screen end of block b1.

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


parameters: p_dis as checkbox,
p_mail as checkbox,
p_down as checkbox,
p_file like rlgrap-filename.

select-options: s_user for somlreci1-receiver no intervals default sy


-uname.
selection-screen end of block b2.

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 of ty_vbap,
vbeln type vbeln_va,
posnr type posnr_va,
matnr type matnr,
matkl 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.

types : begin of ty_vbrp,


vbeln type vbeln_vf,
posnr type posnr_vf,
vgbel type vgbel,
vgpos type vgpos,
end of ty_vbrp.

types : begin of ty_vbrk,


vbeln type vbeln_vf,
fkdat type fkdat,
bukrs type bukrs,
netwr type netwr,
end of ty_vbrk.

types : begin of ty_makt,


matnr type matnr,
maktx type maktx,
spras type spras,
end of ty_makt.

types : begin of ty_kna1,


name1 type name1_gp,
ort01 type ort01_gp,
kunnr type kunnr,
end of ty_kna1.

types : begin of ty_final,


vbeln_vbak type vbeln_va,
posnr_vbap type posnr_va,
audat type audat,
vkorg type vkorg,
vkgrp type vkgrp,
vkbur type vkbur,
matnr type matnr,
maktx type maktx,
matkl type matkl,
vbeln_likp type vbeln_vl,
posnr_lips type posnr_vl,
vstel type vstel,
lfdat type lfdat_v,
werks type werks_d,
lgort type lgort_d,
kunnr type kunwe,
name1 type name1_gp,
ort01 type ort01_gp,
vbeln_vbrk type vbeln_vf,
posnr_vbrp type posnr_vf,
fkdat type fkdat,
bukrs type bukrs,
netwr type netwr,
end of ty_final.

data:i_vbak type standard table of ty_vbak,


wa_vbak type ty_vbak.

data:i_vbap type standard table of ty_vbap,


wa_vbap type ty_vbap.

data:i_lips type standard table of ty_lips,


wa_lips type ty_lips.

data:i_likp type standard table of ty_likp,


wa_likp type ty_likp.

data: i_vbrp type standard table of ty_vbrp,


wa_vbrp type ty_vbrp.
data : i_vbrk type standard table of ty_vbrk,
wa_vbrk type ty_vbrk.

data : i_makt type standard table of ty_makt,


wa_makt type ty_makt.

data : i_kna1 type standard table of ty_kna1,


wa_kna1 type ty_kna1.

data : i_final type standard table of ty_final,


wa_final type ty_final.

data:fieldcatalog type slis_t_fieldcat_alv with header line.

data : p_string type string.

*********************************************************************
******************************************

data doc_data like sodocchgi1.


data object_id like soodk.
data objcont like soli occurs 10 with header line.
data receiver like 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 vkgrp vkbur from vbak into table i_vbak
whERE vbeln IN s_sdno.
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 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_lips-
posnr.

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.

loop at i_vbap into wa_vbap.


read table i_vbak with key vbeln = wa_vbap-vbeln into wa_vbak.
if sy-subrc = 0.
read table i_lips with key vgbel = wa_vbap-vbeln vgpos = wa_
vbap-posnr 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_vbrp with key vgbel = wa_lips-vbeln vgpos =
wa_lips-posnr INTO wa_vbrp.
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.

elseif p_deldoc = 'X'.

select vbeln vstel lfdat kunnr from likp into table i_likp where
vbeln IN s_ddocno.

if sy-subrc = 0 and i_likp is not initial.

select vbeln vgbel vgpos posnr werks lgort from lips into table
i_lips FOR ALL ENTRIES IN i_likp WHERE vbeln = i_likp-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_lips-
vgpos.

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_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_lips-
posnr.
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.

loop at i_lips into wa_lips.


read table i_likp with key vbeln = wa_lips-vbeln into wa_likp.
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 wa_vb
ak.
if sy-subrc = 0.
read table i_vbrp with key vgbel = wa_lips-vbeln vgpos =
wa_lips-posnr INTO wa_vbrp.
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.

elseif p_bildoc = 'X'.


select vbeln fkdat bukrs netwr from vbrk into table i_vbrk where
vbeln IN s_bdocno.

if sy-subrc = 0 and i_vbrk is not initial.

select vbeln posnr vgbel vgpos from vbrp into table i_vbrp for
all ENTRIES IN i_vbrk WHERE vbeln = i_vbrk-vbeln.

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_lips-
vgpos.

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.

loop at i_vbrp into wa_vbrp.


read table i_vbrk with key vbeln = wa_vbrp-vbeln into wa_vbrk.
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 type string,
filename type string,
path type string,
* user_action TYPE i,
encoding type 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.

* IF user_action <> cl_gui_frontend_services=>action_ok.


* EXIT.
* ENDIF.

else.
fullpath = p_file.

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.

call function 'GUI_DOWNLOAD'


exporting
* BIN_FILESIZE =
filename = p_string
filetype = 'DAT'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* 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 = 'VBELN_LIKP'.
fieldcatalog-seltext_m = 'delivery document no'.
fieldcatalog-col_pos = 10.
fieldcatalog-emphasize = 'X'.
append fieldcatalog .
clear fieldcatalog.

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 = 'VBELN_VBRK'.
fieldcatalog-seltext_m = 'billing document no'.
fieldcatalog-col_pos = 19.
fieldcatalog-emphasize = 'X'.
append fieldcatalog .
clear fieldcatalog.

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 .

call function 'REUSE_ALV_GRID_DISPLAY'


exporting
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = fieldcatalog[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
*
* i_save = 'X'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* 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 = i_final
exceptions
program_error = 1
others = 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 .

loop at i_final into wa_final.

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 = 5
x_error = 6
enqueue_error = 7
others = 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 .

loop at i_final into wa_final.


write:/ 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 ,
wa_final-netwr.

endloop.

endform. " NORMAL_DISPLAY

SCREENSHOT1: Selection screen.


SCREENSHOT2: Displaying ALV (ABAP list viewer) Grid display.

Values given S_SDNO (sales doc no) field in selection screen: 83 to 160

Checkbox P_DIS when checked.

Then press F8.

S-ar putea să vă placă și