Refer to PR Create purchase contract (ME31K) BDC mode

Source: Internet
Author: User





SAP does not currently have BAPI to create a service-class purchase contract, so it is created with BDC. The following is a reference to the PR, in the BDC mode to create a service line of the purchase contract (can contain material lines)


FUNCTION zfun1039. * "----------------------------------------------------------------------*" * "Local Interface: *" Importing * "REFERENCE (iv_ Bdcmode) Type CHAR1 OPTIONAL * "REFERENCE (iv_mode) type CHAR1 *" REFERENCE (is_header) type Zmm_s_contract_heade R * "REFERENCE (it_item) type Zmm_t_contract_item *" REFERENCE (it_account) type Zmm_t_contract_account * "REF Erence (it_conditions) type Zmm_t_contract_conditions * "REFERENCE (it_partner) type Zmm_t_contract_partner *" REF Erence (it_services) type Zmm_t_contract_services * "REFERENCE (it_header_text) type Zmm_t_longtext *" REFERENCE (I     T_item_text) Type Zmm_t_longtext * "Exporting *" value (ev_msg) type CHAR255 * "Value (ev_code) type STRING *" VALUE (ev_contract_num) TYPE Ebeln * "EXCEPTIONS *" Unkown_mode * "----------------------------------------------- -----------------------data:rec_ite type Zmm_s_contract_item, REC_ACC type Zmm_s_contract_account, rec_s ER TYPE ZMM_s_contract_services, Rec_con type zmm_s_contract_conditions, Rec_par type Zmm_s_contract_partner, R


 Ec_txt TYPE Zmm_s_longtext.


DATA:TAB_BDC TYPE TABLE of Bdcdata. *BDC value conversion data definition DATA:L_DATE_STR1 type CHAR10, l_date_str2 type char10, l_ktwrt_str type Char15, l_wkurs _STR type Char10, L_bukrs type Bukrs, l_ktmng_str type Char20, l_netpr_str type CHAR20, L_


MENGE_STR type CHAR20, l_tbtwr_str type Char20, l_poski_str type char8, L_vbelp_str type CHAR5.


 *BDC data definition data:tab_msg type TABLE of Bdcmsgcoll, rec_msg type Bdcmsgcoll, L_mode type C VALUE ' N '.


 Data:l_lines Type I, L_ebelp type CHAR5.


 DATA:TAB_ESLL type TABLE of ESLL, REC_ESLL type ESLL.


WRITE Is_header-bedat to L_date_str1 dd/mm/yyyy. splash screen start********************************** PERFORM frm_bdc_add_dynnr TABLES tab_bdc USING '


 sapmm06e ' 0200 '.


 PERFORM Frm_bdc_add_field:         TABLES TAB_BDC using ' bdc_okcode ' Kopf ', "header detail button TABLES TAB_BDC using ' ekko-ekgrp ' is_header-e KGRP, "procurement group TABLES TAB_BDC using ' ekko-ekorg ' is_header-ekorg," procurement organization TABLES TAB_BDC using ' Rm06e-vedat ' L_date_str1, ' protocol date TABLES TAB_BDC USING ' Rm06e-evart ' Is_header-bsart, ' protocol type TABLES TAB_BDC usin G ' Ekko-lifnr ' Is_header-lifnr.


 "Vendor Select single Bukrs to L_bukrs from t024e WHERE ekorg = is_header-ekorg.


   IF SY-SUBRC NE 0 OR l_bukrs is INITIAL.


   The Company code input screen PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0514 '.  PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode ' =ente ', "Enter TABLES TAB_BDC using ' Ekko-bukrs ' Is_header-bukrs.


"Company Code ENDIF. splash screen end********************************** *********************** header screen start**************


 * Data Format conversion WRITE IS_HEADER-KDATB to L_date_str1 mm/dd/yyyy. WRITE Is_headeR-kdate to L_date_str2 mm/dd/yyyy.


 WRITE is_header-ktwrt to L_ktwrt_str no-grouping decimals 2.


 WRITE is_header-wkurs to L_wkurs_str no-grouping decimals 2.


 PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0201 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode ' =prtn ', "partner button TABLES TAB_BDC using ' EKKO-KDATB ' l_date_str1, ' The validity period begins TABLES tab_bdc USING ' ekko-kdate ' l_date_str2, ' end of validity TABLES TAB_BD


       C using ' Ekko-unsez ' Is_header-unsez, "Our reference TABLES TAB_BDC using ' ekko_ci-zzhtbh ' IS_HEADER-ZZHTBH," contract number TABLES TAB_BDC using ' EKKO_CI-ZZHTMC ' IS_HEADER-ZZHTMC, "contract name TABLES TAB_BDC using ' ekko-ktwrt ' L_ktwrt_str," Target value TABLES TAB_BDC using ' ekko-waers ' is_header-waers, "currency TABLES TAB_BDC using ' ekko-wkurs ' l_wku RS_STR, "exchange rate TABLES TAB_BDC using ' Ekko-angnr ' Is_header-angnr," quote TABLES TAB_BDC using ' Ekko-inco


      1 ' is_header-incoterms1, TABLES TAB_BDC using ' Ekko-inco2 ' is_header-incoterms2, TABLES tab_bdc using ' ekko-zterm ' is_header-zterm . "Payment Terms *********************** Header screen end********************************** *********************** partner Screen start*******


   IF it_partner[] is not INITIAL.


   PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplekpa ' 0102 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode ' =DISL ', ' Show button TABLES TAB_BDC using '    Rm06e-selkz ("X").


     "Select the first line of LOOP at It_partner to Rec_par.


    PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplekpa ' 0101 '.


     PERFORM Frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =new '.


     PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplekpa ' 0101 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode '/00 ', TABLES TAB_BDC using ' MM PA-PARVW ' rec_par-parvw, ' function TABLES tab_bdc USING ' Wrf02k-gparn (02) 'Rec_par-lifn2. "


