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-STEPS AND CODING

Former Member
0 Likes
632

HI

HI I WANT THE STEPS AND CODING USING THESE FUNCTION PLEASE SEND IT

1) BCD_OPEN_GROUP

2) BCD_INSERT

3) BCD_CLOSE_GROUP

ADVANCE THANKA FOR U

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
593

Hi

Regards,

Suruchi

4 REPLIES 4
Read only

Former Member
0 Likes
594

Hi

Regards,

Suruchi

Read only

Former Member
0 Likes
593

Hi Siva,

Check the development

&----


*& Report Z34331_BDC *

*& *

&----


*& Creating a test program for uplaoding a CSV or XLS file and pass *

*& the internal table value to a BDC program *

&----


REPORT Z34331_BDC.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

*for excel file

PARAMETERS: P_IFILE TYPE RLGRAP-FILENAME.

*for csv and txt file

*PARAMETERS: p_ifile TYPE dxfile-filename.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-002.

PARAMETERS: P_SESS RADIOBUTTON GROUP G3 "create session

DEFAULT 'X' USER-COMMAND BDC,

P_CTU RADIOBUTTON GROUP G3. "call transaction

SELECTION-SCREEN END OF BLOCK B3.

*for csv and txt file

*DATA : BEGIN OF itab OCCURS 0,

  • str TYPE string,

  • END OF itab,

*for xls file

DATA : ITAB LIKE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

DATA : L_FILE TYPE STRING,

T_BDCDATA TYPE STANDARD TABLE OF BDCDATA,

WA_BDCDATA LIKE LINE OF T_BDCDATA.

*----


  • AT SELECTION SCREEN ON VALUE REQUEST

*----


  • Value request for the filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IFILE.

PERFORM HELP_INPUT_FILE.

START-OF-SELECTION.

CLEAR L_FILE.

*for csv and txt file

  • l_file = p_ifile.

*for xls file

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_IFILE

I_BEGIN_COL = 1

I_BEGIN_ROW = 1

I_END_COL = 2

I_END_ROW = 2

TABLES

INTERN = ITAB

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

*for csv and txt file

  • CALL FUNCTION 'GUI_UPLOAD'

  • EXPORTING

  • filename = l_file

  • filetype = 'ASC'

  • TABLES

  • data_tab = itab

  • 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.

*Start new session

IF P_SESS = 'X'.

PERFORM BDC_OPEN.

ENDIF.

LOOP AT ITAB.

PERFORM CREAT_BATCH_INPUT.

PERFORM BDC_INSERT.

IF P_CTU = 'X'.

CALL TRANSACTION 'SE38' USING T_BDCDATA MODE 'A'.

ENDIF.

ENDLOOP.

IF P_SESS = 'X'.

PERFORM BDC_CLOSE .

IF SY-SUBRC EQ 0.

MESSAGE I001(ZM) WITH 'Session created check in transaction SM35'.

ENDIF.

ENDIF.

&----


*& Form bdc_open

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_OPEN .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = 'ZMUK'

USER = SY-UNAME

EXCEPTIONS

CLIENT_INVALID = 1

DESTINATION_INVALID = 2

GROUP_INVALID = 3

GROUP_IS_LOCKED = 4

HOLDDATE_INVALID = 5

INTERNAL_ERROR = 6

QUEUE_ERROR = 7

RUNNING = 8

SYSTEM_LOCK_ERROR = 9

USER_INVALID = 10

OTHERS = 11.

ENDFORM. " bdc_open

&----


*& Form creat_batch_input

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CREAT_BATCH_INPUT .

PERFORM BDC_DYNPRO USING 'SAPLWBABAP' '0100'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=STRT'.

*for csv and txt file

  • PERFORM bdc_field USING 'RS38M-PROGRAMM'

  • itab-str.

*for xls file

PERFORM BDC_FIELD USING 'RS38M-PROGRAMM'

ITAB-VALUE.

PERFORM BDC_FIELD USING 'RS38M-FUNC_EDIT'

