Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

session method

Former Member
0 Likes
613

hi expert

i want to create a bdc programme using session can u please help how can i do it

5 REPLIES 5
Read only

Former Member
0 Likes
589

hi,

&----


*& Report Z243_KA_BD_01

*&

&----


*&

*&

&----


REPORT Z243_KA_BD_01.

TABLES : ZSALES_ORDER.

&----


DATA:OK_CODE LIKE SY-UCOMM.

DATA : BATCH(6),CALL(6) .

DATA :I TYPE I,A TYPE I.

DATA: IT_TAB LIKE TABLE OF ZSALES_ORDER WITH HEADER LINE,

WA_TAB LIKE LINE OF IT_TAB.

DATA: IT_BDCTAB LIKE TABLE OF BDCDATA WITH HEADER LINE .

DATA: IT_MESS LIKE TABLE OF BDCMSGCOLL WITH HEADER LINE,

WA_MESS LIKE LINE OF IT_MESS.

DATA: R(10) TYPE C.

&--


SELECTION-SCREEN--

SELECTION-SCREEN : BEGIN OF SCREEN 9004.

SELECT-OPTIONS MAT_NO FOR ZSALES_ORDER-MATERIAL_NO.SKIP.

SELECT-OPTIONS CUST_NO FOR ZSALES_ORDER-CUSTOMER_NO .SKIP.

PARAMETERS: UPLOADED.

SELECTION-SCREEN : END OF SCREEN 9004.

CALL SCREEN 9002.

&----


*& Module USER_COMMAND_9002 INPUT

&----


  • text

----


MODULE USER_COMMAND_9002 INPUT.

CASE OK_CODE.

WHEN 'UPLOAD'.

CALL SCREEN 9003.

WHEN 'REPORT'.

LEAVE TO LIST-PROCESSING.

WRITE :'NO OF RECORDS READ'.

DESCRIBE TABLE IT_TAB LINES A.

WRITE A.

SELECT COUNT(*) FROM ZSALES_ORDER INTO I.

SKIP.

ULINE.

WRITE: / 'NO OF RECORDS UPLOADED'. WRITE I.

ULINE.

SELECT * FROM ZSALES_ORDER INTO ZSALES_ORDER.

WRITE: / 'MATERIAL NO ', 'CUSTOMER NO','CUSTOMER MATE NO','SLAES ORGANISATION','PROCESSING ORG',' TRAN AMT'.

WRITE: / ZSALES_ORDER-MATERIAL_NO UNDER 'MATERIAL NO '.write:12 sy-vline, ZSALES_ORDER-CUSTOMER_NO UNDER 'CUSTOMER NO'.write:20 sy-vline,

ZSALES_ORDER-CUST_MAT_NO UNDER 'CUSTOMER MATE NO'.write:30 sy-vline, ZSALES_ORDER-SALE_ORG UNDER 'SLAES ORGANISATION'.write:40 sy-vline,

ZSALES_ORDER-PROCESS_DATE UNDER 'PROCESSING ORG'.write:50 sy-vline, ZSALES_ORDER-TRAN_AMT UNDER 'TRAN AMT'.write:60 sy-vline.

ENDSELECT.

SKIP.

ULINE.

WRITE: ' NO OF ERRORS RECORDS'.

DESCRIBE TABLE IT_TAB LINES A.

WRITE: A.

SET PF-STATUS SPACE.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_9002 INPUT

&----


*& Module USER_COMMAND_9003 INPUT

&----


  • text

----


MODULE USER_COMMAND_9003 INPUT.

CLEAR OK_CODE.

IF CALL = 'X'.

CALL SELECTION-SCREEN 9004.

REFRESH IT_TAB.

SELECT * FROM ZSALES_ORDER.

CHECK MAT_NO.

IT_TAB-MATERIAL_NO = ZSALES_ORDER-MATERIAL_NO.

APPEND IT_TAB.

ENDSELECT.

PERFORM GUI_UPLOAD.

PERFORM TRAN USING 'Z243BDC'.

ELSEIF BATCH = 'X'.

CALL SELECTION-SCREEN 9004.

PERFORM GUI_UPLOAD.

PERFORM BATCH_TRANSACTION.

ENDIF.

ENDMODULE. " USER_COMMAND_9003 INPUT

&----


*& Form GUI_UPLOAD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GUI_UPLOAD .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\siva\bdcflatfile.TXT'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = IT_TAB

.

IF SY-SUBRC <> 0.

ENDIF.

LOOP AT IT_TAB INTO WA_TAB.

PERFORM PNAME USING 'Z243_KA_BDC_01' '9001'.

PERFORM FNAME USING 'ZSALES_ORDER-MATERIAL_NO' WA_TAB-MATERIAL_NO.

PERFORM FNAME USING 'ZSALES_ORDER-CUSTOMER_NO' WA_TAB-CUSTOMER_NO.

