Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BDC ---Call transaction

Former Member
0 Likes
735

Hi

Can any of you give me a detailed program on BDC---call transaction methid including the transaction program,MPP program the structure and also the report program

With regards

Vijay

Hi

Can any of you give me a detailed program on BDC---call transaction methid including the transaction program,MPP program the structure and also the report program

With regards

Vijay

5 REPLIES 5
Read only

Former Member
0 Likes
688

Hi,

find out the code below

*****************************************************************

  • types Declaration *

*****************************************************************

types: begin of t_tab1 ,

vendor(10),

material(18),

pur_org(4),

wglif(18),

end of t_tab1.

******************************************************************

  • Data Declaration *

******************************************************************

data : begin of it_tab5 occurs 0,

vendor(10),

material(18),

end of it_tab5.

**DATA : BEGIN OF IT_TAB6 OCCURS 0,

    • VENDOR(10),

    • MATERIAL(18),

    • END OF IT_TAB6.

data: it_tab1 type standard table of t_tab1 with header line.

data: wa_tab1 type t_tab1.

data: wa_tab2 type t_tab1.

data: it_tab3 like bdcdata occurs 0 with header line.

data: it_tab4 like bdcdata occurs 0 with header line.

data: it_tab2 type table of bdcmsgcoll with header line.

data: d_file_name like ibipparms-path,

d_file_name1 type string.

****************************************************************

  • Start-of-selection *

****************************************************************

start-of-selection.

        • FM for finding the flat file

call function 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

importing

file_name = d_file_name.

d_file_name1 = d_file_name.

******FM for uploading data from flat file into internal table

call function 'GUI_UPLOAD'

exporting

filename = d_file_name1

filetype = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = it_tab5

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.

*************************************************************

  • End-of-selection *

*************************************************************

end-of-selection.

sort it_tab5 by vendor.

loop at it_tab5.

perform bdc_dynpro using 'SAPLBG00' 0101 .

perform bdc_field using 'BDC_OKCODE' '/00' .

perform bdc_dynpro using 'SAPLBG00' 1000 .

perform bdc_field using 'BDC_OKCODE' '=BUCH' .

perform bdc_field using 'BDC_SUBSCR'

'SAPLBG00 1101KOPF_1000'.

perform bdc_field using 'GBGMK-GAART' '2' .

perform bdc_field using 'GBGMK-GAERB' 'X' .

perform bdc_field using 'BDC_SUBSCR'

'SAPLBG00 1103TAB_SUB_1000'.

perform bdc_field using 'BDC_CURSOR' 'GBGMP-LSTNR(01)' .

perform bdc_field using 'GBGMP-LSTNR(01)' it_tab5-material .

call transaction 'BGM1' using it_tab3 mode 'A' messages into it_tab2.

refresh it_tab3.

        • ON CHANGE OF IT_TAB5-VENDOR.

        • EXIT.

        • ENDON.

****

        • ENDLOOP.

****

        • LOOP AT IT_TAB5.

wa_tab1-pur_org = 'ABCP'.

loop at it_tab2.

endloop.

perform bdc_dynpro using 'SAPMM06I' 0100 .

perform bdc_field using 'BDC_CURSOR' 'EINE-EKORG' .

perform bdc_field using 'BDC_OKCODE' '/00' .

perform bdc_field using 'EINA-LIFNR' it_tab5-vendor .

perform bdc_field using 'EINA-MATNR' it_tab5-material .

perform bdc_field using 'EINE-EKORG' wa_tab1-pur_org .

perform bdc_field using 'RM06I-NORMB' 'X' .

perform bdc_dynpro using 'SAPMM06I' 0101 .

perform bdc_field using 'BDC_CURSOR' 'EINA-WGLIF' .

perform bdc_field using 'BDC_OKCODE' '=BU' .

perform bdc_field using 'EINA-WGLIF' it_tab2-msgv1 .

call transaction 'ME12' using it_tab3 mode 'A'.

refresh it_tab3.

refresh it_tab2.

endloop.

&----


*& Form BDC_DYNPRO

&----


  • Start new screen

----


  • -->P_FNAM text

  • -->P_FVAL text

----


form bdc_dynpro using program

dynpro.

clear it_tab3.

it_tab3-program = program.

it_tab3-dynpro = dynpro.

it_tab3-dynbegin = 'X'.

append it_tab3.

endform. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • Insert field

----


  • -->P_FNAM text

  • -->P_FVAL text

----


form bdc_field using fnam

fval.

clear it_tab3.

it_tab3-fnam = fnam.

it_tab3-fval = fval.

append it_tab3.

endform. " BDC_FIELD

reard if helpful

Read only

