Transcript
7/28/2019 BDC Session
http://slidepdf.com/reader/full/bdc-session 1/5
Example on BDC Session Method
By Debesh Page 1
Sometimes there is a need to populate custom table using BDC. That time first the custom table is
created and then the TMG (Table maintenance generator) is created.
Now from SM30 new entries can be entered into the table through TMG. If the SM30 transaction can be
recorded, then the screen sequence of the SM30 transaction can be called inside the data loop(Data can
be collected from a desktop file to internal table) to make the table update process automated.
So record the SM30 transaction through SHDB and generate the code and transfer the code into anABAP report. Comment the unnecessary includes and perform statements and write the code as
follows.
***************************************************************
* REPORT ytest_bdc *
* BDC Session Method example *
***************************************************************
7/28/2019 BDC Session
http://slidepdf.com/reader/full/bdc-session 2/5
Example on BDC Session Method
By Debesh Page 2
* By Debesh *
* Date 07/06/2013 *
***************************************************************
REPORT ytest_bdc
NO STANDARD PAGE HEADING LINE-SIZE 255.
PARAMETERS : p_path TYPE rlgrap-filename.
TYPES : BEGIN OF ty_file ,
str(255),
END OF ty_file.
DATA : lt_itab TYPE STANDARD TABLE OF ty_file,
lt_itab1 TYPE TABLE OF ycustom_tab .
DATA :ls_itab LIKE LINE OF lt_itab,
ls_itab1 LIKE LINE OF lt_itab1.
DATA : lv_file TYPE string,
ls_path TYPE file_table,
lt_ftab TYPE filetable,lv_rc TYPE i.
DATA : lt_bdc TYPE STANDARD TABLE OF bdcdata,
ls_bdc TYPE bdcdata.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = lt_ftab
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed = 1cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
READ TABLE lt_ftab INTO ls_path INDEX 1.
IF sy-subrc IS INITIAL.
p_path = ls_path-filename.
ENDIF.
ENDIF.
START-OF-SELECTION.
lv_file = p_path.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
7/28/2019 BDC Session
http://slidepdf.com/reader/full/bdc-session 3/5
Example on BDC Session Method
By Debesh Page 3
filetype = 'ASC'
TABLES
data_tab = lt_itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2no_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 = 14disk_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.
LOOP AT lt_itab INTO ls_itab.
SPLIT ls_itab-str AT ' ' INTO ls_itab1-field1 ls_itab1-field2
ls_itab1-field3.APPEND ls_itab1 TO lt_itab1.
CLEAR ls_itab1.
ENDLOOP.
START-OF-SELECTION.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'DEMO_SESSION'
keep = 'X'
user = sy-uname.
*perform open_group.
LOOP AT lt_itab1 INTO ls_itab1.
PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR' 'VIEWNAME'.
PERFORM bdc_field USING 'BDC_OKCODE' '=UPD'.
PERFORM bdc_field USING 'VIEWNAME' 'YCUSTOM_TAB'.
PERFORM bdc_field USING 'VIMDYNFLDS-LTD_DTA_NO' 'X'.
7/28/2019 BDC Session
http://slidepdf.com/reader/full/bdc-session 4/5
Example on BDC Session Method
By Debesh Page 4
PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'.
PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=NEWL'.
PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'.
PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD3(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=SAVE'.PERFORM bdc_field USING 'YCUSTOM_TAB-FIELD1(01)'
ls_itab1-field1.
PERFORM bdc_field USING 'YCUSTOM_TAB-FIELD2(01)'
ls_itab1-field2.
PERFORM bdc_field USING 'YCUSTOM_TAB-FIELD3(01)'
ls_itab1-field3.
PERFORM bdc_dynpro USING 'SAPLSTRD' '0300'.
PERFORM bdc_field USING 'BDC_CURSOR' 'KO008-TRKORR'.
PERFORM bdc_field USING 'BDC_OKCODE' '=LOCK'.
PERFORM bdc_field USING 'KO008-TRKORR' 'DEVK900002'.
PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'.
PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(02)'.PERFORM bdc_field USING 'BDC_OKCODE' '=SAVE'.
PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'.
PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(02)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.
PERFORM bdc_dynpro USING 'SAPLZDEMO_FG' '1011'.
PERFORM bdc_field USING 'BDC_CURSOR' 'YCUSTOM_TAB-FIELD1(02)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.
PERFORM bdc_dynpro USING 'SAPMSVMA' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE' '/EBACK'.
PERFORM bdc_field USING 'BDC_CURSOR' 'VIEWNAME'.
APPEND ls_bdc TO lt_bdc.CLEAR ls_bdc.
ENDLOOP.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'SM30'
TABLES
dynprotab = lt_bdc.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* Send BDC screen details to BDC Data
*----------------------------------------------------------------------*
* -->P_0668 program name
* -->P_0669 screen no
*----------------------------------------------------------------------*
FORM bdc_dynpro USING value(p_0668)
7/28/2019 BDC Session
http://slidepdf.com/reader/full/bdc-session 5/5
Example on BDC Session Method
By Debesh Page 5
value(p_0669).
CLEAR ls_bdc.
ls_bdc-program = p_0668.
ls_bdc-dynpro = p_0669.
ls_bdc-dynbegin = 'X'.
APPEND ls_bdc TO lt_bdc.
ls_bdc-fnam = ''.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* Send Screen field values to BDC DATA
*----------------------------------------------------------------------*
* -->P_0673 field name
* -->P_0674 field value
*----------------------------------------------------------------------*
FORM bdc_field USING value(p_0673)value(p_0674).
CLEAR ls_bdc.
ls_bdc-fnam = p_0673.
ls_bdc-fval = p_0674.
APPEND ls_bdc TO lt_bdc.
ENDFORM. " BDC_FIELD
top related