Bdc Program

15
report zfi_vendor_master_load line-size 150 line-count 65 message-id zhr. ************************************************************************ * Program name :ZFI_VENDOR_MASTER_LOAD * Author :Shounak Mukherjee * Date :July 29, 2003 * Description :Vendor Master Load [FK01] * DEV ID :ITIGABAP ************************************************************************ * Modification Log (Latest Changes First) ************************************************************************ * Programmer : * Change Date : * Description : * Dev ID : ************************************************************************ ************************************************************************ * Declaration For Internal Tables *********************************************************************** data: begin of it_itab occurs 0, line(1000), end of it_itab. data: begin of it_bdc occurs 0. include structure bdcdata. data: end of it_bdc. data: it_messg like bdcmsgcoll occurs 0 with header line. data: begin of it_vendor occurs 0, bukrs(4), accgrp(4), *Address DATA name1(35), street(35), post_code(10), city1(35), country(3), pobox(10), region(3), street2(40), tel_num(16), name_co(40), *Account Information akont(10), altkn(10),

description

Bdc Program

Transcript of Bdc Program

Page 1: Bdc Program

report zfi_vendor_master_load line-size 150 line-count 65 message-id zhr.

************************************************************************* Program name :ZFI_VENDOR_MASTER_LOAD* Author :Shounak Mukherjee* Date :July 29, 2003* Description :Vendor Master Load [FK01]* DEV ID :ITIGABAP************************************************************************* Modification Log (Latest Changes First)************************************************************************* Programmer :* Change Date :* Description :* Dev ID :************************************************************************

************************************************************************* Declaration For Internal Tables***********************************************************************

data: begin of it_itab occurs 0, line(1000), end of it_itab.

data: begin of it_bdc occurs 0. include structure bdcdata.data: end of it_bdc.

data: it_messg like bdcmsgcoll occurs 0 with header line.

data: begin of it_vendor occurs 0, bukrs(4), accgrp(4),*Address DATA name1(35), street(35), post_code(10), city1(35), country(3), pobox(10), region(3), street2(40), tel_num(16), name_co(40),*Account Information akont(10), altkn(10),*Payment Terms zterm(4), zwels(10),*Correspondence Accounting zsabe(15), tlfns(30), kverm(30), tlfxs(31), intad(130),

Page 2: Bdc Program

end of it_vendor.

*IT to Hold Error Recordsdata: begin of it_err occurs 0, accgrp like rf02k-ktokk, name1 like adrc-name1, country like adrc-country, altkn like lfb1-altkn, akont like lfb1-akont, zterm like lfb1-zterm, remarks like bdcmsgcoll-msgv1, end of it_err.

*IT to Hold Success Recordsdata: begin of it_success occurs 0, accgrp like rf02k-ktokk, name1 like adrc-name1, country like adrc-country, altkn like lfb1-altkn, akont like lfb1-akont, zterm like lfb1-zterm, remarks like bdcmsgcoll-msgv1, end of it_success.

************************************************************************* Declaration For Global data***********************************************************************data: flag_bdc_open.data: v_tcode like sy-tcode value 'FK01'.data: v_rep.data: tot_vendor like sy-index, tot_suc like sy-index, tot_err like sy-index.

data: v_no_lines type i, v_wrk_tabix like sy-tabix.

data: delimiter(1) type x value '09'.

************************************************************************* Selection Screen************************************************************************

selection-screen begin of block bel with frame title text-001.

parameter p_flnam like rlgrap-filename obligatory.selection-screen: skip.parameter: p_pc radiobutton group abc default 'X'.parameter: p_unix radiobutton group abc.

selection-screen end of block bel.

parameter: p_grpid like apqi-groupid default 'VENDOR_LOAD'.*parameter: p_mode(1) default 'A'.

************************************************************************

Page 3: Bdc Program

* AT SELECTION SCREEN************************************************************************

at selection-screen on value-request for p_flnam. perform f4_help using 'P_FILE'.

************************************************************************* Initialization.************************************************************************

************************************************************************* AT SELECTION SCREEN *************************************************************************

*********************************************************************** Top-Of-Page**********************************************************************top-of-page.

perform top_of_page.*********************************************************************** Start-of-selection.**********************************************************************

start-of-selection.

* READ FILE AND LOAD INTERNAL TABLE if p_pc = 'X'.

