Skip to Content
author's profile photo Former Member
Former Member

i devoloped the bdc for me 38 using notepad but i want excel suggest me idea how to accept excel file for same code

*&------------------------------------------------------------------*&
*& Devoloped By : Shrinivas R Sawre *&
*& BDC For Material Shedule *&
*& Date: 26.5.2013 *&
*&------------------------------------------------------------------*&
REPORT zbdc_me38
NO STANDARD PAGE HEADING LINE-SIZE 255.
*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 ***

DATA: file_path TYPE string.

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 LIKE bdcdata OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
* error session opened (' ' or 'X')
DATA: E_GROUP_OPENED.
* message texts
TABLES: T100.

DATA: BEGIN OF record OCCURS 0,
* 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_03_005(001),
* data element: EEIND
EEIND_03_006(010),
* data element: ETMEN
MENGE_03_007(017),
* data element: ETNR1
ETNR1_008(004),
* data element: AUFEP
EBELP_009(005),
END OF record.


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 .



INITIALIZATION.
PERFORM log_create.
*PARAMETERS: dataset(132) lower case.
*perform open_dataset using dataset.
*Uploading data from the local file C:\MSchedule.txt
*CALL FUNCTION 'WS_UPLOAD'
* EXPORTING
* FILENAME = 'C:\MSCHEDULE.TXT'
* FILETYPE = 'DAT'
* TABLES
* data_tab = I_BDCDATA .
*
*IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_url.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ''
IMPORTING
file_name = file_url.

start-of-selection.

IF NOT file_url IS INITIAL.

MOVE file_url TO file_path.
PERFORM read_file.
ENDIF.

LOOP AT 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'
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'
record-EBELP_002.
perform bdc_field using 'RM06E-TCSELFLAG(01)'
record-TCSELFLAG_01_003.
perform bdc_dynpro using 'SAPMM06E' '1117'.
perform bdc_field using 'BDC_CURSOR'
'EKET-MENGE(03)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RM06E-ETNR1'
record-ETNR1_004.
perform bdc_field using 'RM06E-LPEIN(03)'
record-LPEIN_03_005.
perform bdc_field using 'RM06E-EEIND(03)'
record-EEIND_03_006.
perform bdc_field using 'EKET-MENGE(03)'
record-MENGE_03_007.
perform bdc_dynpro using 'SAPMM06E' '1117'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-LPEIN(03)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_field using 'RM06E-ETNR1'
record-ETNR1_008.
perform bdc_dynpro using 'SAPMM06E' '0222'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-EVRTP(01)'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'RM06E-EBELP'
record-EBELP_009.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'ME38'.
WAIT UP TO 2 SECONDS.
clear i_bdcdata[].
CLEAR record.
ENDLOOP.


perform log_show.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR i_bdcdata.
i_bdcdata-program = program.
i_bdcdata-dynpro = dynpro.
i_bdcdata-dynbegin = 'X'.
APPEND i_bdcdata.
ENDFORM. "BDC_DYNPRO
*
**&---------------------------------------------------------------------*
**& Form BDC_FIELD
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** -->FNAM text
** -->FVAL text
**----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR i_bdcdata.
i_bdcdata-fnam = fnam.
i_bdcdata-fval = fval.
APPEND i_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 'N' " modes can A = step by step foreground.
" mode N = background direct.
" mode E = using error display.
MESSAGES INTO messtab.

PERFORM msg_generation.
ENDFORM. "BDC_TRANSACTION


FORM read_file .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_path
filetype = 'ASC'
has_field_separator = 'X'
* HEADER_LENGTH = 0
read_by_line = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = record
* 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.

ENDFORM. " read_file

*&---------------------------------------------------------------------*
*& Form msg_generation
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM msg_generation .
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

Add comment
10|10000 characters needed characters exceeded

2 Answers

  • Posted on May 30, 2013 at 10:03 AM

    Hi,

    Change your FM 'WS_UPLOAD' to 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    Example :

    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

    filename = PR_FILE

    i_begin_col = C_BEG_COL

    i_begin_row = C_BEG_ROW

    i_end_col = C_END_COL

    i_end_row = C_END_ROW

    tables

    intern = IT_EXCEL

    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.

    Else you can check following threads

    http://scn.sap.com/thread/378989

    http://scn.sap.com/thread/799560

    how to use Excel file in BDC

    upload excel file to BDC

    Thanks

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2013 at 10:08 AM

    Hi Shrinivas,

    * This is a simple example program to get data from an excel
    * file and store it in an internal table.

    TYPE-POOLS: TRUXS.

    PARAMETERS: P_FILE TYPE RLGRAP-FILENAME.

    TYPES: BEGIN OF T_DATATAB,
    COL01 TYPE CHAR50,
    COL02 TYPE CHAR50,
    COL03 TYPE CHAR50,
    COL04 TYPE CHAR50,
    COL05 TYPE CHAR50,
    COL06 TYPE CHAR50,
    END OF T_DATATAB.
    DATA: IT_DATATAB TYPE STANDARD TABLE OF T_DATATAB,
    WA_DATATAB TYPE T_DATATAB.

    DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.


    ***********************************************************************
    * At selection screen
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    FIELD_NAME = 'P_FILE'
    IMPORTING
    FILE_NAME = P_FILE.


    ***********************************************************************
    *START-OF-SELECTION.
    START-OF-SELECTION.

    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
    * I_FIELD_SEPERATOR =
    * I_LINE_HEADER = 'X'
    I_TAB_RAW_DATA = IT_RAW "WORK TABLE
    I_FILENAME = P_FILE
    TABLES
    I_TAB_CONVERTED_DATA = IT_DATATAB[] "ACTUAL DATA
    EXCEPTIONS
    CONVERSION_FAILED = 1
    OTHERS = 2.

    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    Hope this will help you.

    Regards,

    Mordhwaj

    Add comment
    10|10000 characters needed characters exceeded