Skip to Content
0
Former Member
Jun 05, 2006 at 09:15 PM

Formating existing Business Partner Telephone No.

256 Views

Hi,

We would like to format the phone nos. of existing business partners(BP) in CRM to xxx.xxx.xxxx.

I have written a program ...and the formatting works fine.

The problem comes when I am trying to update the BP's...I have written a BDC..and it doesn't seem to work. I am not very good in BDC...so would appreciate if somebody could help tweaking the code.

Further, would appreciate to know..whether using a BDC is the right approach...is there any BAPI's that can do the trick.

Once again, thanks to everbody once again.

Rajib

Code:

-


&----


*& Report ZTEST_RD1 *

*& *

&----


*& *

*& *

&----


REPORT ZTEST_RD1 .

.

tables : but000.

data: begin of t_output occurs 0,

bp like but000-partner,

home_phone like BAPIADTEL-TELEPHONE,

mobile_phone like BAPIADTEL-TELEPHONE,

fax like BAPIADTEL-TELEPHONE,

work_phone like BAPIADTEL-TELEPHONE,

end of t_output.

data: workphone like BAPIADTEL-TELEPHONE.

data: begin of t_bp occurs 0,

partner like but000-partner,

end of t_bp.

data: w_addressguid like bapibus1006_addresses_int-addrguid,

w_addrnr like bapibus1006_addresses_int-ADDRNUMBER,

w_addressdata like bapibus1006_address,

t_address like bapibus1006_addresses occurs 0 with header line,

t_return like bapiret2 occurs 0 with header line,

t_tel like bapiadtel occurs 0 with header line,

t_fax like bapiadfax occurs 0 with header line.

  • bdc declaration

  • Batchinputdata of single transaction

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  • messages of call transaction

DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

  • error session opened (' ' or 'X')

DATA: E_GROUP_OPENED.

  • message texts

TABLES: T100.

  • bdc

start-of-selection.

selection-screen begin of block b2 with frame title text-105.

*Business Partner Number

select-options: s_bp for but000-partner, " obligatory,

s_bpkind for but000-bpkind, " obligatory,

s_bptype for but000-type. " obligatory.

selection-screen end of block b2.

end-of-selection.

  • get the basic data

select partner

from but000

into table t_bp

where partner in s_bp and

bpkind in s_bpkind and

type in s_bptype.

loop at t_bp.

  • write :/1 t_bp-partner.

  • get the address guids.

call function 'BAPI_BUPA_ADDRESSES_GET'

EXPORTING

businesspartner = t_bp-partner

addresstype = 'HOME'

IMPORTING

standardaddressguid = w_addressguid

STANDARDADDRESSNUMBER = w_addrnr

TABLES

addresses = t_address

return = t_return.

  • Get Address Detail

call function 'BAPI_BUPA_ADDRESS_GETDETAIL'

EXPORTING

businesspartner = t_bp-partner

addressguid = t_address-ADDRESSGUID

IMPORTING

addressdata = w_addressdata

TABLES

bapiadtel = t_tel

bapiadfax = t_fax.

  • populate the data in the output table

t_output-bp = t_bp-partner.

  • home and mobile phone

loop at t_tel.

if t_tel-TELEPHONE is not initial.

if t_tel-R_3_USER = '1'. "Home Phone

perform format_phone USING t_tel-TELEPHONE.

t_output-home_phone = t_tel-TELEPHONE.

else. "Mobile Phone

perform format_phone USING t_tel-TELEPHONE.

t_output-mobile_phone = t_tel-TELEPHONE.

endif.

endif.

endloop.

  • get fax number

loop at t_fax.

if t_fax-FAX is not initial.

perform format_phone USING t_fax-FAX.

t_output-fax = t_fax-FAX.

endif.

endloop.

  • get work number

select single ADEXT from BUT020 into workphone

where PARTNER = t_bp-partner

and ADDRNUMBER = w_addrnr.

if workphone is not initial.

perform format_phone USING workphone.

endif.

t_output-work_phone = workphone.

clear: t_tel[], t_fax[], workphone.

append t_output.

clear: t_output.

endloop.

write :/1 ' bp ', 20 ' home_phone ', 35 ' mobile_phone ',

50 'fax', 75 'workphone'.

skip 3.

loop at t_output.