PERFORM FNAME USING 'ZSALES_ORDER-CUST_MAT_NO' WA_TAB-CUST_MAT_NO.

PERFORM FNAME USING 'ZSALES_ORDER-SALE_ORG' WA_TAB-SALE_ORG.

PERFORM FNAME USING 'ZSALES_ORDER-PROCESS_DATE' WA_TAB-PROCESS_DATE.

PERFORM FNAME USING 'ZSALES_ORDER-TRAN_AMT' WA_TAB-TRAN_AMT.

PERFORM FNAME USING 'BDC_OKCODE' '=SAVE'.

ENDLOOP.

PERFORM PNAME USING 'Z243_KA_BDC_01' '9001'.

PERFORM FNAME USING 'BDC_OKCODE' '=EXIT'.

DESCRIBE TABLE IT_TAB LINES A.

ENDFORM. " GUI_UPLOAD

&----


*& Form PNAME

&----


  • text

----


  • -->P_0105 text

  • -->P_0106 text

----


FORM PNAME USING PRGNAME

SCRNAME.

CLEAR IT_BDCTAB.

IT_BDCTAB-PROGRAM = PRGNAME.

IT_BDCTAB-DYNPRO = SCRNAME.

IT_BDCTAB-DYNBEGIN = 'X'.

APPEND IT_BDCTAB.

ENDFORM. " PNAME

&----


*& Form FNAME

&----


  • text

----


  • -->P_0110 text

  • -->P_WA_TAB_MATERIAL_NO text

----


FORM FNAME USING FIELDNAME

FIELDVAL.

CLEAR : IT_BDCTAB.

IT_BDCTAB-FNAM = FIELDNAME.

IT_BDCTAB-FVAL = FIELDVAL.

APPEND IT_BDCTAB.

ENDFORM. " FNAME

&----


*& Form TRAN

&----


  • text

----


  • -->P_0054 text

----


FORM TRAN USING STRAN.

CALL TRANSACTION STRAN USING IT_BDCTAB

MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_MESS.

ENDFORM. " TRAN

&----


*& Form BATCH_TRANSACTION

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BATCH_TRANSACTION .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = 'SIVA'

USER = sy-uname.

IF SY-SUBRC <> 0.

ENDIF.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'Z243BDC'

TABLES

DYNPROTAB = IT_BDCTAB

.

IF SY-SUBRC <> 0.

ENDIF.

CALL FUNCTION 'BDC_CLOSE_GROUP'

.

IF SY-SUBRC <> 0.

ENDIF.

CALL TRANSACTION 'SM35'.

ENDFORM. " BATCH_TRANSACTION

&----


*& Module STATUS_9003 OUTPUT

&----


  • text

----


MODULE STATUS_9003 OUTPUT.

SET PF-STATUS 'SCREEN'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_9003 OUTPUT

http://www.sappoint.com/abap/bdcconcept.pdf

http://www.sap-img.com/bdc.htm

http://www.sapdevelopment.co.uk/bdc/updhome.htm

Reward Useful points

Regards

Siva

Message was edited by:

SivaKumar

Read only

Former Member
0 Likes
589

Hi,

Follow the below steps,

1) First have a test data for the transaction, use SHDB transaction to record the transaction with the test data.

2) Through recording you will find the structure of the screen data like ....

Program Name, Screen Number, Dynbegin, Field name & Field value.

3) There are 3 standard function modules to create sessions.

BDC_OPEN_GROUP

BDC_INSERT

BDC_CLOSE_GROUP.

4) Once you create the session then you can go to SM35 to process the session

5) If you process the session then data will be updated in corresponsing tables of the transaction.

Regards,

  • Dj

reward, if its useul.

Read only

Former Member
0 Likes
589

do the recording in shdb and it creates program.

when you see the selection and it has both session and call transaction.

Session method :

Use FM :

BDC_OPEN_GROUP - It creates the session in Sm35 Transaction

BDC_INSERT -> Insert ur transaction

BDC_CLOSE_GROUP - > close the session

Thanks

Seshu

Read only

Former Member
0 Likes
589

Hi,

<b>follow these steps to create a bdc program using Session.</b>

1) declare all the varialbes as per your requirement.

2) upload data from flat file to Source structure(internal table).

for uploading you use <b>ws_upload</b> or <b>gui_upload</b> or method

<b> cl_gui_frontend_services=>gui_upload</b>

3) Crate Session, for that one we use function module BDC_OPEN_GROUP.

call function 'bdc_open_group'

exporting

user = sy-uname

client = sy-mandt

group = ' ' 'here provide name, with this name system

genarate session.

4) process internal table and move the cursor to application and crresponding

screen.

LOOP AT <internal table>.

refresh BDCDATA.

****here call two subroutinees which are used to moving the cursor to

        • application , screen , fand fields.