manubhutani
Active Contributor
0 Likes
688

let me know if u need anything else..

please reward points

&----


*& Include ZHR_ECM_IT0025_DATE_CHANGE_F

&----


&----


*& Form CHANGE_ENDDA

&----


  • hecks the conditions and updates the End date in IT0025

----


FORM f100_change_endda .

  • Get the Latest Employee Record for 0025 (Appraisals)

rp_provide_from_last p0025 space pn-begda pn-endda.

IF pnp-sw-found = 1.

WRITE: p0025-begda TO v_begda, " Begin Date

p0025-endda TO v_endda. " End Date

IF p0025-begda LE c-c_check1. " 20070304

end_date = c-c_endda1. " End Date

app_criteria = p0025-krt01. " Appraisal Criteria

ELSEIF p0025-begda GE c-c_check2. " 20070305

end_date = c-c_endda2. " End Date

app_criteria = c-c_10. " Appraisal Criteria

ENDIF.

  • Fill BDCDATA Record for 0025 Infotype

PERFORM bdc_dynpro USING 'SAPMP50A' '1000'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=MOD'.

PERFORM bdc_field USING 'RP50G-PERNR'

pernr-pernr.

PERFORM bdc_field USING 'BDC_CURSOR'

'RP50G-ENDDA'.

PERFORM bdc_field USING 'RP50G-TIMR6'

'X'.

PERFORM bdc_field USING 'RP50G-BEGDA'

v_begda.

PERFORM bdc_field USING 'RP50G-ENDDA'

v_endda.

PERFORM bdc_field USING 'RP50G-CHOIC'

c-c_it0025.

PERFORM bdc_dynpro USING 'MP002500' '2000'.

PERFORM bdc_field USING 'BDC_CURSOR'

'P0025-KRT01'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=UPD'.

PERFORM bdc_field USING 'P0025-BEGDA'

v_begda.

PERFORM bdc_field USING 'P0025-ENDDA'

end_date.

PERFORM bdc_field USING 'P0025-KRT01'

app_criteria.

  • PERFORM bdc_field USING 'P0025-PKT01'

  • ' 15'.

  • PERFORM bdc_field USING 'P0025-ZZRATING_CODE'

  • 'O'.

  • Perform BDC Call Transaction

PERFORM bdc_transaction.

ELSE.

fail_count = fail_count + 1.

wa_error-pernr = pernr-pernr.

wa_error-msg = 'No IT 0025 record maintained for this Employee No'(001).

APPEND wa_error TO t_error.

ENDIF.

ENDFORM. " F100_CHANGE_ENDDA

&----


*& Form f400_top_info_allstate

&----


  • Header for the Summary Report

----


FORM f400_show_allstate_header.

CALL FUNCTION 'Z_HEADER'

EXPORTING

flex_text = 'Program to Change the ENDDA of the latest valid records'(002).

WRITE:/ 'User : '(013) , syst-uname.

ULINE.

ENDFORM. " f400_top_info_allstate

&----


*& Form f200_generate_summary

&----


  • Generates Summery Headings

----


FORM f200_generate_summary .

SKIP.

WRITE: 'Summary Report'(003).

ULINE.

SKIP.

WRITE:/ 'No of successful records'(004),

35 v_success.

WRITE:/ 'No of unsuccessful records'(005),

35 fail_count.

ULINE.

ENDFORM. " f200_generate_summary

&----


*& Form bdc_dynpro

&----


  • Fills the BDCDATA table

----


  • -->program Program Name

  • -->dynpro Screen Number

----


FORM bdc_dynpro USING program dynpro.

CLEAR t_bdcdata.

t_bdcdata-program = program.

t_bdcdata-dynpro = dynpro.

t_bdcdata-dynbegin = 'X'.

APPEND t_bdcdata.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • Fills the BDCDATA table

----


  • -->fnam Field Name

  • -->fval Field Value

----


FORM bdc_field USING fnam fval.

CLEAR t_bdcdata.

t_bdcdata-fnam = fnam.

t_bdcdata-fval = fval.

APPEND t_bdcdata.

ENDFORM. " bdc_field

&----


*& Form bdc_transaction

&----


  • Call transaction and fills the Error and Success tables

----


FORM bdc_transaction.

CLEAR : t_bdcmsgcoll[].

CALL TRANSACTION 'PA30' USING t_bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO t_bdcmsgcoll.

IF syst-subrc = 0.

v_success = v_success + 1.

LOOP AT t_bdcmsgcoll.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = t_bdcmsgcoll-msgid

lang = sy-langu

no = t_bdcmsgcoll-msgnr

v1 = t_bdcmsgcoll-msgv1

v2 = t_bdcmsgcoll-msgv2