perform bdc_update.

write :/1 t_output-bp, 20 t_output-home_phone, 35

t_output-mobile_phone, 50 t_output-fax, 75 t_output-work_phone.

endloop.

&----


*& Form format_phone

&----


  • text

----


  • -->P_PHONE text

----


FORM format_phone USING p_phone.

Data: w_strlen type i,

w_offset type i.

clear w_offset. clear w_strlen.

w_strlen = STRLEN( p_phone ).

do w_strlen times.

if p_phone+w_offset(1) na '0123456789 '.

p_phone+w_offset(1) = ' '.

endif.

w_offset = w_offset + 1.

enddo.

condense p_phone no-gaps.

clear w_offset. clear w_strlen.

w_strlen = STRLEN( p_phone ).

if w_strlen gt '10'.

w_offset = w_strlen - 10.

endif.

p_phone = p_phone+w_offset(10).

w_strlen = STRLEN( p_phone ).

if w_strlen ne '10'.

MESSAGE

'Please enter 10 digit phone number in the format'

TYPE 'E'.

else.

concatenate p_phone(3) '.' p_phone3(3) '.' p_phone6(4) into

p_phone.

endif.

ENDFORM. " format_phone

&----


*& Form BDC_DYNPRO

&----


  • text

----


  • -->PROGRAM text

  • -->DYNPRO text

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM. "BDC_DYNPRO

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

  • IF FVAL <> NODATA.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

  • ENDIF.

ENDFORM. "BDC_FIELD

&----


*& Form bdc_update

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_update .

perform bdc_dynpro using 'SAPLBUS_LOCATOR' '3000'.

perform bdc_field using 'BDC_OKCODE'

'=BUS_LOCATOR_SRCH_GO'.

perform bdc_field using 'BDC_CURSOR'

'BUS_LOCA_SRCH01-SEARCH_TYPE'.

perform bdc_field using 'BUS_LOCA_SRCH01-SEARCH_TYPE'

'1'.

perform bdc_field using 'BUS_LOCA_SRCH01-SEARCH_ID'

'1'.

perform bdc_field using 'BUS_JOEL_SEARCH-PARTNER_NUMBER'

'1000'.

perform bdc_dynpro using 'SAPLBUS_LOCATOR' '3000'.

perform bdc_field using 'BDC_OKCODE'

'=%_GC 116 3'.

perform bdc_field using 'BUS_LOCA_SRCH01-SEARCH_TYPE'

'1'.

perform bdc_field using 'BUS_LOCA_SRCH01-SEARCH_ID'

'1'.

perform bdc_field using 'BUS_JOEL_SEARCH-PARTNER_NUMBER'

'1000'.

perform bdc_dynpro using 'SAPLBUS_LOCATOR' '3000'.

perform bdc_field using 'BDC_OKCODE'

'=BUS_MAIN_SAVE'.

perform bdc_field using 'BUS_JOEL_MAIN-PARTNER_ROLE'

'000000'.

perform bdc_field using 'BUT000-NAME_FIRST'

'KUMAR'.

perform bdc_field using 'BUT000-NAME_LAST'

'ASHOK'.

perform bdc_field using 'BUT000-NAMEMIDDLE'

'S'.

perform bdc_field using 'BUT000-NAME1_TEXT'

'KUMAR ASHOK'.

perform bdc_field using 'BUS000FLDS-LANGUCORR'

'EN'.

perform bdc_field using 'BUT000-BU_SORT1'

'KUMAR'.

perform bdc_field using 'BUT000-BU_SORT2'

'ASHOK'.

perform bdc_field using 'ADDR2_DATA-HOUSE_NUM1'

'5638'.

perform bdc_field using 'ADDR2_DATA-STREET'

'SHAWN TER'.

perform bdc_field using 'ADDR2_DATA-CITY2'

'GWINNETT'.

perform bdc_field using 'ADDR2_DATA-POST_CODE1'

'30092-1536'.

perform bdc_field using 'ADDR2_DATA-CITY1'

'NORCROSS'.

perform bdc_field using 'ADDR2_DATA-REGION'

'GA'.

perform bdc_field using 'ADDR2_DATA-COUNTRY'

'US'.

perform bdc_field using 'ADDR2_DATA-TIME_ZONE'

'EST'.