Partner number Endloop.


   * Fallback level partner screen PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplekpa ' 0101 '.


 PERFORM Frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =back '.


ENDIF.


 * Fallback header screen PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplekpa ' 0102 '.


PERFORM Frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =back '.


 * Enter the overview screen (header + line) PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0201 '.


PERFORM Frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =ab '. Partner Screen end******************************** *********************** Overview Screen start**************


   LOOP at It_item to Rec_ite.


   WRITE rec_ite-ktmng to L_ktmng_str no-grouping decimals 2.


WRITE REC_ITE-NETPR to L_netpr_str no-grouping decimals 2.


   * Refer to the purchase requisition button PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0220 '.


PERFORM Frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =bs '. * Fill in the purchase requisition number screen Data:l_bnfpo_str TYPE CHAR5.


   L_bnfpo_str = Rec_ite-bnfpo.


   PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0501 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode ' =ente ', TABLES TAB_BDC using ' Eket -banfn ' Rec_ite-banfn, TABLES tab_bdc USING ' Eket-bnfpo ' l_bnfpo_str, TABLES TAB_BDC USI


NG ' Eban-ekgrp ' is_header-ekgrp, TABLES tab_bdc USING ' RM06E-OFFBA '.


   * Copy purchase requisition PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0125 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode ' =refh ', TABLES TAB_BDC using ' bdc_


CURSOR ' Eban-banfn ', TABLES tab_bdc USING ' rm06e-tcselflag ' X '.


   * Line Detail Screen PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0211 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode '/00 ', TABLES TAB_BDC using ' ekpo-m


   Wskz ' Rec_ite-mwskz. Clear:tab_esll[].


             SELECT * into TABLE tab_esll from Esll WHERE packno in (select Sub_packno "Remove Child package number


                    From Esll WHERE packno in (select Packno purchase line overview package number from Eban WHERE BANFN eq rec_ite-banfn and BNFPO eq Rec_ite-bnfpo))


   .


   CLEAR L_lines.


   DESCRIBE TABLE tab_esll LINES l_lines.


     IF L_lines is INITIAL.


     DATA:L_BPUMN_STR type CHAR3, L_bpumz_str type CHAR3.


     WRITE rec_ite-ktmng to L_ktmng_str no-grouping decimals 2.


     WRITE REC_ITE-NETPR to L_netpr_str no-grouping decimals 2.


     WRITE Rec_ite-bpumn to L_bpumn_str.  Write Rec_ite-bpumz to L_BPUMZ_STR. * Non-service purchase requisition lines, fill in line additional information PERFORM frm_bdc_add_field:tables TAB_BDC USING ' Ekpo-ktmng ' l_ktmng_str, "quantity TABLES tab_bdc USING ' EKPO-NETPR ' l_netpr_str," unit price TABLES Tab_ BDC USING ' Ekpo-bprme ' rec_ite-bprme, "Pricing unit TABLES TAB_BDC using ' ekpo-bpumn ' l_bpumn_str," molecular TABLES TAB_BDC using ' ekpo-bpumz ' L_bpumz_str. "Denominator ELSE." Service line PERFORM frm_bdc_add_field:tables tab_bdc USING ' ekpo-txz01 ' rec_ite-txz01, TABLES tab


   _BDC USING ' Ekpo-matkl ' REC_ITE-MATKL.


   ENDIF.


Do l_lines times.


     * Exit Account Assignment Screen PERFORM frm_bdc_add_dynnr TABLES tab_bdc USING ' Saplmlsk ' 0200 '.


   PERFORM Frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =back '.


Enddo.


   * Anchor Line l_ebelp = Rec_ite-ebelp.


   PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0220 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode '/00 ', TABLES TAB_BDC using ' rm06e -ebelp ' L_ebelp.