v3 = t_bdcmsgcoll-msgv3

v4 = t_bdcmsgcoll-msgv4

IMPORTING

msg = success_msg

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

MOVE success_msg TO wa_success-msg.

wa_success-pernr = pernr-pernr.

APPEND wa_success TO t_success.

ENDIF.

EXIT.

ENDLOOP.

ELSE.

fail_count = fail_count + 1.

LOOP AT t_bdcmsgcoll WHERE msgtyp = 'E'.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = t_bdcmsgcoll-msgid

lang = sy-langu

no = t_bdcmsgcoll-msgnr

v1 = t_bdcmsgcoll-msgv1

v2 = t_bdcmsgcoll-msgv2

v3 = t_bdcmsgcoll-msgv3

v4 = t_bdcmsgcoll-msgv4

IMPORTING

msg = err_msg

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

MOVE err_msg TO wa_error-msg.

wa_error-pernr = pernr-pernr.

APPEND wa_error TO t_error.

ENDIF.

ENDLOOP.

ENDIF.

REFRESH t_bdcdata. " Refreshes the BDCDATA Internal table for the next record

CLEAR : t_bdcdata[].

ENDFORM. " bdc_transaction

&----


*& Form f300_generate_error_report

&----


  • Generates the Report

----


FORM f300_generate_error_report .

DATA: messg(100) TYPE c.

SKIP.

WRITE:/ 'Success Report' COLOR 4.

SKIP.

ULINE.

WRITE:/ 'Personnel Number'(006),

35 'Success Message'(007).

ULINE.

SKIP.

LOOP AT t_success INTO wa_success.

WRITE : / wa_success-pernr,

35 wa_success-msg.

ENDLOOP.

ULINE.

SKIP.

WRITE:/ 'Error Report' COLOR 6.

SKIP.

ULINE.

WRITE:/ 'Personnel Number'(006),

35 'Error Message'(008).

ULINE.

SKIP.

LOOP AT t_error INTO wa_error.

WRITE : / wa_error-pernr,

35 wa_error-msg.

ENDLOOP.

ENDFORM. " f300_generate_error_report

Read only

Former Member
0 Likes
688

Hi

check this code....

-


STRUCTURE DECLARATION

-


TYPES : BEGIN OF st_vendor,

ktokk TYPE rf02k-ktokk, "account group

anred TYPE lfa1-anred, "title

name1 TYPE lfa1-name1, "vendor name

sortl TYPE lfa1-sortl, "search term

pstlz TYPE lfa1-pstlz, "postal code

land1 TYPE lfa1-land1, "country

banks TYPE lfbk-banks,

bankl TYPE lfbk-bankl, "bank key

bankn TYPE lfbk-bankn, "account number

END OF st_vendor.

TYPES : BEGIN OF st_success,

lifnr TYPE lfa1-lifnr, "vendor number

name TYPE lfa1-name1, "vendor name

END OF st_success.

TYPES: BEGIN OF st_error,

linno TYPE i, "line number

message TYPE string, "error message

END OF st_error.

-


INTERNAL TABLE DECLARATIONS

WORK AREA DECLARATIONS

-


DATA : it_vendor TYPE STANDARD TABLE OF st_vendor,

wa_vendor TYPE st_vendor,

it_success TYPE STANDARD TABLE OF st_success,

wa_success TYPE st_success,

it_error TYPE STANDARD TABLE OF st_error,

wa_error TYPE st_error,

it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,

it_message LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

-


DATA DECLARATION

-


DATA : v_file TYPE string,

v_tcode(4) VALUE 'XK01',

v_index LIKE sy-tabix,

v_totalrec TYPE i,

v_errrec TYPE i,

v_succrec TYPE i.

-


SELECTION SCREEN

-


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-010.

PARAMETERS p_mode LIKE ctu_params-dismode DEFAULT 'N' .

"A: show all dynpros

"E: show dynpro on error only

"N: do not display dynpro

PARAMETERS p_update LIKE ctu_params-updmode DEFAULT 'S'.

"S: synchronously

"A: asynchronously

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-011.

PARAMETERS : p_group(12) DEFAULT '50871'. "group name for error session

SELECTION-SCREEN END OF BLOCK b3.

-


AT SELECTION SCREEN ON VALUE-REQUEST

-


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = ' '

IMPORTING

file_name = p_file.

-


START-OF-SELECTION

-


START-OF-SELECTION.

v_file = p_file.

*gui upload

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = it_vendor

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.

*loadind data into it_bdcdata

LOOP AT it_vendor INTO wa_vendor.

v_index = sy-tabix.

PERFORM load_bdcdata.

-


CALL TRANSACTION

-