perform bdc_field using 'ADDR2_DATA-PO_BOX'

'02255217'.

perform bdc_field using 'ADDR2_DATA-POST_CODE2'

'30045-1111'.

perform bdc_field using 'SZA7_D0400-TEL_NUMBER'

'678.770.0001'.

perform bdc_field using 'SZA7_D0400-MOB_NUMBER'

'678.770.0002'.

perform bdc_field using 'SZA7_D0400-FAX_NUMBER'

'678.770.0003'.

perform bdc_field using 'BDC_CURSOR'

'BUS000FLDS-ADEXT'.

perform bdc_field using 'BUS000FLDS-ADEXT'

'678-770-0004'.

perform bdc_field using 'SZA11_0100-TEL_COUNTR'

'US'.

perform bdc_field using 'SZA11_0100-MOB_COUNTR'

'US'.

perform bdc_field using 'SZA11_0100-FAX_COUNTR'

'US'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

perform bdc_dynpro using 'SAPLBUS_LOCATOR' '3000'.

perform bdc_field using 'BDC_OKCODE'

'=BUS_MAIN_SAVE'.

perform bdc_field using 'BUS_JOEL_MAIN-PARTNER_ROLE'

'000000'.

perform bdc_field using 'BUT000-NAME_FIRST'

'KUMAR'.

perform bdc_field using 'BUT000-NAME_LAST'

'ASHOK'.

perform bdc_field using 'BUT000-NAMEMIDDLE'

'S'.

perform bdc_field using 'BUT000-NAME1_TEXT'

'KUMAR ASHOK'.

perform bdc_field using 'BUS000FLDS-LANGUCORR'

'EN'.

perform bdc_field using 'BUT000-BU_SORT1'

'KUMAR'.

perform bdc_field using 'BUT000-BU_SORT2'

'ASHOK'.

perform bdc_field using 'ADDR2_DATA-HOUSE_NUM1'

'5638'.

perform bdc_field using 'ADDR2_DATA-STREET'

'SHAWN TER'.

perform bdc_field using 'ADDR2_DATA-CITY2'

'GWINNETT'.

perform bdc_field using 'ADDR2_DATA-POST_CODE1'

'30092-1536'.

perform bdc_field using 'ADDR2_DATA-CITY1'

'NORCROSS'.

perform bdc_field using 'ADDR2_DATA-REGION'

'GA'.

perform bdc_field using 'ADDR2_DATA-COUNTRY'

'US'.

perform bdc_field using 'ADDR2_DATA-TIME_ZONE'

'EST'.

perform bdc_field using 'ADDR2_DATA-PO_BOX'

'02255217'.

perform bdc_field using 'ADDR2_DATA-POST_CODE2'

'30045-1111'.

perform bdc_field using 'SZA7_D0400-TEL_NUMBER'

'678.770.0001'.

perform bdc_field using 'SZA7_D0400-MOB_NUMBER'

'678.770.0002'.

perform bdc_field using 'SZA7_D0400-FAX_NUMBER'

'678.770.0003'.

perform bdc_field using 'BDC_CURSOR'

'BUS000FLDS-ADEXT'.

perform bdc_field using 'BUS000FLDS-ADEXT'

'678-770-0004'.

perform bdc_field using 'SZA11_0100-TEL_COUNTR'

'US'.

perform bdc_field using 'SZA11_0100-MOB_COUNTR'

'US'.

perform bdc_field using 'SZA11_0100-FAX_COUNTR'

'US'.

  • perform bdc_transaction using 'BP'.

CALL TRANSACTION 'BP' USING BDCDATA

MODE 'N' UPDATE 'S'

MESSAGES INTO MESSTAB.

  • message tab

DATA: L_MSTRING(480).

LOOP AT MESSTAB.

SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA

AND ARBGB = MESSTAB-MSGID

AND MSGNR = MESSTAB-MSGNR.

IF SY-SUBRC = 0.

L_MSTRING = T100-TEXT.

IF L_MSTRING CS '&1'.

REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.

REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.

REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.

REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.

ELSE.

REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.

ENDIF.

CONDENSE L_MSTRING.

WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).

ELSE.

WRITE: / MESSTAB.

ENDIF.

ENDLOOP.

SKIP.

  • end message tab

ENDFORM. " bdc_update