'X'.

PERFORM BDC_DYNPRO USING 'SAPLSLVC_FULLSCREEN' '0500'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=&F03'.

PERFORM BDC_DYNPRO USING 'SAPLWBABAP' '0100'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=BACK'.

*for csv and txt file

  • PERFORM bdc_field USING 'RS38M-PROGRAMM'

  • itab-str.

*for xls file

PERFORM BDC_FIELD USING 'RS38M-PROGRAMM'

ITAB-VALUE.

PERFORM BDC_FIELD USING 'RS38M-FUNC_EDIT'

'X'.

ENDFORM. " creat_batch_input

&----


*& Form bdc_insert

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_INSERT .

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'SE38'

TABLES

DYNPROTAB = T_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7.

ENDFORM. " bdc_insert

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0168 text

  • -->P_0169 text

----


FORM BDC_DYNPRO USING P_PROGRAM TYPE ANY

P_DYNPRO TYPE ANY.

CLEAR WA_BDCDATA.

WA_BDCDATA-PROGRAM = P_PROGRAM.

WA_BDCDATA-DYNPRO = P_DYNPRO.

WA_BDCDATA-DYNBEGIN = 'X'.

APPEND WA_BDCDATA TO T_BDCDATA.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_0179 text

  • -->P_0180 text

----


FORM BDC_FIELD USING P_FNAM TYPE ANY

P_FVAL TYPE ANY.

CLEAR WA_BDCDATA.

WA_BDCDATA-FNAM = P_FNAM.

WA_BDCDATA-FVAL = P_FVAL.

CONDENSE WA_BDCDATA-FVAL.

APPEND WA_BDCDATA TO T_BDCDATA.

ENDFORM. " bdc_field

&----


*& Form bdc_close

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC_CLOSE .

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

ENDFORM. " bdc_close

*&----


**& Form help_input_file

*&----


    • text

*----


    • --> p1 text

    • <-- p2 text

*----


FORM HELP_INPUT_FILE .

DATA: LT_FILE_TABLE TYPE FILETABLE,

LA_FILE_TABLE LIKE LINE OF LT_FILE_TABLE,

L_RC TYPE I,

L_PCDSN TYPE CFFILE-FILENAME.

REFRESH LT_FILE_TABLE.

CLEAR LA_FILE_TABLE.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

CHANGING

FILE_TABLE = LT_FILE_TABLE

RC = L_RC.

READ TABLE LT_FILE_TABLE INTO LA_FILE_TABLE INDEX 1.

L_PCDSN = LA_FILE_TABLE-FILENAME.

MOVE L_PCDSN TO P_IFILE.

ENDFORM. " help_input_file

Read only

Former Member
0 Likes
593

Hi Siva,

Just go through below link:

url=http://www.sap-img.com/ab001.htm]http://www.sap-img.com/ab001.htm[/url]