"Anchor Row IF tab_esll[] is not INITIAL.


     * Enter the line service screen PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0220 '.       PERFORM frm_bdc_add_field:tables tab_bdc USING ' Bdc_okcode '   ' =dien ', TABLES tab_bdc USING ' rm06e-tcselflag ' ' X '.


   ENDIF.


LOOP at Tab_esll to REC_ESLL.


     * Locate row Data:l_extrow TYPE char10.


L_extrow = Rec_esll-extrow.


     * Location Service detail Line PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplmlsp ' ' 0201 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode '/00 ', TABLES TAB_BDC using ' rm11p


     -new_row ' L_extrow.


                                      READ TABLE it_services into rec_ser with KEY ebelp = Rec_ite-ebelp


     Extrow = Rec_esll-extrow.


IF SY-SUBRC EQ 0.


       * Modified data WRITE rec_ser-menge to L_menge_str no-grouping decimals 2.


       WRITE REC_SER-TBTWR to L_tbtwr_str no-grouping decimals 2.


       PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplmlsp ' 0201 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode '/00 ', TABLES TAB_BDC using ' Esll-ktext1 ' Rec_ser-kteXT1, TABLES TAB_BDC using ' Esll-menge ' L_menge_str, "TABLES TAB_BDC using ' esll-meins (01) ' Rec_ser-meins, TABLES tab_bdc USING ' ESLL-TBTWR ' l_tbtwr_str. * Account Confirmation screen (exit) PERFORM FRM_BDC


       _add_dynnr TABLES tab_bdc USING ' Saplmlsk ' 0200 '.


     PERFORM frm_bdc_add_field:tables tab_bdc USING ' bdc_okcode ' =back '. ELSE. "


       There is no such service line in the interface, you need to remove PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplmlsp ' 0201 '. PERFORM frm_bdc_add_field:tables TAB_BDC using ' bdc_okcode '/ebdz ', TABLES TAB_BDC using ' RM


11p-selkz ("X").


       * Delete Confirmation screen PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' SAPLSPO1 ' 0100 '.


     PERFORM Frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =yes '.


   ENDIF.


Endloop.


   * Exit the service screen PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' saplmlsp ' 0201 '. PERFORM frm_bdc_add_field TABLES tab_bdc USING ' bdc_okcode ' =esb '. Endloop. " END of It_item *********************** Overview screen end******************************** IF iv_mode EQ ' C '. "


   Create * Save PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0220 '.


PERFORM frm_bdc_add_field:tables tab_bdc USING ' bdc_okcode ' =bu '.


   * No message confirming PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' SAPLSPO1 ' 0300 '.


 PERFORM frm_bdc_add_field:tables tab_bdc USING ' bdc_okcode ' =yes '. ELSEIF iv_mode EQ ' X '.


   Data check * Exit transaction PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' sapmm06e ' 0220 '.


PERFORM frm_bdc_add_field:tables tab_bdc USING ' bdc_okcode ' =back '.


   * Do not save data PERFORM Frm_bdc_add_dynnr TABLES tab_bdc USING ' SAPLSPO1 ' 0100 '.


 PERFORM frm_bdc_add_field:tables tab_bdc USING ' bdc_okcode ' =no '.


   ELSE.


 RAISE Unkown_mode.


 ENDIF.


   IF iv_bdcmode CO ' AEN '.


 L_mode = Iv_bdcmode.


ENDIF. * Calling BDC call TRANSACTION ' me31k 'USING TAB_BDC MODE l_mode MESSAGES into tab_msg.


   LOOP at Tab_msg to Rec_msg. IF Rec_msg-msgtyp = ' S ' and Rec_msg-msgid = ' and Rec_msg-msgnr = ' 017 '.


     "Created successfully MESSAGE s017 () with Rec_msg-msgv1 rec_msg-msgv2 to ev_msg.


     Ev_code = 0.


Ev_contract_num = Rec_msg-msgv2. * Created successfully, updated text call FUNCTION ' ZFUN1034 ' exporting Iv_contract_num = Ev_contract_num It_heade


     R_text = It_header_text It_item_text = it_item_text.


   EXIT.


     ELSEIF Rec_msg-msgtyp = ' E '.


     Ev_code = 4.


                  MESSAGE ID rec_msg-msgid TYPE rec_msg-msgtyp number Rec_msg-msgnr with Rec_msg-msgv1 rec_msg-msgv2


   Rec_msg-msgv3 rec_msg-msgv4 into ev_msg.


 ENDIF.


 Endloop. IF iv_mode EQ ' X '.


     Data Check mode IF Ev_code is INITIAL and Ev_msg is INITIAL.


     Ev_code = 0.


   ev_msg = ' data validation successful '.


 ENDIF.


ENDIF. Endfunction.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.