Create BP and Customer Using ABAP in SAP

Create BP And Customer


Input Screen : 



The Following Code Here :

*&---------------------------------------------------------------------*
*& Report ZBP_UPLOAD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSD_BP_UPLOAD.

TABLES: but000,kna1,lfa1,pa0006,pa0002.
TYPES: BEGIN OF ty_file_bp,
         serial        TYPE char10,                     " Serial of type Integers
         role1         TYPE bu_partnerrole,
         role2         TYPE bu_partnerrole,
         role3         TYPE bu_partnerrole,
         role4         TYPE bu_partnerrole,
         bpartner      TYPE bapibus1006_head-bpartner,  " Business Partner Number
         partn_cat     TYPE bapibus1006_head-partn_cat, " Business Partner Category
         partn_grp     TYPE bapibus1006_head-partn_grp, " Business Partner Grouping
         title         TYPE ad_titletx,                 " Title text
         name1         TYPE bu_nameor1,                 " Name 1 of organization
         name2         TYPE bu_nameor1,                 " Name 1 of organization
         sterm1        TYPE sortl,                   "Search Term 1
         sterm2        TYPE bu_sort2,                   "Search Term 2
         street        TYPE ad_street,                  " Street
         house_no      TYPE ad_hsnm1,                   "House No
         str_suppl1    TYPE ad_strspp1,                 "Street 2
         str_suppl2    TYPE ad_strspp2,                 "Street 3
         str_suppl3    TYPE ad_strspp3,                 "Street 4
         location      TYPE ad_lctn,                    "Street 5
         district      TYPE ad_city2,                   "District
         postl_cod1    TYPE ad_pstcd1,                  "City Postal Code
         city          TYPE ad_city1,                   "City
         country       TYPE land1,                      "Country
         region        TYPE regio,                      "Region
         langu         TYPE spras,                      "Language
         tel_number    TYPE ad_tlnmbr,                  " Telephone no.: dialling code+number
         mob_number    TYPE ad_tlnmbr,                  " Telephone no.: dialling code+number
         smtp_addr     TYPE ad_smtpadr,                 " E-Mail Address
         fax           TYPE ad_fxnmbr1,          " First fax no.: dialling code+number
         taxtype(4),   "Tax Type
         taxnumber(20),   "Tax number
       END OF ty_file_bp.

TYPES: BEGIN OF ty_file_emp,
         bpartner   TYPE bapibus1006_head-bpartner,  " Business Partner Number
         pernr      TYPE char8,                      " Pernr of type CHAR8
         partn_cat  TYPE bapibus1006_head-partn_cat, " Business Partner Category
         partn_grp  TYPE bapibus1006_head-partn_grp, " Business Partner Grouping
         title      TYPE ad_titletx,                 " Title text
         name1      TYPE bu_nameor1,                 " Name 1 of organization
         name2      TYPE bu_nameor1,                 " Name 1 of organization
         street     TYPE ad_street,                  " Street
         str_suppl3 TYPE ad_strspp3,                 "Street 4
         location   TYPE ad_lctn,                    "Street 5
         district   TYPE ad_city2,                   "District
         postl_cod1 TYPE ad_pstcd1,                  "City Postal Code
         city       TYPE ad_city1,                   "City
         country    TYPE land1,                      "Country
         region     TYPE regio,                      "Region
         langu      TYPE spras,                      "Language
         tel_number TYPE ad_tlnmbr,                  " Telephone no.: dialling code+number
         mob_number TYPE ad_tlnmbr,                  " Telephone no.: dialling code+number
         smtp_addr  TYPE ad_smtpadr,                 " E-Mail Address
       END OF ty_file_emp.

TYPES: BEGIN OF ty_file_vendorc,
         serial     TYPE char10,
         lifnr      TYPE lifnr,      " Account Number of Vendor or Creditor
         pernr      TYPE char8,      "Employee No
         bukrs      TYPE lfb1-bukrs, " Company Code
         akont      TYPE akont,      "Recon Account
         zuawa      TYPE dzuawa,     "Sort Key
         cdi(1),                  "Check Dup Inv
         zterm      TYPE dzterm,     " Terms of payment key
         fdgrv      TYPE fdgrv,      " Planning Group
         altkn      TYPE altkn,      " Previous Master Record Number
         zwels      TYPE dzwels,     " List of Respected Payment Methods
         hbkid      TYPE hbkid,      " Short key for a house bank
         taxtyp1    TYPE bapibus1006tax-taxtype,  " Tax Number Category
         taxnum1    TYPE bapibus1006tax-taxnumber, " Business Partner Tax Number
         taxtyp2    TYPE bapibus1006tax-taxtype,  " Tax Number Category
         taxnum2    TYPE bapibus1006tax-taxnumber, " Business Partner Tax Number
         bank_ctry1 TYPE banks,
         bank_key1  TYPE bankk,
         bank_acct1 TYPE bankn,
         bank_ref1  TYPE bkref,
         bank_hold1 TYPE bu_koinh,
         bank_name1 TYPE bu_bankaccname,
         bank_ctry2 TYPE banks,
         bank_key2  TYPE bankk,
         bank_acct2 TYPE bankn,
         bank_ref2  TYPE bkref,
         bank_hold2 TYPE bu_koinh,
         bank_name2 TYPE bu_bankaccname,
       END OF ty_file_vendorc.

TYPES: BEGIN OF ty_file_vendorp,
         serial   TYPE char10,
         lifnr    TYPE lifnr,  " Account Number of Vendor or Creditor
         vkorg    TYPE vkorg,  " Sales Organization
         waers    TYPE waers,  " Currency Key
         kalsk    TYPE kalsk,  " Group for Calculation Schema (Supplier)
         webre    TYPE webre,  " Indicator: GR-Based Invoice Verification
         zterm    TYPE dzterm, " Terms of payment key
         inco1    TYPE inco1,  " Incoterms (Part 1)
         inco2    TYPE inco2,  " Incoterms (Part 2)
         verkf    TYPE verkf,
         telef    TYPE telef,
         vsbed    TYPE vsbed,
         lebre    TYPE lebre,
         ekgrp    TYPE ekgrp,
         plifz(2) TYPE c,
       END OF ty_file_vendorp.

TYPES: BEGIN OF ty_file_customerc,
         kunnr TYPE kunnr,      " Customer Number
         bukrs TYPE lfb1-bukrs, " Company Code
         akont TYPE akont,      "Recon Account
         zuawa TYPE dzuawa,     "Sort Key
         fdgrv TYPE fdgrv,      "Planning group
         zterm TYPE dzterm,     "Payment Terms
         xzver TYPE xzver,      "Record Payment History
       END OF ty_file_customerc.

TYPES: BEGIN OF ty_file_cr_segment,
         kunnr            TYPE kunnr,      " Customer Number
         limit_rule(10),
         risk_class(3),
         check_rule(10),
         credit_group(4),
         cr_segment(10),
         credit_limit(15),
       END OF ty_file_cr_segment.

TYPES: BEGIN OF ty_file_pf_segment,
         kunnr            TYPE kunnr,      " Customer Number
         vkorg(4),
         vtweg(2),
         spart(2),
         parvw(4),
         kunnr_assign(10),
         del_ind(1),
       END OF ty_file_pf_segment.


TYPES: BEGIN OF ty_file_customers,
         kunnr      TYPE kunnr,      " Customer Number
         vkorg      TYPE knvv-vkorg, " Sales Organization
         vtweg      TYPE knvv-vtweg, " Distribution Channel
         spart      TYPE knvv-spart, " Division
         bzirk      TYPE knvv-bzirk, " Sales District
         kdgrp      TYPE knvv-kdgrp, " Customer Group
         vkbur      TYPE knvv-vkbur, " Sales office
         vkgrp      TYPE knvv-vkgrp, "Sales Group New
         awahr(3),      "TYPE knvv-awahr, "Order Probablity
         waers      TYPE knvv-waers, "Currency New
         kurst      TYPE knvv-kurst, "Exchange Rate  New
         konda      TYPE knvv-konda, "Price Group  New
         kalks      TYPE knvv-kalks, "Customer Pricing Procedure
         pltyp      TYPE knvv-pltyp, "Price List New
         versg      TYPE knvv-versg, "Customer Statistic Group
         agrel      TYPE knvv-agrel, "Indicator: Relevant for Settlement Management
         lprio(2),                   "   TYPE KNVV-LPRIO,"Delivery Prio
         kzazu      TYPE knvv-kzazu, "Order Combination
         vsbed      TYPE knvv-vsbed, "Shipping Conditions
         untto      TYPE string,     "KNVV-UNTTO, "Under Delivery tolerance New
         uebto      TYPE string,     "KNVV-UEBTO, "Over Delivery tolerance New
         bokre      TYPE knvv-bokre, " Rebate
         prfre      TYPE knvv-prfre, " Pricing
         incov      TYPE knvv-incov, "Incoming terms version
         inco1      TYPE knvv-inco1, " Incoterms (Part 1)
         inco2      TYPE knvv-inco2, " Incoterms (Part 2)
         inco3_l    TYPE knvv-inco3_l, " Incoterms 2 location
         zterm      TYPE knvv-zterm, " Terms of payment key
         kkber      TYPE knvv-kkber, "Credit Control Area New
         ktgrd      TYPE knvv-ktgrd, "Account Assignment Group
         taxkd01(1),
         taxkd02(1),
         taxkd03(1),
         taxkd04(1),
         taxkd05(1),
         vwerk      TYPE knvv-vwerk,      " From plant
         podkz      TYPE knvv-podkz,          "POD
         kvgr1      TYPE knvv-kvgr1,
         kvgr2      TYPE knvv-kvgr2,
         kvgr3      TYPE knvv-kvgr3,
         kvgr4      TYPE knvv-kvgr4,
         kvgr5      TYPE knvv-kvgr5,

       END OF ty_file_customers.

DATA: t_filevc TYPE TABLE OF ty_file_vendorc.
DATA: w_filevc TYPE ty_file_vendorc.
DATA: t_filevp TYPE TABLE OF ty_file_vendorp.
DATA: w_filevp TYPE ty_file_vendorp.
DATA: t_filecc TYPE TABLE OF ty_file_customerc.
DATA: w_filecc TYPE ty_file_customerc.
DATA: t_filecs TYPE TABLE OF ty_file_customers.
DATA: w_filecs TYPE ty_file_customers.
DATA: t_filecr TYPE TABLE OF ty_file_cr_segment.

DATA: w_filecr TYPE ty_file_cr_segment.

DATA: t_filepf TYPE TABLE OF ty_file_pf_segment.
DATA: t_filepf1 TYPE TABLE OF ty_file_pf_segment.
DATA: w_filepf TYPE ty_file_pf_segment.

DATA businesspartnerextern        TYPE bapibus1006_head-bpartner. " Business Partner Number
DATA partnercategory              TYPE bapibus1006_head-partn_cat. " Business Partner Category
DATA partnergroup                 TYPE bapibus1006_head-partn_grp. " Business Partner Grouping
DATA centraldata                  TYPE bapibus1006_central. " General BP Data, Independent of Business Partner Category
DATA centraldataperson            TYPE bapibus1006_central_person. " SAP BP: BAPI Structure for Personal Data
DATA centraldataorganization      TYPE bapibus1006_central_organ. " SAP BP: BAPI Structure for Organization Data
DATA addressdata                  TYPE bapibus1006_address. " SAP BP: BAPI Structure for Address Data
DATA businesspartner              TYPE bapibus1006_head-bpartner. " Business Partner Number
DATA it_telephondata                  TYPE STANDARD TABLE OF bapiadtel. " BAPI Structure for Telephone Numbers (Bus. Address Services)
DATA wa_telephondata                  TYPE bapiadtel. " BAPI Structure for Telephone Numbers (Bus. Address Services)
DATA it_maildata                   TYPE STANDARD TABLE OF bapiadsmtp. " BAPI Structure for E-Mail Addresses (Bus. Address Services)
DATA wa_maildata                   TYPE bapiadsmtp. " BAPI Structure for E-Mail Addresses (Bus. Address Services)
DATA return                       TYPE STANDARD TABLE OF bapiret2. " Return Parameter
************************
DATA : it_raw    TYPE truxs_t_text_data.
DATA: it_file TYPE TABLE OF ty_file_bp.
DATA: wa_file TYPE ty_file_bp.
DATA: it_file_e TYPE TABLE OF ty_file_emp.
DATA: wa_file_e TYPE ty_file_emp.
DATA: t_fcat TYPE slis_t_fieldcat_alv.
DATA: w_fcat TYPE slis_fieldcat_alv.
DATA: s_layout TYPE slis_layout_alv.
DATA : lwa_return TYPE bapiret2.
DATA: t_log TYPE TABLE OF zbp_upload, "TY_LOG,
      w_log TYPE zbp_upload.

DATA : r4 TYPE c,
       r5 TYPE c.
DATA : gwa_knvi TYPE knvi.


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-101.
PARAMETERS:p_flname TYPE localfile ,        "File Path
           head(5)  DEFAULT '1' OBLIGATORY. "Header Rows