perform <name> using <application name> <screen>.

perform <name> using <screen-field> <internal table value>.

5) call function module BDC_INSERT to add transaction code and BDCDATA.

call function 'bdc_insert'

exporting

tr_code = <tr code>

changing

dynp_tab = <internal table>

6) now end loop with ENDLOOP statement.

7) now call the function module BDC_CLOSE_GROUP.

we call this function module to close the session which was created in previous

steps.

call function 'bdc_close_group'.

😎 create subroutinees.

form <name> using prog scre.

refresh bdcdata.

bdcdata-program = prog.

bdcdata-dynpro = scre.

bdcdata-dynbegin = 'X'.

append bdcdata.

endform.

form <name> using fnam fval.

refresh bdcdata.

bdcdata-fnam = prog.

bdcdata-fval = scre.

append bdcdata.

endform.

upto now programming part is compleate.

still the data is not updated in data base, the data will be update only after processing processing the SESSION, which was created in previous steps.

for processing session we work with <b>SM35</b>.

<b>goto SM35->select SESSION name---> select PROCESS.</b>

<b>or</b>

we can also create bdc program using session method by RECORDING.

transaction code for recording is SHDB.

if we are working with RECORDING for creating data transfer program, it provide 85% of the logic.

<b>it provides</b>

1) one include program INCLUDE BDCRECX1.

2) internal tables BDCDATA .

3) two subroutinees BDC_DYNPRO and BDC_FIELD

4) two subroutinees OPEN_GROUP( it contains bdc_open_group and bdc_insert)

CLOSE_GROUP( it contains bdc_close_group).

goto SHDB-->it dispalys initial screen of recording with required firlds, here provide information like name of recording, TRANSACTION used for recording->choose START recording->it dispalys the screens of TRANSACTION->provide data to the fields as per your needs---->save.

up to now recording is compleated, by using this information we can create SESSION for that one .

goto SHDB-->choose OVERVIEW-> position the cursor on the relavent recording and choose SESSION--> enter SESSION NAME--->enter USER NAME->choose CONTINUE to exitthe dialog box.

<b>for sample program, you follow this link.</b>

regards,

Ashokreddy.

Read only

Former Member
0 Likes
589

hi,

check the below ex:

REPORT ZSR_BDC_SESSION.

DATA: BEGIN OF ITAB OCCURS 0,

LIFNR LIKE RF02K-LIFNR,

KTOKK LIKE RF02K-KTOKK,

NAME1 LIKE LFA1-NAME1,

SORTL LIKE LFA1-SORTL,

LAND1 LIKE LFA1-LAND1,

SPRAS LIKE LFA1-SPRAS,

END OF ITAB.

DATA : BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

*include bdcrecx1.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'z:\flatfiles\sr1.txt'

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 = ITAB

  • 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.

*perform open_group.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

  • DEST = FILLER8

GROUP = 'SR'

  • HOLDDATE = FILLER8

KEEP = 'X'

USER = SY-UNAME

  • RECORD = FILLER1

  • PROG = SY-CPROG

  • 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.

ENDIF.

LOOP AT ITAB.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '0100'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'RF02K-KTOKK'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'RF02K-LIFNR'

ITAB-LIFNR.

PERFORM BDC_FIELD USING 'RF02K-KTOKK'

ITAB-KTOKK.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '0110'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'LFA1-SPRAS'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'LFA1-NAME1'

ITAB-NAME1.

PERFORM BDC_FIELD USING 'LFA1-SORTL'

ITAB-SORTL.

PERFORM BDC_FIELD USING 'LFA1-LAND1'

ITAB-LAND1.

PERFORM BDC_FIELD USING 'LFA1-SPRAS'

ITAB-SPRAS.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '0120'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'LFA1-KUNNR'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'LFBK-BANKS(01)'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=ENTR'.

PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0300'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=YES'.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'XK01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

DYNPROTAB = BDCTAB

  • 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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDLOOP.

*perform bdc_transaction using 'XK01'.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

*perform close_group.

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0069 text

  • -->P_0070 text

----


FORM BDC_DYNPRO USING VALUE(P_0069)

VALUE(P_0070).

CLEAR BDCTAB.

BDCTAB-PROGRAM = P_0069.

BDCTAB-DYNPRO = P_0070.

BDCTAB-DYNBEGIN = 'X'.

APPEND BDCTAB.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_0074 text

  • -->P_0075 text

----


FORM BDC_FIELD USING VALUE(P_0074)

VALUE(P_0075).

IF P_0075 IS NOT INITIAL.

CLEAR BDCTAB.

BDCTAB-FNAM = P_0074.

BDCTAB-FVAL = P_0075.

APPEND BDCTAB.

ENDIF.

ENDFORM. " bdc_field

flat file:tab delimited

4567 0001 sudhu u IN EN