Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

8/18/2018 BDC using Session Method

Home • Trainings • Quiz • Tips • Tutorials • Functional • Cert Q's • Interview Q's • Jobs • Testimonials • Advertise • Contact Us

Custom Search
SAP Virtual/Onsite BDC using Session Method Search
Trainings By Kumar Saurabh, Yash Technologies

When SAP is implemented, we need


Document Categories: Data to be migrated from non-SAP
system i.e. Legacy system to SAP
ABAPTM
system. One way of doing this is BDC
Adobe Forms (Batch Data Communication).
ABAP-HR
ALE & IDocs Requirement: - For Developing BDC
ALV using Session Method we need
BAPI Recording & flat file in which data is
BASIS stored. Flat file can be Text file or Excel
BSP File.
Business Objects
Business Workflow In Session Method following function
CRM NEW Modules are used.
LSMW
SAP Script/Smart Forms 1. BDC_OPEN_GROUP.
BI/BW
eXchange Infrastructure (XI) 2. BDC_INSERT.
Enterprise Portals (EP)
eCATT 3. BDC_CLOSE_GROUP.
Object Oriented Programming
SAP Query In BDC we use structure BDCDATA
Userexits/BADIs for Batch Input, Which has following
WebDynpro for Java/ABAPTM components.
Others
PROGRAM - BDC module pool

What's New? DYNPRO- BDC Screen number

DYNBEGIN- BDC screen start


ABAP Test Cockpit HOT
SAP ABAP Pragmas FNAM- Field name
Understanding SE32 (ABAP
Text Element Maintenance) FVAL- BDC field value
Creating an IDoc File on SAP
Application Server A BDCDATA structure can contain the batch input data for only a single run of a transaction
Understanding “Advance with
dialog” option of SAP Workflow
Lets for the sake of convenience our flat file looks like this.
SAP Workflow Scenario:
Maintenance Notification
Approval (If you are using the same file for practice make sure you remove the above two heading rows.)
Enhancements to a standard
class
Working with Floating Field in
Adobe Forms
Inserting data from Internal
Table into the step “Send Mail”
Display GL Account long text
using enhancement framework
Differences between
polymorphism in JAVA and
ABAP
Passing multiline parameters
from an ABAP Class event to a
Workflow container
Concept of Re-evaluate agents
for active work items in SAP
Workflow
Dynamic creation of component
usage in ABAP WebDynpro
Adobe Forms: Display symbols
like copyright and others
Deactivate Hold functionality in
Purchase order (ME21N)
Quiz on OOABAP
Add fields in FBL5N using
BADIs
Tutorial on Wide casting From above flat file we came to know about the structure of the internal table in which data will be
Defining a Range in Module uploaded.
Pool Program
Copy fields from one DATA:
structure/table into another BEGIN OF fs_field,
structure/table
bsart TYPE eban-bsart, ” Document Type.
Side Panel Usage in NWBC
matnr TYPE eban-matnr, " Material Number.
menge TYPE eban-menge, " Quantity Requested.
Contribute? werks TYPE eban-werks, " Plant.
END OF fs_field.

Sample Specs Recoding is done in Transacton – SHDB .

Here we have done Recording for the transaction- ME51 .


What's Hot? The Recording which you get will be in following format.

Web Dynpro for ABAP Tutorials

http://saptechnical.com/Tutorials/ABAP/BDC/Session.htm 1/5
8/18/2018 BDC using Session Method
Join the Mailing List

Enter name and email address below:


Name:

Email:

Subscribe Unsubscribe
GO

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(2) TYPE 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(4096) TYPE c OCCURS 0 .

DATA:
w_struct TYPE fs_struct.

* Uploading excel file.


CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'

http://saptechnical.com/Tutorials/ABAP/BDC/Session.htm 2/5
8/18/2018 BDC using Session Method
* 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.
http://saptechnical.com/Tutorials/ABAP/BDC/Session.htm 3/5
8/18/2018 BDC using Session Method
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
http://saptechnical.com/Tutorials/ABAP/BDC/Session.htm 4/5
8/18/2018 BDC using Session Method
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

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM


Home • Contribute • About Us • Privacy • Terms Of Use • Disclaimer • Safe • Companies: Advertise on SAPTechnical.COM | Post Job • Contact Us
©2006-2007 SAPTechnical.COM. All rights reserved.
All product names are trademarks of their respective companies. SAPTechnical.COM is in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver, and and any other SAP trademarks are registered trademarks of SAP AG in Germany and in several other countries.
Every effort is made to ensure content integrity. Use information on this site at your own risk.

Graphic Design by Round the Bend Wizards

http://saptechnical.com/Tutorials/ABAP/BDC/Session.htm 5/5

You might also like