*PARAMETERS : c1 AS CHECKBOX.             "

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-102.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:r1 RADIOBUTTON GROUP g1 USER-COMMAND r.
SELECTION-SCREEN COMMENT 5(50) TEXT-001 FOR FIELD r1.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:r2 RADIOBUTTON GROUP g1.
SELECTION-SCREEN COMMENT 5(50) TEXT-005 FOR FIELD r2.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:r3 RADIOBUTTON GROUP g1.
SELECTION-SCREEN COMMENT 5(50) TEXT-004 FOR FIELD r3.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:r6 RADIOBUTTON GROUP g1.
SELECTION-SCREEN COMMENT 3(50) TEXT-006 FOR FIELD r3.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:r7 RADIOBUTTON GROUP g1.
SELECTION-SCREEN COMMENT 3(50) TEXT-007 FOR FIELD r7.
SELECTION-SCREEN END OF LINE.


SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b6 WITH FRAME TITLE TEXT-106.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK b6.

AT SELECTION-SCREEN OUTPUT.
  PERFORM at_selection_out.
*&---------------------------------------------------------------------*
*&     SEARCH HELP
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flname.
  PERFORM value_request. "Value Request for File

AT SELECTION-SCREEN.
  PERFORM at_selection.

*&---------------------------------------------------------------------*
*&     Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM validations.
*&---------------------------------------------------------------------*
*&     Create Business Partner
*&---------------------------------------------------------------------*
  IF r1 = 'X'.
    PERFORM upload_xl. "Upload Excel File
    PERFORM fill_fcat_bplog.

* Check whether customers are already created or not
    PERFORM f_validate_ip.

    PERFORM create_bp_add_role. "Create Business Partner with 2 default Roles
    PERFORM display_log_bp.

*&---------------------------------------------------------------------*
*&     Extend Customer Master Sales Data
*&---------------------------------------------------------------------*
  ELSEIF r2 = 'X'.
    PERFORM upload_xl_customer_s. "Upload Customer Sales Area
    PERFORM fill_fcat_customer_s_log.
    PERFORM maintain_customer_s.
    PERFORM display_log_customer_s.

*&---------------------------------------------------------------------*
*&     Extend Customer Master Company Code
*&---------------------------------------------------------------------*

  ELSEIF r3 = 'X'.
    PERFORM upload_xl_customer_cc. "Upload Customer Company Code & Purchase Data Flat File
    PERFORM fill_fcat_customer_cc_log.
    PERFORM maintain_customer_cc.
    PERFORM display_log_customer_cc.

  ELSEIF r6 = abap_true. " ++ By
    PERFORM upload_xl_customer_cr.
    PERFORM fill_fcat_customer_cr_log.
    PERFORM maintain_customer_cr.
    PERFORM display_log_customer_cr.

  ELSEIF r7 = abap_true. " ++ By Roton
    PERFORM upload_xl_customer_pf.
    PERFORM fill_fcat_customer_pf_log.
    PERFORM maintain_customer_pf.
    PERFORM display_log_customer_pf.

  ENDIF. " IF r1 = 'X'

*&---------------------------------------------------------------------*
*&      Form  CALL_BAPI_BUPA_CREATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM call_bapi_bupa_create USING wa_file TYPE ty_file_bp
      CHANGING lv_error.

  DATA: tax_ret TYPE TABLE OF bapiret2,
        lv_bp   TYPE bu_partner.

  CLEAR businesspartner.
  CLEAR: lv_error, w_log.

  lv_bp =  wa_file-sterm1.

  CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
    EXPORTING
      businesspartnerextern   = businesspartnerextern
      partnercategory         = partnercategory
      partnergroup            = partnergroup
      centraldata             = centraldata
      centraldataperson       = centraldataperson
      centraldataorganization = centraldataorganization
      addressdata             = addressdata
    IMPORTING
      businesspartner         = businesspartner
    TABLES
      telefondata             = it_telephondata
      e_maildata              = it_maildata
      return                  = return.

*  LOOP AT return INTO lwa_return WHERE type CA 'EAW'.
  LOOP AT return INTO lwa_return WHERE type CA 'EA'.
*    IF businesspartnerextern IS NOT INITIAL.
*      w_log-bu_partner = businesspartnerextern.
*    ELSE. " ELSE -> IF businesspartnerextern IS NOT INITIAL
*      w_log-bu_partner = businesspartner.
*    ENDIF. " IF businesspartnerextern IS NOT INITIAL

    w_log-sortl = lv_bp.
    w_log-bu_partnerx = 'B'.
    w_log-msg  =  lwa_return-message.
    w_log-msgtyp = lwa_return-type.
    w_log-msgnr = lwa_return-number.
    w_log-uzeit = sy-uzeit.
    w_log-erdat = sy-datum.
    w_log-uname = sy-uname.
*    w_log-bpname = lwa_return-name1.
*    w_log-serial = lwa_return-serial.
    APPEND w_log TO t_log.
*    INSERT zbp_upload FROM w_log.
    CLEAR w_log.

    lv_error = abap_true.

  ENDLOOP.


  IF lv_error IS NOT INITIAL.
    ROLLBACK WORK.
  ENDIF.

  IF businesspartner IS NOT INITIAL.

    IF lv_error IS INITIAL.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
** Added  for Tax numbers
      CALL FUNCTION 'BAPI_BUPA_TAX_ADD'
        EXPORTING
          businesspartner = businesspartner
          taxtype         = wa_file-taxtype
          taxnumber       = wa_file-taxnumber
        TABLES
          return          = tax_ret.
    ENDIF.

    w_log-bu_partner = businesspartner.
    w_log-bu_partnerx = 'B'.

    READ TABLE return INTO DATA(wa) WITH KEY type = 'E'. " Read table return into data(wa of type
    IF sy-subrc = 0.
      w_log-msg  = 'Business Partner Num Generated/Not Created'.
      w_log-msgnr = '002'.
    ELSE. " ELSE -> IF sy-subrc = 0
      w_log-msg  = 'Business Partner Created'.
      w_log-msgnr = '001'.
    ENDIF. " IF sy-subrc = 0

    w_log-msgtyp = 'S'.
    w_log-serial = wa_file-serial.
    w_log-uzeit = sy-uzeit.
    w_log-erdat = sy-datum.
    w_log-uname = sy-uname.
    w_log-serial = wa_file-serial.
    w_log-bpname = wa_file-name1.
    w_log-sortl = centraldata-searchterm1.
    APPEND w_log TO t_log.
    INSERT zbp_upload FROM w_log.
    CLEAR w_log.
*    WAIT UP TO 1 SECONDS.  "comment by Roton


  ENDIF. " IF businesspartner IS NOT INITIAL



**  Error Log Even if Number is generated "Happening in few cases for email.
*  READ TABLE return INTO wa WITH KEY type = 'E'. " Read table return into wa with of type
*  IF sy-subrc = 0.

*  ENDIF. " IF sy-subrc = 0
  IF businesspartnerextern IS NOT INITIAL.
    businesspartner =  businesspartnerextern.
  ENDIF. " IF businesspartnerextern IS NOT INITIAL
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_XL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload_xl .
*  IF P_FLNAME CS '.XLS' OR P_FLNAME CS '.xls'.
*    IF V3 IS INITIAL.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = it_raw
      i_filename           = p_flname
    TABLES
      i_tab_converted_data = it_file.
  DO head TIMES.
    DELETE it_file INDEX 1.
  ENDDO.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FILL_ADDRESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_address .

  IF partnercategory = 2.
    centraldataorganization-name1 = wa_file-name1.
    centraldataorganization-name2 = wa_file-name2.
  ELSEIF partnercategory = 1.
    centraldataperson-firstname = wa_file-name1.
    centraldataperson-lastname = wa_file-name2.
  ENDIF. " IF partnercategory = 2
  addressdata-street =     wa_file-street.
  addressdata-str_suppl1 = wa_file-str_suppl1.
  addressdata-str_suppl2 = wa_file-str_suppl2.
  addressdata-str_suppl3 = wa_file-str_suppl3.
  addressdata-house_no = wa_file-house_no.
  addressdata-location   = wa_file-location  .
  addressdata-district   = wa_file-district  .
  addressdata-postl_cod1 = wa_file-postl_cod1.
  addressdata-city       = wa_file-city      .
  addressdata-country    = wa_file-country   .
  addressdata-region     = wa_file-region    .
  addressdata-langu      = wa_file-langu     .

  REFRESH it_telephondata.
*For Telphone No
  wa_telephondata-country = wa_file-country.
  wa_telephondata-telephone = wa_file-mob_number.
  wa_telephondata-std_no = 'X'.
*  WA_TELEPHONDATA-EXTENSION = '91'.
  wa_telephondata-r_3_user = '3'.
  wa_telephondata-consnumber = '001'.
  wa_telephondata-home_flag = 'X'.
  APPEND wa_telephondata TO it_telephondata.

*for mobile number
  CLEAR wa_telephondata.
  wa_telephondata-country = wa_file-country.
  wa_telephondata-telephone = wa_file-tel_number.
  wa_telephondata-std_no = 'X'.
*  WA_TELEPHONDATA-EXTENSION = '91'.
  wa_telephondata-r_3_user = '1'.
  wa_telephondata-consnumber = '002'.
  wa_telephondata-home_flag = 'X'.
  APPEND wa_telephondata TO it_telephondata.

  REFRESH it_maildata.
  wa_maildata-e_mail = wa_file-smtp_addr.
  wa_maildata-std_no = 'X'.
  wa_maildata-std_recip = 'X'.
  wa_maildata-home_flag = 'X'.
  wa_maildata-consnumber = '001'.
  APPEND wa_maildata TO it_maildata.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FILL_CENTRALDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_centraldata .
  centraldata-searchterm1 = wa_file-sterm1.
*  centraldata-PARTNERTYPE = '0006'.
  centraldata-searchterm2 = wa_file-sterm2.
*  centraldata-partnerlanguage = 'E'.
  centraldata-title_key = wa_file-title.
  centraldata-partnerexternal = wa_file-serial.  "added by Roton

  IF partnercategory = 2.
  ELSE.
*    centraldataperson-correspondlanguage = 'E'.
*    centraldataperson-correspondlanguageiso = 'EN'.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  ADD_ROLE_BP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM add_role_bp.
  DATA businesspartnerrolecategory TYPE bapibus1006_bproles-partnerrolecategory. " BP Role Category
  DATA all_businesspartnerroles    TYPE bapibus1006_x-mark. " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
  DATA businesspartnerrole         TYPE bapibus1006_bproles-partnerrole. " BP Role
  DATA differentiationtypevalue    TYPE bapibus1006_bproles-difftypevalue. " BP: Differentiation type value
  DATA validfromdate               TYPE bapibus1006_bprole_validity-bprolevalidfrom.
  DATA validuntildate              TYPE bapibus1006_bprole_validity-bprolevalidto.
  DATA return                      TYPE STANDARD TABLE OF bapiret2. " Return Parameter
*&---------------------------------------------------------------------*
*&    Add Vendor Roles
*&---------------------------------------------------------------------*
  BREAK-POINT.
  IF wa_file-role1 IS NOT INITIAL.
    DATA : lv_rltyp TYPE but100-rltyp.

    businesspartnerrole = wa_file-role1.
    CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2'
      EXPORTING
        businesspartner             = businesspartner
        businesspartnerrolecategory = businesspartnerrolecategory
        all_businesspartnerroles    = ' '
        businesspartnerrole         = businesspartnerrole
        differentiationtypevalue    = differentiationtypevalue
*       VALIDFROMDATE               = P_DATE
        validuntildate              = '99991231'
      TABLES
        return                      = return.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    DO 5 TIMES.
      CLEAR lv_rltyp.
      SELECT SINGLE rltyp INTO lv_rltyp FROM but100 WHERE partner = businesspartner
                                                      AND rltyp = wa_file-role1.

      IF lv_rltyp IS INITIAL.
        WAIT UP TO 1 SECONDS.  "comment by Roton
      ELSE.
        CONTINUE.
      ENDIF.
    ENDDO.


  ENDIF. " IF v1 IS NOT INITIAL
  IF wa_file-role2 IS NOT INITIAL.
    businesspartnerrole = wa_file-role2.
    CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2'
      EXPORTING
        businesspartner             = businesspartner
        businesspartnerrolecategory = businesspartnerrolecategory
        all_businesspartnerroles    = ' '
        businesspartnerrole         = businesspartnerrole
        differentiationtypevalue    = differentiationtypevalue
*       VALIDFROMDATE               = P_DATE
        validuntildate              = '99991231'
      TABLES
        return                      = return.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    DO 5 TIMES.
      CLEAR lv_rltyp.
      SELECT SINGLE rltyp INTO lv_rltyp FROM but100 WHERE partner = businesspartner
                                                      AND rltyp = wa_file-role2.

      IF lv_rltyp IS INITIAL.
        WAIT UP TO 1 SECONDS.  "comment by Roton
      ELSE.
        CONTINUE.
      ENDIF.
    ENDDO.


*    WAIT UP TO 1 SECONDS. ""comment by

  ENDIF. " IF v2 IS NOT INITIAL

*&---------------------------------------------------------------------*
*&    Add Customer Roles
*&---------------------------------------------------------------------*
  IF wa_file-role3 IS NOT INITIAL.
    businesspartnerrole = wa_file-role3.
    CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2'
      EXPORTING
        businesspartner             = businesspartner
        businesspartnerrolecategory = businesspartnerrolecategory
        all_businesspartnerroles    = ' '
        businesspartnerrole         = businesspartnerrole
        differentiationtypevalue    = differentiationtypevalue
