Hi JoJo ,
The below report will return you BP GUID from emails that is stored in a single column .xls file and assign the BP to a target group.
REPORT zexcel. *---------------------------------------------------------------------* * G L O B A L D A T A D E C L A R A T I O N *---------------------------------------------------------------------\* TYPE-POOLS : ole2. TYPES : BEGIN OF typ_xl_line, email TYPE ad_smtpadr, END OF typ_xl_line. TYPES : typ_xl_tab TYPE TABLE OF typ_xl_line. DATA : t_data TYPE typ_xl_tab, lt_bu_guid TYPE TABLE OF bu_partner_guid, ls_bu_guid TYPE bu_partner_guid, lt_guids TYPE TABLE OF bapi1185_bp, ls_guids TYPE bapi1185_bp, lt_return TYPE bapiret2_t. *---------------------------------------------------------------------* * S E L E C T I O N S C R E E N L A Y O U T *---------------------------------------------------------------------* PARAMETERS : p_xfile TYPE localfile, p_tgguid TYPE bapi1185_key . *---------------------------------------------------------------------* * E V E N T - A T S E L E C T I O N S C R E E N *---------------------------------------------------------------------\* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_xfile. CALL FUNCTION 'WS_FILENAME_GET' IMPORTING filename = p_xfile EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. IF sy-subrc <> 0. CLEAR p_xfile. ENDIF. *---------------------------------------------------------------------* * E V E N T - S T A R T O F S E L E C T I O N *---------------------------------------------------------------------* START-OF-SELECTION. * Get data from Excel File PERFORM sub_import_from_excel USING p_xfile CHANGING t_data. SELECT but000~partner_guid FROM but000 INNER JOIN but020 ON but000~partner = but020~partner INNER JOIN adr6 ON but020~addrnumber = adr6~addrnumber INTO TABLE lt_bu_guid FOR ALL ENTRIES IN t_data WHERE adr6~smtp_addr = t_data-email. CLEAR: lt_guids,ls_guids. LOOP AT lt_bu_guid INTO ls_bu_guid. ls_guids-bupartnerguid = ls_bu_guid. APPEND ls_guids TO lt_guids. ENDLOOP. CALL FUNCTION 'BAPI_TARGETGROUP_ADD_BP' EXPORTING targetgroupguid = p_tgguid TABLES return = lt_return businesspartner = lt_guids. *&---------------------------------------------------------------------* *& Form SUB_IMPORT_FROM_EXCEL *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->U_FILE text * -->C_DATA text *----------------------------------------------------------------------* FORM sub_import_from_excel USING u_file TYPE localfile CHANGING c_data TYPE typ_xl_tab. CONSTANTS : const_max_row TYPE sy-index VALUE '65536'. DATA : l_dummy TYPE typ_xl_line, cnt_cols TYPE i. DATA : h_excel TYPE ole2_object, h_wrkbk TYPE ole2_object, h_cell TYPE ole2_object. DATA : l_row TYPE sy-index, l_col TYPE sy-index, l_value TYPE string. FIELD-SYMBOLS : <fs_dummy> TYPE ANY. * Count the number of columns in the internal table. DO. ASSIGN COMPONENT sy-index OF STRUCTURE l_dummy TO <fs_dummy>. IF sy-subrc EQ 0. cnt_cols = sy-index. ELSE. EXIT. ENDIF. ENDDO. * Create Excel Application. CREATE OBJECT h_excel 'Excel.Application'. CHECK sy-subrc EQ 0. * Get the Workbook object. CALL METHOD OF h_excel 'Workbooks' = h_wrkbk. CHECK sy-subrc EQ 0. * Open the Workbook specified in the filepath. CALL METHOD OF h_wrkbk 'Open' EXPORTING #1 = u_file. CHECK sy-subrc EQ 0. * For all the rows - Max upto 65536. DO const_max_row TIMES. CLEAR l_dummy. l_row = l_row + 1. * For all columns in the Internal table. CLEAR l_col. DO cnt_cols TIMES. l_col = l_col + 1. * Get the corresponding Cell Object. CALL METHOD OF h_excel 'Cells' = h_cell EXPORTING #1 = l_row #2 = l_col. CHECK sy-subrc EQ 0. * Get the value of the Cell. CLEAR l_value. GET PROPERTY OF h_cell 'Value' = l_value. CHECK sy-subrc EQ 0. * Value Assigned ? pass to internal table. CHECK NOT l_value IS INITIAL. ASSIGN COMPONENT l_col OF STRUCTURE l_dummy TO <fs_dummy>. <fs_dummy> = l_value. ENDDO. * Check if we have the Work Area populated. IF NOT l_dummy IS INITIAL. APPEND l_dummy TO c_data. ELSE. EXIT. ENDIF. ENDDO. * Now Free all handles. FREE OBJECT h_cell. FREE OBJECT h_wrkbk. FREE OBJECT h_excel. ENDFORM. " SUB_IMPORT_FROM_EXCEL
Just copy paste the code and run the report select any local xls file with emails and pass the target group guid.
snap shot of excel file:
Let me know if it was useful.