perform load_pc_file.

elseif p_unix = 'X'.

perform load_unix_file.

endif.

perform load_into_structure.

perform build_bdc_tab.

*********************************************************************** End of Selection**********************************************************************end-of-selection.

perform write_report.

*&---------------------------------------------------------------------**& Form LOAD_PC_FILE*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form load_pc_file.

Page 4: Bdc Program

call function 'WS_UPLOAD' exporting filename = p_flnam filetype = 'DAT' tables data_tab = it_vendor exceptions conversion_error = 1 invalid_table_width = 2 invalid_type = 3 no_batch = 4 unknown_error = 5 gui_refuse_filetransfer = 6 others = 7. if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif.

endform. " LOAD_PC_FILE*&---------------------------------------------------------------------**& Form LOAD_UNIX_FILE*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form load_unix_file.

open dataset p_flnam for input in text mode.

if sy-subrc <> 0.

else.

do. read dataset p_flnam into it_itab-line. if sy-subrc <> 0. exit. endif. append it_itab. clear it_itab. enddo.

endif.

close dataset p_flnam.

endform. " LOAD_UNIX_FILE*&---------------------------------------------------------------------**& Form LOAD_INTO_STRUCTURE*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*

Page 5: Bdc Program

* --> p1 text* <-- p2 text*----------------------------------------------------------------------*form load_into_structure.

describe table it_vendor lines tot_vendor.

endform. " LOAD_INTO_STRUCTURE*&---------------------------------------------------------------------**& Form BUILD_BDC_TAB*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form build_bdc_tab.

clear flag_bdc_open.

if not it_vendor[] is initial.

describe table it_vendor lines v_no_lines.

if flag_bdc_open <> 'X'. perform bdc_open_group. flag_bdc_open = 'X'. endif.

loop at it_vendor.

v_wrk_tabix = sy-tabix.

perform progress_indicator.

perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0105'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'USE_ZAV'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '/00'. perform fill_bdc_tab using: '' 'RF02K-BUKRS' it_vendor-bukrs. perform fill_bdc_tab using: '' 'RF02K-KTOKK' it_vendor-accgrp. perform fill_bdc_tab using: '' 'USE_ZAV' 'X'.

perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0111'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '=$AOC'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'ADDR1_DATA-COUNTRY'. perform fill_bdc_tab using: '' 'ADDR1_DATA-NAME1' it_vendor-name1. perform fill_bdc_tab using: '' 'ADDR1_DATA-STREET' it_vendor-street. perform fill_bdc_tab using: '' 'ADDR1_DATA-POST_CODE1' it_vendor-post_code. perform fill_bdc_tab using:

Page 6: Bdc Program

'' 'ADDR1_DATA-CITY1' it_vendor-city1. perform fill_bdc_tab using: '' 'ADDR1_DATA-COUNTRY' it_vendor-country. perform fill_bdc_tab using: '' 'ADDR1_DATA-REGION' it_vendor-region. perform fill_bdc_tab using: '' 'ADDR1_DATA-PO_BOX' it_vendor-pobox. perform fill_bdc_tab using: '' 'SZA1_D0100-TEL_NUMBER' it_vendor-tel_num. perform fill_bdc_tab using: '' 'ADDR1_DATA-LANGU' 'EN'.

perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0111'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '/00'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'ADDR1_DATA-NAME_CO'. perform fill_bdc_tab using: '' 'ADDR1_DATA-NAME1' it_vendor-name1. perform fill_bdc_tab using: '' 'ADDR1_DATA-STREET' it_vendor-street. perform fill_bdc_tab using: '' 'ADDR1_DATA-NAME_CO' it_vendor-name_co. perform fill_bdc_tab using: '' 'ADDR1_DATA-STR_SUPPL1' it_vendor-street2. perform fill_bdc_tab using: '' 'ADDR1_DATA-POST_CODE1' it_vendor-post_code. perform fill_bdc_tab using: '' 'ADDR1_DATA-CITY1' it_vendor-city1. perform fill_bdc_tab using: '' 'ADDR1_DATA-COUNTRY' it_vendor-country. perform fill_bdc_tab using: '' 'ADDR1_DATA-REGION' it_vendor-region. perform fill_bdc_tab using: '' 'ADDR1_DATA-PO_BOX' it_vendor-pobox. perform fill_bdc_tab using: '' 'SZA1_D0100-TEL_NUMBER' it_vendor-tel_num. perform fill_bdc_tab using: '' 'ADDR1_DATA-LANGU' 'EN'.

perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0120'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'LFA1-KUNNR'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '/00'. perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0130'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'LFBK-BANKS(01)'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '=ENTR'.

perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0210'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'LFB1-ALTKN'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '/00'.

Page 7: Bdc Program

perform fill_bdc_tab using: '' 'LFB1-AKONT' it_vendor-akont. perform fill_bdc_tab using: '' 'LFB1-ALTKN' it_vendor-altkn.

perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0215'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'LFB1-ZWELS'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '/00'. perform fill_bdc_tab using: '' 'LFB1-ZTERM' it_vendor-zterm. perform fill_bdc_tab using: '' 'LFB1-REPRF' 'X'. perform fill_bdc_tab using: '' 'LFB1-ZWELS' it_vendor-zwels.

perform fill_bdc_tab_scr using: 'X' 'SAPMF02K' '0220'. perform fill_bdc_tab using: '' 'BDC_CURSOR' 'LFB1-KVERM'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '/00'. perform fill_bdc_tab using: '' 'LFB1-ZSABE' it_vendor-zsabe. perform fill_bdc_tab using: '' 'LFB1-TLFNS' it_vendor-tlfns. perform fill_bdc_tab using: '' 'LFB1-TLFXS' it_vendor-tlfxs. perform fill_bdc_tab using: '' 'LFB1-INTAD' it_vendor-intad. perform fill_bdc_tab using: '' 'LFB1-KVERM' it_vendor-kverm.

perform fill_bdc_tab_scr using: 'X' 'SAPLSPO1' '0300'. perform fill_bdc_tab using: '' 'BDC_OKCODE' '=YES'.

* call transaction v_tcode* using it_bdc* mode p_mode* update 'S'* messages into it_messg.

perform bdc_insert.

clear: it_bdc, it_messg. refresh: it_bdc, it_messg.

endloop.

if flag_bdc_open = 'X'. perform bdc_close_group. endif.

endif.

Page 8: Bdc Program

endform. " BUILD_BDC_TAB*&---------------------------------------------------------------------**& Form FILL_BDC_TAB_SCR*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->P_0178 text* -->P_0179 text* -->P_0180 text*----------------------------------------------------------------------*form fill_bdc_tab_scr using new_scr program screen_num.

move program to it_bdc-program. move screen_num to it_bdc-dynpro. move new_scr to it_bdc-dynbegin.

append it_bdc. clear it_bdc.

endform. " FILL_BDC_TAB_SCR*&---------------------------------------------------------------------**& Form FILL_BDC_TAB*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->P_0178 text* -->P_0179 text* -->P_0180 text*----------------------------------------------------------------------*form fill_bdc_tab using new_scr fieldname fieldvalue.

move fieldname to it_bdc-fnam. move fieldvalue to it_bdc-fval.

append it_bdc. clear it_bdc.

endform. " FILL_BDC_TAB

*&---------------------------------------------------------------------**& Form BDC_OPEN_GROUP*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form bdc_open_group.

call function 'BDC_OPEN_GROUP' exporting client = sy-mandt* DEST = FILLER8 group = p_grpid

Page 9: Bdc Program

* HOLDDATE = FILLER8 keep = 'X' user = sy-uname 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 . if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif.

flag_bdc_open = 'X'.

endform. " BDC_OPEN_GROUP*&---------------------------------------------------------------------**& Form BDC_INSERT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form bdc_insert.

call function 'BDC_INSERT' exporting tcode = v_tcode tables dynprotab = it_bdc exceptions internal_error = 1 not_open = 2 queue_error = 3 tcode_invalid = 4 printing_invalid = 5 posting_invalid = 6 others = 7. if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif.

endform. " BDC_INSERT*&---------------------------------------------------------------------**& Form BDC_CLOSE_GROUP*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*

Page 10: Bdc Program

form bdc_close_group.

call function 'BDC_CLOSE_GROUP' exceptions not_open = 1 queue_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.

endform. " BDC_CLOSE_GROUP*&---------------------------------------------------------------------**& Form WRITE_REPORT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form write_report.