*       VALIDFROMDATE               = P_DATE
        validuntildate              = '99991231'
      TABLES
        return                      = return.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

*    WAIT UP TO 1 SECONDS.  ""comment


    DO 5 TIMES.
      CLEAR lv_rltyp.
      SELECT SINGLE rltyp INTO lv_rltyp FROM but100 WHERE partner = businesspartner
                                                      AND rltyp = wa_file-role3.

      IF lv_rltyp IS INITIAL.
        WAIT UP TO 1 SECONDS.  "comment by
      ELSE.
        CONTINUE.
      ENDIF.
    ENDDO.

  ENDIF. " IF c1 IS NOT INITIAL

  IF wa_file-role4 IS NOT INITIAL.
    businesspartnerrole = wa_file-role4.
    CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2'
      EXPORTING
        businesspartner             = businesspartner
        businesspartnerrolecategory = businesspartnerrolecategory
        all_businesspartnerroles    = ' '
        businesspartnerrole         = businesspartnerrole
        differentiationtypevalue    = differentiationtypevalue
*       VALIDFROMDATE               = P_DATE
        validuntildate              = '99991231'
      TABLES
        return                      = return.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

*    WAIT UP TO 1 SECONDS.  ""comment by

    DO 5 TIMES.
      CLEAR lv_rltyp.
      SELECT SINGLE rltyp INTO lv_rltyp FROM but100 WHERE partner = businesspartner
                                                      AND rltyp = wa_file-role4.

      IF lv_rltyp IS INITIAL.
        WAIT UP TO 1 SECONDS.  "comment by
      ELSE.
        CONTINUE.
      ENDIF.
    ENDDO.


  ENDIF. " IF c2 IS NOT INITIAL

*  CALL FUNCTION 'ZBP_GET_VENDOR'
*    EXPORTING
*      ibu_partner = businesspartner
*    IMPORTING
*      elifnr      = w_log-vendor.

*  CALL FUNCTION 'ZBP_GET_CUSTOMER'
*    EXPORTING
*      ibu_partner = businesspartner
*    IMPORTING
*      ekunnr      = w_log-customer.
*
*  MODIFY t_log FROM w_log TRANSPORTING vendor customer WHERE
*        bu_partner = businesspartner.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  VALUE_REQUEST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM value_request .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name = sy-cprog
    IMPORTING
      file_name    = p_flname.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  CREATE_BP_ADD_ROLL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_bp_add_role .
*  DATA: lw_index TYPE sy-tabix. " ABAP System Field: Row Index of Internal Tables
*  IF V3 IS INITIAL.
  DATA : lv_error TYPE flag.

*  BREAK bhaving.
  DATA l_name1 TYPE kna1-name1. " Name 1
  LOOP AT it_file INTO wa_file.
*    lw_index = sy-tabix.
    partnercategory = wa_file-partn_cat.
    partnergroup = wa_file-partn_grp.
    CLEAR businesspartnerextern.

    IF wa_file-bpartner IS NOT INITIAL.
      businesspartnerextern = wa_file-bpartner.
*      businesspartnerextern = wa_file-serial.
    ENDIF. " IF wa_file-bpartner IS NOT INITIAL

    PERFORM fill_centraldata.
    PERFORM fill_address.
    PERFORM call_bapi_bupa_create USING wa_file CHANGING lv_error.  "comment by Roton for testing.
    IF businesspartner IS NOT INITIAL AND lv_error IS INITIAL.
      PERFORM add_role_bp. "Add Roles for Company Code and Purchase Org data
    ELSE. " ELSE -> IF businesspartner IS NOT INITIAL
*      EXIT.
    ENDIF. " IF businesspartner IS NOT INITIAL
  ENDLOOP. " LOOP AT it_file INTO wa_file
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  UPLOAD_XL_VENDOR_CC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload_xl_vendor_cc.
  IF p_flname CS '.XLS' OR p_flname CS '.xls'.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_tab_raw_data       = it_raw
        i_filename           = p_flname
      TABLES
        i_tab_converted_data = t_filevc.
  ENDIF. " IF p_flname CS ' XLS' OR p_flname CS ' xls'
  DO head TIMES.
    DELETE t_filevc INDEX 1.
  ENDDO.
ENDFORM.
**----------------------------------------------------------------------*
**       CLASS lcl_data IMPLEMENTATION
**----------------------------------------------------------------------*
**
**----------------------------------------------------------------------*
*CLASS lcl_data IMPLEMENTATION. " Data class
**&---------------------------------------------------------------------*
**&  Method to Prepare data for Vendor Creation
**&---------------------------------------------------------------------*
*  METHOD prepare_data.
**   Local Data Declaration
*    DATA: lt_contacts     TYPE vmds_ei_contacts_t,
*          ls_contacts     TYPE vmds_ei_contacts,       " Ext. Interface: Contact Person
*          lt_vendors      TYPE vmds_ei_extern_t,
*          ls_vendors      TYPE vmds_ei_extern,         " Complex External Interface for Vendors
*          ls_address      TYPE cvis_ei_address1,       " Ext. Interface: Address of Organization
*          lt_company      TYPE vmds_ei_company_t,
*          ls_company      TYPE vmds_ei_company,        " Ext. Interface: Company Code Data
*          ls_company_data TYPE vmds_ei_vmd_company,    " Ext. Interface: Company Code Data
*          ls_purchas_data TYPE vmds_ei_vmd_purchasing, " Ext. Interface: Purchasing Data
*          lt_purchasing   TYPE vmds_ei_purchasing_t,
*          ls_purchasing   TYPE vmds_ei_purchasing,     " Ext. Interface: Purchasing Organization
*          lt_purch_func   TYPE vmds_ei_functions_t,
*          ls_purch_func   TYPE vmds_ei_functions,      " Ext. Interface: Partner Roles
*          ls_message      TYPE cvis_message,           " Error Indicator and System Messages
*          lv_contactid    TYPE bapicontact_01-contact. " Number of contact person
*
**   Clear the work area initially.
*    CLEAR gs_vmds_extern.
*    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*      EXPORTING
*        input  = w_filevc-lifnr
*      IMPORTING
*        output = ls_vendors-header-object_instance-lifnr.
*
*    ls_vendors-header-object_task = 'U'. "Represents Insert or Create
*    ls_address-postal-data-name          = but000-mc_name1. "Name of the Vendor
*    ls_address-postal-data-country       = lfa1-land1.
*    ls_address-postal-datax-name         = 'X'.
*    ls_address-postal-datax-country      = 'X'.
*    ls_address-task                      = 'U'.
*
**   Set the Address for the Vendor
*    ls_vendors-central_data-address = ls_address.
*
*
**&---------------------------------------------------------------------*
**&  *   Set the Company Code and GL Account
**&---------------------------------------------------------------------*
*
*    IF w_filevc-bukrs IS NOT INITIAL.
***   Set the Account Group
*      ls_vendors-central_data-central-data-ktokk  = w_filevc-ktokk.
**   Set the DATAX flags
*      ls_vendors-central_data-central-datax-ktokk = 'X'.
*      REFRESH: lt_company[].
*      CLEAR ls_company.
*      ls_company-task                    = 'I'.
*      ls_company-data_key-bukrs  = w_filevc-bukrs.
*      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*        EXPORTING
*          input  = w_filevc-akont
*        IMPORTING
*          output = ls_company-data-akont.
*      ls_company-data-zuawa        = w_filevc-zuawa. "Sort Key
*      ls_company-data-reprf        = w_filevc-cdi. "Check Double invoice                             "Payment Terms
*      ls_company-data-pernr       = w_filevc-pernr.
*      ls_company-datax-pernr       = 'X'.
*      ls_company-datax-akont       = 'X'.
*      ls_company-datax-zuawa      = 'X'.
*      ls_company-datax-reprf        = 'X'. "Check Double invoice
*      APPEND ls_company TO lt_company.
*      ls_company_data-company = lt_company[].
*      ls_vendors-company_data = ls_company_data.
*    ENDIF. " IF w_filevc-bukrs IS NOT INITIAL
**&---------------------------------------------------------------------*
**&  *   Set the Purchasing Data
**&---------------------------------------------------------------------*
*    IF w_filevp-vkorg IS NOT INITIAL.
*      ls_purchasing-task                   = 'I'.
*      ls_purchasing-data_key-ekorg = w_filevp-vkorg. "Purchasing Organization
*      ls_purchasing-data-waers = w_filevp-waers.
*      ls_purchasing-datax-waers = 'X'.
*
*      ls_purchasing-data-zterm = w_filevp-zterm.
*      ls_purchasing-datax-zterm = 'X'.
*
*      ls_purchasing-data-inco1 = w_filevp-inco1.
*      ls_purchasing-datax-inco1 = 'X'.
*
*      ls_purchasing-data-inco2 = w_filevp-inco2.
*      ls_purchasing-datax-inco2 = 'X'.
*
*      ls_purchasing-data-kalsk         = w_filevp-kalsk. "Schema Group, Vendor
*      ls_purchasing-datax-kalsk       = 'X'.
*
*      ls_purchasing-data-webre       = w_filevp-webre . "GR Based Invoice Verification
*      ls_purchasing-datax-webre      = 'X'.
*************************************
**      DATA iv_ktokd TYPE ktokd. " Customer Account Group
**      DATA et_parvw TYPE vmds_parvw_t.
**      REFRESH et_parvw.
**      CALL METHOD vmd_ei_api_check=>get_mand_partner_functions
**        EXPORTING
**          iv_ktokk = w_filev-ktokk
**        IMPORTING
**          et_parvw = et_parvw.
**
**      LOOP AT et_parvw INTO DATA(wa_parvw).
**        ls_purch_func-task = 'I'.
***        CALL FUNCTION 'CONVERSION_EXIT_PARVW_OUTPUT'
***          EXPORTING
***            INPUT  = WA_PARVW-PARVW
***          IMPORTING
***            OUTPUT = LS_PURCH_FUNC-DATA_KEY-PARVW.
**        ls_purch_func-data_key-parvw = wa_parvw-parvw.
**        ls_purch_func-data-partner = w_filev-lifnr.
**        ls_purch_func-datax-partner = 'X'.
**        APPEND ls_purch_func TO lt_purch_func.
**        CLEAR ls_purch_func.
**      ENDLOOP. " LOOP AT et_parvw INTO DATA(wa_parvw)
**      ls_purchasing-functions-functions = lt_purch_func[].
**      APPEND ls_purchasing TO lt_purchasing.
*
**   Set the Purchasing Data
*      ls_purchas_data-purchasing = lt_purchasing[].
*
*******************************
*      ls_vendors-purchasing_data = ls_purchas_data.
*    ENDIF. " IF w_filevp-vkorg IS NOT INITIAL
*    APPEND ls_vendors TO lt_vendors.
**   Set the Final Vendor Data based on which it has to be created
**   Note if multiple vendors are to be created...please maintain multiple entries in LT_VENDORS
*    gs_vmds_extern-vendors = lt_vendors[].
*  ENDMETHOD. "prepare_data
**&---------------------------------------------------------------------*
**&  Method to Create Vendor Data
**&---------------------------------------------------------------------*
*  METHOD create_vendor_data.
**   Local Data Declaration
*    DATA: lv_return TYPE i. " Return of type Integers
*
**   Prepare the data to be used for Vendor Creation
*    lv_return =  me->prepare_data( ).
*
**   Do not proceed if the Vendor Data for creation was not prepared
*    IF lv_return IS NOT INITIAL.
*      EXIT.
*    ENDIF. " IF lv_return IS NOT INITIAL
*
**   Initialize all the data
*    vmd_ei_api=>initialize( ).
**   Call the Method for creation of Vendor.
*    CALL METHOD vmd_ei_api=>maintain_bapi
*      EXPORTING
*        is_master_data           = gs_vmds_extern
*      IMPORTING
*        es_master_data_correct   = gs_vmds_succ
*        es_message_correct       = gs_succ_messages
*        es_master_data_defective = gs_vmds_error
*        es_message_defective     = gs_err_messages.
*
**    IF gs_err_messages-is_error IS INITIAL.
**      COMMIT WORK.
**      WAIT UP TO 1 SECONDS.
**      w_log-BU_PARTNER = w_filev-lifnr.
**      w_log-BU_PARTNERx = 'V'.
**      w_log-msg  = 'Vendor Extended' .
**      w_log-msgtyp = 'S'.
**      w_log-msgnr = '001'.
**      w_log-uzeit = sy-uzeit.
**      w_log-erdat = sy-datum.
**      w_log-uname = sy-uname.
**      w_log-bpname = but000-name_first.
**      APPEND w_log TO t_log.
**      INSERT zbp_upload FROM w_log.
**      CLEAR w_log.
**    ELSE. " ELSE -> IF gs_err_messages-is_error IS INITIAL
**      LOOP AT gs_err_messages-messages INTO DATA(wa).
**        w_log-BU_PARTNER = w_filev-lifnr.
**        w_log-BU_PARTNERx = 'V'.
**        w_log-msg  = wa-message.
**        w_log-msgtyp = wa-type.
**        w_log-msgnr = wa-number.
**        w_log-uzeit = sy-uzeit.
**        w_log-erdat = sy-datum.
**        w_log-uname = sy-uname.
**        w_log-bpname = but000-name_first.
**        APPEND w_log TO t_log.
**        INSERT zbp_upload FROM w_log.
**        CLEAR w_log.
**      ENDLOOP. " LOOP AT gs_err_messages-messages INTO DATA(wa)
**    ENDIF. " IF gs_err_messages-is_error IS INITIAL
*  ENDMETHOD. "create_vendor_data
*ENDCLASS. "lcl_data IMPLEMENTATION
*&---------------------------------------------------------------------*
*&      Form  FILL_FCAT_VENDORLOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_fcat_vendorlog_cc .
  s_layout-colwidth_optimize = 'X'.
  s_layout-zebra = 'X'.

  w_fcat-fieldname = 'SERIAL'.
  w_fcat-seltext_l = 'Serial'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR: w_fcat.

  w_fcat-fieldname = 'MSGTYP'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message Type'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGNR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message No'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'BU_PARTNER'.
  w_fcat-no_zero = 'X'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Bu.Partner'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSG'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'BPNAME'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Vendor Name'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'VENDOR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Vendor'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'SORTL'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Serach Term 1'.
  APPEND w_fcat TO t_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_LOG_VENDOR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_log_vendor_cc.
  CHECK t_log IS NOT INITIAL.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_title = 'Log'
      is_layout    = s_layout
      it_fieldcat  = t_fcat
    TABLES
      t_outtab     = t_log
* EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS       = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF. " IF sy-subrc <> 0
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_LOG_BP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_log_bp .
  CHECK t_log IS NOT INITIAL.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_title = 'Log'
      is_layout    = s_layout
      it_fieldcat  = t_fcat
    TABLES
      t_outtab     = t_log
* EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS       = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF. " IF sy-subrc <> 0
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FILL_FCAT_BPLOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_fcat_bplog .
  s_layout-colwidth_optimize = 'X'.
  s_layout-zebra = 'X'.

  w_fcat-fieldname = 'SERIAL'.
  w_fcat-seltext_l = 'Serial'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGTYP'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message Type'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGNR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message No'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'BU_PARTNER'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-no_zero = 'X'.
  w_fcat-seltext_l = 'Business Partner'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

*  w_fcat-fieldname = 'PERNR'.
*  w_fcat-tabname = 'T_LOG'.
*  w_fcat-no_zero = 'X'.
*  w_fcat-seltext_l = 'Employee'.
*  APPEND w_fcat TO t_fcat.
*  CLEAR w_fcat.

  w_fcat-fieldname = 'MSG'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'BPNAME'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Business partner Name'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'VENDOR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Vendor'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'SORTL'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Serach Term 1'.
  APPEND w_fcat TO t_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  UPDATE_LOG_BP_NOT_FOUND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM update_log_bp_not_found USING p_lifnr p_serial.
  w_log-bu_partner = p_lifnr.
  w_log-bu_partnerx = 'V'.
  w_log-msg  = 'Business Partner not found'.
  w_log-msgtyp = 'E'.
  w_log-msgnr = '001'.
  w_log-uzeit = sy-uzeit.
  w_log-erdat = sy-datum.
  w_log-uname = sy-uname.
  w_log-serial = p_serial.
*  W_LOG-BPNAME =
  APPEND w_log TO t_log.
  INSERT zbp_upload FROM w_log.
  CLEAR w_log.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  MAINTAIN_VENDOR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM maintain_vendor_cc.

*   Local Data Declaration
  DATA: lt_vendors       TYPE vmds_ei_extern_t,
        ls_vendors       TYPE vmds_ei_extern,      " Complex External Interface for Vendors
        ls_address       TYPE cvis_ei_address1,    " Ext. Interface: Address of Organization
        lt_company       TYPE vmds_ei_company_t,
        ls_company       TYPE vmds_ei_company,     " Ext. Interface: Company Code Data
        ls_company_data  TYPE vmds_ei_vmd_company, " Ext. Interface: Company Code Data
        ls_message       TYPE cvis_message,        " Error Indicator and System Messages
        gs_vmds_extern   TYPE vmds_ei_main,        " Ext. Interface: Vendor Total Data
        gs_succ_messages TYPE cvis_message,        " Error Indicator and System Messages
        gs_vmds_error    TYPE vmds_ei_main,        " Ext. Interface: Vendor Total Data
        gs_err_messages  TYPE cvis_message,        " Error Indicator and System Messages
        gs_vmds_succ     TYPE vmds_ei_main,        " Ext. Interface: Vendor Total Data
        gv_ktokk         TYPE ktokk,               " Vendor account group
        gv_ccode         TYPE bukrs,               " Company Code
        gv_akont         TYPE akont,               " Reconciliation Account in General Ledger
        gv_name          TYPE name1.               " Name

  DATA: lw_bupa TYPE bu_partner.
* Create an instance of our class
*  CREATE OBJECT lo_data.
  LOOP AT t_filevc INTO w_filevc.

    CALL FUNCTION 'ZGET_BUPA_NUMBER_V'
      EXPORTING
        ivendor     = w_filevc-lifnr
      IMPORTING
        ebu_partner = lw_bupa.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filevc-lifnr
      IMPORTING
        output = w_filevc-lifnr.

    SELECT SINGLE * FROM lfa1 WHERE lifnr = w_filevc-lifnr.
    IF sy-subrc = 0.
*   Clear the work area initially.
      CLEAR gs_vmds_extern.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = w_filevc-lifnr
        IMPORTING
          output = ls_vendors-header-object_instance-lifnr.

      ls_vendors-header-object_task = 'U'. "Represents Insert or Create
      ls_address-postal-data-name          = lfa1-name1. "Name of the Vendor
      ls_address-postal-data-country       = lfa1-land1.
      ls_address-postal-datax-name         = 'X'.
      ls_address-postal-datax-country      = 'X'.
      ls_address-task                      = 'U'.

*   Set the Address for the Vendor
      ls_vendors-central_data-address = ls_address.
*&---------------------------------------------------------------------*
*&  *   Set the Company Code
*&---------------------------------------------------------------------*

      IF w_filevc-bukrs IS NOT INITIAL.

        REFRESH: lt_company[],lt_vendors.
        CLEAR: ls_company_data.
        CLEAR ls_company.
        ls_company-task                    = 'I'.
        ls_company-data_key-bukrs  = w_filevc-bukrs.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            input  = w_filevc-akont
          IMPORTING
            output = ls_company-data-akont.
        ls_company-data-zuawa        = w_filevc-zuawa. "Sort Key
        ls_company-data-reprf        = w_filevc-cdi. "Check Double invoice                             "Payment Terms
        ls_company-data-pernr       = w_filevc-pernr.
        ls_company-data-zterm       = w_filevc-zterm.
        ls_company-data-fdgrv = w_filevc-fdgrv.
        ls_company-data-altkn = w_filevc-altkn.
        ls_company-data-zwels = w_filevc-zwels.
        ls_company-data-hbkid = w_filevc-hbkid.
*        ls_company-data-
        ls_company-datax-pernr       = 'X'.
        ls_company-datax-akont       = 'X'.
        ls_company-datax-zuawa      = 'X'.
        ls_company-datax-zterm = 'X'.
        ls_company-datax-reprf        = 'X'. "Check Double invoice
        ls_company-datax-fdgrv = 'X'.
        ls_company-datax-altkn = 'X'.
        ls_company-datax-zwels = 'X'.
        ls_company-datax-hbkid = 'X'.

        APPEND ls_company TO lt_company.
        ls_company_data-company = lt_company[].
        ls_vendors-company_data = ls_company_data.
      ENDIF. " IF w_filevc-bukrs IS NOT INITIAL
      APPEND ls_vendors TO lt_vendors.
      gs_vmds_extern-vendors = lt_vendors[].
*   Initialize all the data
      vmd_ei_api=>initialize( ).
*   Call the Method for creation of Vendor.
      CALL METHOD vmd_ei_api=>maintain_bapi
        EXPORTING
          is_master_data           = gs_vmds_extern
        IMPORTING
          es_master_data_correct   = gs_vmds_succ
          es_message_correct       = gs_succ_messages
          es_master_data_defective = gs_vmds_error
          es_message_defective     = gs_err_messages.

      IF gs_err_messages-is_error IS INITIAL.
        COMMIT WORK.
        WAIT UP TO 1 SECONDS.
        w_log-vendor = w_filevc-lifnr.
        w_log-bu_partner = lw_bupa.
        w_log-bu_partnerx = 'V'.
        w_log-msg  = 'Vendor Extended' .
        w_log-msgtyp = 'S'.
        w_log-msgnr = '001'.
        w_log-uzeit = sy-uzeit.
        w_log-erdat = sy-datum.
        w_log-uname = sy-uname.
        w_log-bpname = lfa1-name1.
        w_log-serial = w_filevc-serial.
        APPEND w_log TO t_log.
        INSERT zbp_upload FROM w_log.
        CLEAR w_log.
        PERFORM update_bp_supplimentary.
      ELSE. " ELSE -> IF gs_err_messages-is_error IS INITIAL
        LOOP AT gs_err_messages-messages INTO DATA(wa).
          w_log-vendor = w_filevc-lifnr.
          w_log-bu_partner = lw_bupa.
          w_log-bu_partnerx = 'V'.
          w_log-msg  = wa-message.
          w_log-msgtyp = wa-type.
          w_log-msgnr = wa-number.
          w_log-uzeit = sy-uzeit.
          w_log-erdat = sy-datum.
          w_log-uname = sy-uname.
          w_log-bpname = lfa1-name1.
          w_log-serial = w_filevc-serial.
          APPEND w_log TO t_log.
          INSERT zbp_upload FROM w_log.
          CLEAR w_log.
        ENDLOOP. " LOOP AT gs_err_messages-messages INTO DATA(wa)
      ENDIF. " IF gs_err_messages-is_error IS INITIAL

    ELSE. " ELSE -> IF w_filevc-bukrs IS NOT INITIAL
      PERFORM update_log_bp_not_found USING w_filevc-lifnr w_filevc-serial.
    ENDIF. " IF sy-subrc = 0
  ENDLOOP. " LOOP AT t_filevc INTO w_filevc
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_XL_CUSTOMER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload_xl_customer_cc .
  IF p_flname CS '.XLS' OR p_flname CS '.xls'.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_tab_raw_data       = it_raw
        i_filename           = p_flname
      TABLES
        i_tab_converted_data = t_filecc.
  ENDIF. " IF p_flname CS ' XLS' OR p_flname CS ' xls'
  DO head TIMES.
    DELETE t_filecc INDEX 1.
  ENDDO.
ENDFORM.
FORM upload_xl_customer_cr .
  IF p_flname CS '.XLS' OR p_flname CS '.xls'.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_tab_raw_data       = it_raw
        i_filename           = p_flname
      TABLES
        i_tab_converted_data = t_filecr.
  ENDIF. " IF p_flname CS ' XLS' OR p_flname CS ' xls'
  DO head TIMES.
    DELETE t_filecr INDEX 1.
  ENDDO.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  AT_SELECTION_OUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM at_selection_out .
*  LOOP AT SCREEN.
*    IF screen-group1 = 'CHK'.
*      IF r1 = 'X' OR ( r1 IS INITIAL AND r2 IS INITIAL AND r3 IS INITIAL AND r4 IS INITIAL AND r5 IS INITIAL ).
*        screen-active = 1.
*      ELSE. " ELSE -> IF r1 = 'X' OR ( r1 IS INITIAL AND r2 IS INITIAL AND r3 IS INITIAL AND r4 IS INITIAL AND r5 IS INITIAL )
*        screen-active = 0.
*      ENDIF. " IF r1 = 'X' OR ( r1 IS INITIAL AND r2 IS INITIAL AND r3 IS INITIAL AND r4 IS INITIAL AND r5 IS INITIAL )
*      MODIFY SCREEN.
*    ENDIF. " IF screen-group1 = 'CHK'
*  ENDLOOP. " LOOP AT SCREEN
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  AT_SELECTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM at_selection .

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  VALIDATIONS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM validations .
*  IF r1 IS NOT INITIAL.
*    IF P_DATE IS INITIAL.
*      MESSAGE 'Fill Date' TYPE 'S'.
*      LEAVE LIST-PROCESSING.
*    ENDIF.
  IF p_flname IS INITIAL.
    MESSAGE 'File Name' TYPE 'S'.
    LEAVE LIST-PROCESSING.
  ENDIF. " IF p_flname IS INITIAL