CALL TRANSACTION v_tcode USING it_bdcdata

MODE p_mode

UPDATE p_update

MESSAGES INTO it_message.

*reading success

IF sy-subrc = 0.

READ TABLE it_message WITH KEY msgtyp = 'S'.

IF sy-subrc = 0.

wa_success-lifnr = it_message-msgv1.

wa_success-name = wa_vendor-name1.

APPEND wa_success TO it_success.

ENDIF.

ELSE.

*reading errors

READ TABLE it_message WITH KEY msgtyp = 'E'.

IF sy-subrc = 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = sy-msgid

no = it_message-msgnr

v1 = it_message-msgv1

v2 = it_message-msgv2

v3 = it_message-msgv3

v4 = it_message-msgv4

IMPORTING

msg = wa_error-message.

wa_error-linno = v_index.

APPEND wa_error TO it_error.

CLEAR wa_error.

ENDIF.

*session opening

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_group

holddate = sy-datum

keep = 'X'

user = sy-uname.

*inserting into session

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'XK01'

TABLES

dynprotab = it_bdcdata.

*closing session

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDIF.

CLEAR: it_bdcdata, it_message.

REFRESH: it_bdcdata, it_message.

ENDLOOP.

-


SUMMARY DISPLAY

-


DESCRIBE TABLE it_vendor LINES v_totalrec.

DESCRIBE TABLE it_error LINES v_errrec.

v_succrec = v_totalrec - v_errrec .

WRITE : /1 text-004 COLOR 1.

WRITE : /2 'Total Records Processed :', 25 v_totalrec,

/2 'Error Records :', 25 v_errrec,

/2 'Successful Records :', 25 v_succrec.

SKIP 2.

WRITE : /1 text-005 COLOR 1.

LOOP AT it_error INTO wa_error.

WRITE:/2 wa_error-linno,

wa_error-message.

ENDLOOP.

SKIP 2.

WRITE : /1 text-009 COLOR 1.

ULINE AT : /2(46).

WRITE :/2 sy-vline ,(10) 'VENDOR NUM' , 15 sy-vline , 17 'VENDOR NAME' , 47 sy-vline.

ULINE AT : /2(46).

LOOP AT it_success INTO wa_success.

WRITE:/2 sy-vline , wa_success-lifnr, 15 sy-vline , 17 wa_success-name , 47 sy-vline.

ENDLOOP.

ULINE AT : /2(46).

&----


*& Form append_bdcdata

&----


FORM append_bdcdata USING p_flag p_fname p_fval.

CLEAR it_bdcdata.

IF p_flag = 'X'.

it_bdcdata-program = p_fname.

it_bdcdata-dynpro = p_fval.

it_bdcdata-dynbegin = 'X'.

APPEND it_bdcdata.

ELSEIF NOT p_fval IS INITIAL.

it_bdcdata-fnam = p_fname.

it_bdcdata-fval = p_fval.

APPEND it_bdcdata.

ENDIF.

ENDFORM. "append_bdcdata

&----


*& Form load_bdcdata

&----


FORM load_bdcdata .

PERFORM append_bdcdata USING : 'X' 'SAPMF02K' '0100',

' ' 'BDC_OKCODE' '/00',

' ' 'RF02K-KTOKK' wa_vendor-ktokk,

'X' 'SAPMF02K' '0110',

' ' 'BDC_OKCODE' '/00',

' ' 'LFA1-ANRED' wa_vendor-anred,

' ' 'LFA1-NAME1' wa_vendor-name1,

' ' 'LFA1-SORTL' wa_vendor-sortl,

' ' 'LFA1-PSTLZ' wa_vendor-pstlz,

' ' 'LFA1-LAND1' wa_vendor-land1,

'X' 'SAPMF02K' '0120',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '0130',

' ' 'BDC_OKCODE' '=ENTR',

' ' 'LFBK-BANKS(01)' wa_vendor-banks,

' ' 'LFBK-BANKL(01)' wa_vendor-bankl,

' ' 'LFBK-BANKN(01)' wa_vendor-bankn,

'X' 'SAPMF02K' '0130',

' ' 'BDC_OKCODE' '=ENTR',

'X' 'SAPLSPO1' '0300',

' ' 'BDC_OKCODE' '=YES'.

ENDFORM. " load_bdcdata

Read only

0 Likes
688

Hi jyosthna

What about the tcode v_tcode.?What is the program for that?

Read only

0 Likes
688

In data declaration part she declared it see here



DATA : v_file TYPE string,
*v_tcode(4) VALUE 'XK01',*
v_index LIKE sy-tabix,
v_totalrec TYPE i,
v_errrec TYPE i,
v_succrec TYPE i.