i wrote bdc code for me38 it will execute succesfully but it cannot update the record to the transaction me38 i use commit work it will not working. please give idea about where i can use the commit work and wait statement.
REPORT zbdc_me381
NO STANDARD PAGE HEADING LINE-SIZE 255.
*following data for excel file and give file name Mschedule
* Po line no Date format Date Schedule Quantity
*520000015 10 D 02.06.2013 1000
*520000025 20 D 02.06.2013 2000
*520000025 20 D 02.06.2013 3000
*520000025 30 D 02.06.2013 4000
*520000025 40 D 02.06.2013 5000
*include bdcrecx1.
*parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
TYPES: BEGIN OF ty_record,
* data element: EVRTN
EVRTN_001(010),
* data element: AUFEP
EBELP_002(005),
* data element: TCSELFLAG
TCSELFLAG_01_003(001),
* data element: ETNR1
ETNR1_004(004),
* data element: LPEIN
LPEIN_04_005(001),
* data element: EEIND
EEIND_04_006(010),
* data element: ETMEN
MENGE_04_007(017),
* data element: ETNR1
ETNR1_008(004),
END OF ty_record.
DATA: w_record TYPE ty_record,
i_record TYPE STANDARD TABLE OF ty_record.
DATA:
l_log_handle TYPE balloghndl,
l_s_log TYPE bal_s_log,
l_s_msg TYPE bal_s_msg,
l_msgno TYPE symsgno.
DATA: i_bdcdata TYPE TABLE OF bdcdata,
w_bdcdata TYPE bdcdata.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
*DATA: i_messtab TYPE TABLE OF bdcmsgcoll,
* w_messtab TYPE bdcmsgcoll.
* error session opened (' ' or 'X')
DATA : it_file TYPE TABLE OF alsmex_tabline,
wa_file TYPE alsmex_tabline.
INITIALIZATION.
PERFORM log_create.
START-OF-SELECTION.
SELECTION-SCREEN BEGIN OF BLOCK mode WITH FRAME TITLE text-003.
PARAMETERS: file_url TYPE rlgrap-filename MODIF ID xyz .
SELECTION-SCREEN END OF BLOCK mode .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_url.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'FILE_URL'
IMPORTING
file_name = file_url.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file_url
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '5'
i_end_row = '10'
TABLES
intern = it_file
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
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 it_file INTO wa_file.
CASE wa_file-col.
WHEN 1.
w_record-EVRTN_001(010) = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_record-EVRTN_001(010)
IMPORTING
output = w_record-EVRTN_001(010).
WHEN 2.
w_record-EBELP_002(005) = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_record-EBELP_002(005)
IMPORTING
output = w_record-EBELP_002(005).
WHEN 3.
w_record-LPEIN_04_005(001) = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_record-LPEIN_04_005(001)
IMPORTING
output = w_record-LPEIN_04_005(001).
WHEN 4.
w_record-EEIND_04_006(010) = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_record-EEIND_04_006(010)
IMPORTING
output = w_record-EEIND_04_006(010).
WHEN 5.
w_record-MENGE_04_007(017) = wa_file-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_record-MENGE_04_007(017)
IMPORTING
output = w_record-MENGE_04_007(017).
ENDCASE.
AT END OF row.
APPEND w_record TO i_record.
COMMIT WORK AND WAIT.
CLEAR w_record.
ENDAT.
ENDLOOP.
LOOP AT i_record INTO w_record. "Filling the BDC table with data
*read dataset dataset into record.
perform bdc_dynpro using 'SAPMM06E' '0205'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-EVRTN'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RM06E-EVRTN'
w_record-EVRTN_001.
perform bdc_dynpro using 'SAPMM06E' '0222'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-EVRTP(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ET'.
perform bdc_field using 'RM06E-EBELP'
w_record-EBELP_002.
perform bdc_field using 'RM06E-TCSELFLAG(01)'
w_record-TCSELFLAG_01_003.
perform bdc_dynpro using 'SAPMM06E' '1117'.
perform bdc_field using 'BDC_CURSOR'
'EKET-MENGE(04)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RM06E-ETNR1'
w_record-ETNR1_004.
perform bdc_field using 'RM06E-LPEIN(04)'
w_record-LPEIN_04_005.
perform bdc_field using 'RM06E-EEIND(04)'
w_record-EEIND_04_006.
perform bdc_field using 'EKET-MENGE(04)'
w_record-MENGE_04_007.
perform bdc_dynpro using 'SAPMM06E' '1117'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-LPEIN(04)'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'RM06E-ETNR1'
w_record-ETNR1_008.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'ME38'.
if sy-subrc = 0.
WAIT UP TO 2 SECONDS.
ENDIF.
CLEAR w_record.
CLEAR : i_bdcdata[].
ENDLOOP.
PERFORM log_show.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR w_bdcdata.
w_bdcdata-program = program.
w_bdcdata-dynpro = dynpro.
w_bdcdata-dynbegin = 'X'.
APPEND w_bdcdata TO i_bdcdata.
CLEAR w_bdcdata.
ENDFORM. "BDC_DYNPRO
*
**&---------------------------------------------------------------------*
**& Form BDC_FIELD
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** -->FNAM text
** -->FVAL text
**----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR w_bdcdata.
w_bdcdata-fnam = fnam.
w_bdcdata-fval = fval.
APPEND w_bdcdata TO i_bdcdata.
CLEAR w_bdcdata.
ENDFORM. "BDC_FIELD
*
*&---------------------------------------------------------------------*
*& Form BDC_TRANSACTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->TCODE text
*----------------------------------------------------------------------*
FORM bdc_transaction USING tc TYPE sy-tcode.
DATA tcode LIKE tstc-tcode.
* tcode = 'ME38'.
CALL TRANSACTION tc USING i_bdcdata
MODE 'A' " modes can A = step by step foreground.
UPDATE 'S' " mode N = background direct.
" mode E = using error display
MESSAGES INTO messtab.
PERFORM msg_genration.
ENDFORM. "BDC_TRANSACTION
FORM msg_genration .
DATA: l_mstring(480).
DATA: l_subrc LIKE sy-subrc.
DATA: l_error TYPE c.
LOOP AT messtab .
* add message to log file
CLEAR l_s_msg.
l_s_msg-msgty = messtab-msgtyp.
l_s_msg-msgid = messtab-msgid.
l_s_msg-msgno = messtab-msgnr.
l_s_msg-msgv1 = messtab-msgv1.
l_s_msg-msgv2 = messtab-msgv2.
l_s_msg-msgv3 = messtab-msgv3.
l_s_msg-msgv4 = messtab-msgv4.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = l_log_handle
i_s_msg = l_s_msg
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF messtab-msgtyp EQ 'E' OR l_subrc NE 0.
l_error = 'X'.
ENDIF.
ENDLOOP.
CLEAR messtab[].
ENDFORM. " msg_generation
*&---------------------------------------------------------------------*
*& Form log_create
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM log_create .
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = l_log_handle
EXCEPTIONS
OTHERS = 1.
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. " log_create
*&---------------------------------------------------------------------*
*& Form log_show
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM log_show .
DATA:
l_s_display_profile TYPE bal_s_prof.
* get a prepared profile
CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
IMPORTING
e_s_display_profile = l_s_display_profile
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* use grid for display if wanted
l_s_display_profile-use_grid = 'X'.
* set report to allow saving of variants
l_s_display_profile-disvariant-report = sy-repid.
* when you use also other ALV lists in your report,
* please specify a handle to distinguish between the display
* variants of these different lists, e.g:
l_s_display_profile-disvariant-handle = 'LOG'.
* call display function module
* We do not specify any filter (like I_S_LOG_FILTER, ...,
* I_T_MSG_HANDLE) since we want to display all logs available
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_s_display_profile = l_s_display_profile
EXCEPTIONS
OTHERS = 1.
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. " log_show
Message was edited by: Matthew Billingham