*    IF c1 IS INITIAL AND c2 IS INITIAL AND v1 IS INITIAL AND v2 IS INITIAL.
*      MESSAGE 'Select atleast 1 Role' TYPE 'S'.
*      LEAVE LIST-PROCESSING.
*    ENDIF. " IF c1 IS INITIAL AND c2 IS INITIAL AND v1 IS INITIAL AND v2 IS INITIAL
*  ENDIF. " IF r1 IS NOT INITIAL
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_XL_CUSTOMER_PUR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload_xl_customer_s .
  IF p_flname CS '.XLS' OR p_flname CS '.xls'.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_tab_raw_data       = it_raw
        i_filename           = p_flname
      TABLES
        i_tab_converted_data = t_filecs.
  ENDIF. " IF p_flname CS ' XLS' OR p_flname CS ' xls'
  DO head TIMES.
    DELETE t_filecs INDEX 1.
  ENDDO.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FILL_FCAT_CUSTOMERLOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_fcat_customer_cc_log .
  s_layout-colwidth_optimize = 'X'.
  s_layout-zebra = 'X'.

  w_fcat-fieldname = 'MSGTYP'.
  w_fcat-seltext_l = 'Message Type'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGNR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message No'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'BU_PARTNER'.
  w_fcat-no_zero = 'X'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'KUNNR'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSG'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'BPNAME'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Customer Name'.
  APPEND w_fcat TO t_fcat.
ENDFORM.
FORM fill_fcat_customer_cr_log .
  s_layout-colwidth_optimize = 'X'.
  s_layout-zebra = 'X'.

  w_fcat-fieldname = 'MSGTYP'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message Type'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGNR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message No'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'BU_PARTNER'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-no_zero = 'X'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'KUNNR'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSG'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'BPNAME'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Customer Name'.
  APPEND w_fcat TO t_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  MAINTAIN_CUSTOMER_CC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM maintain_customer_cc .
*DATA IV_TEST_RUN              TYPE XFELD.
*DATA IV_COLLECT_MESSAGES      TYPE XFELD.
  DATA is_master_data           TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_master_data_correct   TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_message_correct       TYPE cvis_message. " Error Indicator and System Messages
  DATA es_master_data_defective TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_message_defective     TYPE cvis_message. " Error Indicator and System Messages

  DATA: lt_customers    TYPE cmds_ei_extern_t,
        ls_customers    TYPE cmds_ei_extern,         " Complex External Interface for Customers
        ls_address      TYPE cvis_ei_address1,       " Ext. Interface: Address of Organization
        lt_company      TYPE cmds_ei_company_t,
        ls_company      TYPE cmds_ei_company,        " Ext. Interface: Company Code Data
        ls_company_data TYPE cmds_ei_cmd_company,    " Ext. Interface: Company Code Data
        ls_message      TYPE cvis_message,           " Error Indicator and System Messages
        lv_contactid    TYPE bapicontact_01-contact. " Number of contact person
  LOOP AT t_filecc INTO w_filecc.
*   Clear the work area initially.
    REFRESH is_master_data-customers.
    REFRESH lt_customers[].
    REFRESH lt_company[].
    CLEAR ls_customers.
    CLEAR ls_company_data.
    CLEAR ls_address.
    CLEAR ls_company.
    CLEAR is_master_data.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filecc-kunnr
      IMPORTING
        output = ls_customers-header-object_instance-kunnr.
    CLEAR kna1.
    SELECT SINGLE * FROM kna1 WHERE kunnr = ls_customers-header-object_instance-kunnr.
    ls_customers-header-object_task = 'U'. "Represents Insert or Create
    ls_address-postal-data-name          = kna1-name1. "Name of the Vendor
    ls_address-postal-data-country       = kna1-land1.
    ls_address-postal-datax-name         = 'X'.
    ls_address-postal-datax-country      = 'X'.
    ls_address-task                      = 'U'.

*   Set the Address for the Vendor
    ls_customers-central_data-address = ls_address.
*   Set the DATAX flags
*    LS_CUSTOMERS-CENTRAL_DATA-CENTRAL-DATAX-KTOKD = 'X'.
*&---------------------------------------------------------------------*
*&  *   Set the Company Code and GL Account
*&---------------------------------------------------------------------*
    REFRESH: lt_company[].
    CLEAR ls_company.
    ls_company-task                    = 'I'.
    ls_company-data_key-bukrs  = w_filecc-bukrs.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filecc-akont
      IMPORTING
        output = ls_company-data-akont.
    ls_company-data-zterm         = w_filecc-zterm. "Terms
    ls_company-data-wakon         = w_filecc-zterm.  " B/E Payment terms
    ls_company-data-zuawa         = w_filecc-zuawa. "Sort key
    ls_company-data-xzver         = w_filecc-xzver. "Record Payment History
    ls_company-data-fdgrv         = w_filecc-fdgrv. "Planning Group
    ls_company-datax-akont        = 'X'.
    ls_company-datax-zterm        = 'X'.
    ls_company-datax-wakon        = 'X'.
    ls_company-datax-zuawa        = 'X'. "Sort key
    ls_company-datax-xzver        = 'X'. "Record Payment History
    ls_company-datax-fdgrv        = 'X'. "Planning Group
    APPEND ls_company TO lt_company.
    ls_company_data-company = lt_company[].
    ls_customers-company_data = ls_company_data.
    APPEND ls_customers TO lt_customers.
    is_master_data-customers = lt_customers[].
    cmd_ei_api=>initialize( ).
    CALL METHOD cmd_ei_api=>maintain_bapi
      EXPORTING
*       IV_TEST_RUN              = SPACE
*       IV_COLLECT_MESSAGES      = SPACE
        is_master_data           = is_master_data
      IMPORTING
        es_master_data_correct   = es_master_data_correct
        es_message_correct       = es_message_correct
        es_master_data_defective = es_master_data_defective
        es_message_defective     = es_message_defective.
    IF es_message_defective-is_error IS INITIAL.
      COMMIT WORK.
      WAIT UP TO 1 SECONDS.
      w_log-bu_partner = w_filecc-kunnr.
      w_log-bu_partnerx = 'C'.
      w_log-msg  = 'Customer Extended to Company Code' .
      w_log-msgtyp = 'S'.
      w_log-msgnr = '001'.
      w_log-uzeit = sy-uzeit.
      w_log-erdat = sy-datum.
      w_log-uname = sy-uname.
      w_log-bpname = kna1-name1.
      APPEND w_log TO t_log.
      INSERT zbp_upload FROM w_log.
      CLEAR w_log.
    ELSE. " ELSE -> IF es_message_defective-is_error IS INITIAL
      LOOP AT es_message_defective-messages INTO DATA(wa).
        w_log-bu_partner = w_filecc-kunnr.
        w_log-bu_partnerx = 'C'.
        w_log-msg  = wa-message.
        w_log-msgtyp = wa-type.
        w_log-msgnr = wa-number.
        w_log-uzeit = sy-uzeit.
        w_log-erdat = sy-datum.
        w_log-uname = sy-uname.
        w_log-bpname = kna1-name1.
        APPEND w_log TO t_log.
        INSERT zbp_upload FROM w_log.
        CLEAR w_log.
      ENDLOOP. " LOOP AT es_message_defective-messages INTO DATA(wa)
    ENDIF. " IF es_message_defective-is_error IS INITIAL
  ENDLOOP. " LOOP AT t_filecc INTO w_filecc
ENDFORM.
FORM maintain_customer_cr .
  DATA:
    io_facade               TYPE REF TO cl_ukm_facade,
    io_partner              TYPE REF TO cl_ukm_business_partner,
    io_bupa_factory         TYPE REF TO cl_ukm_bupa_factory,
    io_account              TYPE REF TO cl_ukm_account,
    io_ref_business_partner TYPE REF TO cl_udm_business_partner,
    i_return                TYPE ukm_t_monitor_return,
    wa_return               LIKE LINE OF i_return,

    wa_ukm_s_bp_cms         TYPE ukm_s_bp_cms,
    wa_ukmbp_sgm            TYPE ukmbp_cms_sgm,
    wa_bp_cms               TYPE ukm_s_bp_cms,

    wa_bp_credit_sgm        TYPE ukm_s_bp_cms_sgm,

    i_credstd               TYPE STANDARD TABLE OF bp1010,

    et_return               TYPE bapiret2_t,

    wa_credstd              TYPE bp1010,
    es_return               LIKE LINE OF et_return.

  DATA:
    lv_partner        TYPE bu_partner,
    lv_credit_segment TYPE ukm_credit_sgmnt.

  LOOP AT t_filecr INTO w_filecr.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filecr-kunnr
      IMPORTING
        output = lv_partner.

    SELECT SINGLE * FROM kna1 WHERE kunnr = lv_partner.

    lv_credit_segment = w_filecr-cr_segment.

    io_facade = cl_ukm_facade=>create( i_activity = cl_ukm_cnst_eventing=>bp_maintenance ).
    io_bupa_factory = io_facade->get_bupa_factory( ).
    io_partner = io_bupa_factory->get_business_partner( lv_partner ).

* Get Credit Profile Data
    io_partner->get_bp_cms( IMPORTING es_bp_cms = wa_bp_cms ).

* Set Credit Profile Data
    wa_bp_cms-check_rule = w_filecr-check_rule.
    wa_bp_cms-limit_rule = w_filecr-limit_rule.
    wa_bp_cms-risk_class = w_filecr-risk_class.
    wa_bp_cms-credit_group = w_filecr-credit_group.

    io_partner->set_bp_cms( EXPORTING is_bp_cms = wa_bp_cms ).

* Get Credit Account
    CALL METHOD io_bupa_factory->get_credit_account
      EXPORTING
        i_partner         = lv_partner
        i_credit_sgmnt    = lv_credit_segment
      RECEIVING
        ro_credit_account = io_account.

    IF io_account IS NOT INITIAL.

* Get credit Segment Data
      io_account->get_bp_cms_sgm( IMPORTING es_bp_cms_sgm = wa_bp_credit_sgm ).

      wa_bp_credit_sgm-credit_limit = w_filecr-credit_limit.

* Set Credit Segment Data.
      io_account->set_bp_cms_sgm( EXPORTING is_bp_cms_sgm = wa_bp_credit_sgm ).
    ENDIF.

* Update the credit segment and credit profile
    io_bupa_factory->save_all( EXPORTING i_upd_task = abap_true
    RECEIVING et_return = i_return   ).
    IF i_return[] IS  INITIAL.
      COMMIT WORK.
      WAIT UP TO 1 SECONDS.
      w_log-bu_partner = w_filecr-kunnr.
      w_log-bu_partnerx = 'S'. " Credit
      w_log-msg  = 'Credit Segment uploaded without any error' .
      w_log-msgtyp = 'S'.
      w_log-msgnr = '001'.
      w_log-uzeit = sy-uzeit.
      w_log-erdat = sy-datum.
      w_log-uname = sy-uname.
      w_log-bpname = kna1-name1.
      APPEND w_log TO t_log.
      INSERT zbp_upload FROM w_log.
      CLEAR w_log.
    ELSE.
      LOOP AT i_return INTO DATA(wa).
        w_log-bu_partner = w_filecr-kunnr.
        w_log-bu_partnerx = 'C'.
        w_log-msg  = wa-message.
        w_log-msgtyp = wa-msgty.
        w_log-msgnr = wa-msgno.
        w_log-uzeit = sy-uzeit.
        w_log-erdat = sy-datum.
        w_log-uname = sy-uname.
        w_log-bpname = kna1-name1.
        APPEND w_log TO t_log.
        INSERT zbp_upload FROM w_log.
        CLEAR w_log.
      ENDLOOP.
    ENDIF.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_LOG_CUSTOMER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_log_customer_cc .
  CHECK t_log IS NOT INITIAL.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_title = 'Log'
      is_layout    = s_layout
      it_fieldcat  = t_fcat
    TABLES
      t_outtab     = t_log
* EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS       = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF. " IF sy-subrc <> 0
ENDFORM.
FORM display_log_customer_cr .
  CHECK t_log IS NOT INITIAL.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_title = 'Log'
      is_layout    = s_layout
      it_fieldcat  = t_fcat
    TABLES
      t_outtab     = t_log
* EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS       = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF. " IF sy-subrc <> 0
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  CLEAR_CC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM clear_cc .

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  FILL_FCAT_CUSTOMER_P_LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_fcat_customer_s_log .
  s_layout-colwidth_optimize = 'X'.
  s_layout-zebra = 'X'.

  w_fcat-fieldname = 'MSGTYP'.
  w_fcat-seltext_l = 'Message Type'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGNR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message No'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'BU_PARTNER'.
  w_fcat-no_zero = 'X'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Customer'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSG'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'BPNAME'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Customer Name'.
  APPEND w_fcat TO t_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  MAINTAIN_CUSTOMER_S
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM maintain_customer_s .
  DATA is_master_data           TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_master_data_correct   TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_message_correct       TYPE cvis_message. " Error Indicator and System Messages
  DATA es_master_data_defective TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_message_defective     TYPE cvis_message. " Error Indicator and System Messages

  DATA: lt_customers    TYPE cmds_ei_extern_t,
        ls_customers    TYPE cmds_ei_extern,         " Complex External Interface for Customers
        ls_address      TYPE cvis_ei_address1,       " Ext. Interface: Address of Organization
        ls_sales_data   TYPE cmds_ei_cmd_sales,      " Ext. Interface: Sales Data
        ls_central_data TYPE cmds_ei_central_data,   " External Interface: Central Data
        lt_sales        TYPE cmds_ei_sales_t,
        ls_sales        TYPE cmds_ei_sales,          " Ext. Interface: Sales Data
        lt_sales_func   TYPE cmds_ei_functions_t,
        ls_sales_func   TYPE cmds_ei_functions,      " Ext. Interface: Partner Roles
        ls_tax_data     TYPE cmds_ei_tax_ind,        " Ext. Interface: Tax Indicators
        lt_tax_data     TYPE cmds_ei_tax_ind_t,
        ls_message      TYPE cvis_message,           " Error Indicator and System Messages
        lv_contactid    TYPE bapicontact_01-contact. " Number of contact person
  LOOP AT t_filecs INTO w_filecs.
