Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
BDC_OPEN_GROUP.
2.
BDC_INSERT.
3.
BDC_CLOSE_GROUP.
In BDC we use structure BDCDATA for Batch Input, Which has following components.
PROGRAM - BDC module pool
DYNPRO-
DYNBEGIN-
FNAM-
Field name
FVAL-
A BDCDATA structure can contain the batch input data for only a single run of a transaction
Lets for the sake of convenience our flat file looks like this.
(If you are using the same file for practice make sure you remove the above two heading rows.)
From above flat file we came to know about the structure of the internal table in which data will be uploaded.
DATA:
BEGIN OF fs_field,
bsart TYPE eban-bsart,
matnr TYPE eban-matnr,
menge TYPE eban-menge,
werks TYPE eban-werks,
END OF fs_field.
Recoding is done in Transacton SHDB .
Here we have done Recording for the transaction- ME51 .
The Recording which you get will be in following format.
Document Type.
*Input Path
PARAMETERS:
p_file
TYPE rlgrap-filename.
* Structure Decleration
DATA :
BEGIN OF fs_field,
bsart TYPE eban-bsart,
matnr TYPE eban-matnr,
menge TYPE eban-menge,
werks TYPE eban-werks,
END OF fs_field.
*Internal table decleration
DATA:
t_field
t_bdcdata
DATA:
fs_bdcdata LIKE LINE OF t_bdcdata,
w_str TYPE string.
* Data decleration
DATA:
wa_path TYPE string ,
wa_error TYPE string,
wa_cnt
TYPE i,
w_mode
TYPE c,
wa_cnt1(2) TYPE n,
it_output type table of ty_s_error,
wa_output like line of it_output.
* Opening window for path selection
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.
TYPES:
fs_struct(4096) TYPE c OCCURS 0 .
DATA:
w_struct TYPE fs_struct.
* Uploading excel file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator
= 'X'
* I_LINE_HEADER
=
i_tab_raw_data
= w_struct
i_filename
= p_file
TABLES
i_tab_converted_data
= t_field
EXCEPTIONS
conversion_failed
= 1
OTHERS
= 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
PERFORM open_group .
LOOP AT t_field INTO fs_field.
REFRESH: t_bdcdata.
CLEAR : fs_bdcdata.
PERFORM populate_bdcdata.
PERFORM insert_data.
ENDLOOP.
*
*
*
*
*
*
*
*
*
ENDFORM.
*&---------------------------------------------------------------------*
*&
Form POPULATE_BDCDATA
*&---------------------------------------------------------------------*
*
Function to populate data
*----------------------------------------------------------------------*
FORM populate_bdcdata .
PERFORM :
fill_bdc_data USING 'SAPMM06B' '0100' 'X' ' ' ' ',
fill_bdc_data USING '' '' ''
'EBAN-BSART' fs_field-bsart,
fill_bdc_data USING '' '' ''
'BDC_OKCODE' '/00',
fill_bdc_data USING 'SAPMM06B' '0106' 'X' ' ' ' ',
fill_bdc_data USING '' '' '' 'EBAN-MATNR(01)' fs_field-matnr,
fill_bdc_data USING '' '' '' 'EBAN-MENGE(01)' fs_field-menge,
d.
fill_bdc_data
fill_bdc_data
fill_bdc_data
fill_bdc_data
ENDFORM.
" POPULATE_BDCDATA
*&---------------------------------------------------------------------*
*&
Form FILL_BDC_DATA
*&---------------------------------------------------------------------*
*
Function to populate data
*----------------------------------------------------------------------*
*
-->VALUE(P_PROGRAM) Program name
*
-->VALUE(P_DYNPRO) screen no
*
-->VALUE(P_BEGIN) screen start
*
-->VALUE(P_FIELD) field name
*
-->VALUE(P_VALUE) field value
*----------------------------------------------------------------------*
FORM fill_bdc_data USING
value(p_program)
value(p_dynpro)
value(p_begin)
value(p_field)
value(p_value).
CLEAR fs_bdcdata.
IF p_begin = 'X'.
*" Screen Values.
fs_bdcdata-program = p_program.
fs_bdcdata-dynpro = p_dynpro.
fs_bdcdata-dynbegin
= p_begin.
APPEND fs_bdcdata TO t_bdcdata.
ELSE.
*" Filed Values.
CLEAR fs_bdcdata.
fs_bdcdata-fnam = p_field.
fs_bdcdata-fval = p_value.
CONDENSE fs_bdcdata-fval.
APPEND fs_bdcdata TO t_bdcdata.
" Plant.
" Enter.
" Save.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&
Form INSERT_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM insert_data .
*Data decleration
DATA:
t_msg TYPE TABLE OF bdcmsgcoll,
w_msg TYPE bdcmsgcoll,
w_msg1(51).
*
*
*
*
ENDFORM.
" INSERT_DATA
*&---------------------------------------------------------------------*
*&
Form CLOSE_GROUP
*&---------------------------------------------------------------------*
*
Function to close BDC group
*----------------------------------------------------------------------*
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open
= 1
queue_error = 2
OTHERS
= 3.
IF sy-subrc <> 0.
MESSAGE 'UNABLE TO CLOSE BDC SESSION !' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
" IF sy-subrc ..
WRITE : / 'CLOSED SESSION'.
ENDFORM.
" CLOSE_GROUP
2.
3.
Display Error If there is any error, it will be displayed in log otherwise it is similar to background mode.
Select the mode from radio button and press Process button
In case of any Error we can go to the log and check the error message from the Log button as shown below.