Batch Data Communication is one of the vital data upload / transaction automation option in many SAP components . I am suggesting here a way out to simplify the programming for a BDC application . It utilizes a template program and gives steps to use it to create your own BDC program on the fly.
This step by step approach can be used to create a Simple BDC program i.e for a transaction which does not have any table control / looping at screen table. The same can also be enhanced to develop a program for transactions involving table controls .
1. Create a new program as executable program using SE38 transaction code.
2. Copy the following template code into your program .
*----------------- Start of Template -----------------*
REPORT
NO STANDARD PAGE HEADING
LINE-SIZE 200
LINE-COUNT 300.
*-------- DATA DECLARATION--------------------------------------------
*---Types
DATA : BEGIN OF t_upload,
FIELD1(10),
FIELD2(2),
FIELD3(18),
FIELD4(35),
END OF t_upload.
*--- Tables
DATA : BEGIN OF i_bdcdata OCCURS 0."to hold the transaction record
INCLUDE STRUCTURE bdcdata.
DATA: END OF i_bdcdata.
DATA: i_upload LIKE STANDARD TABLE OF t_upload," to hold file data.
i_upload1 LIKE STANDARD TABLE OF t_upload." to hold file data.
*--- Work Areas
DATA: wa_upload2 LIKE t_upload,
wa_upload LIKE t_upload,
wa_upload1 LIKE t_upload.
*--- Variables
DATA: v_count1(4) TYPE n,
v_error TYPE c,
v_session(12),
v_field(21) TYPE c,
v_message(60) type 'C'.
*--Constants
DATA: c_open TYPE c VALUE '(',
c_close TYPE c VALUE ')',
c_x TYPE c VALUE 'X'.
*---Initialisation
initialization.
refresh : i_upload , i_upload1 ,i_bdcdata.
*-------Selection Screen Design ---------------------------------------*
*Selection screen for input of upload file address
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.
*---AT SELECTION SCREEN -----------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*--For popup to select file.
PERFORM give_help.
*-----START OF SELECTION ----------------------------------------------*
START-OF-SELECTION.
*--Data upload using WS_Upload.
PERFORM get_data.
*-- OPEN SESSION
PERFORM open_group.
*--Insert transactions using BDCDATA table in the session.
PERFORM do_transaction .
*-- Close the session.
PERFORM close_group.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form f_get_data
*&---------------------------------------------------------------------*
* For data upload from external file.
*----------------------------------------------------------------------*
FORM get_data.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = i_upload
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
DELETE I_UPLOAD INDEX 1.
ENDIF.
ENDFORM. " f_get_data
*&---------------------------------------------------------------------*
*& Form F_open_group
*&---------------------------------------------------------------------*
* To open session in session management.
*----------------------------------------------------------------------*
FORM open_group.
v_session = 'TCODE'.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = v_session
user = sy-uname
keep = 'X'.
ENDFORM. " F_open_group
*&---------------------------------------------------------------------*
*& Form f_do_transaction
*&---------------------------------------------------------------------*
* Insert transactions in session after passing values to BDCDATA
*----------------------------------------------------------------------*
FORM do_transaction.
LOOP AT i_upload INTO wa_upload .
*---- insert your generated codes from recording at SHDB here
*----- insertion ends
perform bdc_transaction using 'TCODE'.
REFRESH : I_BDCDATA.
CLEAR : WA_UPLOAD.
* ENDIF.
ENDLOOP.
ENDFORM. " f_do_transaction
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* For appending screen details to BDCDATA
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR i_bdcdata.
i_bdcdata-program = program.
i_bdcdata-dynpro = dynpro.
i_bdcdata-dynbegin = 'X'.
APPEND i_bdcdata.
CLEAR i_bdcdata.
ENDFORM. "bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* For appending field details to bdcdata table
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR i_bdcdata.
i_bdcdata-fnam = fnam.
i_bdcdata-fval = fval.
APPEND i_bdcdata.
CLEAR i_bdcdata.
ENDFORM. " bdc_field
*&---------------------------------------------------------------------*
*& Form bdc_transaction
*&---------------------------------------------------------------------*
* For inserting Transaction in the session
*----------------------------------------------------------------------*
FORM bdc_transaction USING tcode.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
TABLES
dynprotab = i_bdcdata.
ENDFORM. " bdc_transaction
*&---------------------------------------------------------------------*
*& Form F_close_group
*&---------------------------------------------------------------------*
* For closing the session created in Session manager SM35
*----------------------------------------------------------------------*
FORM close_group.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
concatenate 'Session ' v_session 'successfully created' into v_field.
MESSAGE v_field type 'I'..
CALL TRANSACTION 'SM35'.
ENDFORM. "f_close_group
*&---------------------------------------------------------------------*
*& Form f_give_help
*&---------------------------------------------------------------------*
* For user help to select file
*----------------------------------------------------------------------*
FORM give_help.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = ',*.*,*.*.'
mode = 'O'
IMPORTING
filename = p_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0 AND NOT sy-msgty IS INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " f_give_help
*------------------ End of Template ------------------*
3.Go to the transaction SHDB in another session ( you can also give TCODE - OSHDB in transaction code window and hit enter ).
4.Create you transaction recording in SHDB . Ensure your transaction recording takes care of input values to all the
fields to which you intend to pass values in the BDC.
5.Once your recording is done correctly create the program from recording in the SHDB transction . You will find the button to create program in SHDB . Choose the option of creating from file when you proceed through the subsequent steps.
6. Define data type t_upload and structure wa_upload in the template program with fields of structure 'RECORD' from the program generated using SHDB recording ( replace the field1, field2 and so on as per your requirement). For your understanding you can remove the suffixes to the
field name but keep the field size unchanged.
7.Copy the coding existing between 'do' and 'enddo' statement from the generated program . Insert the copied code between the loop and endloop code of form 'Do_transaction '. Replace fields of structure 'RECORD' with respective fields of structure wa_upload.Insert constant values wherever possible in transaction recording.You can also handle customised data conversions here.
8.Replace 'TCODE' in the template program with the transaction code you intend to process in this BDC.
9.Please carry out further syntax check and resolve the related issues.
This program will provide for input help to select upload file from local machine. The file needs to be in Tab delimited format and is assumed to have first row as column headers .
On successful creation of session you will be prompted with a Information popup giving the name of session ,and will take you to the SM35 transaction to process your session.
Friday, December 28, 2007
Step by Step approach to ceate simple BDC session program using reusable template.
Labels:
bdc
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2007
(952)
-
▼
December
(236)
- Working with events in a Global Class
- Events in Table Maintenance
- Archiving IDocs
- Using Sorted table and Index while processing Inte...
- Highlighting only a particular cell instead of ent...
- Raising exceptions in a method and handling the sa...
- Maintaining Translations for Work item texts and O...
- Understanding "Local Workflow"
- Implementing Enhancements in a view
- Sending recursive mails upon reaching the deadline...
- ABAP Proxy communication
- Creation of a web service in SAP
- Step by Step approach to ceate simple BDC session ...
- General Application Transaction Codes
- Inroduction TO LSMW
- 24 Column Account Managers Report
- sap ABAP report on Column Account Managers Report
- sap ABAP report on Detail Transaction Report (DTR)...
- sap ABAP report on Summary Statement Quick Reference
- free download book on abap reporting on all modules
- ABAP REPORTS
- Report YRS_DOWNLOAD_TRANSPORT_REQUEST
- Report YRS_UPLOAD_TRANSPORT_REQUEST
- Displaying Available Report Variants in sap
- Creating Report Variants in sap
- SAP helpful reports, transactions and tables
- Useful SAP Tables
- ABAP REPORTING
- SAP Solution Manager’s centralized solution
- SAP Solution Manager
- Report Tree Using SARP and SERP
- User Profile Parameters
- XML sample file
- XSLT options
- Create XSLT program
- XML XSLT with ABAP
- Transport Guide
- ABAP Acronyms
- ABAP Code Sample
- ALV Pdf books
- ALV Articles
- Class ALV
- How to do the EXCISE ANNEXURE10 report?
- How to calculate last date of the month?
- How to change the deadline of the workitem program...
- How to convert from one currency value to other?
- How do I display / add the Terms and Conditions to...
- How do I create a long text for a document?*
- Where are the long texts of a document stored and ...
- I am using a SELECT query on a database table. Sin...
- How can I convert numerals into the corresponding ...
- How can I read an Excel file from presentation ser...
- How can I download my internal table into an Excel...
- How can I get the IP address of the system program...
- How do I download data in my internal table in a C...
- How to convert a date to internal or external format?
- How are RANGES different from SELECT-OPTIONS?
- What does R/3 stands for ?
- What does ABAP stand for?
- What is this new transaction 'n' all about?
- Casino Game in SAP ABAP
- Moving Characters in SAP ABAP Report Output
- Database Table Operations- A Performance Considera...
- SAP ABAP Performnace consideration while using ‘fo...
- Applying the having clause
- Avoid nested SELECT-ENDSELECT loops
- Use high-speed array operations with UPDATE, INSER...
- Coding Style
- Building A Binary Table
- how can we change the font for weite statement
- Import graphics to SAP
- Uploading Graphics TTF files into SAp Script Text
- Schedule Background Job
- How to change Package name/Development class for a...
- Useful User Paramters
- Finding a transaction code via SE93
- Standard Conversion Exits
- How to transport Standard Texts
- Search SAP Menu
- A FM which can create internal session
- Procedure for uploading Font
- Save content of internal tables in Excel format du...
- Where all SAP ABAP programs get stored!!
- Debugging a popup window
- Spool Conversion tp PDF
- A tips on error message while writting a BDC program
- Get the next available number in Number Range Object
- SAP ABAP Macro to validate Date
- Adding pushbuttons on the application toolbar of r...
- Display your report output lines inside a Title Box
- Using Subscreens on Report Selection Screens
- Save your ABAP report list output in your desktop ...
- Listbox on Selection Screen
- Get the Report selection Criteria
- What is sequence of event triggered in report?
- What is the difference between Primary key and Uni...
- What are the various types of selection screen event?
- What are standard layouts sets in the SAP Script?
- What are the data types of Internal Tables?
- What is the difference between 'Select single * ' ...
-
▼
December
(236)
No comments:
Post a Comment