*   Clear the work area initially.
    REFRESH lt_tax_data.
    REFRESH is_master_data-customers.
    REFRESH lt_customers[].
    REFRESH lt_sales[].
    REFRESH lt_sales_func.
    CLEAR ls_tax_data.
    CLEAR ls_sales_func.
    CLEAR ls_customers.
    CLEAR ls_address.
    CLEAR is_master_data.
    CLEAR ls_sales_data.
    CLEAR lt_sales     .
    CLEAR ls_sales     .
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filecs-kunnr
      IMPORTING
        output = ls_customers-header-object_instance-kunnr.
    CLEAR kna1.
    SELECT SINGLE * FROM kna1 WHERE kunnr = ls_customers-header-object_instance-kunnr.
    ls_customers-header-object_task = 'U'. "Represents Insert or Create
    ls_address-postal-data-name          = kna1-name1. "Name of the Vendor
    ls_address-postal-data-country       = kna1-land1.
    ls_address-postal-datax-name         = 'X'.
    ls_address-postal-datax-country      = 'X'.
    ls_address-task                      = 'U'.

*   Set the Address for the Vendor
    ls_customers-central_data-address = ls_address.
*   Set the DATAX flags
    ls_sales-task = 'I'.

    ls_sales-data_key-vkorg = w_filecs-vkorg.
    ls_sales-data_key-vtweg = w_filecs-vtweg.
    ls_sales-data_key-spart = w_filecs-spart.

    ls_sales-data-bzirk = w_filecs-bzirk.
    ls_sales-data-kdgrp = w_filecs-kdgrp.
    ls_sales-data-vkbur = w_filecs-vkbur.
    ls_sales-data-vkgrp = w_filecs-vkgrp.
    ls_sales-data-waers = w_filecs-waers.
    ls_sales-data-kurst = w_filecs-kurst.
    ls_sales-data-konda = w_filecs-konda.
    ls_sales-data-kalks = w_filecs-kalks.
    ls_sales-data-versg = w_filecs-versg.
    ls_sales-data-lprio = w_filecs-lprio.
    ls_sales-data-kzazu = w_filecs-kzazu.
    ls_sales-data-vsbed = w_filecs-vsbed.
    ls_sales-data-untto = w_filecs-untto.
    ls_sales-data-uebto = w_filecs-uebto.
    ls_sales-data-inco1 = w_filecs-inco1.
    ls_sales-data-inco2 = w_filecs-inco2.
    ls_sales-data-zterm = w_filecs-zterm.
    ls_sales-data-kkber = w_filecs-kkber.
    ls_sales-data-ktgrd = w_filecs-ktgrd.
    ls_sales-data-pltyp = w_filecs-pltyp.
    ls_sales-data-vwerk = w_filecs-vwerk.
*    ls_sales-data-kabss = '0002'.
    ls_sales-data-podkz =  w_filecs-podkz.
    ls_sales-data-kvgr1 = w_filecs-kvgr1.
    ls_sales-data-kvgr2 = w_filecs-kvgr2.
    ls_sales-data-kvgr3 = w_filecs-kvgr3.
    ls_sales-data-kvgr4 = w_filecs-kvgr4.
    ls_sales-data-kvgr5 = w_filecs-kvgr5.
    ls_sales-data-kurst = 'M'.
** Added by
    ls_sales-data-awahr = w_filecs-awahr.
    ls_sales-data-agrel = w_filecs-agrel.
    ls_sales-data-bokre = w_filecs-bokre.
    ls_sales-data-incov = w_filecs-incov.
    ls_sales-data-inco3_l = w_filecs-inco3_l.
    ls_sales-data-prfre  = w_filecs-prfre.



    ls_sales-datax-bzirk = 'X'.
    ls_sales-datax-kdgrp = 'X'.
    ls_sales-datax-vkbur = 'X'.
    ls_sales-datax-vkgrp = 'X'.
    ls_sales-datax-waers = 'X'.
    ls_sales-datax-kurst = 'X'.
    ls_sales-datax-konda = 'X'.
    ls_sales-datax-kalks = 'X'.
    ls_sales-datax-versg = 'X'.
    ls_sales-datax-lprio = 'X'.
    ls_sales-datax-kzazu = 'X'.
    ls_sales-datax-vsbed = 'X'.
    ls_sales-datax-untto = 'X'.
    ls_sales-datax-uebto = 'X'.
    ls_sales-datax-inco1 = 'X'.
    ls_sales-datax-inco2 = 'X'.
    ls_sales-datax-zterm = 'X'.
    ls_sales-datax-kkber = 'X'.
    ls_sales-datax-ktgrd = 'X'.
    ls_sales-datax-pltyp = 'X'.
    ls_sales-datax-vwerk = 'X'.
    ls_sales-datax-podkz = 'X'.
    ls_sales-datax-kvgr1 = 'X'.
    ls_sales-datax-kvgr2 = 'X'.
    ls_sales-datax-kvgr3 = 'X'.
    ls_sales-datax-kvgr4 = 'X'.
    ls_sales-datax-kvgr5 = 'X'.
    ls_sales-datax-kurst = 'X'.

    ls_sales-datax-awahr = 'X'.
    ls_sales-datax-agrel = 'X'.
    ls_sales-datax-bokre = 'X'.
    ls_sales-datax-incov = 'X'.

    DATA iv_ktokd TYPE ktokd. " Customer Account Group
    DATA et_parvw TYPE cmds_parvw_t.
    REFRESH et_parvw.
    REFRESH lt_sales_func.
    CALL METHOD cmd_ei_api_check=>get_mand_partner_functions
      EXPORTING
        iv_ktokd = kna1-ktokd
      IMPORTING
        et_parvw = et_parvw.

    LOOP AT et_parvw INTO DATA(wa_parvw).
      ls_sales_func-task = 'I'.
      ls_sales_func-data_key-parvw = wa_parvw-parvw.
      ls_sales_func-data-partner = kna1-kunnr.
      ls_sales_func-datax-partner = 'X'.
      APPEND ls_sales_func TO lt_sales_func.
      CLEAR ls_sales_func.
    ENDLOOP. " LOOP AT et_parvw INTO DATA(wa_parvw)
    ls_sales-functions-functions = lt_sales_func[].
    APPEND ls_sales TO lt_sales.
***************************************************************
*   Set the Sales Data
    ls_sales_data-sales = lt_sales[].
    SELECT SINGLE kunnr FROM knvv INTO @DATA(l_kunnr) WHERE kunnr = @ls_customers-header-object_instance-kunnr.
    IF sy-subrc <> 0.
      " Adding tax_data

      CLEAR gwa_knvi.
      SELECT SINGLE * FROM knvi INTO gwa_knvi WHERE kunnr = w_filecs-kunnr
                                                AND aland = 'IN'
                                                AND tatyp = 'JOIG' .
      IF gwa_knvi IS INITIAL.
        ls_tax_data-task = 'I'.
        ls_tax_data-data_key-aland = 'IN'.
        ls_tax_data-data_key-tatyp = 'JOIG'.
        ls_tax_data-data-taxkd     = w_filecs-taxkd01.
        ls_tax_data-datax-taxkd    = 'X'.
        APPEND ls_tax_data TO lt_tax_data.
      ENDIF.
      CLEAR gwa_knvi.
      SELECT SINGLE * FROM knvi INTO gwa_knvi WHERE kunnr = w_filecs-kunnr
                                                AND aland = 'IN'
                                                AND tatyp = 'JOCG' .

      IF gwa_knvi IS INITIAL.
        " Adding tax_data
        ls_tax_data-task = 'I'.
        ls_tax_data-data_key-aland = 'IN'.
        ls_tax_data-data_key-tatyp = 'JOCG'.
        ls_tax_data-data-taxkd     = w_filecs-taxkd02.
        ls_tax_data-datax-taxkd    = 'X'.
        APPEND ls_tax_data TO lt_tax_data.
      ENDIF.

      CLEAR gwa_knvi.

      SELECT SINGLE * FROM knvi INTO gwa_knvi WHERE kunnr = w_filecs-kunnr
                                                AND aland = 'IN'
                                                AND tatyp = 'JOSG' .

      IF gwa_knvi IS INITIAL.
        " Adding tax_data
        ls_tax_data-task = 'I'.
        ls_tax_data-data_key-aland = 'IN'.
        ls_tax_data-data_key-tatyp = 'JOSG'.
        ls_tax_data-data-taxkd     = w_filecs-taxkd03.
        ls_tax_data-datax-taxkd    = 'X'.
        APPEND ls_tax_data TO lt_tax_data.
      ENDIF.


      CLEAR gwa_knvi.
      SELECT SINGLE * FROM knvi INTO gwa_knvi WHERE kunnr = w_filecs-kunnr
                                                AND aland = 'IN'
                                                AND tatyp = 'JOUG' .

      IF gwa_knvi IS INITIAL.
        " Adding tax_data
        ls_tax_data-task = 'I'.
        ls_tax_data-data_key-aland = 'IN'.
        ls_tax_data-data_key-tatyp = 'JOUG'.
        ls_tax_data-data-taxkd     = w_filecs-taxkd04.
        ls_tax_data-datax-taxkd    = 'X'.
        APPEND ls_tax_data TO lt_tax_data.
      ENDIF.

      CLEAR gwa_knvi.
      SELECT SINGLE * FROM knvi INTO gwa_knvi WHERE kunnr = w_filecs-kunnr
                                                AND aland = 'IN'
                                                AND tatyp = 'JCOS' .

      IF gwa_knvi IS INITIAL.
        " Adding tax_data
        ls_tax_data-task = 'I'.
        ls_tax_data-data_key-aland = 'IN'.
        ls_tax_data-data_key-tatyp = 'JCOS'.
        ls_tax_data-data-taxkd     = w_filecs-taxkd05.
        ls_tax_data-datax-taxkd    = 'X'.
        APPEND ls_tax_data TO lt_tax_data.
      ENDIF.

      ls_central_data-tax_ind-tax_ind = lt_tax_data.
    ENDIF. " IF sy-subrc <> 0
    ls_customers-central_data = ls_central_data.
    ls_customers-sales_data = ls_sales_data.
    APPEND ls_customers TO lt_customers.
    is_master_data-customers = lt_customers[].
    cmd_ei_api=>initialize( ).
    CALL METHOD cmd_ei_api=>maintain_bapi
      EXPORTING
*       IV_TEST_RUN              = SPACE
*       IV_COLLECT_MESSAGES      = SPACE
        is_master_data           = is_master_data
      IMPORTING
        es_master_data_correct   = es_master_data_correct
        es_message_correct       = es_message_correct
        es_master_data_defective = es_master_data_defective
        es_message_defective     = es_message_defective.

    IF es_message_defective-is_error IS INITIAL.
      COMMIT WORK.
      WAIT UP TO 1 SECONDS.
      w_log-bu_partner = w_filecs-kunnr.
      w_log-bu_partnerx = 'C'.
      CONCATENATE 'Cust. Extended to Sales Area' w_filecs-vkorg w_filecs-vtweg w_filecs-spart INTO w_log-msg SEPARATED BY space.
      w_log-msgtyp = 'S'.
      w_log-msgnr = '001'.
      w_log-uzeit = sy-uzeit.
      w_log-erdat = sy-datum.
      w_log-uname = sy-uname.
      w_log-bpname = kna1-name1.
      APPEND w_log TO t_log.
      INSERT zbp_upload FROM w_log.
      CLEAR w_log.
    ELSE. " ELSE -> IF es_message_defective-is_error IS INITIAL
      LOOP AT es_message_defective-messages INTO DATA(wa).
        WAIT UP TO 1 SECONDS.
        w_log-bu_partner = w_filecs-kunnr.
        w_log-bu_partnerx = 'C'.
        w_log-msg  = wa-message.
        w_log-msgtyp = wa-type.
        w_log-msgnr = wa-number.
        w_log-uzeit = sy-uzeit.
        w_log-erdat = sy-datum.
        w_log-uname = sy-uname.
        w_log-bpname = kna1-name1.
        APPEND w_log TO t_log.
        INSERT zbp_upload FROM w_log.
        CLEAR w_log.
      ENDLOOP. " LOOP AT es_message_defective-messages INTO DATA(wa)
    ENDIF. " IF es_message_defective-is_error IS INITIAL
  ENDLOOP. " LOOP AT t_filecs INTO w_filecs
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_LOG_CUSTOMER_S
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_log_customer_s .
  CHECK t_log IS NOT INITIAL.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_title = 'Log'
      is_layout    = s_layout
      it_fieldcat  = t_fcat
    TABLES
      t_outtab     = t_log
* EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS       = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF. " IF sy-subrc <> 0
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  FILL_ADDRESS_EMP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_address_emp .
  IF partnercategory = 1.
    centraldataperson-firstname = wa_file-name1.
    centraldataperson-lastname = wa_file-name2.
    centraldataperson-correspondlanguage = 'EN'.
  ENDIF. " IF partnercategory = 1
  addressdata-street =     wa_file-street.
  addressdata-str_suppl1 = wa_file-str_suppl1.
  addressdata-str_suppl2 = wa_file-str_suppl2.
  addressdata-str_suppl3 = wa_file-str_suppl3.
  addressdata-house_no = wa_file-house_no.
  addressdata-location   = wa_file-location  .
  addressdata-district   = wa_file-district  .
  addressdata-postl_cod1 = wa_file-postl_cod1.
  addressdata-city       = wa_file-city      .
  addressdata-country    = wa_file-country   .
  addressdata-region     = wa_file-region    .
  addressdata-langu      = wa_file-langu     .
*for mobile number
  CLEAR wa_telephondata.
  wa_telephondata-country = wa_file-country.
  wa_telephondata-telephone = wa_file-tel_number.
  wa_telephondata-std_no = 'X'.
*  WA_TELEPHONDATA-EXTENSION = '91'.
  wa_telephondata-r_3_user = '1'.
  wa_telephondata-consnumber = '002'.
  wa_telephondata-home_flag = 'X'.
  APPEND wa_telephondata TO it_telephondata.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FILL_CENTRALDATA_EMP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_centraldata_emp .
  centraldata-searchterm1 = wa_file-name1.
*  CENTRALDATA-PARTNERLANGUAGE = 'E'.
  centraldata-title_key = '0002'.
ENDFORM.

FORM upload_xl_vendor_p.
  IF p_flname CS '.XLS' OR p_flname CS '.xls'.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_tab_raw_data       = it_raw
        i_filename           = p_flname
      TABLES
        i_tab_converted_data = t_filevp.
  ENDIF. " IF p_flname CS ' XLS' OR p_flname CS ' xls'
  DO head TIMES.
    DELETE t_filevp INDEX 1.
  ENDDO.
ENDFORM.


FORM fill_fcat_vendorlog_p.
  s_layout-colwidth_optimize = 'X'.
  s_layout-zebra = 'X'.

  w_fcat-fieldname = 'MSGTYP'.
  w_fcat-seltext_l = 'Message Type'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGNR'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message No'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'BU_PARTNER'.
  w_fcat-no_zero = 'X'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Vendor'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSG'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'BPNAME'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Vendor Name'.
  APPEND w_fcat TO t_fcat.
ENDFORM.

FORM maintain_vendor_p.
  DATA: lt_contacts      TYPE vmds_ei_contacts_t,
        ls_contacts      TYPE vmds_ei_contacts,       " Ext. Interface: Contact Person
        lt_vendors       TYPE vmds_ei_extern_t,
        ls_vendors       TYPE vmds_ei_extern,         " Complex External Interface for Vendors
        ls_address       TYPE cvis_ei_address1,       " Ext. Interface: Address of Organization
        ls_purchas_data  TYPE vmds_ei_vmd_purchasing, " Ext. Interface: Purchasing Data
        lt_purchasing    TYPE vmds_ei_purchasing_t,
        ls_purchasing    TYPE vmds_ei_purchasing,     " Ext. Interface: Purchasing Organization
        lt_purch_func    TYPE vmds_ei_functions_t,
        ls_purch_func    TYPE vmds_ei_functions,      " Ext. Interface: Partner Roles
        ls_message       TYPE cvis_message,           " Error Indicator and System Messages
        lv_contactid     TYPE bapicontact_01-contact, " Number of contact person
        gs_vmds_extern   TYPE vmds_ei_main,           " Ext. Interface: Vendor Total Data
        gs_succ_messages TYPE cvis_message,           " Error Indicator and System Messages
        gs_vmds_error    TYPE vmds_ei_main,           " Ext. Interface: Vendor Total Data
        gs_err_messages  TYPE cvis_message,           " Error Indicator and System Messages
        gs_vmds_succ     TYPE vmds_ei_main,           " Ext. Interface: Vendor Total Data
        gv_ktokk         TYPE ktokk,                  " Vendor account group
        gv_ccode         TYPE bukrs,                  " Company Code
        gv_akont         TYPE akont,                  " Reconciliation Account in General Ledger
        gv_name          TYPE name1.                  " Name

  DATA: lw_bupa TYPE bu_partner.

  LOOP AT t_filevp INTO w_filevp.

    CALL FUNCTION 'ZGET_BUPA_NUMBER_V'
      EXPORTING
        ivendor     = w_filevp-lifnr
      IMPORTING
        ebu_partner = lw_bupa.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filevp-lifnr
      IMPORTING
        output = w_filevp-lifnr.
*    SELECT SINGLE * FROM but000 WHERE partner = w_filev-lifnr.

    SELECT SINGLE * FROM lfa1 WHERE lifnr = w_filevp-lifnr.
    IF sy-subrc = 0.
*   Clear the work area initially.
      CLEAR gs_vmds_extern.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = w_filevp-lifnr
        IMPORTING
          output = ls_vendors-header-object_instance-lifnr.

      ls_vendors-header-object_task = 'U'. "Represents Insert or Create
      ls_address-postal-data-name          = lfa1-name1. "Name of the Vendor
      ls_address-postal-data-country       = lfa1-land1.
      ls_address-postal-datax-name         = 'X'.
      ls_address-postal-datax-country      = 'X'.
      ls_address-task                      = 'U'.

*   Set the Address for the Vendor
      ls_vendors-central_data-address = ls_address.
      CLEAR: lt_purchasing[],lt_vendors.
*&---------------------------------------------------------------------*
*&  *   Set the Purchasing Data
*&---------------------------------------------------------------------*
      IF w_filevp-vkorg IS NOT INITIAL.

        ls_purchasing-task                   = 'I'.
        ls_purchasing-data_key-ekorg = w_filevp-vkorg. "Purchasing Organization
        ls_purchasing-data-waers = w_filevp-waers.
        ls_purchasing-datax-waers = 'X'.

        ls_purchasing-data-zterm = w_filevp-zterm.
        ls_purchasing-datax-zterm = 'X'.

        ls_purchasing-data-inco1 = w_filevp-inco1.
        ls_purchasing-datax-inco1 = 'X'.

        ls_purchasing-data-inco2 = w_filevp-inco2.
        ls_purchasing-datax-inco2 = 'X'.

        ls_purchasing-data-kalsk         = w_filevp-kalsk. "Schema Group, Vendor
        ls_purchasing-datax-kalsk       = 'X'.

        ls_purchasing-data-webre       = w_filevp-webre . "GR Based Invoice Verification
        ls_purchasing-datax-webre      = 'X'.

        ls_purchasing-data-verkf = w_filevp-verkf.
        ls_purchasing-datax-verkf = 'X'.

        ls_purchasing-data-telf1 = w_filevp-telef.
        ls_purchasing-datax-telf1 = 'X'.

        ls_purchasing-data-vsbed = w_filevp-vsbed.
        ls_purchasing-datax-vsbed = 'X'.

        ls_purchasing-data-lebre = w_filevp-lebre.
        ls_purchasing-datax-lebre = 'X'.

        ls_purchasing-data-ekgrp = w_filevp-ekgrp.
        ls_purchasing-datax-ekgrp = 'X'.

        ls_purchasing-data-plifz = w_filevp-plifz.
        ls_purchasing-datax-plifz = 'X'.

*        ls_purchasing-data- = w_filevp-.
*        ls_purchasing-datax- = 'X'.

        APPEND ls_purchasing TO lt_purchasing.

*   Set the Purchasing Data
        ls_purchas_data-purchasing = lt_purchasing[].

        ls_vendors-purchasing_data = ls_purchas_data.
      ENDIF. " IF w_filevp-vkorg IS NOT INITIAL

      APPEND ls_vendors TO lt_vendors.
*   Set the Final Vendor Data based on which it has to be created
      gs_vmds_extern-vendors = lt_vendors[].

      vmd_ei_api=>initialize( ).
*   Call the Method for creation of Vendor.
      CALL METHOD vmd_ei_api=>maintain_bapi
        EXPORTING
          is_master_data           = gs_vmds_extern
        IMPORTING
          es_master_data_correct   = gs_vmds_succ
          es_message_correct       = gs_succ_messages
          es_master_data_defective = gs_vmds_error
          es_message_defective     = gs_err_messages.

      IF gs_err_messages-is_error IS INITIAL.
        COMMIT WORK.
        WAIT UP TO 1 SECONDS.
        w_log-bu_partner = lw_bupa.
        w_log-vendor = w_filevp-lifnr.
        w_log-bu_partnerx = 'V'.
        w_log-msg  = 'Vendor Extended' .
        w_log-msgtyp = 'S'.
        w_log-msgnr = '001'.
        w_log-uzeit = sy-uzeit.
        w_log-erdat = sy-datum.
        w_log-uname = sy-uname.
        w_log-bpname = lfa1-name1.
        w_log-serial = w_filevp-serial.
        APPEND w_log TO t_log.
        INSERT zbp_upload FROM w_log.
        CLEAR w_log.
      ELSE. " ELSE -> IF gs_err_messages-is_error IS INITIAL
        LOOP AT gs_err_messages-messages INTO DATA(wa).
          w_log-bu_partner = lw_bupa.
          w_log-vendor = w_filevp-lifnr.
          w_log-bu_partnerx = 'V'.
          w_log-msg  = wa-message.
          w_log-msgtyp = wa-type.
          w_log-msgnr = wa-number.
          w_log-uzeit = sy-uzeit.
          w_log-erdat = sy-datum.
          w_log-uname = sy-uname.
          w_log-bpname = lfa1-name1.
          w_log-serial = w_filevp-serial.
          APPEND w_log TO t_log.
          INSERT zbp_upload FROM w_log.
          CLEAR w_log.
        ENDLOOP. " LOOP AT gs_err_messages-messages INTO DATA(wa)
      ENDIF. " IF gs_err_messages-is_error IS INITIAL
    ELSE. " ELSE -> IF w_filevp-vkorg IS NOT INITIAL
      PERFORM update_log_bp_not_found USING w_filevp-lifnr w_filevp-serial.
    ENDIF. " IF sy-subrc = 0
  ENDLOOP. " LOOP AT t_filevp INTO w_filevp
ENDFORM.

FORM display_log_vendor_p.
  CHECK t_log IS NOT INITIAL.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_title = 'Log'
      is_layout    = s_layout
      it_fieldcat  = t_fcat
    TABLES
      t_outtab     = t_log
* EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS       = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF. " IF sy-subrc <> 0
ENDFORM.