perform summary_report.* perform error_report.* perform success_report.

endform. " WRITE_REPORT*&---------------------------------------------------------------------**& Form TOP_OF_PAGE*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form top_of_page.

if v_rep = '1'. "SUMMARY

write:/ sy-datum, 45 text-hd1, "VENDOR MASTER LOAD - SUMMARY REPORT 101 text-hd4, 109 sy-pagno.

uline.

elseif v_rep = '2'. " SUCCESS

write:/ sy-datum, 45 text-hd2, "VENDOR MASTER LOAD - SUCCESS REPORT 101 text-hd4, "Page: 109 sy-pagno.

uline. write: / text-101,

Page 11: Bdc Program

10 text-102, 60 text-103, 65 text-104, 80 text-105, 100 text-106, 110 text-107. uline.

elseif v_rep = '3'. "ERROR.

write:/ sy-datum, 45 text-hd3, "VENDOR MASTER LOAD - ERROR REPORT 101 text-hd4, 109 sy-pagno.

uline. write: / text-101, 10 text-102, 60 text-103, 65 text-104, 80 text-105, 100 text-106, 110 text-107. uline.

endif.

endform. " TOP_OF_PAGE*&---------------------------------------------------------------------**& Form SUMMARY_REPORT*&---------------------------------------------------------------------** Summary Report*----------------------------------------------------------------------*form summary_report.

v_rep = '1'. write: / 'NUMBER OF RECORDS:',65 tot_vendor.

uline. skip.* write: / 'NUMBER OF VENDORS CREATED:',65 tot_suc.** uline.* skip.* write: / 'NUMBER OF VENDORS IN ERROR:',65 tot_err.** uline.

endform. " SUMMARY_REPORT*&---------------------------------------------------------------------**& Form ERROR_REPORT*&---------------------------------------------------------------------** Error Report*----------------------------------------------------------------------*form error_report.

new-page.

Page 12: Bdc Program

v_rep = '3'. if not it_err[] is initial. write:/ 'ERROR CREATING THE FOLLOWING VENDORS '. uline.

loop at it_err . write: / it_err-accgrp under text-101, it_err-name1 under text-102, it_err-country under text-103, it_err-altkn under text-104, it_err-akont under text-105, it_err-zterm under text-106, it_err-remarks under text-107. endloop. else. write:/ 'NO ERROR RECORDS '. uline. endif.

endform. " ERROR_REPORT*&---------------------------------------------------------------------**& Form SUCCESS_REPORT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form success_report.

new-page. v_rep = '2'. if not it_success[] is initial. write:/ 'THE FOLLOWING VENDORS WERE CREATED SUCCESSFULLY'. uline. loop at it_success . write: / it_success-accgrp under text-101, it_success-name1 under text-102, it_success-country under text-103, it_success-altkn under text-104, it_success-akont under text-105, it_success-zterm under text-106, it_success-remarks under text-107.

endloop. else. write:/ 'NO VENDORS WERE CREATED SUCCESSFULLY'. uline.

endif.

endform. " SUCCESS_REPORT

*&---------------------------------------------------------------------**& Form F4_HELP*&---------------------------------------------------------------------** To get the file path and name*----------------------------------------------------------------------

Page 13: Bdc Program

form f4_help using p_f4name like rlgrap-filename.

data: dl_file like rlgrap-filename. " File Path

call function 'F4_FILENAME' exporting program_name = syst-cprog dynpro_number = syst-dynnr importing file_name = dl_file.

if p_f4name = 'P_FILE'. p_flnam = dl_file. endif.endform. " F4_HELP

*&---------------------------------------------------------------------**& Form progress_indicator*&---------------------------------------------------------------------** Progress Indicator*----------------------------------------------------------------------*form progress_indicator.

data: v_wrk_text(100). data: v_wrk_percent(3) type n. if not v_no_lines is initial. v_wrk_percent = v_wrk_tabix * 100 / v_no_lines . endif. write: v_wrk_percent to v_wrk_percent using edit mask '==ALPHA'. concatenate '...' v_wrk_percent text-hd5 into v_wrk_text separated by space. "#EC NOTEXT call function 'SAPGUI_PROGRESS_INDICATOR' exporting percentage = v_wrk_percent text = v_wrk_text.

endform. " progress_indicator