BDC PROGRAMMING

BDC using CALL TRANSACTION method


Objective: - Steps For implementing BDC using call transaction Method .
When SAP is implemented we need Data to migrate from non-SAP system i.e.  Legacy system to SAP system. One way of doing this is BDC (Batch Data Communication).
Requirement:-  For Developing BDC using CALL TRANSACTION method we need  to do the recording of the corresponding transaction  &  flat file in which data is stored. Flat file can be Text file or Excel File. In CALL TRANSACTION we also have to create the Error Log file.
In BDC we use structure BDCDATA for Batch Input, which has following components.
PROGRAM  -   BDC module pool
DYNPRO-        BDC Screen number
DYNBEGIN-    BDC screen start                                                          
FNAM-            Field name
FVAL-              BDC field value
A BDCDATA structure can contain the batch input data for only a single run of a transaction
In CALL TRANSACTION method, we need to create Log for the Error Message, for this we use structure BDCMSGCOLL.
For our demo purpose, we would be considering the file format.
(If you are using the same file for practice make sure you remove the above two heading rows.)
Define the internal table structure as per the above file structure.
DATA:
  
BEGIN OF fs_field,
    bsart 
TYPE eban-bsart,             ” Document Type.
    matnr 
TYPE eban-matnr,             " Material Number.
    menge 
TYPE eban-menge,             " Quantity Requested.
    werks 
TYPE eban-werks,             " Plant.
  
END OF fs_field.
Recoding is done using the Transaction – SHDB.
Here we have done Recording for the transaction- ME51.
The Recording which you get will be in following format.


