2007 Jun 27 12:26 PM
hi to all
my querry isas follows
develop a bdc program to change customer details(like address ) and add more contact persons for that customer using call tran method . pls give coding .
points will rewarded for good answers .
2007 Jun 27 12:31 PM
hi..
first u need to create a recording and then code
a sample code
----
Program : ZMM_BDCP_VENDOR_AS01 *
Title : BDC for vendor Data Upload *
----
REPORT zmm_bdcp_customer_as01
NO STANDARD PAGE HEADING LINE-SIZE 255.
*-----Include Program for data declarations and subroutines
INCLUDE zsd_incl_vendor_as01.
----
START-OF-SELECTION *
----
START-OF-SELECTION.
*-----Uploading a file from the PC to the server
PERFORM data_upload .
*-----Loop for all records
LOOP AT it_struc1 INTO x_struc1.
*-----Filling the fields
PERFORM fill_bdc USING : 'X' 'SAPMF02K' '0100',
' ' 'BDC_OKCODE' '/00',
' ' 'RF02K-LIFNR' x_struc1-lifnr,
' ' 'RF02K-KTOKK' x_struc1-ktokk,
'X' 'SAPMF02K' '0110',
' ' 'BDC_OKCODE' '/00',
' ' 'LFA1-ANRED' x_struc1-anred,
' ' 'LFA1-NAME1' x_struc1-name1,
' ' 'LFA1-SORTL' x_struc1-sortl,
' ' 'LFA1-LAND1' x_struc1-land1,
'X' 'SAPMF02K' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02K' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPLSPO1' '0300',
' ' 'BDC_OKCODE' '=YES'.
*-----Start new transaction according to parameters
PERFORM bdc_transaction USING 'XK01'.
ENDLOOP.
----
END-OF-SELECTION *
----
END-OF-SELECTION.
*-----Printing all success messages
IF it_messtab1 IS NOT INITIAL.
WRITE:/ 'SUCCESS MESSAGES'.
LOOP AT it_messtab1 INTO x_messtab1.
WRITE 😕 x_messtab1-mstring.
ENDLOOP.
ENDIF.
SKIP 2.
*-----Printing all error messages
IF it_messtab2 IS NOT INITIAL.
WRITE:/ 'ERROR MESSAGES'.
LOOP AT it_messtab2 INTO x_messtab2.
CHECK x_messtab2-msgtyp = 'E'.
WRITE 😕 x_messtab2-mstring.
ENDLOOP.
ENDIF.
*-----Close batch input session
PERFORM close_group.
Include's Coding
----
Program : ZSD_INCL_VENDOR_AS01 *
Title : Include for ZSD_BDCP_VENDOR_AS01 *
----
*-----Table declaration
TABLES: t100.
----
Data definition
----
*-----Types Declaration
TYPES : BEGIN OF x_struc1,
lifnr TYPE rf02k-lifnr, "Vendor Account Number
ktokk TYPE rf02k-ktokk, "Vendor account group
anred TYPE lfa1-anred, "Title
name1 TYPE lfa1-name1, "Name 1
sortl TYPE lfa1-sortl, "Sort field
land1 TYPE lfa1-land1, "Country Key
END OF x_struc1,
BEGIN OF x_struc2,
msgtyp TYPE bdcmsgcoll-msgtyp,"Message Type
mstring TYPE string, "Message Text
END OF x_struc2.
*-----Internal table declaration
DATA : it_messtab TYPE TABLE OF bdcmsgcoll,
it_messtab1 TYPE TABLE OF x_struc2,
it_messtab2 TYPE TABLE OF x_struc2,
it_bdcdata TYPE TABLE OF bdcdata,
it_struc1 TYPE TABLE OF x_struc1,
*-----Work area declaration
x_bdcdata TYPE bdcdata,
x_struc1 TYPE x_struc1,
x_messtab TYPE bdcmsgcoll,
x_messtab1 TYPE x_struc2,
x_messtab2 TYPE x_struc2,
*-----flags declaration
fg_group_opened(1) TYPE c,
fg_e_group_opened TYPE c,
*-----local variable declaration
v_subrc TYPE sy-subrc,
v_mstring TYPE string,
v_fname TYPE string.
----
SELECTION-SCREEN declaration *
----
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_sesion RADIOBUTTON GROUP rb_c.
SELECTION-SCREEN COMMENT 3(20) text-s07 FOR FIELD p_sesion.
SELECTION-SCREEN POSITION 45.
PARAMETERS p_ctu RADIOBUTTON GROUP rb_c.
SELECTION-SCREEN COMMENT 48(20) text-s08 FOR FIELD p_ctu.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s01 FOR FIELD p_group.
SELECTION-SCREEN POSITION 25.
PARAMETERS p_group(12).
SELECTION-SCREEN COMMENT 48(20) text-s05 FOR FIELD p_ctumod.
SELECTION-SCREEN POSITION 70.
PARAMETERS p_ctumod TYPE ctu_params-dismode DEFAULT 'N'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s03 FOR FIELD px_keep.
SELECTION-SCREEN POSITION 25.
PARAMETERS: px_keep AS CHECKBOX.
SELECTION-SCREEN COMMENT 48(20) text-s09 FOR FIELD p_e_grp.
SELECTION-SCREEN POSITION 70.
PARAMETERS p_e_grp(12).
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) text-s03 FOR FIELD px_e_kep.
SELECTION-SCREEN POSITION 70.
PARAMETERS: px_e_kep AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s11 FOR FIELD p_fname.
SELECTION-SCREEN POSITION 25.
PARAMETERS: p_fname(128) TYPE c.
SELECTION-SCREEN END OF LINE.
----
AT SELECTION-SCREEN *
----
AT SELECTION-SCREEN.
*-----Group must be filled for create session
IF p_sesion = 'X' AND
p_group = space.
MESSAGE e613(ms).
ENDIF.
----
AT SELECTION-SCREEN ON VALUE-REQUEST *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
*-----Calling function for selecting the local file
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_fname.
v_fname = p_fname.
--
FORM open_group.
*-----Open batchinput group
IF p_sesion = 'X'.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_group
user = sy-uname
keep = px_keep.
ENDIF.
ENDFORM. "OPEN_GROUP
--
FORM close_group.
*-----Close batch input session
IF p_sesion = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) text-001.
ELSE.
IF fg_e_group_opened = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Error session created'(i01).
ENDIF.
ENDIF.
ENDFORM. "CLOSE_GROUP
--
FORM bdc_transaction USING tcode TYPE any.
*-----Batch input session
IF p_sesion = 'X'.
IF fg_group_opened = ' '.
*-----Open batch input session for adding transactions
PERFORM open_group.
fg_group_opened = 'X'.
ENDIF.
*-----Insert batch input transactions in batch input session
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
TABLES
dynprotab = it_bdcdata.
WRITE: / 'INSERT SUCCESSFULL'.
*-----Call transaction
ELSE.
REFRESH it_messtab.
CALL TRANSACTION tcode USING it_bdcdata
MODE p_ctumod
MESSAGES INTO it_messtab.
v_subrc = sy-subrc.
LOOP AT it_messtab INTO x_messtab.
SELECT SINGLE * FROM t100 WHERE sprsl = x_messtab-msgspra
AND arbgb = x_messtab-msgid
AND msgnr = x_messtab-msgnr.
IF sy-subrc = 0.
v_mstring = t100-text.
IF v_mstring CS '&1'.
REPLACE '&1' WITH x_messtab-msgv1 INTO v_mstring.
REPLACE '&2' WITH x_messtab-msgv2 INTO v_mstring.
REPLACE '&3' WITH x_messtab-msgv3 INTO v_mstring.
REPLACE '&4' WITH x_messtab-msgv4 INTO v_mstring.
ELSE.
REPLACE '&' WITH x_messtab-msgv1 INTO v_mstring.
REPLACE '&' WITH x_messtab-msgv2 INTO v_mstring.
REPLACE '&' WITH x_messtab-msgv3 INTO v_mstring.
REPLACE '&' WITH x_messtab-msgv4 INTO v_mstring.
ENDIF.
CONDENSE v_mstring.
*-----Determining of messages
CASE x_messtab-msgtyp.
WHEN 'S'.
x_messtab1-msgtyp = x_messtab-msgtyp.
x_messtab1-mstring = v_mstring.
APPEND x_messtab1 TO it_messtab1.
WHEN 'E'.
x_messtab2-msgtyp = x_messtab-msgtyp.
x_messtab2-mstring = v_mstring.
APPEND x_messtab2 TO it_messtab2.
ENDCASE.
ELSE.
WRITE: / x_messtab.
ENDIF.
ENDLOOP.
SKIP.
IF v_subrc <> 0 AND p_e_grp <> space.
IF fg_e_group_opened = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_e_grp
user = sy-uname
keep = px_e_kep.
fg_e_group_opened = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
TABLES
dynprotab = it_bdcdata.
ENDIF.
ENDIF.
REFRESH it_bdcdata.
ENDFORM. "BDC_TRANSACTION
--
FORM fill_bdc USING value(l_dynbegin) TYPE any
value(l_fname) TYPE any
value(l_value) TYPE any.
CLEAR : x_bdcdata.
IF l_dynbegin = 'X'.
x_bdcdata-dynbegin = 'X'.
x_bdcdata-program = l_fname.
x_bdcdata-dynpro = l_value.
ELSE.
x_bdcdata-fnam = l_fname.
x_bdcdata-fval = l_value.
ENDIF.
APPEND x_bdcdata TO it_bdcdata.
ENDFORM. " fill_bdc
--
FORM data_upload .
*-----loading a file from the PC to the server
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_fname
has_field_separator = 'X'
TABLES
data_tab = it_struc1
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " data_upload
reward if useful
Regards
Ashu
2007 Jun 27 12:31 PM
Have you even attempted to do this yourself? Perhaps you should try first and post specific threads when you run into problems.
Award points if helpful
2007 Jun 27 12:34 PM
HI.
refer this code.
REPORT ZSYSTEM LINE-SIZE 255.
TABLES: T100.
Batch-input data
DATA: BEGIN OF G_BDCDATA OCCURS 100.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF G_BDCDATA.
DATA: G_MESSAGE(200).
PERFORM FILL_BDCDATA.
CALL TRANSACTION 'FI01' USING G_BDCDATA MODE 'N'.
of course it is nicer with a message itab, but this example
should also demostrate the use of system variables.
SELECT SINGLE * FROM T100 WHERE
SPRSL = 'E'
AND ARBGB = SY-MSGID
AND MSGNR = SY-MSGNO.
G_MESSAGE = T100-TEXT.
PERFORM REPLACE_PARAMETERS USING SY-MSGV1
SY-MSGV2
SY-MSGV3
SY-MSGV4
CHANGING G_MESSAGE.
WRITE: / 'System variables:'.
SKIP.
WRITE: / ' Sy-msgty:', SY-MSGTY.
WRITE: / ' Sy-msgid:', SY-MSGID.
WRITE: / ' Sy-msgno:', SY-MSGNO.
WRITE: / ' Sy-msgv1:', SY-MSGV1.
WRITE: / ' Sy-msgv2:', SY-MSGV2.
WRITE: / ' Sy-msgv3:', SY-MSGV3.
WRITE: / ' Sy-msgv4:', SY-MSGV4.
SKIP.
WRITE: / 'The transaction was called with a wrong country code.'.
WRITE: / 'The error message should be either that or that you have'.
WRITE: / ' no authorisation to execute the transaction'.
SKIP.
WRITE: / 'Message:'.
SKIP.
WRITE: / SY-MSGTY, G_MESSAGE.
----
Build up the BDC-table *
----
FORM FILL_BDCDATA.
REFRESH G_BDCDATA.
PERFORM BDC_DYNPRO USING 'SAPMF02B' '0100'.
PERFORM BDC_FIELD USING 'BNKA-BANKS' 'ZZZ'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' 'QQQQQ'.
ENDFORM.
----
FORM BDC_DYNPRO *
----
Batchinput: Start new Dynpro *
----
FORM BDC_DYNPRO USING P_PROGRAM P_DYNPRO.
CLEAR G_BDCDATA.
G_BDCDATA-PROGRAM = P_PROGRAM.
G_BDCDATA-DYNPRO = P_DYNPRO.
G_BDCDATA-DYNBEGIN = 'X'.
APPEND G_BDCDATA.
ENDFORM. " BDC_DYNPRO
----
FORM BDC_FIELD *
----
Batchinput: Feld hinzufugen *
----
FORM BDC_FIELD USING P_FNAM P_FVAL.
CLEAR G_BDCDATA.
G_BDCDATA-FNAM = P_FNAM.
G_BDCDATA-FVAL = P_FVAL.
APPEND G_BDCDATA.
ENDFORM. " BDC_FIELD
----
FORM REPLACE_PARAMETERS *
----
........ *
----
--> P_PAR_1 *
--> P_PAR_2 *
--> P_PAR_3 *
--> P_PAR_4 *
--> P_MESSAGE *
----
FORM REPLACE_PARAMETERS USING P_PAR_1
P_PAR_2
P_PAR_3
P_PAR_4
CHANGING P_MESSAGE.
erst mal pruefen, ob numerierte Parameter verwendet wurden
DO.
REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
falls keine numerierten Parameter vorh., ersetzen wie gehabt
REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. "replace_parameters
Reward all helpfull answers.
Regards.
Jay