2007 Dec 18 3:34 AM
Can anyone give me a sample BDC code using call transaction method to change vendor master MK02
2007 Dec 18 3:44 AM
Hi Pradeep,
Should you be making use of the BAPI : BAPI_VENDOR_EDIT for the same requirement.
Regards
Gopi
2007 Dec 18 4:24 AM
report ZVEND_MST no standard page heading line-size
255.
*include bdcrecx1.
*parameters: dataset(132) lower case default
'c:\vend.mst'.
DO NOT CHANGE - the generated data section - DO
NOT CHANGE ***
*
If it is nessesary to change the data section use
the rules:
1.) Each definition of a field exists of two lines
2.) The first line shows exactly the comment
'* data element: ' followed with the data
element
which describes the field.
If you don't have a data element use the
comment without a data element name
3.) The second line shows the fieldname of the
structure, the fieldname must consist of
a fieldname and optional the character '_' and
three numbers and the field length in brackets
4.) Each field must be type C.
*
Generated data section with specific formatting -
DO NOT CHANGE ***
data: begin of record,
data element: LIF16
LIFNR_001(016),
data element: BUKRS
BUKRS_002(004),
data element: EKORG
EKORG_003(004),
data element: KTOKK
KTOKK_004(004),
data element: NAME1_GP
NAME1_005(035),
data element: SORTL
SORTL_006(010),
data element: LAND1_GP
LAND1_007(003),
data element: SPRAS
SPRAS_008(002),
data element: BSTWA
WAERS_009(005),
end of record.
End generated data section ***
DATA : ITAB TABLE OF RECORD WITH HEADER LINE.
start-of-selection.
*perform open_dataset using dataset.
*perform open_group.
*
*do.
*
*read dataset dataset into record.
*if sy-subrc <> 0. exit. endif.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\VENDOR.TXT'
"TEXT FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = ITAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT ITAB.
*In Loop Change Record With ITAB
like record-lifnr_001 with itab-lifnr_001
perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
record-LIFNR_001.
perform bdc_field using 'RF02K-BUKRS'
record-BUKRS_002.
perform bdc_field using 'RF02K-EKORG'
record-EKORG_003.
perform bdc_field using 'RF02K-KTOKK'
record-KTOKK_004.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
record-NAME1_005.
perform bdc_field using 'LFA1-SORTL'
record-SORTL_006.
perform bdc_field using 'LFA1-LAND1'
record-LAND1_007.
perform bdc_field using 'LFA1-SPRAS'
record-SPRAS_008.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0210'.
perform bdc_field using 'BDC_CURSOR'
'LFB1-AKONT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0215'.
perform bdc_field using 'BDC_CURSOR'
'LFB1-ZTERM'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0220'.
perform bdc_field using 'BDC_CURSOR'
'LFB5-MAHNA'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
record-WAERS_009.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'XK01'.
endLOOP..
and then pass the syntax:
CALL TRANSACTION 'VA01' USING bdcdata_tab OPTIONS FROM opt.
2007 Dec 18 6:20 AM
REPORT ZF_VENDOR_UPDATE_COM NO STANDARD PAGE HEADING
LINE-SIZE 132
LINE-COUNT 55
MESSAGE-ID ZM.
*----
SAP Tables
*----
TABLES: lfa1, "Vendor Master (General Section)
lfb1, "Vendor Master (Company Code)
lfm1, "Vendor Master (purchasing organization data)
tsac, "Communication types (central address management)
t100. "Messages
*----
Internal Tables
*----
TYPES: BEGIN OF typ_k_kbuka,
lifnr LIKE lfa1-lifnr,
bukrs LIKE lfb1-bukrs,
END OF typ_k_kbuka.
TYPES: BEGIN OF typ_tsac,
comm_type LIKE tsac-comm_type,
END OF typ_tsac.
TYPES: BEGIN OF typ_lfa1,
lifnr LIKE lfa1-lifnr,
land1 LIKE lfa1-land1,
adrnr LIKE lfa1-adrnr,
END OF typ_lfa1.
File data table.
DATA: it_kbuka TYPE HASHED TABLE OF typ_k_kbuka WITH UNIQUE KEY
lifnr bukrs WITH HEADER LINE.
DATA: it_tsac TYPE HASHED TABLE OF typ_tsac WITH UNIQUE KEY comm_type
WITH HEADER LINE.
DATA: it_lfa1 TYPE HASHED TABLE OF typ_lfa1 WITH UNIQUE KEY
lifnr WITH HEADER LINE.
DATA: BEGIN OF t_filedata OCCURS 0,
record(1000) TYPE c,
END OF t_filedata.
Vendor file layout
DATA: BEGIN OF t_vend OCCURS 0,
ekorg LIKE rf02k-ekorg,
lifnr LIKE lfa1-lifnr,
deflt_comm LIKE addr1_data-deflt_comm,
fax LIKE sza1_d0100-fax_number,
tel LIKE sza1_d0100-tel_number,
email LIKE sza1_d0100-smtp_addr ,
verkf LIKE lfm1-verkf, "Contact person
waers LIKE lfm1-waers, "Order currency
zterm LIKE lfm1-zterm, "Payment terms
webre LIKE lfm1-webre, "GR-based invoice inveri check
END OF t_vend.
DATA: BEGIN OF bdcdata OCCURS 0.
INCLUDE STRUCTURE bdcdata.
DATA: END OF bdcdata.
DATA: it_error LIKE t_vend OCCURS 0,
messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,
t_bapiad1vl TYPE TABLE OF bapiad1vl WITH HEADER LINE,
t_bapiadtel TYPE TABLE OF bapiadtel WITH HEADER LINE,
t_bapiadfax TYPE TABLE OF bapiadfax WITH HEADER LINE,
t_bapiadsmtp TYPE TABLE OF bapiadsmtp WITH HEADER LINE,
t_bapicomrem TYPE TABLE OF bapicomrem WITH HEADER LINE,
t_ret TYPE TABLE OF bapiret2 WITH HEADER LINE,
tx_bapiad1vlx TYPE TABLE OF bapiad1vlx WITH HEADER LINE,
tx_bapiadtelx TYPE TABLE OF bapiadtelx WITH HEADER LINE,
tx_bapiadfaxx TYPE TABLE OF bapiadfaxx WITH HEADER LINE,
tx_bapiadsmtx TYPE TABLE OF bapiadsmtx WITH HEADER LINE,
tx_bapicomrex TYPE TABLE OF bapicomrex WITH HEADER LINE.
For validate telephone number
DATA: g_check_address LIKE szad_field-flag VALUE 'X', "*131i
returncode LIKE szad_field-returncode.
DATA: BEGIN OF tel_table OCCURS 0.
INCLUDE STRUCTURE adtel.
DATA: END OF tel_table.
DATA: BEGIN OF error_table OCCURS 0.
INCLUDE STRUCTURE addr_error.
DATA: END OF error_table.
DATA: adrnr LIKE bapi4001_1-addr_no,
MAPPE(12),
QID LIKE APQI-QID.
*----
Constants
*----
CONSTANTS: c_true(1) TYPE c VALUE 'X',
c_false(1) TYPE c VALUE ' ',
c_tcode LIKE sy-tcode VALUE 'ME22',
c_filetype(10) TYPE c VALUE 'ASC',
c_0(1) TYPE c VALUE '0',
c_1(1) TYPE c VALUE '1',
c_2(1) TYPE c VALUE '2',
c_x(1) TYPE c VALUE 'X',
c_amper(1) TYPE c VALUE '&',
c_char_b(1) TYPE c VALUE 'B',
c_slsh(1) TYPE c VALUE '/',
c_update(1) TYPE c VALUE 'A',
c_xd01(4) TYPE c VALUE 'XD01'.
*----
Work Field Area
*----
DATA: w_validation_errors(1) TYPE c,
l_first,
w_date(10) TYPE c,
w_group LIKE bgr00-group,
w_n TYPE i,
w_lines TYPE i,
w_seq_no TYPE i VALUE 0,
w_read_ctr TYPE p,
w_process_ctr TYPE p,
w_error_ctr TYPE p,
w_txt(110) TYPE c,
e_group_opened,
smalllog(1) TYPE c VALUE 'X',
uc_filename type string,
errfile TYPE string.
*----
Selection Screen
*----
SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME TITLE text-004.
PARAMETERS: p_hdrdel(1) TYPE n,
p_filenm like RLGRAP-FILENAME OBLIGATORY,
p_erfile like RLGRAP-FILENAME.
PARAMETERS: p_testmd AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN: END OF BLOCK a.
*----
At Selection Screen Event
*----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_filenm.
Allow user to browse for file
PERFORM get_file_name CHANGING p_filenm.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_erfile.
Allow user to browse for file
PERFORM get_file_name CHANGING p_erfile.
----
at selection screen *
----
AT SELECTION-SCREEN ON p_erfile.
IF p_testmd IS INITIAL AND p_erfile IS INITIAL.
MESSAGE e398(00) WITH 'Please enter error filename'.
ENDIF.
*----
Top of Page Event
*----
TOP-OF-PAGE.
*
Print standard company header
*
PERFORM print_report_header.
*
Print column headings
*
FORMAT COLOR COL_HEADING ON.
*
WRITE: /001 text-004,
017 text-005,
040 text-006.
*
ULINE.
*
FORMAT COLOR COL_NORMAL ON.
*----
Initialization Event
*----
INITIALIZATION.
PERFORM initialisation.
*----
Start-of-selection Event
*----
START-OF-SELECTION.
WRITE sy-datum TO w_date DD/MM/YYYY.
Upload file into internal table. The file should be tab delimited
In excel save the file with extension .TXT
PERFORM read_file_data.
Validate the input file
PERFORM validate_file_data.
Create Vendor Records
IF p_testmd = c_false .
Change Vendors
PERFORM change_vendor.
PERFORM download_error.
ENDIF.
*----
End of Selection Event
*----
END-OF-SELECTION.
Write report footer or send 'No Data' message
PERFORM print_report_footer.
*----
Includes
*----
INCLUDE fzxxi001. "Routine for printing the report header
INCLUDE fzxxi002. "Routine for printing the report footer
----
Form A0100_INITIALISATION
----
Initialise variables and internal tables.
----
FORM initialisation.
REFRESH: t_filedata,
t_vend.
MOVE: 'VEND_' TO MAPPE,
SY-UZEIT TO MAPPE+5(6).
ENDFORM. " A0100_INITIALISATION
----
Form A0200_READ_FILE_DATA
----
Read and store the data from the file.
----
FORM read_file_data.
DATA: l_line TYPE i,
SUBRC LIKE SY-SUBRC.
Display program execution progress.
TEXT-002 : Read file data.............
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = text-002
EXCEPTIONS
OTHERS = 1.
Upload data file from presentation server
uc_filename = p_filenm.
PERFORM WS_UPLOAD TABLES T_VEND
USING UC_FILENAME
C_FILETYPE
'X'
CHANGING SUBRC.
SORT t_vend BY lifnr.
Delete unwanted header lines
IF NOT p_hdrdel IS INITIAL.
DELETE t_vend TO p_hdrdel.
ENDIF.
Delete any other blank line
DELETE t_vend WHERE lifnr EQ space
AND deflt_comm EQ space.
DESCRIBE TABLE t_vend LINES l_line.
IF p_hdrdel > l_line.
WRITE: / 'No of Header Lines declared are more than total lines'.
EXIT.
ENDIF.
WRITE: / 'No of Lines read and stored:', l_line.
ENDFORM. " A0200_READ_FILE_DATA
----
FORM validate_file_data *
----
........ *
----
FORM validate_file_data.
STATICS: l_flag(1) TYPE c,
l_rec LIKE sy-tabix,
l_tabix LIKE sy-tabix.
Display program execution progress.
TEXT-004 : Validate the file data ........
CLEAR: l_flag, l_tabix.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = text-004
EXCEPTIONS
OTHERS = 1.
SKIP 2.
WRITE: / 'Validating vendor''s data' COLOR COL_HEADING.
SKIP 1.
LOOP AT t_vend.
l_tabix = sy-tabix.
TRANSLATE t_vend TO UPPER CASE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_vend-lifnr
IMPORTING
output = t_vend-lifnr.
MODIFY t_vend INDEX l_tabix.
ENDLOOP.
Get vendor's details into internal tables
IF NOT t_vend IS INITIAL.
REFRESH it_tsac.
SELECT comm_type INTO TABLE it_tsac
FROM tsac
FOR ALL ENTRIES IN t_vend
WHERE comm_type = t_vend-deflt_comm.
REFRESH it_lfa1.
SELECT lifnr land1 adrnr INTO TABLE it_lfa1
FROM lfa1
FOR ALL ENTRIES IN t_vend
WHERE lifnr = t_vend-lifnr.
ENDIF.
l_rec = p_hdrdel.
LOOP AT t_vend.
l_tabix = sy-tabix.
CLEAR w_txt.
l_rec = l_rec + 1.
check if vendor exist.
READ TABLE it_lfa1 WITH TABLE KEY lifnr = t_vend-lifnr.
IF sy-subrc NE 0.
clear w_txt.
w_validation_errors = c_true.
CONCATENATE 'Error-Vendor' t_vend-lifnr 'does not exist'
INTO w_txt SEPARATED BY space.
WRITE: / 'Row No:', l_rec, w_txt.
ENDIF.
Check standard communication type
READ TABLE it_tsac WITH TABLE KEY comm_type = t_vend-deflt_comm.
IF sy-subrc NE 0.
clear w_txt.
w_validation_errors = c_true.
CONCATENATE 'Error-Com' t_vend-deflt_comm 'does not exist'
INTO w_txt SEPARATED BY space.
WRITE: / 'Row No:', l_rec, w_txt.
ENDIF.
Check Telephone number
perform check_telephone.
loop at error_table.
SELECT SINGLE * FROM t100 WHERE sprsl = sy-langu
AND arbgb = error_table-msg_id
AND msgnr = error_table-msg_number.
IF sy-subrc = 0.
w_txt = t100-text.
IF w_txt CS '&1'.
REPLACE '&1' WITH error_table-msg_var1 INTO w_txt.
REPLACE '&2' WITH error_table-msg_var2 INTO w_txt.
REPLACE '&3' WITH error_table-msg_var3 INTO w_txt.
REPLACE '&4' WITH error_table-msg_var4 INTO w_txt.
ELSE.
REPLACE '&' WITH error_table-msg_var1 INTO w_txt.
REPLACE '&' WITH error_table-msg_var2 INTO w_txt.
REPLACE '&' WITH error_table-msg_var3 INTO w_txt.
REPLACE '&' WITH error_table-msg_var4 INTO w_txt.
ENDIF.
CONDENSE w_txt.
ELSE.
w_txt = error_table.
ENDIF.
if error_table-msg_type = 'E' or error_table-msg_type = 'A'.
w_validation_errors = c_true.
concatenate 'Error-' w_txt into w_txt.
else.
concatenate 'Warning-' w_txt into w_txt.
endif.
WRITE: / 'Row No:', l_rec, w_txt.
ENDLOOP.
refresh error_table.
For Purchasing view
IF NOT T_VEND-EKORG IS INITIAL.
SELECT SINGLE * FROM LFM1 WHERE LIFNR = T_VEND-LIFNR
AND EKORG = T_VEND-EKORG.
IF SY-SUBRC NE 0. "Create
Check Order Currency - cannot be blank if create Purchasing View
IF T_VEND-WAERS IS INITIAL.
clear w_txt.
w_validation_errors = c_true.
w_txt = 'Error-Order Currency cannot be blank if Create' &
'Purchasing View'.
WRITE: / 'Row No:', l_rec, w_txt.
ENDIF.
Check Payment Terms - cannot be blank if create Purchasing View
IF T_VEND-ZTERM IS INITIAL.
clear w_txt.
w_validation_errors = c_true.
w_txt = 'Error-Payment Terms cannot be blank if Create' &
'Purchasing View'.
WRITE: / 'Row No:', l_rec, w_txt.
ENDIF.
Check GR-based invoice inverification - cannot be blank if
create Purchasing View
IF T_VEND-WEBRE IS INITIAL.
clear w_txt.
w_validation_errors = c_true.
w_txt = 'Error-GR Based Inv Inveri cannot be blank if Create'
& 'Purchasing View'.
WRITE: / 'Row No:', l_rec, w_txt.
ENDIF.
ENDIF.
ELSE.
Purchasing Org can not be blank if want to create purchasing view
IF T_VEND-WAERS NE SPACE OR T_VEND-ZTERM NE SPACE OR
T_VEND-VERKF NE SPACE OR T_VEND-WEBRE NE SPACE.
clear w_txt.
w_validation_errors = c_true.
w_txt = 'Error-Purchasing Organization is blank =>' &
'cannot Create Purchasing View'.
WRITE: / 'Row No:', l_rec, w_txt.
ENDIF.
ENDIF. "For Purchasing view
IF w_validation_errors = c_true.
CLEAR w_validation_errors.
APPEND t_vend TO it_error.
DELETE t_vend INDEX l_tabix.
ENDIF.
ENDLOOP.
IF it_error[] IS INITIAL.
skip 2.
WRITE: / 'No errors found'.
SKIP 2.
ENDIF.
ENDFORM. " A0400_VALIDATE_FILE_DATA
----
Form CHECK_TELEPHONE
----
Validate Telephone number
----
form check_telephone.
CLEAR it_lfa1.
READ TABLE it_lfa1 WITH TABLE KEY lifnr = t_vend-lifnr.
CALL FUNCTION 'ADDR_COMM_GET'
EXPORTING
address_handle = space
address_number = it_lfa1-adrnr
table_type = 'ADTEL'
IMPORTING
returncode = returncode
TABLES
comm_table = tel_table
error_table = error_table
EXCEPTIONS
parameter_error = 1
address_not_exist = 2
internal_error = 3
OTHERS = 99.
if sy-subrc = 0.
refresh error_table.
if tel_table[] is initial.
tel_table-country = it_lfa1-land1.
tel_table-tel_number = t_vend-tel.
tel_table-updateflag = 'I'.
append tel_table.
else.
loop at tel_table.
tel_table-tel_number = t_vend-tel.
tel_table-updateflag = 'U'.
modify tel_table.
endloop.
endif.
CALL FUNCTION 'ADDR_COMM_MAINTAIN'
EXPORTING
address_handle = g_address_handle "blank
address_number = it_lfa1-adrnr
table_type = 'ADTEL'
check_address = g_check_address
IMPORTING
returncode = returncode
TABLES
comm_table = tel_table
error_table = error_table
EXCEPTIONS
parameter_error = 1
address_not_exist = 2
internal_error = 3
OTHERS = 99.
else.
refresh error_table.
endif.
REFRESH: tel_table,
t_bapiad1vl ,
t_bapiadsmtp ,
t_bapicomrem ,
tx_bapiad1vlx,
tx_bapiadtelx,
tx_bapiadfaxx,
tx_bapiadsmtx,
tx_bapicomrex,
t_ret.
CLEAR: tel_table,
t_bapiad1vl ,
t_bapiadsmtp ,
t_bapicomrem ,
tx_bapiad1vlx,
tx_bapiadtelx,
tx_bapiadfaxx,
tx_bapiadsmtx,
tx_bapicomrex.
endform.
----
Start new screen *
----
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "bdc_dynpro
----
Insert field *
----
FORM bdc_field USING fnam fval.
IF NOT fval IS INITIAL.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDIF.
ENDFORM. "bdc_field
----
FORM get_file_name *
----
........ *
----
FORM get_file_name CHANGING p_file LIKE rlgrap-filename.
*BEGIN SYDK980765
DATA: L_FILE TYPE STRING,
T_FILES TYPE FILETABLE,
L_SUBRC TYPE I,
L_TITLE TYPE STRING VALUE 'File System for Pres. Server'.
L_FILE = P_FILE.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING WINDOW_TITLE = L_TITLE
DEFAULT_FILENAME = L_FILE
CHANGING FILE_TABLE = T_FILES
RC = L_SUBRC
EXCEPTIONS FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
OTHERS = 4.
READ TABLE T_FILES INDEX 1 INTO P_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = space
def_path = p_file
mask = ' ,.,..'
mode = 's'
IMPORTING
filename = p_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
*END SYDK980765
ENDFORM. "get_file_name
----
FORM CHANGE_VENDOR *
----
Change Vendor details *
----
FORM CHANGE_VENDOR.
Display program execution progress.
TEXT-005 : Create the BDC session ........
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = text-005
EXCEPTIONS
OTHERS = 1.
GET VENDOR'S COMPANY
IF NOT t_vend[] IS INITIAL.
REFRESH it_kbuka.
SELECT lifnr bukrs INTO TABLE it_kbuka
FROM k_kbuka
FOR ALL ENTRIES IN t_vend
WHERE lifnr = t_vend-lifnr.
BDC_OPEN_GROUP
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = MAPPE
KEEP = 'X'
USER = SY-UNAME
IMPORTING QID = QID
EXCEPTIONS CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
ENDIF.
Call BAPI to update vendor addr or BDC to create/chg purchasing view
LOOP AT t_vend.
Update Vendor Address
PERFORM maintain_email.
Change or create Vendor Purchasing View
SELECT SINGLE * FROM LFM1 WHERE LIFNR = T_VEND-LIFNR
AND EKORG = T_VEND-EKORG.
IF SY-SUBRC = 0.
PERFORM CHANGE_VENDOR_PURCH. "Change
ELSE.
PERFORM CREATE_VENDOR_PURCH. "Create
ENDIF.
ENDLOOP.
BDC_CLOSE_GROUP
IF SY-SUBRC = 0.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
PERFORM RELEASE_BDC_SESSION.
ENDIF.
ENDFORM. "change_vendor
&----
*& FORM CHANGE_VENDOR_PURC
&----
Change the data in Purchasing View - Order currency, Payment terms
Contact person and GR-based invoice inverification
----
FORM CHANGE_VENDOR_PURCH.
REFRESH bdcdata.
PERFORM bdc_dynpro USING 'SAPMF02K' '0101'.
PERFORM bdc_field USING 'RF02K-LIFNR' t_vend-lifnr.
PERFORM bdc_field USING 'RF02K-EKORG' t_vend-ekorg.
PERFORM bdc_field USING 'RF02K-D0310' 'X'. "PURCHASING
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0310'.
PERFORM bdc_field USING 'LFM1-WAERS' t_vend-WAERS.
PERFORM bdc_field USING 'LFM1-ZTERM' t_vend-ZTERM.
PERFORM bdc_field USING 'LFM1-VERKF' t_vend-VERKF.
PERFORM bdc_field USING 'LFM1-WEBRE' t_vend-WEBRE.
PERFORM bdc_field USING 'BDC_OKCODE' '=UPDA'.
PERFORM bdc_transaction USING 'XK02'.
ENDFORM. " create_vendor_transaction
&----
*& FORM CREATE_VENDOR_PURC
&----
Create the data in Purchasing View - Order currency, Payment terms
Contact person and GR-based invoice inverification
----
FORM CREATE_VENDOR_PURCH.
REFRESH bdcdata.
PERFORM bdc_dynpro USING 'SAPMF02K' '0100'.
PERFORM bdc_field USING 'RF02K-LIFNR' t_vend-lifnr.
PERFORM bdc_field USING 'RF02K-EKORG' t_vend-ekorg.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0310'.
PERFORM bdc_field USING 'LFM1-WAERS' t_vend-WAERS.
PERFORM bdc_field USING 'LFM1-ZTERM' t_vend-ZTERM.
PERFORM bdc_field USING 'LFM1-VERKF' t_vend-VERKF.
PERFORM bdc_field USING 'LFM1-WEBRE' t_vend-WEBRE.
PERFORM bdc_field USING 'BDC_OKCODE' '=UPDA'.
PERFORM bdc_transaction USING 'XK01'.
ENDFORM.
----
Start new transaction according to parameters *
----
FORM bdc_transaction USING tcode.
BDC_INSERT
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA
EXCEPTIONS INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
REFRESH bdcdata.
ENDFORM. "bdc_transaction
&----
*& Form RELEASE_BDC_SESSION
&----
Release BDC session automatically
----
FORM RELEASE_BDC_SESSION.
data: V_BDC_JOB_NAME(32) TYPE C,
V_BDC_JOB_NUMB(8) TYPE C.
Create a job to execute the BDC session (RSBDCBTC)
V_BDC_JOB_NAME = MAPPE.
CALL FUNCTION 'JOB_OPEN'
EXPORTING JOBGROUP = TEXT-007
JOBNAME = V_BDC_JOB_NAME
IMPORTING JOBCOUNT = V_BDC_JOB_NUMB
EXCEPTIONS ALREADY_LOCKED = 1
JOBCOUNT_CANTGEN = 2
JOBGROUP_MISSING = 3
JOBNAME_MISSING = 4
LOCK_FAILED = 5
OLD_DATABASE = 6
PLAN_NOAUTH = 7
START_PAST = 8
OTHERS = 99.
Release BDC session thru job
SUBMIT RSBDCBTC
USER SY-UNAME
VIA JOB V_BDC_JOB_NAME
NUMBER V_BDC_JOB_NUMB
WITH QUEUE_ID = QID
WITH MAPPE = MAPPE
WITH MODUS = 'N'
WITH LOGALL = ''
AND RETURN.
Release the job
CALL FUNCTION 'JOB_CLOSE'
EXPORTING JOBCOUNT = V_BDC_JOB_NUMB
JOBNAME = V_BDC_JOB_NAME
STRTIMMED = 'X'
EXCEPTIONS ALREADY_LOCKED = 1
JOBCOUNT_CANTGEN = 2
JOBGROUP_MISSING = 3
JOBNAME_MISSING = 4
LOCK_FAILED = 5
OLD_DATABASE = 6
PLAN_NOAUTH = 7
START_PAST = 8
CANT_START_IMMEDIATE = 9
JOB_CLOSE_FAILED = 10
OTHERS = 99.
ENDFORM.
&----
*& Form download_error
&----
text
----
FORM download_error .
DATA SUBRC LIKE SY-SUBRC.
Download error file
ERRFILE = P_ERFILE.
PERFORM WS_DOWNLOAD TABLES IT_ERROR
USING SPACE
ERRFILE
C_FILETYPE
'X'
'X'
CHANGING SUBRC.
ENDFORM. " download_error
&----
*& Form maintain_email
&----
Maintain Vendor Address details
----
FORM MAINTAIN_EMAIL.
STATICS: l_lifnr LIKE bapi4001_1-objkey.
l_lifnr = t_vend-lifnr.
CLEAR it_lfa1.
READ TABLE it_lfa1 WITH TABLE KEY lifnr = t_vend-lifnr.
CALL FUNCTION 'BAPI_ADDRESSORG_GETDETAIL'
EXPORTING
obj_type = 'LFA1'
obj_id = l_lifnr
IMPORTING
address_number = adrnr
TABLES
bapiad1vl = t_bapiad1vl
bapiadtel = t_bapiadtel
bapiadfax = t_bapiadfax
bapiadsmtp = t_bapiadsmtp
bapicomrem = t_bapicomrem
return = t_ret.
REFRESH t_ret.
Update Standard Communication Method field
LOOP AT t_bapiad1vl.
t_bapiad1vl-comm_type = t_vend-deflt_comm.
MODIFY t_bapiad1vl.
ENDLOOP.
IF sy-subrc EQ 0.
tx_bapiad1vlx-comm_type = 'X'.
tx_bapiad1vlx-updateflag = 'U'.
APPEND tx_bapiad1vlx.
ENDIF.
Update Telephone number field
LOOP AT t_bapiadtel.
t_bapiadtel-telephone = t_vend-tel.
MODIFY t_bapiadtel.
ENDLOOP.
IF sy-subrc NE 0. "Create
t_bapiadtel-country = it_lfa1-land1.
t_bapiadtel-countryiso = it_lfa1-land1.
t_bapiadtel-std_no = 'X'.
t_bapiadtel-home_flag = 'X'.
t_bapiadtel-consnumber = '001'.
t_bapiadtel-telephone = t_vend-tel.
APPEND t_bapiadtel.
tx_bapiadtelx-home_flag = 'X'.
tx_bapiadtelx-consnumber = 'X'.
tx_bapiadtelx-country = 'X'.
tx_bapiadtelx-countryiso = 'X'.
tx_bapiadtelx-std_no = 'X'.
tx_bapiadtelx-updateflag = 'I'.
ELSE. "Change
tx_bapiadtelx-updateflag = 'U'.
ENDIF.
tx_bapiadtelx-telephone = 'X'.
APPEND tx_bapiadtelx.
Update Fax number field
LOOP AT t_bapiadfax.
t_bapiadfax-fax = t_vend-fax.
MODIFY t_bapiadfax.
ENDLOOP.
IF sy-subrc NE 0. "Create
t_bapiadfax-country = it_lfa1-land1.
t_bapiadfax-countryiso = it_lfa1-land1.
t_bapiadfax-std_no = 'X'.
t_bapiadfax-home_flag = 'X'.
t_bapiadfax-consnumber = '001'.
t_bapiadfax-fax = t_vend-fax.
APPEND t_bapiadfax.
tx_bapiadfaxx-std_no = 'X'.
tx_bapiadfaxx-home_flag = 'X'.
tx_bapiadfaxx-country = 'X'.
tx_bapiadfaxx-countryiso = 'X'.
tx_bapiadfaxx-consnumber = 'X'.
tx_bapiadfaxx-updateflag = 'I'.
ELSE. "Change
tx_bapiadfaxx-updateflag = 'U'.
ENDIF.
tx_bapiadfaxx-fax = 'X'.
APPEND tx_bapiadfaxx.
Update Email address field
LOOP AT t_bapiadsmtp.
t_bapiadsmtp-e_mail = t_vend-email.
MODIFY t_bapiadsmtp.
ENDLOOP.
IF sy-subrc NE 0. "Create
t_bapiadsmtp-std_no = 'X'.
t_bapiadsmtp-home_flag = 'X'.
t_bapiadsmtp-consnumber = '001'.
t_bapiadsmtp-e_mail = t_vend-email.
APPEND t_bapiadsmtp.
tx_bapiadsmtx-std_no = 'X'.
tx_bapiadsmtx-home_flag = 'X'.
tx_bapiadsmtx-consnumber = 'X'.
tx_bapiadsmtx-updateflag = 'I'.
ELSE. "Change
tx_bapiadsmtx-updateflag = 'U'.
ENDIF.
tx_bapiadsmtx-e_mail = 'X'.
APPEND tx_bapiadsmtx.
Update the Available Communication type
Email address
LOOP AT t_bapicomrem WHERE comm_type = 'INT'.
EXIT.
ENDLOOP.
IF sy-subrc NE 0.
t_bapicomrem-comm_type = 'INT'.
t_bapicomrem-langu = sy-langu.
t_bapicomrem-langu_iso = sy-langu.
t_bapicomrem-consnumber = '001'.
APPEND t_bapicomrem.
tx_bapicomrex-comm_type = 'X'.
tx_bapicomrex-langu = 'X'.
tx_bapicomrex-langu_iso = 'X'.
tx_bapicomrex-consnumber = 'X'.
tx_bapicomrex-updateflag = 'I'.
APPEND tx_bapicomrex.
ENDIF.
Fax
LOOP AT t_bapicomrem WHERE comm_type = 'FAX'.
EXIT.
ENDLOOP.
IF sy-subrc NE 0.
t_bapicomrem-comm_type = 'FAX'.
t_bapicomrem-langu = sy-langu.
t_bapicomrem-langu_iso = sy-langu.
t_bapicomrem-consnumber = '001'.
APPEND t_bapicomrem.
tx_bapicomrex-comm_type = 'X'.
tx_bapicomrex-langu = 'X'.
tx_bapicomrex-langu_iso = 'X'.
tx_bapicomrex-consnumber = 'X'.
tx_bapicomrex-updateflag = 'I'.
APPEND tx_bapicomrex.
ENDIF.
Telephone
LOOP AT t_bapicomrem WHERE comm_type = 'TEL'.
EXIT.
ENDLOOP.
IF sy-subrc NE 0.
t_bapicomrem-comm_type = 'TEL'.
t_bapicomrem-langu = sy-langu.
t_bapicomrem-langu_iso = sy-langu.
t_bapicomrem-consnumber = '001'.
APPEND t_bapicomrem.
tx_bapicomrex-comm_type = 'X'.
tx_bapicomrex-langu = 'X'.
tx_bapicomrex-langu_iso = 'X'.
tx_bapicomrex-consnumber = 'X'.
tx_bapicomrex-updateflag = 'I'.
APPEND tx_bapicomrex.
ENDIF.
Call the BAPI to update the Vendor address
CALL FUNCTION 'BAPI_ADDRESSORG_CHANGE'
EXPORTING
obj_type = 'LFA1'
obj_id = l_lifnr
save_address = 'X'
TABLES
bapiad1vl = t_bapiad1vl
bapiadtel = t_bapiadtel
bapiadfax = t_bapiadfax
bapiadsmtp = t_bapiadsmtp
bapicomrem = t_bapicomrem
bapiad1vl_x = tx_bapiad1vlx
bapiadtel_x = tx_bapiadtelx
bapiadfax_x = tx_bapiadfaxx
bapiadsmt_x = tx_bapiadsmtx
bapicomre_x = tx_bapicomrex
return = t_ret.
REFRESH: t_bapiad1vl ,
t_bapiadtel ,
t_bapiadfax ,
t_bapiadsmtp ,
t_bapicomrem ,
tx_bapiad1vlx,
tx_bapiadtelx,
tx_bapiadfaxx,
tx_bapiadsmtx,
tx_bapicomrex,
t_ret.
CLEAR: t_bapiad1vl ,
t_bapiadsmtp ,
t_bapicomrem ,
tx_bapiad1vlx,
tx_bapiadtelx,
tx_bapiadfaxx,
tx_bapiadsmtx,
tx_bapicomrex.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDFORM. " maintain_email
INCLUDE ZZX0002F.
cheers
Aveek