1. From Z Program
2. From Standard Program
1. From Z Program :
*&---------------------------------------------------------------------*
*& Report Z_SD_L_SALES_CONTRACT_UNIT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report z_sd_l_sales_contract_unit.
*********************************************************************
* Tables *
*********************************************************************
tables: vbak, "Sales Document: Header Data
vbap, "Sales Document: Item Data
vbkd, "Sales Document: Business Data
konv, "Conditions (Transaction Data)
vbpa. "Sales Document: Partner
********************************************************************
* Types Declaration *
********************************************************************
*-- Sales Document: Header Data
types: begin of t_vbak,
vbeln type vbak-vbeln, "Sales Document
erdat type vbak-erdat, "Date on which the record was crtd
auart type vbak-auart, "Sales Document Type
waerk type vbak-waerk, "SD document currency
knumv type vbak-knumv, "Number of the document condition
kunnr type vbak-kunnr, "sold-to-party
bukrs_vf type vbak-bukrs_vf, "Company code to be billed
vkorg type vbak-vkorg,
end of t_vbak,
*-- Sales Document: Item Data
begin of t_vbap,
vbeln type vbap-vbeln, "Sales Document
posnr type vbap-posnr, "Sales Document Item
matnr type vbap-matnr, "Material Number
matkl type vbap-matkl, "Material group
arktx type vbap-arktx, "Short text for sales order item
kdmat type vbap-kdmat, "Material Number Used by Cust
kwmeng type vbap-kwmeng, "Cumulative order quan in sales units
vrkme type vbap-vrkme, "Weight Unit
vgbel type vbap-vgbel, "Document number of the reference document
vgpos type vbap-vgpos, "Item number of the reference item
werks type vbap-werks, "Plant
* abgru TYPE vbap-abgru, "Reason for rejection
end of t_vbap,
*-- Sales Document: Business Data
begin of t_vbkd,
vbeln type vbkd-vbeln, "Sales Document
posnr type vbkd-posnr, "Sales Document Item
inco1 type vbkd-inco1, "Incoterms (part 1)
inco2 type vbkd-inco2, "Incoterms (part 1)
zterm type vbkd-zterm, "Terms of payment key
bstkd type vbkd-bstkd, "Customer purchase order number
bstdk type vbkd-bstdk, "Customer purchase order date
end of t_vbkd,
*-- Conditions (Transaction Data)
begin of t_konv,
knumv type konv-knumv, "Number of the doc condition
kposn type konv-kposn, "Condition item number
kbetr type konv-kbetr, "Rate
kwert type konv-kwert, "Condition value
kschl type konv-kschl, "Condition type
end of t_konv,
*-- Sales Item (Additional DataB)
begin of t_zsoi1,
vbeln type zsoi1-vbeln, "Sales Document
posnr type zsoi1-posnr, "Sales Document Item
crn type zsoi1-crn, "Customer REF NO
cpo type zsoi1-cpo, "Customer PO NO
fini type zsoi1-fini, "Finish Type
ppc type zsoi1-ppc, "PPC Delivery Date
rem type zsoi1-rem, "Remarks
end of t_zsoi1,
*-- Sales Header (Additional DataB)
* BEGIN OF t_zsoh,
* vbeln TYPE zsoh-vbeln, "Sales Document
* width TYPE zsoh-width, "Width
* pakt TYPE zsoh-pakt, "Packing Type
* picl TYPE zsoh-picl, "Piece Length
* pos TYPE zsoh-pos, "Port Of Shipment
* pod TYPE zsoh-pod , "Port Of Destination
* podi TYPE zsoh-podi, "Port Of Discharge
* mos TYPE zsoh-mos, "Mode Of Shipment
* con TYPE zsoh-con, "Container
* sm TYPE zsoh-sm, "Shipping Marks
* pric TYPE zsoh-pric, "Price
* dc TYPE zsoh-dc, "Destination Country
* END OF t_zsoh,
*-- Sales Document: Partner for Buyer
begin of t_buyer,
vbeln type vbpa-vbeln, "Sales Document
parvw type vbpa-parvw, "Partner function
kunnr type vbpa-kunnr, "Customer Number 1
* J_1IILSTNO type J_1IMOCUST-J_1ILSTNO, "VAT NUMBER
* J_1ICSTNO type J_1IMOCUST-J_1ICSTNO, "CST NO
end of t_buyer,
*-- Sales Document: Partner for Consignee
begin of t_cons,
vbeln type vbpa-vbeln, "Sales Document
parvw type vbpa-parvw, "Partner function
kunnr type vbpa-kunnr, "Customer Number 1
end of t_cons,
*-- Sales Document: Partner for Notify
begin of t_not,
vbeln type vbpa-vbeln, "Sales Document
parvw type vbpa-parvw, "Partner function
lifnr type vbpa-lifnr, "Customer Number 1
end of t_not.
*-------------------------------------------------------------------*
*-- Internal table declarations *
*-------------------------------------------------------------------*
data: i_vbak type table of t_vbak,
i_vbap type table of t_vbap,
i_vbkd type table of t_vbkd,
i_buyer type table of t_buyer,
i_zsoi1 type table of t_zsoi1,
i_zsoh1 type table of zsoh1,
i_konv type table of t_konv,
* i_disc TYPE TABLE OF t_konv,
i_cons type table of t_cons,
i_not type table of t_not,
i_final type table of zsalcon1,
i_adrc type adrc.
*-------------------------------------------------------------------*
*-- Work area declarations *
*-------------------------------------------------------------------*
data: wa_vbak type t_vbak,
wa_vbap type t_vbap,
wa_vbkd type t_vbkd,
wa_zsoi1 type t_zsoi1,
wa_zsoh1 type zsoh1,
wa_konv type t_konv,
* wa_disc TYPE t_konv,
wa_buyer type t_buyer,
wa_cons type t_cons,
wa_not type t_not,
wa_final like line of i_final.
*-------------------------------------------------------------------*
*-- Variables declaration *
*-------------------------------------------------------------------*
data: fname type rs38l_fnam.
data: v_bukrs(10) type c.
data: v_kunnrb type vbpa-kunnr.
data: v_kunnrc type vbpa-kunnr.
data: v_kunnrn type vbpa-kunnr.
data: v_knumv type vbak-knumv.
data : v_kunnr type vbak-kunnr.
data: v_tkwert type konv-kwert.
data: v_tkwmeng type vbap-kwmeng.
data: v_vbeln type vbap-vbeln,
v_str(30) type c.
data : p_vbeln type vbak-vbeln.
include rvadtabl.
*&---------------------------------------------------------------------*
*& Form ENTRY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RETURN_CODE text
* -->US_SCREEN text
*----------------------------------------------------------------------*
form entry using return_code type i
us_screen type c.
* CLEAR RETCODE.
* XSCREEN = US_SCREEN.
perform processing.
* IF RETCODE NE 0.
* RETURN_CODE = 1.
* ELSE.
* RETURN_CODE = 0.
* ENDIF.
endform. "ENTRY
**********************************************************************
*** Selection - Screen *
**********************************************************************
*PARAMETERS: p_vbeln TYPE vbak-vbeln.
*-------------------------------------------------------------------*
* START-OF-SELECTION *
*-------------------------------------------------------------------*
*START-OF-SELECTION.
form processing.
perform get_data.
perform process_data.
perform display_data.
endform. "processing
*&------------------------------------------------------------------*
*& Form get_data
*&------------------------------------------------------------------*
* text
*-------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------------------*
form get_data .
*-- Selecting Sales Document: Header Data
select vbeln erdat auart waerk knumv kunnr bukrs_vf vkorg
from vbak
into table i_vbak
where vbeln eq nast-objky.
if not i_vbak is initial.
select single *
from vbak
where vbeln eq nast-objky.
*-- Selecting Sales Document: Item Data
select vbeln posnr matnr matkl arktx kdmat kwmeng vrkme vgbel
vgpos werks "abgru
from vbap
into table i_vbap
for all entries in i_vbak
where vbeln eq i_vbak-vbeln.
* IF NOT i_vbap[] IS INITIAL.
* DELETE i_vbap WHERE abgru NE space.
* ENDIF.
* READ TABLE i_vbap INTO wa_vbap INDEX 1.
* IF wa_vbap-werks NE '1100'.
* LEAVE TO SCREEN 0.
* ENDIF.
*-- Selecting Sales Order Item for Additional data Details
select vbeln posnr crn cpo fini ppc rem
from zsoi1
into table i_zsoi1
for all entries in i_vbap
where vbeln eq i_vbap-vbeln
and posnr eq i_vbap-posnr.
*-- Selecting Sales Order Header for Additional data Details
select * "vbeln width pakt picl pos pod podi mos con sm pric rem dc
from zsoh1
into table i_zsoh1
for all entries in i_vbak
where vbeln eq i_vbak-vbeln.
*-- Selecting Sales Document: Item Data
select vbeln posnr inco1 inco2 zterm bstkd bstdk
from vbkd
into table i_vbkd
for all entries in i_vbak
where vbeln eq i_vbak-vbeln.
*-- Selecting Value & Rate for Conditions (Transaction Data)
if vbak-bukrs_vf = '1000'.
select knumv kposn kbetr kwert kschl
from konv
into table i_konv
for all entries in i_vbak
where kschl = 'ZP07'
and knumv eq i_vbak-knumv.
if sy-subrc is not initial.
select knumv kposn kbetr kwert kschl
from konv
into table i_konv
for all entries in i_vbak
where kschl in ('ZP01', 'ZP04', 'ZP05', 'ZP06')
and knumv eq i_vbak-knumv.
endif.
else.
select knumv kposn kbetr kwert kschl
from konv
into table i_konv
for all entries in i_vbak
where kschl in ('ZP01', 'ZP04', 'ZP05', 'ZP06')
and knumv eq i_vbak-knumv.
* AND kposn EQ i_vbak-
endif.
*-- Sales Document: Partner for Buyer
select vbeln parvw kunnr
from vbpa
into table i_buyer
for all entries in i_vbak
where vbeln eq i_vbak-vbeln
and parvw eq 'AG'.
*-- Sales Document: Partner for Consignee
select vbeln parvw kunnr
from vbpa
into table i_cons
for all entries in i_vbak
where vbeln eq i_vbak-vbeln
and parvw eq 'WE'.
*-- Sales Document: Partner for Notify
select vbeln parvw lifnr
from vbpa
into table i_not
for all entries in i_vbak
where vbeln eq i_vbak-vbeln
and parvw in ('ZN', 'Z0').
endif.
*-->
select single vbeln from vbak into v_vbeln where vbeln = nast-objky.
endform. " get_data
*&------------------------------------------------------------------*
*& Form process_data
*&------------------------------------------------------------------*
* text
*-------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------------------*
form process_data .
loop at i_vbap into wa_vbap.
clear v_str.
move wa_vbap-vbeln to wa_final-vbeln.
move wa_vbap-posnr to wa_final-posnr.
move wa_vbap-matnr to wa_final-matnr.
move wa_vbap-matkl to wa_final-matkl.
move wa_vbap-arktx to wa_final-arktx.
move wa_vbap-kdmat to wa_final-kdmat.
move wa_vbap-kwmeng to wa_final-kwmeng.
move wa_vbap-vrkme to wa_final-vrkme.
move wa_vbap-vgbel to wa_final-vgbel.
move wa_vbap-werks to wa_final-werks.
write wa_vbap-vgpos to wa_final-vgpos no-zero.
if wa_final-vgbel ne space.
concatenate wa_final-vgbel '/' wa_final-vgpos into v_str.
move v_str to wa_final-v_str.
endif.
v_tkwmeng = v_tkwmeng + wa_final-kwmeng.
*-- Getting record created Date from Sales Document Header Internal Table
read table i_vbak into wa_vbak with key vbeln = wa_final-vbeln.
if sy-subrc is initial.
move wa_vbak-erdat to wa_final-erdat.
move wa_vbak-waerk to wa_final-waerk.
move wa_vbak-auart to wa_final-auart.
move wa_vbak-knumv to v_knumv.
move wa_vbak-kunnr to v_kunnr.
move wa_vbak-bukrs_vf to v_bukrs.
move wa_vbak-vkorg to wa_final-vkorg.
condense v_bukrs.
endif.
*-- Getting PoNo & PoDate from Sales Document: Business Data Internal Table
read table i_vbkd into wa_vbkd with key vbeln = wa_final-vbeln
posnr = wa_final-posnr.
if sy-subrc is initial.
move wa_vbkd-inco1 to wa_final-inco1.
move wa_vbkd-inco2 to wa_final-inco2.
move wa_vbkd-bstkd to wa_final-bstkd.
move wa_vbkd-bstdk to wa_final-bstdk.
move wa_vbkd-zterm to wa_final-zterm.
endif.
*-- Getting CustRefNo,CustPONO from Sales Item(Additional Data B)
read table i_zsoi1 into wa_zsoi1 with key vbeln = wa_final-vbeln
posnr = wa_final-posnr.
if sy-subrc is initial.
move wa_zsoi1-crn to wa_final-crn.
move wa_zsoi1-cpo to wa_final-cpo.
move wa_zsoi1-fini to wa_final-fini.
move wa_zsoi1-ppc to wa_final-ppc.
move wa_zsoi1-rem to wa_final-remi.
endif.
*-- Getting CustRefNo,CustPONO from Sales Header(Additional Data B)
read table i_zsoh1 into wa_zsoh1 with key vbeln = wa_final-vbeln.
if sy-subrc is initial.
move wa_zsoh1-pric to wa_final-pric.
move wa_zsoh1-pakt to wa_final-pakt.
move wa_zsoh1-width to wa_final-width.
move wa_zsoh1-pos to wa_final-pos.
move wa_zsoh1-pod to wa_final-pod.
move wa_zsoh1-podi to wa_final-podi.
move wa_zsoh1-sm to wa_final-sm.
move wa_zsoh1-mos to wa_final-mos.
move wa_zsoh1-con to wa_final-con.
move wa_zsoh1-dc to wa_final-dc.
move wa_zsoh1-picl to wa_final-picl.
endif.
*-- Getting Rate & Value from Conditions (Transaction Data)
read table i_konv into wa_konv with key knumv = wa_vbak-knumv
kposn = wa_final-posnr.
if sy-subrc eq 0.
if ( wa_vbak-auart = 'OR10' ) or ( wa_vbak-auart = 'OR11' ).
if wa_konv-kschl = 'ZP01'.
wa_final-kbetr = wa_konv-kbetr / 10.
move wa_konv-kwert to wa_final-kwert.
v_tkwert = v_tkwert + wa_final-kwert.
endif.
elseif ( wa_vbak-auart = 'OR50' ) or ( wa_vbak-auart = 'OR51' ).
if ( wa_konv-kschl = 'ZP04' ) or ( wa_konv-kschl = 'ZP05' )
or ( wa_konv-kschl = 'ZP06' ).
wa_final-kbetr = wa_konv-kbetr / 10.
move wa_konv-kwert to wa_final-kwert.
v_tkwert = v_tkwert + wa_final-kwert.
endif.
endif.
endif.
*-- Getting Buyer Number from Sales Document: Partner
read table i_buyer into wa_buyer with key vbeln = wa_final-vbeln.
if sy-subrc is initial.
move wa_buyer-kunnr to v_kunnrb.
condense v_kunnrb.
endif.
*-- Getting Consignee Number from Sales Document: Partner
read table i_cons into wa_cons with key vbeln = wa_final-vbeln.
if sy-subrc is initial.
move wa_cons-kunnr to v_kunnrc.
condense v_kunnrc.
endif.
*-- Getting Notify Number from Sales Document: Partner
read table i_not into wa_not with key vbeln = wa_final-vbeln.
if sy-subrc is initial.
move wa_not-lifnr to v_kunnrn.
condense v_kunnrn.
endif.
append wa_final to i_final.
clear wa_final.
endloop.
*-- Getting Buyer Number from Sales Document: Partner
read table i_vbak into wa_vbak index 1.
if sy-subrc is initial.
move wa_vbak-bukrs_vf to v_bukrs.
read table i_buyer into wa_buyer with key vbeln = wa_vbak-vbeln.
if sy-subrc is initial.
move wa_buyer-kunnr to v_kunnrb.
condense v_kunnrb.
endif.
*-- Getting Consignee Number from Sales Document: Partner
read table i_cons into wa_cons with key vbeln = wa_vbak-vbeln.
if sy-subrc is initial.
move wa_cons-kunnr to v_kunnrc.
condense v_kunnrc.
endif.
endif.
endform. " process_data
*&------------------------------------------------------------------*
*& Form display_data
*&------------------------------------------------------------------*
* text
*-------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*-------------------------------------------------------------------*
form display_data .
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'Z_SD_L_SALES_CONTRACT_UNIT'
* VARIANT = ' '
* DIRECT_CALL = ' '
importing
fm_name = fname
exceptions
no_form = 1
no_function_module = 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.
call function fname
exporting
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
* CONTROL_PARAMETERS =
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* OUTPUT_OPTIONS =
* USER_SETTINGS = 'X'
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
v_bukrs = v_bukrs
v_kunnrb = v_kunnrb
v_kunnrc = v_kunnrc
v_kunnrn = v_kunnrn
v_tkwmeng = v_tkwmeng
v_tkwert = v_tkwert
v_knumv = v_knumv
v_kunnr = v_kunnr
v_vbeln = v_vbeln
tables
i_final = i_final
exceptions
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others = 5
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
clear:i_final[],
v_tkwert.
endform. " display_data
2. From Standard Program :
*----------------------------------------------------------------------*
* Print of a invoice by SAPscript SMART FORMS *
*----------------------------------------------------------------------*
report rlb_invoice.
* declaration of data
include rlb_invoice_data_declare.
* definition of forms
include rlb_invoice_form01.
include rlb_print_forms.
*---------------------------------------------------------------------*
* FORM ENTRY
*---------------------------------------------------------------------*
form entry using return_code us_screen.
data: lf_retcode type sy-subrc.
clear retcode.
xscreen = us_screen.
perform processing using us_screen
changing lf_retcode.
if lf_retcode ne 0.
return_code = 1.
else.
return_code = 0.
endif.
endform. "ENTRY
*---------------------------------------------------------------------*
* FORM PROCESSING *
*---------------------------------------------------------------------*
form processing using proc_screen
changing cf_retcode.
data: ls_print_data_to_read type lbbil_print_data_to_read.
data: ls_bil_invoice type lbbil_invoice.
data: lf_fm_name type rs38l_fnam.
data: ls_control_param type ssfctrlop.
data: ls_composer_param type ssfcompop.
data: ls_recipient type swotobjid.
data: ls_sender type swotobjid.
data: lf_formname type tdsfname.
data: ls_addr_key like addr_key.
data: ls_dlv-land like vbrk-land1.
data: ls_job_info type ssfcrescl.
* SmartForm from customizing table TNAPR
lf_formname = tnapr-sform.
* determine print data
perform set_print_data_to_read using lf_formname
changing ls_print_data_to_read
cf_retcode.
if cf_retcode = 0.
* select print data
perform get_data using ls_print_data_to_read
changing ls_addr_key
ls_dlv-land
ls_bil_invoice
cf_retcode.
endif.
if cf_retcode = 0.
perform set_print_param using ls_addr_key
ls_dlv-land
changing ls_control_param
ls_composer_param
ls_recipient
ls_sender
cf_retcode.
endif.
if cf_retcode = 0.
* determine smartform function module for invoice
call function 'SSF_FUNCTION_MODULE_NAME'
exporting formname = lf_formname
* variant = ' '
* direct_call = ' '
importing fm_name = lf_fm_name
exceptions no_form = 1
no_function_module = 2
others = 3.
if sy-subrc <> 0.
* error handling
cf_retcode = sy-subrc.
perform protocol_update.
endif.
endif.
if cf_retcode = 0.
perform check_repeat.
if ls_composer_param-tdcopies eq 0.
nast_anzal = 1.
else.
nast_anzal = ls_composer_param-tdcopies.
endif.
ls_composer_param-tdcopies = 1.
do nast_anzal times.
* In case of repetition only one time archiving
if sy-index > 1 and nast-tdarmod = 3.
nast_tdarmod = nast-tdarmod.
nast-tdarmod = 1.
ls_composer_param-tdarmod = 1.
endif.
if sy-index ne 1 and repeat is initial.
repeat = 'X'.
endif.
* call smartform invoice
call function lf_fm_name
exporting
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
* mail_appl_obj =
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = space
is_bil_invoice = ls_bil_invoice
is_nast = nast
is_repeat = repeat
importing job_output_info = ls_job_info
* document_output_info =
* job_output_options =
exceptions formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others = 5.
if sy-subrc <> 0.
* error handling
cf_retcode = sy-subrc.
perform protocol_update.
* get SmartForm protocoll and store it in the NAST protocoll
perform add_smfrm_prot.
endif.
enddo.
* get SmartForm spoolid and store it in the NAST protocoll
data ls_spoolid like line of ls_job_info-spoolids.
loop at ls_job_info-spoolids into ls_spoolid.
if ls_spoolid ne space.
perform protocol_update_spool using '342' ls_spoolid
space space space.
endif.
endloop.
ls_composer_param-tdcopies = nast_anzal.
if not nast_tdarmod is initial.
nast-tdarmod = nast_tdarmod.
clear nast_tdarmod.
endif.
endif.
* get SmartForm protocoll and store it in the NAST protocoll
* PERFORM ADD_SMFRM_PROT.
endform. "PROCESSING