Sap Abap Sample Report
Sap Abap Sample Report
Sap Abap Sample 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.
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.
6. According to user selection display report or download report in excel format and
send e-mail to SAP inbox with excel attachment.
F. Sales office(VBAK-VKBUR)
G. Material(VBAP-MATNR)
H. Material Description(MAKT-MAKTX)
I. Material Group(VBAP-MATKL)
L. Shipping Point(LIKP-PATEL)
M. Delivery Date(LIKP-LFDAT)
N. Plant(LIPS-WERKS)
Q. Ship-to-party name(KNA1-NAME1)
R. Ship-to-party city(KNA1-ORT01)
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.
Report ZSR_427.
tables:vbak,vbap,lips,likp,vbrp,vbrk,makt,kna1,somlreci1.
type-pools:slis.
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.
*********************************************************************
******************************************
*********************************************************************
******************************************
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.
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.
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.
select vbeln vstel lfdat kunnr from likp into table i_likp where
vbeln IN s_ddocno.
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.
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.
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.
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.
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.
select vbeln vstel lfdat kunnr from likp into table i_likp for
all ENTRIES IN i_lips WHERE vbeln = i_lips-vbeln.
endif.
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.
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.
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.
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.
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.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*&-------------------------------------------------------------------
--*
*& 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.
endform. "mail
*&-------------------------------------------------------------------
--*
*& Form NORMAL_DISPLAY
*&-------------------------------------------------------------------
--*
* text
*--------------------------------------------------------------------
--*
* --> p1 text
* <-- p2 text
*--------------------------------------------------------------------
--*
form normal_display .
endloop.
Values given S_SDNO (sales doc no) field in selection screen: 83 to 160