Reward if useful![

Read only

Former Member
0 Likes
593

HI siva,

PLease find the sample code.

&----


*& Report ZB02BDC *

*& *

&----


*& *

*& *

&----


report zb02bdc line-size 125 .

*-TABLES DECLARATION.

tables : zb02splfi , zb02sflight.

*-END OF DECLARATION.

*-DECLARING THE PARAMETERS FOR FILES.

parameters : p_file1 type rlgrap-filename default

'd:/chandu/master1.txt',

p_file2 type rlgrap-filename default 'd:/chandu/flight.txt'

.

*-END.

*-DECLARING THE INTERNAL TABLES.

data : begin of itab1 occurs 0 ,

carrid type s_carr_id,

connid(10) type c,

countryfr type land1,

cityfrom type s_from_cit,

airpfrom type s_fromairp,

countryto type land1,

cityto type s_to_city,

airpto type s_toairp,

end of itab1.

data : g_field type fnam_____4,

g_count(4) type n value 0.

data : begin of itab2 occurs 0,

carrid(3) type c,

connid(4) type c,

fldate(10) type c,

price(15) type c,

currency(5) type c,

planetype(10) type c,

seatsmax(10) type c,

seatsoccs(10) type c,

end of itab2.

data : itab_bdc like standard table of bdcdata,

wa_bdc like bdcdata.

*-END OF INTERNAL TABLES DECLARATION.

*-UPLOADING DATA FROM FLAT FILES.

call function 'WS_UPLOAD'

exporting

filename = p_file1

filetype = 'DAT'

tables

data_tab = itab1

exceptions

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

no_authority = 10

others = 11.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

*-UPLOADING DATA FROM FLAT FILES.

call function 'WS_UPLOAD'

exporting

filename = p_file2

filetype = 'DAT'

tables

data_tab = itab2

exceptions

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

no_authority = 10

others = 11.

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 UPLOAD.

*-DISPLAY UPLOADED DATA USING LOOP.

loop at itab1.

write : / itab1.

endloop.

*-DISPLAY UPLOADED DATA USING LOOP.

loop at itab2.

write : / itab2.

endloop.

*-BDC_OPEN_GROUP.

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

group = 'B02BDCDATA'

user = sy-uname

exceptions

client_invalid = 1

destination_invalid = 2

group_invalid = 3

group_is_locked = 4

holddate_invalid = 5

internal_error = 6

queue_error = 7

running = 8

system_lock_error = 9

user_invalid = 10

others = 11.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

*-UPLOADING EACH DATA USING WORK AREA.

loop at itab1.

clear itab_bdc.

wa_bdc-program = 'SAPMZB02MODULE1' .

wa_bdc-dynpro = '1000'.

wa_bdc-dynbegin = 'X'.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND CARRID.

wa_bdc-fnam = 'ZB02SPLFI-CARRID'.

wa_bdc-fval = itab1-carrid.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND CONNID.

wa_bdc-fnam = 'ZB02SPLFI-CONNID'.

wa_bdc-fval = itab1-connid.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-OKCODE FOR PROCEED.

wa_bdc-fnam = 'BDC_OKCODE'.

wa_bdc-fval = 'PROCEED'.

append wa_bdc to itab_bdc.

clear wa_bdc.

wa_bdc-program = 'SAPMZB02MODULE1' .

wa_bdc-dynpro = '1001'.

wa_bdc-dynbegin = 'X'.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND COUNTRYFR.

wa_bdc-fnam = 'ZB02SPLFI-COUNTRYFR'.

wa_bdc-fval = itab1-countryfr.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND CITYFROM.

wa_bdc-fnam = 'ZB02SPLFI-CITYFROM'.

wa_bdc-fval = itab1-cityfrom.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND AIRFROM.

wa_bdc-fnam = 'ZB02SPLFI-AIRPFROM'.

wa_bdc-fval = itab1-airpfrom.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND COUNTRYTO.

wa_bdc-fnam = 'ZB02SPLFI-COUNTRYTO'.

wa_bdc-fval = itab1-countryto.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND CITYTO.

wa_bdc-fnam = 'ZB02SPLFI-CITYTO'.

wa_bdc-fval = itab1-cityto.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPEND AIRPTO.

wa_bdc-fnam = 'ZB02SPLFI-AIRPTO'.

wa_bdc-fval = itab1-airpto.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-OKCODE FOR NEXT.

wa_bdc-fnam = 'BDC_OKCODE'.

wa_bdc-fval = 'NEXT'.

append wa_bdc to itab_bdc.

clear wa_bdc.

clear g_count.

*-LOOP AT INTERNAL TABLE2 FOR APPENDING FLIGHT DETAILS.

loop at itab2 where carrid = itab1-carrid and connid = itab1-connid.

g_count = g_count + 1.

wa_bdc-program = 'SAPMZB02MODULE1' .

wa_bdc-dynpro = '1002'.

wa_bdc-dynbegin = 'X'.

append wa_bdc to itab_bdc.

clear wa_bdc.

wa_bdc-fnam = 'BDC_OKCODE'.

wa_bdc-fval = 'ZTAB1_INSR'.

append wa_bdc to itab_bdc.

clear wa_bdc.

wa_bdc-program = 'SAPMZB02MODULE1' .

wa_bdc-dynpro = '1002'.

wa_bdc-dynbegin = 'X'.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-APPENDING THE FLIGHT DETAILS IN ZB02SFLIGHT TABLE.

zb02sflight-carrid = itab2-carrid.

zb02sflight-connid = itab2-connid.

concatenate 'ZB02SFLIGHT-FLDATE(' g_count ')' into g_field.

*-APPENDING FLDATE FROM TABLE WIZARD CONTROL.

wa_bdc-fnam = g_field.

wa_bdc-fval = itab2-fldate.

append wa_bdc to itab_bdc.

clear wa_bdc.

clear g_field.

concatenate 'ZB02SFLIGHT-PRICE(' g_count ')' into g_field .

*-APPENDING PRICE FROM TABLE WIZARD CONTROL.

wa_bdc-fnam = g_field.

wa_bdc-fval = itab2-price.

append wa_bdc to itab_bdc.

clear wa_bdc.

clear g_field.

concatenate 'ZB02SFLIGHT-CURRENCY(' g_count ')' into g_field .

*-APPENDING CURRENCY FROM TABLE WIZARD CONTROL.

wa_bdc-fnam = g_field.

wa_bdc-fval = itab2-currency.

append wa_bdc to itab_bdc.

clear wa_bdc.

clear g_field.

*-APPENDING PLANETYPE FROM TABLE WIZARD CONTROL.

concatenate 'ZB02SFLIGHT-PLANETYPE(' g_count ')' into g_field .

wa_bdc-fnam = g_field.

wa_bdc-fval = itab2-planetype.

append wa_bdc to itab_bdc.

clear wa_bdc.

clear g_field.

concatenate 'ZB02SFLIGHT-SEATSMAX(' g_count ')' into g_field .

*-APPENDING SEATMAX FROM TABLE WIZARD CONTROL.

wa_bdc-fnam = g_field.

wa_bdc-fval = itab2-seatsmax.

append wa_bdc to itab_bdc.

clear wa_bdc.

clear g_field.

concatenate 'ZB02SFLIGHT-SEATSOCCS(' g_count ')' into g_field .

*-APPENDING SEATSOCCS FROM TABLE WIZARD CONTROL.

wa_bdc-fnam = g_field.

wa_bdc-fval = itab2-seatsoccs.

append wa_bdc to itab_bdc.

clear wa_bdc.

clear g_field.

wa_bdc-fnam = 'BDC_OKCODE'.

wa_bdc-fval = '/00'.

append wa_bdc to itab_bdc.

clear wa_bdc.

wa_bdc-program = 'SAPMZB02MODULE1' .

wa_bdc-dynpro = '1002'.

wa_bdc-dynbegin = 'X'.

append wa_bdc to itab_bdc.

clear wa_bdc.

endloop.

*-END OF LOOP

*-OKCODE FOR SAVE BUTTON.

wa_bdc-fnam = 'BDC_OKCODE'.

wa_bdc-fval = 'SAVE'.

append wa_bdc to itab_bdc.

clear wa_bdc.

wa_bdc-program = 'SAPMZB02MODULE1' .

wa_bdc-dynpro = '1002'.

wa_bdc-dynbegin = 'X'.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-OKCODE FOR EXIT.

wa_bdc-fnam = 'BDC_OKCODE'.

wa_bdc-fval = 'EXIT'.

append wa_bdc to itab_bdc.

clear wa_bdc.

*-BDC-INSERT.

call function 'BDC_INSERT'

exporting

tcode = 'zb02flight1'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

tables

dynprotab = itab_bdc

exceptions

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

printing_invalid = 5

posting_invalid = 6

others = 7

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endloop.

BDC-CLOSE-GROUP.

PS:Reward Points if helpful.

Thanks,

Reddy.