Now  go to ABAP Editor (SE38).
Enter the following code:
*Structure for error message
TYPES : BEGIN OF ty_s_error,
          msg_err(
60TYPE c,
        
END OF ty_s_error.

*Input Path
SELECTION-
SCREEN BEGIN OF BLOCK blck WITH FRAME TITLE text-011.
PARAMETERS:
  p_file   
TYPE rlgrap-filename,                  " File Path
  e_file   
TYPE rlgrap-filename OBLIGATORY,       " Error File Path
  p_mode   
TYPE c OBLIGATORY DEFAULT 'N'.         " Mode
SELECTION-
SCREEN END OF BLOCK blck.

* Structure Decleration
DATA :
  
BEGIN OF fs_field,
    bsart 
TYPE eban-bsart,             " Document Type.
    matnr 
TYPE eban-matnr,             " Material Number.
    menge 
TYPE eban-menge,             " Quantity Requested.
    werks 
TYPE eban-werks,             " Plant.
 
END OF fs_field.

*Internal table decleration
DATA:
   t_field    
LIKE TABLE OF fs_field,
   t_bdcdata  
LIKE TABLE OF bdcdata.

DATA:
  fs_bdcdata 
LIKE LINE OF t_bdcdata,   " Structure type of 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(
2TYPE n,
  it_output 
type table of ty_s_error,
  wa_output 
like line of it_output.

AT SELECTION-SCREEN.
* Mode 'A' = Foreground mode
* Mode 'N' = Background mode
  
IF p_mode = 'A' OR p_mode = 'N' .

    w_mode = p_mode.

  
ELSE.
*Error Message
    
MESSAGE 'PLEASE ENTER THE MODE A or N' TYPE 'E'.
  
ENDIF.

* 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(
4096TYPE 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.

*Opening window for Error file download
AT SELECTION-SCREEN ON VALUE-REQUEST FOR e_file.
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 
' '
    
IMPORTING
      file_name     = e_file.

* start of selection event.
START-
OF-SELECTION.

  
LOOP AT t_field INTO fs_field .
    
REFRESH: t_bdcdata.
    
CLEAR fs_bdcdata.
    
PERFORM populate_bdcdata.
    
PERFORM insert_data.
  
ENDLOOP.                               " LOOP AT it_c.

*********************(populate_bdcdata)***********************
* part 1
FORM populate_bdcdata.
PERFORM :
  fill_bdc_data 
USING 'SAPMM06B' '0100' 'X'  ' '  ' ',
  fill_bdc_data 
USING  ''  ''  ''   'EBAN-BSART' fs_field-bsart,   " Document Type.
  fill_bdc_data 
USING  ''  ''  ''   'BDC_OKCODE' '/00',            " Enter.

  fill_bdc_data 
USING 'SAPMM06B'  '0106' 'X' ' ' ' ',
  fill_bdc_data 
USING  '' '' '' 'EBAN-MATNR(01)'  fs_field-matnr,   " Material Number.
  fill_bdc_data 
USING  '' '' ''  'EBAN-MENGE(01)' fs_field-menge,   " Quantity Requested.
  fill_bdc_data 
USING  '' '' ''  'EBAN-WERKS(01)' fs_field-werks,   " Plant.
  fill_bdc_data 
USING  '' '' ''  'BDC_OKCODE'   '/00',              " Enter.

  fill_bdc_data 
USING 'SAPMM06B' '0102' 'X' ''  '' ,
  fill_bdc_data 
USING  '' '' ''  'BDC_OKCODE' '=BU'.                 " Save.

ENDFORM.                               " Form populate_bdc.

* part 2
FORM fill_bdc_data USING value(p_program)
                      
value(p_dynpro)
                      
value(p_dynbegin)
                      
value(p_fnam)
                      
value(p_fval).
  
CLEAR fs_bdcdata .
  
IF p_dynbegin = 'X' .
    fs_bdcdata-
program = p_program .
    fs_bdcdata-
dynpro  = p_dynpro .
    fs_bdcdata-dynbegin = p_dynbegin .
    
APPEND fs_bdcdata TO t_bdcdata.
  
ELSE.
    fs_bdcdata-fnam = p_fnam.
    fs_bdcdata-fval = p_fval.
    
CONDENSE fs_bdcdata-fval.
    
APPEND fs_bdcdata TO t_bdcdata.
  
ENDIF.                               " IF p_dynbeg..

ENDFORM .                              " Fill_entry

*********************(insert_data)****************************
FORM insert_data.

*Data decleration for Error Message
  
DATA:
       t_msg 
TYPE TABLE OF bdcmsgcoll,   " Collecting Error messages
       w_msg 
TYPE bdcmsgcoll,
       w_msg1(
51).

* Call transaction 'ME51'
  
CALL TRANSACTION 'ME51' USING t_bdcdata
    
MODE w_mode
    
UPDATE 'S'
    MESSAGES 
INTO t_msg.

  
IF sy-subrc EQ 0.
*    Uploaded into the database
    
WRITE :/ 'DATA UPLOADED IN TABLE EBAN...' .
  
ELSE.
*    Error Found
    
LOOP AT t_msg INTO w_msg WHERE msgtyp EQ 'E'.
*     Format Message
      
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
        
EXPORTING
          msgid               = w_msg-msgid
          msgnr               = w_msg-msgnr
          msgv1               = w_msg-msgv1
          msgv2               = w_msg-msgv2
          msgv3               = w_msg-msgv3
          msgv4               = w_msg-msgv4
        
IMPORTING
          message_text_output = w_msg1.


      wa_output-msg_err = w_msg1.

*Error message in downloaded file
data:
   wa_string(
10type c.

    wa_string = fs_field-matnr.

    
concatenate wa_string wa_output-msg_err into wa_output-msg_err separated by space.

     
APPEND wa_output-msg_err TO it_output.

      wa_error = e_file.

      
CALL FUNCTION 'GUI_DOWNLOAD'
        
EXPORTING
*         BIN_FILESIZE                    =
          filename                        = wa_error
*         FILETYPE                        = 'ASC'
*         APPEND                          = ' '
          write_field_separator           = 
'X'
        
TABLES
          data_tab                        = it_output
*
                .
      
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 sy-subrc <> 0.

    
ENDLOOP.

  
ENDIF.

ENDFORM.                    "insert_data
Run the Program.

Enter the path of file you need to upload.
And then enter the path of a file where error log will be created.
Finally select the mode. We have following option for the mode.
1.             A   =  Foreground   (Step by step processing will be done by you)
2.             N   =  Background  (All the Processing will be done in Background)
3.             E   =  Display Error ( If there is any error, it will be displayed in log otherwise it is similar to background mode)
Finally when all the data is uploaded .
In case of Error in the upload of any data, an Error file gets generated at the above given path.


BDC using Session Method


When SAP is implemented, we need Data to be migrated from non-SAP system i.e.  Legacy system to SAP system. One way of doing this is BDC (Batch Data Communication).
Requirement: - For Developing BDC using Session Method we need Recording & flat file in which data is stored. Flat file can be Text file or Excel File.
In Session Method following function Modules are used.
1.       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-        BDC Screen number
DYNBEGIN-    BDC screen start                                                          
FNAM-            Field name
FVAL-              BDC field value
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,             ” Document Type.
    matnr 
TYPE eban-matnr,             " Material Number.
    menge 
TYPE eban-menge,             " Quantity Requested.
    werks 
TYPE eban-werks,             " Plant.
  
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.
Now  go to Abap Editor (SE38).
Do the following coding.
*Input Path
PARAMETERS:
  p_file   
TYPE rlgrap-filename.                  " File Path

* Structure Decleration
DATA :
  
BEGIN OF fs_field,
    bsart 
TYPE eban-bsart,             " Document Type.
    matnr 
TYPE eban-matnr,             " Material Number.
    menge 
TYPE eban-menge,             " Quantity Requested.
    werks 
TYPE eban-werks,             " Plant.
 
END OF fs_field.

*Internal table decleration
DATA:
   t_field    
LIKE TABLE OF fs_field,
   t_bdcdata  
LIKE TABLE OF bdcdata.

DATA:
  fs_bdcdata 
LIKE LINE OF t_bdcdata,   ”Structure type of 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(
2TYPE 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(
4096TYPE 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.                               " LOOP AT t_f..

* Function to close BDC group.
PERFORM close_group.

*&---------------------------------------------------------------------*
*&      Form  open_group
*&---------------------------------------------------------------------*
*    Function to open BDC
*----------------------------------------------------------------------*
FORM open_group.

   
CALL FUNCTION 'BDC_OPEN_GROUP'
  
EXPORTING
*     CLIENT                    = SY-MANDT
*     DEST                      = FILLER8
     
group                     = 'YH1610'
*     HOLDDATE                  = FILLER8
     keep                      = 
'X'
     user                      = sy-uname
*     RECORD                    = FILLER1
*     PROG                      = SY-CPROG
*     DCPFM                     = '%'
*     DATFM                     = '%'
*   IMPORTING
*     QID                       =
  
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.
  
ELSE.
    
WRITE :/ 'Group Open' .

  
ENDIF.                               " IF sy-subrc <>

ENDFORM.                               " Open_group

*&---------------------------------------------------------------------*
*&      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,   " Document Type.
  fill_bdc_data 
USING  ''  ''  ''   'BDC_OKCODE' '/00',            " Enter.

  fill_bdc_data 
USING 'SAPMM06B'  '0106' 'X' ' ' ' ',
  fill_bdc_data 
USING  '' '' '' 'EBAN-MATNR(01)'  fs_field-matnr,   " Material Number.
  fill_bdc_data 
USING  '' '' ''  'EBAN-MENGE(01)' fs_field-menge,   " Quantity Requested.
  fill_bdc_data 
USING  '' '' ''  'EBAN-WERKS(01)' fs_field-werks,   " Plant.
  fill_bdc_data 
USING  '' '' ''  'BDC_OKCODE'   '/00',              " Enter.
  fill_bdc_data 
USING 'SAPMM06B' '0102' 'X' ''  '' ,
  fill_bdc_data 
USING  '' '' ''  'BDC_OKCODE' '=BU'.                 " Save.

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.    " program name
    fs_bdcdata-
dynpro  = p_dynpro.     " screen no
    fs_bdcdata-dynbegin   = p_begin.   
" screen start
    
APPEND fs_bdcdata TO t_bdcdata.
  
ELSE.
*" Filed Values.
    
CLEAR fs_bdcdata.
    fs_bdcdata-fnam = p_field.         
" Field name
    fs_bdcdata-fval = p_value.         
" Field value
    
CONDENSE fs_bdcdata-fval.         
    
APPEND fs_bdcdata TO t_bdcdata.

  
ENDIF.                               " IF P_BEGIN = 'X'

ENDFORM.                               " FILL_BDC_DATA

*&---------------------------------------------------------------------*
*&      Form  INSERT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM insert_data .

*Data decleration
  
DATA:
       t_msg 
TYPE TABLE OF bdcmsgcoll,   " Collecting messages
       w_msg 
TYPE bdcmsgcoll,
       w_msg1(
51).

  
CALL FUNCTION 'BDC_INSERT'
   
EXPORTING
     tcode                  = 
'ME51'
*   POST_LOCAL             = NOVBLOCAL
*   PRINTING               = NOPRINT
*   SIMUBATCH              = ' '
*   CTUPARAMS              = ' '
    
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
            .
  
IF sy-subrc <> 0.
*    Error Found
    
WRITE : / 'DATA Not INSERTED'.
  
ELSE.
    
WRITE : / 'DATA INSERTED'.
  
ENDIF .                              " IF sy-subr

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  

Execute the Program.
Now go to Transaction SM35 for Session Overview.
Line select your Program and press the Button ‘Process’.
We will get the 3 options for Processing
1.       Foreground - Step by step processing will be done by you.
2.       Background – All the Processing will be done in Background.
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
Following information message will be displayed if processing is successfully completed.
We can press ‘session overview’ button to see the session overview
This symbol under ‘Stat’ indicates successful processing.
In case of any Error we can go to the log and check the error message from the  ‘Log’  button as shown below.

 

Handling conversion errors - File Encoding

By Sarveswararao Sombhatla, Yash Technologies  
 One of the major effects that need to be taken care when reading the file from Application Server  
File encoding format  
What is Encoding?  
Encoding means converting the message into different format or symbols.  
Example: When we create a notepad and save it, by default the Encoding format will be ANSI. When we reopen the file it reads the characters as per the encoding format we saved and shows us the same characters what we have actually written in that notepad.  
ANSI Encoding  
Below is the screenshot how notepad file saved in ANSI Encoding format with a line ‘ABC’ is interpreted in a Hex-Editor.  
Here we have the simple hexadecimal conversion. 41 is A, 42 is B, 43 is C.  
Unicode Encoding  
The same file when saved in Unicode Encoding format, then how this gets interpreted in Hex-Editor  
We can see some additional hexadecimal characters when a file is stored in Unicode Encoding format.  
FF FE is the signature of the file encoded in Unicode or UTF-16 Big Endean format  
UTF-8 Encoding  
The same file when saved in UTF-8 Encoding format, then it gets interpreted in Hex-Editor as below:  
EF BB BF is the signature of the file encoded in UTF-8 format  
This way with the first additional characters of the files we can identify what is the encoding format used in this file.
What happens when a file with UTF-8 format and ANSI format file is placed on the SAP Application server directly?  
1. If a file saved with encoding UTF-8 format is placed on the SAP Application server, the file is read in AL11 as shown in the below screen-shot.  
We can see the special characters as they are because, by default SAP uses UTF-8 encoding format.
When we read this in ABAP program using OPEN DATASET statement with the addition ENCODING DEFAULT we can read the file with the special characters without any code page conversion problem.  
2. If a file saved with encoding ANSI format is placed on the SAP Application server, the file is read in AL11 as shown in the below screen-shot.  
In this case we are not able to see the special characters as they are encoded in ANSI format. When we read this file in ABAP program using OPEN DATASET statement with the addition ENCODING DEFAULT the program goes for a runtime error as the encoding format used by SAP is different from the encoding format the file is saved. We need to use OPEN DATASET statement with the addition ENCODING NON-UNICODE to read this file so we won’t get any runtime error.
To avoid this kind of runtime errors when we read the file from application server in SAP, we need to have always the same encoding format file to be placed on the Application server. 

 How to do BDC without writing BDC program
1. Go to Transaction SHDB and click “New Recording” button.
 
2.  The following popup screen gets populated, there you enter the Recording name and transaction for which you wish to do the BDC (In this example it is VV31). Click “Start recording” button.
 
3. In the Transaction, enter the mandatory field. In   his case it is Output type (AUS1). Hit enter key.
 
4. The following screen appears for more entry. Enter all the mandatory fields and click on save.  
5. SAP will give the Recorded program as shown in the following screen shot.  
6. Click the Export button    and save the file as word document file into the system.
7. Now open the newly created word document file.  
8. Select/Highlight the first field in the word document for which for which BDC needs to done. (In this case it is output type i.e. AUS1) and go to the menu path Insert à Field
9. A new screen will get populated and there you select the “Merge Field” option from the list box and enter the Column Name (In this case the 1st column is output_type).
10.  Now you can see in the word document that the highlighted field will get replaced with the column name.
 
 
11.    Similarly you highlight the other fields for which we need to create the BDC and give the unique column names for those fields.
12.   Now you can see that all the required fields have been mapped with unique column names.
13.    Now go the menu path Tools à Letters and Mailings à Mail Merge Wizard.
14.    A mail merge wizard will gets opened in the right hand side.
15.    Now open the excel file where which you have the data to do the BDC for transaction VV31. Check that the column name in the word document is matching with the column name in the Excel file.
16.    Close the Excel File.
17.    Switch to world document and Now Click “Next: Start document” link in the bottom of Mail Merge wizard
18.   Now click on “Next: Select recipients” link
19.   Now click on “Browse” link
20.    It will open the popup for selecting the file (which is having data for BDC).
21.    Press “Open” button
22.    A new popup will get triggered.

 

23.    Select the work sheet of the Excel file where the actual data present. In this case it is Sheet1$ and Click “OK” button.
24.     A new popup screen would appear with the data. Click “OK” button.
25.     Now click “Next: Write your letter” link.
26.     Click “Next: Preview your letters” link.
27.      Now you can see the first record got merged with the word document.
28.     Click “Next: Complete the merge” link.
29.     Click the “Edit individual letters…” link
30.      A new popup will get triggered, there you select “All” radio button and click “OK” button.
31.     Now you can see the merge has been done in the word document and it will create the BDC program for all the records in the Excel sheet. (In this case we had 10 records in excel sheet, hence the merge has created 10 pages in the word document. One page for each record)
32.     Now Select the entire content in the word document (i.e. all the 10 pages) and copy it in a notepad and save as separate “TXT” file.
33.    Go to the SHDB transaction and select your recording and click “Change” button.
 
34.    Now use the “Import” button   to download the TXT file which we saved in Step # 32.
35.    Once you click the Import button, a popup will come from there you select the file and click “Transfer” button.
36.    It will transfer the entire content to the SHDB. Now Save the changes. Click “Back” button.
37.    Now click the “Session” button, in order to create a new session.
38.     The following popup will get triggered, there you enter the new session name and check the “Keep session” check box and click “Continue” button.
39.     You will get the “Success Message” that “Batch input session ZTST_GOK was created”.
40.     Now go to the Transaction SM35 (Batch Input: Session Overview), there you select your “Session” which you have created in Step # 38 (You can the status of your session will be New) and click “Process” button.
41.     A small popup will get triggered, there you select the “Background” radio button and check the “Extended Log” check box. Click “Process” button.
42.     You will get the success message “1 session(s) transferred to background processing”.
43.     And you can also see the status of your session has been changed from “New” to “In background”.
44.     Click “Log” button, to see the details about the BDC.
45.     You will taken to the another screen, there you can see status of the BDC.
46.     In our case, the status is “Errors”, to know the details further. Select the entry and click “Analyze session”. It will display the status of all the records.
47.     In the above screen shot you can see the first two records were failed and others were processed. The reason for the same is: For the first time when we used SHDB we created the first condition record. Since this record is already there it failed in the second time. The same thing applies to the second failure case

 Creating a simple database table using BDC 

Report ypriyatest.
TABLES:
      bdcdata.
DATA:t_bdcdata LIKE
        STANDARD TABLE
        OF bdcdata.
PARAMETERS :
   p_table(15) TYPE c.
DATA:
  MSG LIKE BDCMSGCOLL,
  T_MSG LIKE TABLE OF MSG,
  MESSAGE(72) TYPE C.
PERFORM PROCESS.
*&---------------------------------------------------------------------
*
*&      Form  fill_screendata
*&---------------------------------------------------------------------

form fill_screendata  using    value(p_0015)
                               value(p_0016).
  BDCDATA-PROGRAM = P_0015.
  BDCDATA-DYNPRO  = P_0016.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA TO T_BDCDATA.
 CLEAR BDCDATA.
endform.                    " fill_screendata
*&---------------------------------------------------------------------
*
*&      Form  FILL_FIELD_DATA
*&---------------------------------------------------------------------

form FILL_FIELD_DATA  using    value(p_0020)
                               value(p_0021).
  BDCDATA-FNAM = P_0020.
  BDCDATA-FVAL = P_0021.
  APPEND BDCDATA TO T_BDCDATA.
 CLEAR BDCDATA.
 endform.                    " FILL_FIELD_DATA
*&---------------------------------------------------------------------
*
*&      Form  PROCESS
*&---------------------------------------------------------------------

form PROCESS .
**first screen
PERFORM fill_screendata
   USING 'SAPMSRD0' '0102'.
PERFORM FILL_FIELD_DATA
   USING 'RSRD1-TBMA' 'X'.
PERFORM FILL_FIELD_DATA
   USING 'RSRD1-TBMA_VAL' p_table.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=ADD'.
**second screen
PERFORM fill_screendata
   USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
   USING 'DD02D-DDTEXT' 'Bdc Table'.
PERFORM FILL_FIELD_DATA
   USING 'DD02D-CONTFLAG' 'A'.
PERFORM FILL_FIELD_DATA
   USING 'DD02D-MAINFLAG' 'X'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=CHANGE_MAINTFLAG'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '/00'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=DEF'.
**second screen filling table fields
PERFORM fill_screendata
   USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
   USING 'DD03P-FIELDNAME(01)' 'mandt'.
PERFORM FILL_FIELD_DATA
   USING 'DD03P-FIELDNAME(02)' 'name'.
PERFORM FILL_FIELD_DATA
   USING 'DD03P-FIELDNAME(03)' 'empid'.
PERFORM FILL_FIELD_DATA
   USING 'DD03D-ROLLNAME(01)' 'mandt'.
PERFORM FILL_FIELD_DATA
   USING 'DD03D-ROLLNAME(02)' 'char20'.
PERFORM FILL_FIELD_DATA
   USING 'DD03D-ROLLNAME(03)' 'numc4'.
PERFORM FILL_FIELD_DATA
   USING 'DD03P-KEYFLAG(01)' 'X'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '/00'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=WB_SAVE'.
**saving the table****
PERFORM fill_screendata
   USING 'SAPLSTRD' '0100'.
PERFORM FILL_FIELD_DATA
   USING 'KO007-L_DEVCLASS' '$TMP'.
PERFORM FILL_FIELD_DATA
   USING 'KO007-L_AUTHOR' 'SAPDEV02'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=TEMP'.
**filling technical settings.
PERFORM fill_screendata
   USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=SE13'.
PERFORM fill_screendata
   USING 'SAPMSEDS' '0050'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_CURSOR' 'DD09V-TABART'.
PERFORM FILL_FIELD_DATA
   USING 'DD09V-TABART' 'APPL0'.
PERFORM FILL_FIELD_DATA
   USING 'DD09V-TABKAT' '0'.
PERFORM FILL_FIELD_DATA
   USING 'ALLOWSTATE-NOT_ALLOWED' 'X'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=SICH'.
PERFORM fill_screendata
   USING 'SAPMSEDS' '0050'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=BACK'.
PERFORM fill_screendata
   USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=WB_SAVE'.
PERFORM fill_screendata
   USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=WB_CHECK'.
PERFORM fill_screendata
   USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=WB_ACTIVATE'.
PERFORM FILL_SCREENDATA
    USING 'SAPLSEWORKINGAREA' '0205'.
PERFORM FILL_FIELD_DATA
    USING 'BDC_OKCODE' '=WEIT'.
PERFORM fill_screendata
   USING 'SAPLSD41' '2200'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=BACK'.
PERFORM fill_screendata
   USING 'SAPMSRD0' '0102'.
PERFORM FILL_FIELD_DATA
   USING 'BDC_OKCODE' '=BACK'.
CALL TRANSACTION 'SE11' USING T_BDCDATA MODE 'A' MESSAGES INTO T_MSG.
LOOP AT T_MSG INTO MSG.
CALL FUNCTION 'FORMAT_MESSAGE'
 EXPORTING
   ID              = MSG-MSGID
   LANG            = 'EN'
   NO              = MSG-MSGNR
   V1              = MSG-MSGV1
   V2              = MSG-MSGV2
   V3              = MSG-MSGV3
   V4              = MSG-MSGV4
 IMPORTING
   MSG             = MESSAGE
 EXCEPTIONS
   NOT_FOUND       = 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.
IF sy-subrc EQ 0.
      WRITE / MESSAGE.
    ENDIF.
ENDLOOP.
endform.                    " PROCESS
Output
First Screen



Setting the delivery class and maintenance
Saving the table
Technical Settings
Activating The Table





BDC recording from testing client to development client


This method would be useful, when you don’t have required datum in development client and when you have same in testing client and you want to BDC recording with that datum.  
Login to the Testing client where you will have data.
Go to transaction SHDB and press new recording.  
As an instance, here we will try to modify vendor’s postal code of his address.  So, give FK02 as the transaction code to be executed and give recording name like ‘ZRECORD’.  
 
Now it goes to Vendor master update screen. Opt a vendor and click the address checkbox and press enter.  
 
It will show the vendor’s address information.  
Now change the existing PIN code 700019 to 560076 and press save. It will take you to the recording screen.  
Now you cannot create a program with this recording information in testing client. So, import your recording information to one presentation server file. Press import button.
Give a text file name and save it in the presentation server.  

Then Go to SHDB transaction in development client and go to new recording. Give the recording name as ZRECORDINGNEW and opt the same vendor master updation transaction code FK02. 
 
In this case your development client should have at least one vendor. If not create it and input the vendor in FK02 transaction and as you did earlier select the address checkbox.  
 
It will show you the address information. You don’t change anything in that and come back. Because this is not the vendor to whom we are going to change his PIN Code.  
Now it will show you the recording information. Delete all the recording information and press the import button and browse bdc_recording file from the presentation server.  
 
 
The previous recording information will loaded in to BDC recording and go back from the screen. It would popup for saving the recording. Now save that recording.  
 
 
Select the recording and press ‘program’ button. It will popup for new program creation. Input the required details and the expected BDC recording program will get created.  
 
   
report ZVENDORUPDATE
       
no standard page heading line-size 255.

include bdcrecx1.

start-
of-selection.

perform open_group.

perform bdc_dynpro      using 'SAPMF02K' '0106'.
perform bdc_field       using 'BDC_CURSOR'
                              
'RF02K-LIFNR'.
perform bdc_field       using 'BDC_OKCODE'
                              
'/00'.
perform bdc_field       using 'RF02K-LIFNR'
                              
'B002568'.
perform bdc_field       using 'RF02K-D0110'
                              
'X'.
perform bdc_dynpro      using 'SAPMF02K' '0110'.
perform bdc_field       using 'BDC_CURSOR'
                              
'LFA1-PSTLZ'.
perform bdc_field       using 'BDC_OKCODE'
                              
'=UPDA'.
perform bdc_field       using 'LFA1-NAME1'
                              
'MURARI SHARAN SRIVASTAVA'.
perform bdc_field       using 'LFA1-SORTL'
                              
'000568'.
perform bdc_field       using 'LFA1-STRAS'
                              
'Brook House, Shakespeare Sarani'.
perform bdc_field       using 'LFA1-ORT01'
                              
'Kolkatta'.
perform bdc_field       using 'LFA1-PSTLZ'
                              
'560076'.
perform bdc_field       using 'LFA1-LAND1'
                              
'IN'.
perform bdc_field       using 'LFA1-REGIO'
                              
'25'.
perform bdc_field       using 'LFA1-SPRAS'
                              
'EN'.
perform bdc_transaction using 'FK02'.

perform close_group.



2 comments:

  1. Howdy, I figure your blog might be having web program similarity issues. At the point when I investigate your site in Safari, it looks fine notwithstanding, when opening in IE, it has some covering issues. I simply needed to give you a brisk heads up! Beside that, superb site!
    live

    ReplyDelete
  2. Sir really aapne bahut accha explanation kiya hai shukriya Professor kaise bane jane puri jankari

    ReplyDelete