FORM update_bp_supplimentary.
  DATA : lt_return TYPE STANDARD TABLE OF bapiret2.
  DATA : lw_details TYPE bapibus1006_bankdetail.

  DATA: lw_bupa TYPE bu_partner.

  CALL FUNCTION 'ZGET_BUPA_NUMBER_V'
    EXPORTING
      ivendor     = w_filevc-lifnr
    IMPORTING
      ebu_partner = lw_bupa.

  CALL FUNCTION 'BAPI_BUPA_TAX_ADD'
    EXPORTING
      businesspartner = lw_bupa
      taxtype         = w_filevc-taxtyp1
      taxnumber       = w_filevc-taxnum1
    TABLES
      return          = lt_return.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = ''.
  COMMIT WORK AND WAIT.
  WAIT UP TO 1 SECONDS.

  CLEAR: lt_return.

  CALL FUNCTION 'BAPI_BUPA_TAX_ADD'
    EXPORTING
      businesspartner = lw_bupa
      taxtype         = w_filevc-taxtyp2
      taxnumber       = w_filevc-taxnum2
    TABLES
      return          = lt_return.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = ''.
  COMMIT WORK AND WAIT.
  WAIT UP TO 1 SECONDS.

  CLEAR: lt_return.
  lw_details-bank_ctry = w_filevc-bank_ctry1.
  lw_details-bank_key = w_filevc-bank_key1.
  lw_details-bank_acct = w_filevc-bank_acct1.
  lw_details-bank_ref = w_filevc-bank_ref1.
  lw_details-accountholder = w_filevc-bank_hold1.
  lw_details-bankaccountname = w_filevc-bank_name1.

  CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
    EXPORTING
      businesspartner = lw_bupa
      bankdetailid    = '0001'
      bankdetaildata  = lw_details
    TABLES
      return          = lt_return.


  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = ''.
  COMMIT WORK AND WAIT.
  WAIT UP TO 1 SECONDS.

  CLEAR: lw_details.
  CLEAR: lt_return.
  lw_details-bank_ctry = w_filevc-bank_ctry2.
  lw_details-bank_key = w_filevc-bank_key2.
  lw_details-bank_acct = w_filevc-bank_acct2.
  lw_details-bank_ref = w_filevc-bank_ref2.
  lw_details-accountholder = w_filevc-bank_hold2.
  lw_details-bankaccountname = w_filevc-bank_name2.

  CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
    EXPORTING
      businesspartner = lw_bupa
      bankdetailid    = '0002'
      bankdetaildata  = lw_details
    TABLES
      return          = lt_return.


  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = ''.
  COMMIT WORK AND WAIT.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form UPLOAD_XL_CUSTOMER_PF
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM upload_xl_customer_pf .

  IF p_flname CS '.XLS' OR p_flname CS '.xls'.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_tab_raw_data       = it_raw
        i_filename           = p_flname
      TABLES
        i_tab_converted_data = t_filepf.
  ENDIF. " IF p_flname CS ' XLS' OR p_flname CS ' xls'
  DO head TIMES.
    DELETE t_filepf INDEX 1.
  ENDDO.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FILL_FCAT_CUSTOMER_PF_LOG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM fill_fcat_customer_pf_log .
  s_layout-colwidth_optimize = 'X'.
  s_layout-zebra = 'X'.

  w_fcat-fieldname = 'MSGTYP'.
  w_fcat-seltext_l = 'Message Type'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSGNR'.
  w_fcat-seltext_l = 'Message No'.
  w_fcat-tabname = 'T_LOG'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'BU_PARTNER'.
  w_fcat-no_zero = 'X'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'KUNNR'.
  APPEND w_fcat TO t_fcat.
  CLEAR w_fcat.

  w_fcat-fieldname = 'MSG'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Message'.
  APPEND w_fcat TO t_fcat.

  w_fcat-fieldname = 'BPNAME'.
  w_fcat-tabname = 'T_LOG'.
  w_fcat-seltext_l = 'Customer Name'.
  APPEND w_fcat TO t_fcat.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAINTAIN_CUSTOMER_PF
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM maintain_customer_pf .

  TYPES : BEGIN OF st_knvp,
            kunnr TYPE knvp-kunnr,
            vkorg TYPE knvp-vkorg,
            vtweg TYPE knvp-vtweg,
            spart TYPE knvp-spart,
            parvw TYPE knvp-parvw,
            parza TYPE knvp-parza,
          END OF st_knvp.

  DATA : gt_knvp  TYPE TABLE OF st_knvp,
         gwa_knvp TYPE st_knvp.

  DATA is_master_data           TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_master_data_correct   TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_message_correct       TYPE cvis_message. " Error Indicator and System Messages
  DATA es_master_data_defective TYPE cmds_ei_main. " Ext. Interface: Total Customer Data
  DATA es_message_defective     TYPE cvis_message. " Error Indicator and System Messages


  DATA: lt_customers    TYPE cmds_ei_extern_t,
        ls_customers    TYPE cmds_ei_extern,         " Complex External Interface for Customers
        ls_address      TYPE cvis_ei_address1,       " Ext. Interface: Address of Organization
        ls_sales_data   TYPE cmds_ei_cmd_sales,      " Ext. Interface: Sales Data
        ls_central_data TYPE cmds_ei_central_data,   " External Interface: Central Data
        lt_sales        TYPE cmds_ei_sales_t,
        ls_sales        TYPE cmds_ei_sales,          " Ext. Interface: Sales Data
        lt_sales_func   TYPE cmds_ei_functions_t,
        ls_sales_func   TYPE cmds_ei_functions,      " Ext. Interface: Partner Roles
        ls_tax_data     TYPE cmds_ei_tax_ind,        " Ext. Interface: Tax Indicators
        lt_tax_data     TYPE cmds_ei_tax_ind_t,
        ls_message      TYPE cvis_message,           " Error Indicator and System Messages
        lv_contactid    TYPE bapicontact_01-contact. " Number of contact person

  DATA: lv_partner        TYPE bu_partner.


  t_filepf1[] = t_filepf[].
  DELETE t_filepf WHERE del_ind IS NOT INITIAL.
  DELETE t_filepf1 WHERE del_ind IS INITIAL.

  DATA : lv_parza TYPE parza.

*  BREAK paragp.
  LOOP AT t_filepf INTO w_filepf.



    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filepf-kunnr
      IMPORTING
        output = lv_partner.
    ls_customers-header-object_instance-kunnr = lv_partner.
    SELECT SINGLE * FROM kna1 WHERE kunnr = lv_partner.

    SELECT kunnr vkorg vtweg spart parvw parza FROM knvp
                                               INTO TABLE gt_knvp
                                               WHERE kunnr = lv_partner
                                                AND  vkorg = w_filepf-vkorg
                                                AND  vtweg = w_filepf-vtweg
                                                AND spart = w_filepf-spart
                                                AND parvw = w_filepf-parvw.
    SORT gt_knvp DESCENDING BY parza.
    READ TABLE gt_knvp INTO gwa_knvp INDEX 1.
    IF sy-subrc = 0.
      IF gwa_knvp-parza IS INITIAL.
        lv_parza = '002'.
      ELSE.
        lv_parza = gwa_knvp-parza + 1.
      ENDIF.
    ENDIF.

    ls_customers-header-object_task = 'U'.
    ls_sales-task = 'U'.

    ls_sales-data_key-vkorg = w_filepf-vkorg.
    ls_sales-data_key-vtweg = w_filepf-vtweg.
    ls_sales-data_key-spart = w_filepf-spart.

    ls_sales_func-task = 'I'.
    ls_sales_func-data_key-parvw = w_filepf-parvw.
    ls_sales_func-data_key-parza = lv_parza.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filepf-kunnr_assign
      IMPORTING
        output = w_filepf-kunnr_assign.
    ls_sales_func-data-partner   = w_filepf-kunnr_assign.
    ls_sales_func-datax-partner  = 'X'.
    APPEND ls_sales_func TO lt_sales_func.
    CLEAR ls_sales_func.

    ls_sales-functions-functions = lt_sales_func[].
    APPEND ls_sales TO lt_sales.

*   Set the Sales Data
    ls_sales_data-sales = lt_sales[].

    ls_customers-sales_data = ls_sales_data.
    APPEND ls_customers TO lt_customers.
    is_master_data-customers = lt_customers[].
    cmd_ei_api=>initialize( ).
    CALL METHOD cmd_ei_api=>maintain_bapi
      EXPORTING
*       IV_TEST_RUN              = SPACE
*       IV_COLLECT_MESSAGES      = SPACE
        is_master_data           = is_master_data
      IMPORTING
        es_master_data_correct   = es_master_data_correct
        es_message_correct       = es_message_correct
        es_master_data_defective = es_master_data_defective
        es_message_defective     = es_message_defective.
    IF es_message_defective-is_error IS INITIAL.
      COMMIT WORK.
      WAIT UP TO 1 SECONDS.
      w_log-bu_partner = w_filepf-kunnr.
      w_log-bu_partnerx = 'C'.
      CONCATENATE 'Cust. Extended to Sales Area' w_filepf-vkorg w_filepf-vtweg w_filepf-spart INTO w_log-msg SEPARATED BY space.
      w_log-msgtyp = 'S'.
      w_log-msgnr = '001'.
      w_log-uzeit = sy-uzeit.
      w_log-erdat = sy-datum.
      w_log-uname = sy-uname.
      w_log-bpname = kna1-name1.
      APPEND w_log TO t_log.
      INSERT zbp_upload FROM w_log.
      CLEAR w_log.
    ELSE. " ELSE -> IF es_message_defective-is_error IS INITIAL
      LOOP AT es_message_defective-messages INTO DATA(wa).
        WAIT UP TO 1 SECONDS.
        w_log-bu_partner = w_filepf-kunnr.
        w_log-bu_partnerx = 'C'.
        w_log-msg  = wa-message.
        w_log-msgtyp = wa-type.
        w_log-msgnr = wa-number.
        w_log-uzeit = sy-uzeit.
        w_log-erdat = sy-datum.
        w_log-uname = sy-uname.
        w_log-bpname = kna1-name1.
        APPEND w_log TO t_log.
        INSERT zbp_upload FROM w_log.
        CLEAR w_log.
      ENDLOOP. " LOOP AT es_message_defective-messages INTO DATA(wa)

    ENDIF. " IF es_message_defective-is_error IS INITIAL

    REFRESH : lt_sales[], lt_sales_func[], lt_customers[].
    CLEAR : is_master_data, ls_sales_data, ls_customers, es_master_data_correct, es_message_correct, es_master_data_defective, es_message_defective.
    CLEAR : is_master_data-customers, ls_customers-sales_data, kna1, lv_partner.
  ENDLOOP.




  LOOP AT t_filepf1 INTO w_filepf.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_filepf-kunnr
      IMPORTING
        output = lv_partner.

    SELECT SINGLE * FROM kna1 WHERE kunnr = lv_partner.



    IF w_filepf-del_ind EQ 'X'.
      DELETE FROM knvp WHERE kunnr = w_filepf-kunnr
                         AND vkorg = w_filepf-vkorg
                         AND vtweg = w_filepf-vtweg
                         AND spart = w_filepf-spart
                         AND parvw = w_filepf-parvw
                         AND kunn2 = w_filepf-kunnr_assign .
      IF sy-subrc = 0.

        COMMIT WORK.
        WAIT UP TO 1 SECONDS.
        w_log-bu_partner = w_filepf-kunnr.
        w_log-bu_partnerx = 'C'.
        CONCATENATE 'Cust. Master Partner Functions deleted' w_filepf-vkorg w_filepf-vtweg w_filepf-spart INTO w_log-msg SEPARATED BY space.
        w_log-msgtyp = 'S'.
        w_log-msgnr = '001'.
        w_log-uzeit = sy-uzeit.
        w_log-erdat = sy-datum.
        w_log-uname = sy-uname.
        w_log-bpname = kna1-name1.
        APPEND w_log TO t_log.
        INSERT zbp_upload FROM w_log.
        CLEAR w_log.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_LOG_CUSTOMER_PF
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM display_log_customer_pf .

  CHECK t_log IS NOT INITIAL.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_title = 'Log'
      is_layout    = s_layout
      it_fieldcat  = t_fcat
    TABLES
      t_outtab     = t_log
* EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS       = 2
    .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF. " IF sy-subrc <> 0


ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_VALIDATE_IP
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_validate_ip .

  TYPES : BEGIN OF lty_kna1,
            kunnr TYPE kunnr,
            name1 TYPE name1,
            sortl TYPE sortl,
          END OF lty_kna1.

  DATA : lt_kna1  TYPE TABLE OF lty_kna1,
         lwa_kna1 TYPE lty_kna1.

  SELECT kunnr name1 sortl
  FROM kna1
  INTO TABLE lt_kna1
  FOR ALL ENTRIES IN it_file
  WHERE sortl EQ it_file-sterm1.

  IF sy-subrc EQ 0.
    LOOP AT it_file INTO wa_file.
      CLEAR lwa_kna1.
      READ TABLE lt_kna1 INTO lwa_kna1 WITH KEY sortl = wa_file-sterm1.
      IF sy-subrc EQ 0.
        DELETE it_file.
        CLEAR w_log.
        w_log-msg = TEXT-008.
        w_log-bu_partner = lwa_kna1-kunnr.
        w_log-bpname = lwa_kna1-name1.
        w_log-sortl = wa_file-sterm1.
        w_log-MSGTYP = 'W'.
        APPEND w_log TO t_log.
      ENDIF.
    ENDLOOP.
  ENDIF.

ENDFORM.

Log Table :


Comments

  1. Hi,

    can you share template for upload data?

    husnulmub@gmail.com

    thanks,

    ReplyDelete
  2. Hi,

    can you share template for upload data?

    vinaykumar.pv@gmail.com

    Thanks,

    ReplyDelete
  3. Hi. This article is very useful :).

    I have a requirement to add data in the standard tables LFBK_EMC_JP_D (Electronic Monetary Claims JAPAN) and DDSJP_DUEDATEPART (Maintain the pattern of due date shift for Japan).
    This tables are filled from BP transaction.

    Please suggest any BAPI/FM/Class which will add data in above tables. Th

    ReplyDelete
  4. Hi,

    Thanks for share your code, it helps me to understand how to use the BAPI_BUPA_CREATE_FROM_DATA.

    can you share template for upload data?

    alexgongoraf@gmail.com

    Thanks in advance for your help

    ReplyDelete
  5. Thanks for share your code This code very help for me, can you share template.

    ReplyDelete
  6. Hi,

    can you share template for upload data?

    mayuraa401@gmail.com

    thanks

    ReplyDelete
  7. Hi,

    Thanks for share your code, can you share template for upload data?

    berkein3@gmail.com

    Thanks

    ReplyDelete
  8. Really lovely information. Thank you for posting this article, and please continue to do so. Really lovely information. ERP Software in Chennai

    ReplyDelete
  9. Genial, me ha ayudado mucho. Gracias!

    ReplyDelete
  10. This information is a treasure.

    can you share template for upload data?

    andreesmarroquin28@gmail.com

    ReplyDelete
  11. Thank you so much!! for in detail and its really helpful. :)

    ReplyDelete
    Replies
    1. Can you share upload template

      Delete
    2. Share upload template kishor.karthan@gmail.com

      Delete
  12. Can you share upload template
    Email kishor.karthan@gmail.com

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  13. Thank you so much!! for in detail and its really helpful. :)
    Can you share upload template
    Email:thakshila.groupit@hemas.com

    ReplyDelete
  14. Thank you so much!!, Can you share upload template
    Email: ripauc@gmail.com

    ReplyDelete
  15. Very good!!, Can you share upload template
    Email: paulohenriquess@gmail.com

    ReplyDelete
  16. Thank you very much! Could you share upload template file?
    Email: i.pavlyukevich@gmail.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Create/Edit/Delete Attachments using GOS in Sap ABAP

Create Secondary Index on SAP Table