Hello,
i give a programming for withholding tax code upload in vendor master through BDC.
*&---------------------------------------------------------------------*
*& Report ZFIR_FK02_NEW
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
************************************************************************
* PROGRAM INFORMATION
************************************************************************
* PROGRAM....... ZFIB_FK02_WITHHOLDINGTAX
* TITLE......... WITHHOLDING TAX CODE UPDATE IN VENDOR MASTER
* AUTHOR........ SABYASACHI KARFORMA
* START DATE.... 11/07/2013
* END DATE.......11/07/2013
* DEV.CLASS......ZFI
* TCODE..........
* R/3 RELEASE....SAP ECC 6.0
* TRANSPORTNR....AEDK900270
* COPIED FROM... N/A
*---------------------------------------------------------------------
* PROGRAM FUNCTION:
* This conversion program is to Upload WITHHOLDING TAX CODE UPDATE IN VENDOR MASTER.
*---------------------------------------------------------------------
* PROGRAM TYPE.. Executable
* LOGICAL DB.... N/A
************************************************************************
************************************************************************
* CHANGE HISTORY
************************************************************************
* DATE CHANGE... <Date of change written>
* AUTHOR........ <Author name>
* CHANGE DESCR.. <Description of change>
* R/3 RELEASE... <Release>
* TRANSPORTNR... <Transport number>
************************************************************************
************************************************************************
report zfib_fk02_withholdingtax.
type-pools: truxs.
data : it_intern type alsmex_tabline occurs 0 with header line ,
ls_itab type alsmex_tabline.
data : t_bdcdata type table of bdcdata,
w_bdcdata like line of t_bdcdata.
types : begin of ty_final,
lifnr type lfa1-lifnr, " vendor No
bukrs type bukrs, " company code
witht1 type witht, " Indicator for withholding tax type
wt_withcd1 type wt_withcd, " Withholding tax code
t_subjct1 type wt_subjct, " Subject to withholding tax
qsrec1 type qsrec, " Type of recipient
end of ty_final.
data : lt_final type table of ty_final,
ls_final like line of lt_final.
selection-screen begin of block b1 with frame.
parameters : p_flname type rlgrap-filename.
selection-screen end of block b1.
initialization.
clear : ls_final.
refresh : lt_final.
at selection-screen on value-request for p_flname.
call function 'KD_GET_FILENAME_ON_F4'
exporting
field_name = 'P_FLNAME'
changing
file_name = p_flname
exceptions
mask_too_long = 1
others = 2.
start-of-selection.
perform excel_upload.
perform update_data.
*&---------------------------------------------------------------------*
*& Form excel_upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form excel_upload.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_flname
i_begin_col = '0001'
i_begin_row = '0003'
i_end_col = '0040'
i_end_row = '9999'
tables
intern = it_intern
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
**********************
data : lv_index type i.
field-symbols <fs>.
sort it_intern by row col.
clear it_intern.
loop at it_intern.
move it_intern-col to lv_index.
assign component lv_index of structure ls_final to <fs>.
move it_intern-value to <fs>.
at end of row.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = ls_final-lifnr
importing
output = ls_final-lifnr.
append ls_final to lt_final.
clear ls_final.
endat.
endloop.
endform. "excel_upload
*&---------------------------------------------------------------------*
*& Form bdc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form update_data.
data : lt_lfbw type table of flfbw,
ls_lfbw type flfbw.
data : lt_lfbw_old type table of lfbw,
ls_lfbw_old type lfbw.
if not lt_final[] is initial.
select * from lfbw into table lt_lfbw_old
for all entries in lt_final
where lifnr = lt_final-lifnr
and bukrs = lt_final-bukrs
and witht = lt_final-witht1
and wt_withcd = lt_final-wt_withcd1
and wt_subjct = lt_final-t_subjct1
and qsrec = lt_final-qsrec1.
endif.
* BREAK-POINT.
loop at lt_final into ls_final.
clear ls_lfbw.
refresh lt_lfbw.
ls_lfbw-mandt = sy-mandt.
ls_lfbw-lifnr = ls_final-lifnr.
ls_lfbw-bukrs = ls_final-bukrs.
ls_lfbw-witht = ls_final-witht1.
ls_lfbw-wt_withcd = ls_final-wt_withcd1.
ls_lfbw-wt_subjct = ls_final-t_subjct1.
ls_lfbw-qsrec = ls_final-qsrec1.
clear ls_lfbw_old.
read table lt_lfbw_old into ls_lfbw_old
with key lifnr = ls_final-lifnr
bukrs = ls_final-bukrs
witht = ls_final-witht1
wt_withcd = ls_final-wt_withcd1
wt_subjct = ls_final-t_subjct1
qsrec = ls_final-qsrec1.
if sy-subrc eq 0.
ls_lfbw-kz = 'U'.
else.
ls_lfbw-kz = 'I'.
endif.
append ls_lfbw to lt_lfbw.
call function 'FI_WT_VENDOR_UPDATE'
tables
t_xlfbw = lt_lfbw
t_ylfbw = lt_lfbw.
if sy-subrc eq 0.
commit work.
else.
write :/ 'Error in Record --', ls_final-lifnr, '..', ls_final-bukrs, '..',
ls_final-witht1, '..', ls_final-wt_withcd1.
endif.
clear ls_final.
endloop.
sort lt_final by lifnr.
delete adjacent duplicates from lt_final comparing lifnr.
* BREAK-POINT.
loop at lt_final into ls_final.
perform bdc_dynpro using 'SAPMF02K' '0106'.
perform bdc_field using 'BDC_CURSOR' 'RF02K-D0610'.
perform bdc_field using 'BDC_OKCODE' '/00'.
perform bdc_field using 'RF02K-LIFNR' ls_final-lifnr.
perform bdc_field using 'RF02K-BUKRS' ls_final-bukrs.
perform bdc_field using 'RF02K-D0610' 'X'.
perform bdc_dynpro using 'SAPMF02K' '0610'.
perform bdc_field using 'BDC_OKCODE' 'ENTR'.
perform bdc_field using 'BDC_CURSOR' 'LFBW-QSREC(01)'.
perform bdc_field using 'LFB1-QLAND' 'IN'.
call transaction 'FK02' using t_bdcdata
mode 'E'.
if sy-subrc eq 0.
commit work.
endif.
clear t_bdcdata[].
endloop.
endform. "update_data
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear w_bdcdata.
w_bdcdata-program = program.
w_bdcdata-dynpro = dynpro.
w_bdcdata-dynbegin = 'X'.
append w_bdcdata to t_bdcdata.
endform. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
clear w_bdcdata.
w_bdcdata-fnam = fnam.
w_bdcdata-fval = fval.
append w_bdcdata to t_bdcdata.
endform. "bdc_field
Regards
Sabyasachi