‎2007 Apr 03 3:28 PM
Hi friends,
I got a task on BADI for validating the fields for creating sales order (BADI_SD_SALES_ITEM and BADI_SD_SALES_BASIC)
Could any one give process and some sample code to do it.
Please do the needful
‎2007 Apr 04 9:35 AM
Hi , in order to use this badi ,
U need to create implementation for these BADI .
GO to se18 wirte name of BADI . click on implemenation->create .
Now go to interface tab .
Double click on method .
Eg 1. ITEM_PRICING_COM_I.
Now write code over there
*--> FIll TKOMP-CAMPAIGN
DATA: ls_tkomp TYPE komp.
FIELD-SYMBOLS:
<fvbkd> TYPE ANY.
ASSIGN ('FVBKD') TO <fvbkd>.
IF sy-subrc NE 0.
*--> abort
EXIT.
ENDIF.
ls_tkomp = ftkomp.
CALL FUNCTION 'CMPD_SALES_PRICING_PREP'
EXPORTING
i_vbkd = <fvbkd>
CHANGING
ie_komp = ls_tkomp.
*--> set new value
ftkomp = ls_tkomp.
Eg2. ITEM_FREEGOOD_COM_I
DATA: ls_tkomp TYPE komp.
ls_tkomp = ftkomp.
CALL FUNCTION 'CMPD_SALES_PRICING_PREP'
EXPORTING
i_vbkd = fvbkd
CHANGING
ie_komp = ls_tkomp.
*--> set new value
ftkomp = ls_tkomp.
Reward Points , if Helpful
Regards manoj .
‎2007 Apr 04 9:41 AM
Ramesh,
The BADI BADI_SD_SALES_ITEM is designed as internal BADI; the implementation can only be done, if the BADI is set to external. The property of a BADI is stored in the table sxs_attr. The flag internal must be cleared to use the BADI as external. The following short program will show you an example:
report z_xpra_upd_badi_def.
data: gt_prot type table of sprot_u,
gs_prot type sprot_u,
gv_simulate type xflag.
Constant Definitions for Protocoll:
constants:
gc_error_fatal value 'E', " Error message with stop_upgrade
gc_error value 'P', " Error message: no prod use!
gc_success value space, " Success
gc_info value space, " Info
gc_warning value 'W', " Warning
gc_lv_error type n value 2, " Level for type 'E'
gc_lv_add_error type n value 2, " Level for additional info
gc_lv_warning type n value 2, " This could be either 2 or 3
gc_lv_success type n value 3, " Success only at 3
gc_lv_info type n value 4, " Info-messages only at 3 or 4
gc_lv_debug type n value 4. " Additional info for yourself
start-of-selection.
----
gv_simulate = space.
perform bc_action using 'BADI_SD_SALES_ITEM'
gv_simulate.
Finally, the transport protocol will be added:
call function 'TR_APPEND_LOG'
tables
xmsg = gt_prot
exceptions
others = 5.
call function 'TR_FLUSH_LOG'.
END OF PROGRAM
&----
*& Form bc_action
&----
Function description/flow
----
Used global variables:
Read/Write
----
form bc_action using li_badi_def type sxs_attr-exit_name
li_simulate type xflag.
data: ls_sxs_attr type sxs_attr.
select single * into ls_sxs_attr
from sxs_attr client specified
where exit_name = li_badi_def.
if sy-subrc = 0.
if not ls_sxs_attr-internal is initial.
if gv_simulate is initial.
clear ls_sxs_attr-internal.
update sxs_attr client specified
from ls_sxs_attr.
endif.
if sy-subrc = 0.
perform bc_append_log using gc_lv_success
gc_success
'5@'
'000'
li_badi_def
text-001
sy-dbcnt
space.
else.
perform bc_append_log using gc_lv_error
gc_error
'5@'
'000'
li_badi_def
text-002
sy-subrc
space.
endif.
else.
perform bc_append_log using gc_lv_success
gc_success
'5@'
'000'
li_badi_def
text-003
space
space.
endif.
else.
perform bc_append_log using gc_lv_success
gc_success
'5@'
'000'
li_badi_def
text-004
space
space.
endif.
endform. "ACTION
&----
*& Form bc_append_log
&----
Function description/flow
----
Used global variables:
Read/Write
----
form bc_append_log using li_level type sprot_u-level " Level
li_severity type sprot_u-severity " Severity
li_ag type sprot_u-ag " Message-ID
li_msgnr type sprot_u-msgnr " Messagenumb
li_var1
li_var2
li_var3
li_var4.
clear gs_prot.
gs_prot-level = li_level.
gs_prot-severity = li_severity.
gs_prot-langu = sy-langu.
gs_prot-ag = li_ag.
gs_prot-msgnr = li_msgnr.
gs_prot-newobj = space.
gs_prot-var1 = li_var1.
gs_prot-var2 = li_var2.
gs_prot-var3 = li_var3.
gs_prot-var4 = li_var4.
append gs_prot to gt_prot.
endform. " bc_bc_append_log
This report can be used as XPRA run; for this you need to assign this report in a transport with property object type XPRA. After importing the transport the report will be started automatically.
Please handle this proposal solution carefully.
I found an approach for a solution; I'd like to provide you this solution in the following short summary:
Definition BADI_SD_SALES_ITEM, Method ITEM_PROCESS
To set up the serial numbers to be assigned, first, you need a kind of buffer, in which the serial number get be transferred from outside to the function group 2032. I use the export/import memory function (export [parameter] from ti id 'MEMORY_NAME) to get/set the serial numbers.
Next, I read the already assigned serial numbers from the tables SER02 and OBJK.
Then I merge the imported serial numbers with the actual serial numbers in DB to decide for deletions and inserts
Based on the prior selected serial numbers I call the corresponding function modules to delete or insert the serial numbers (in buffer)
Process Serial Numbers (Deletion):
loop at lt_serial_no_ins assigning <serial_no>.
...
call function 'SERNR_DEL_FROM_AU'
exporting
sernr = <serial_no>-serial_no
material = fvbap-matnr
document = fvbap-vbeln
item = fvbap-posnr
importing
anzsn = fvbap-anzsn
serial_commit = lv_dataloss
exceptions
serialnumber_errors = 1
serialnumber_warnings = 2
others = 3.
...
endloop.
Process Serial Numbers (Inserts):
loop at lt_serial_no_ins assigning <serial_no>.
...
call function 'SERNR_ADD_TO_AU'
exporting
sernr = <serial_no>-serial_no
profile = fvbap-serail
material = fvbap-matnr
quantity = 1
cuobj = fvbap-cuobj
document = fvbap-vbeln
item = fvbap-posnr
debitor = ls_vbak-kunnr
vbtyp = ls_vbak-vbtyp
sd_auart = ls_vbak-auart
sd_postyp = fvbap-pstyv
importing
anzsn = fvbap-anzsn
serial_commit = lv_dataloss
exceptions
konfigurations_error = 1
serialnumber_errors = 2
serialnumber_warnings = 3
others = 4.
...
emdloop.
After this all the serial numbers are stored in the buffer of function group IPW1
Next, the stored serial numbers in IPW1 will be posted by the post process, this will be done also by a BadI (see Next)
Definition BADI_SD_SALES, Method SAVE_DOCUMENT
Using Check Handling with Operation SDAP for Update:
call function 'SERIALPROFILE_CHECK'
exporting
operation = 'SDAP'
tables
tab_cuobj = lt_dbcuobj.
To use the above mentioned BadIs, you have to consider the following:
The Badis are provided with package VA_BADI
This BadIs are all internally
To use / create a implementation you have to set the internal to external (Table SXS_ATTR, Field INTERNAL)
The best way is to write a report, in which the flag will be set for definite BadIs, so this report can be link as XPRA in the transport request; for this you have to set the following additional entry in the transport request:
R3TR XPRA Z_GEMINI_XPRA_UPD_BADI_DEF
Don't forget toreward if useful.