04-04-2006 4:31 AM
Hi Friends,
Here is my problem. I need to develop a BDC for Tcode FBS1 by using structure and Both Call Trans and Session method.
I need to put all the code in subroutine and Call Trans has to execute first if fails then session has to execute.
i need to use the FBS1 fields in structure there r 19 fields in the structure. I need to include that structure in the itab. I have to use this itab in the subroutine.i am just passing hard code data into itab.
if any one have code please pass to me.
thanks in advance
04-04-2006 2:21 PM
This should get you started:
*&---------------------------------------------------------------------*
* Budget Transfers *
*----------------------------------------------------------------------*
form transfer_budget using p_fmarea
changing tran_int structure tran_int.
data: okcode(3).
clear bdcdata.
refresh bdcdata.
*& budget transfer initial screen
perform dynpro using:
'X' 'SAPMKBUA' '0101',
' ' 'BPDY-BLDAT' tran_int-doc_date,
' ' 'FMPS-FIKRS' p_fmarea,
' ' 'BPDY-VERSN' tran_int-versn,
' ' 'BPDY-U_S_GEBER' tran_int-geber, "send
' ' 'BPDY-U_E_GEBER' tran_int-geber, "receive
' ' 'BPDY-U_SJAHR' tran_int-gjahr, "send
' ' 'BPDY-U_EJAHR' tran_int-gjahr, "receive
' ' 'BPDY-WGES' tran_int-overall, "check box
' ' 'BPDY-SGTXT' tran_int-desc."text
*& Budget transfer detail screen
if p_test = space.
okcode = '/11'. "save
else.
okcode = '/09'. "check
endif.
perform dynpro using:
'X' 'SAPMKBUA' '0300',
' ' 'FMPS-FISTL(1)' tran_int-objnr_s+6(6), "send fund center
' ' 'BPFMPS-FISTL(1)' tran_int-objnr_r+6(6), "receive fund center
' ' 'BPAK-WERT(1)' tran_int-wert,"amount
' ' 'FMPS-FIPOS(1)' tran_int-fipos, "send CI
' ' 'BPFMPS-FIPOS(1)' tran_int-fipos, "receive CI
' ' 'BDC_OKCODE' okcode. "save or check
if p_test = 'X'. "exit from screen after check
perform dynpro using: "exit
'X' 'SAPMKBUA' '0300',
' ' 'BDC_OKCODE' '/15'.
perform dynpro using: "popup
'X' 'SAPLSPO1' '0200',
' ' 'BDC_CURSOR' 'SPOP-OPTION1'. "choose yes
endif.
*& call transaction and capture results
clear sy_int.
call transaction 'FM28' using bdcdata mode p_dmode update 'S'
messages into messtab.
move-corresponding sy to sy_int.
if sy_int-subrc = 0.
tran_int-subrc = 0.
else.
tran_int-subrc = 1.
if p_test ne 'X'.
<b>perform batch_input using 'FM28'.</b>
endif.
endif.
if p_test ne 'X'.
move sy-msgv1 to tran_int-doc#.
endif.
if p_test ne 'X'.
move sy-msgv1 to tran_int-doc#.
endif.
perform get_message using sy_int
changing tran_int-text.
endform. " TRANSFER_BUDGET
*&---------------------------------------------------------------------*
*& Form BATCH_INPUT
*&---------------------------------------------------------------------*
* Create a batch input sessions to process and analyze errors. *
*----------------------------------------------------------------------*
form batch_input using transaction.
if first_err = 'YES'.
move 'NO' to first_err.
perform open_batch_session using p_job.
endif.
perform insert_batch_session using transaction.
endform. " BATCH_INPUT
Rob
04-04-2006 4:34 AM
Chandra,
I am sure this link will help you with all the info you need.
http://www.sap-img.com/bdc.htm
What you will have to do is to capture the errors from the CALL Transaction and pass that the Session method.
Regards,
Ravi
Note : Please mark the helpful answers
04-04-2006 4:34 AM
Hi,
Go to SHDB.
Create a new recording for your transaction.
And then generate a program from the recording.
It would have methods for both Session and Call transaction.
You may have to modify some logic in the program to suit your needs.
Regards,
Wenceslaus.
04-04-2006 2:21 PM
This should get you started:
*&---------------------------------------------------------------------*
* Budget Transfers *
*----------------------------------------------------------------------*
form transfer_budget using p_fmarea
changing tran_int structure tran_int.
data: okcode(3).
clear bdcdata.
refresh bdcdata.
*& budget transfer initial screen
perform dynpro using:
'X' 'SAPMKBUA' '0101',
' ' 'BPDY-BLDAT' tran_int-doc_date,
' ' 'FMPS-FIKRS' p_fmarea,
' ' 'BPDY-VERSN' tran_int-versn,
' ' 'BPDY-U_S_GEBER' tran_int-geber, "send
' ' 'BPDY-U_E_GEBER' tran_int-geber, "receive
' ' 'BPDY-U_SJAHR' tran_int-gjahr, "send
' ' 'BPDY-U_EJAHR' tran_int-gjahr, "receive
' ' 'BPDY-WGES' tran_int-overall, "check box
' ' 'BPDY-SGTXT' tran_int-desc."text
*& Budget transfer detail screen
if p_test = space.
okcode = '/11'. "save
else.
okcode = '/09'. "check
endif.
perform dynpro using:
'X' 'SAPMKBUA' '0300',
' ' 'FMPS-FISTL(1)' tran_int-objnr_s+6(6), "send fund center
' ' 'BPFMPS-FISTL(1)' tran_int-objnr_r+6(6), "receive fund center
' ' 'BPAK-WERT(1)' tran_int-wert,"amount
' ' 'FMPS-FIPOS(1)' tran_int-fipos, "send CI
' ' 'BPFMPS-FIPOS(1)' tran_int-fipos, "receive CI
' ' 'BDC_OKCODE' okcode. "save or check
if p_test = 'X'. "exit from screen after check
perform dynpro using: "exit
'X' 'SAPMKBUA' '0300',
' ' 'BDC_OKCODE' '/15'.
perform dynpro using: "popup
'X' 'SAPLSPO1' '0200',
' ' 'BDC_CURSOR' 'SPOP-OPTION1'. "choose yes
endif.
*& call transaction and capture results
clear sy_int.
call transaction 'FM28' using bdcdata mode p_dmode update 'S'
messages into messtab.
move-corresponding sy to sy_int.
if sy_int-subrc = 0.
tran_int-subrc = 0.
else.
tran_int-subrc = 1.
if p_test ne 'X'.
<b>perform batch_input using 'FM28'.</b>
endif.
endif.
if p_test ne 'X'.
move sy-msgv1 to tran_int-doc#.
endif.
if p_test ne 'X'.
move sy-msgv1 to tran_int-doc#.
endif.
perform get_message using sy_int
changing tran_int-text.
endform. " TRANSFER_BUDGET
*&---------------------------------------------------------------------*
*& Form BATCH_INPUT
*&---------------------------------------------------------------------*
* Create a batch input sessions to process and analyze errors. *
*----------------------------------------------------------------------*
form batch_input using transaction.
if first_err = 'YES'.
move 'NO' to first_err.
perform open_batch_session using p_job.
endif.
perform insert_batch_session using transaction.
endform. " BATCH_INPUT
Rob
04-04-2006 3:10 PM
Hi here is my code can anyone help with this. the field WRBTR is not accepting 1000 but in database that.
thanks,
chandramouli
report ZFBS1_BDC
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 ***
End generated data section ***
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE ZSFBS1_DATA.
DATA: END OF ITAB.
DATA: DATE TYPE SY-DATUM.
DATA :MSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA :ETAB LIKE MSG OCCURS 0 WITH HEADER LINE.
DATA : L TYPE I.
data: fac(20) type c.
ITAB-BLDAT = '03292006'.
ITAB-BLART = 'SA'.
ITAB-BUKRS = 1005.
ITAB-BUDAT = '03/31/2006'.
ITAB-WAERS = 'USD'.
ITAB-STGRD = '05'.
ITAB-STODT = '04042006'.
ITAB-NEWBS = '40'.
ITAB-NEWKO = '74999001'.
ITAB-WRBTR = '1000.00'.
ITAB-MWSKZ = 'B1'.
ITAB-TXJCD = '000003749'.
ITAB-NEWBS1 = '50'.
ITAB-NEWKO1 = '20131005'.
ITAB-WRBTR1 = 1000.
ITAB-MWSKZ1 = 'B1'.
ITAB-TXJCD1 = '000003749'.
APPEND ITAB.
PERFORM ZFBS1_bdc TABLES itab changing fac.
*start-of-selection.
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
&----
*& Form ZFBS1_bdc
&----
text
----
-->P_RECORD text
<--P_FAC text
----
FORM ZFBS1_bdc TABLES P_itab STRUCTURE zsfbs1_data
CHANGING P_FAC.
*
*CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
DEST = FILLER8
GROUP = 'sess01'
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.
REFRESH BDCDATA.
perform bdc_dynpro using 'SAPMF05A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BKPF-BLDAT'
itab-BLDAT.
perform bdc_field using 'BKPF-BLART'
itab-blart.
perform bdc_field using 'BKPF-BUKRS'
itab-BUKRS.
perform bdc_field using 'itab-BUDAT'
itab-budat.
*perform bdc_field using 'BKPF-MONAT'
itab-MONAT_005.
perform bdc_field using 'BKPF-WAERS'
itab-WAERS.
perform bdc_field using 'BKPF-STGRD'
itab-STGRD.
perform bdc_field using 'BKPF-STODT'
itab-STODT.
*perform bdc_field using 'FS006-DOCID'
record-DOCID_009.
perform bdc_field using 'RF05A-NEWBS'
itab-NEWBS.
perform bdc_field using 'RF05A-NEWKO'
itab-NEWKO.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'itab-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BSEG-WRBTR'
itab-WRBTR.
perform bdc_field using 'BSEG-MWSKZ'
itab-MWSKZ.
perform bdc_field using 'BSEG-TXJCD'
itab-TXJCD.
perform bdc_field using 'RF05A-NEWBS'
itab-NEWBS1.
perform bdc_field using 'RF05A-NEWKO'
itab-NEWKO1.
*perform bdc_field using 'DKACB-FMORE'
record-FMORE_017.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-GSBER'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'itab-TXJCD'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BSEG-WRBTR'
itab-WRBTR.
perform bdc_field using 'BSEG-MWSKZ'
itab-MWSKZ.
perform bdc_field using 'BSEG-TXJCD'
itab-TXJCD.
*perform bdc_field using 'DKACB-FMORE'
ITAB-FMORE.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-GSBER'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'itab-WRBTR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BSEG-WRBTR'
itab-WRBTR.
perform bdc_field using 'BSEG-MWSKZ'
itab-MWSKZ.
perform bdc_field using 'BSEG-TXJCD'
itab-TXJCD.
*perform bdc_field using 'DKACB-FMORE'
record-FMORE_025.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-GSBER'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'BSEG-WRBTR'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BSEG-WRBTR'
itab-WRBTR.
perform bdc_field using 'BSEG-MWSKZ'
itab-MWSKZ.
perform bdc_field using 'BSEG-TXJCD'
itab-TXJCD.
*perform bdc_field using 'DKACB-FMORE'
record-FMORE_029.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_OKCODE'
'/EESC'.
perform bdc_field using 'BDC_CURSOR'
'COBL-GSBER'.
perform bdc_dynpro using 'SAPMF05A' '0700'.
perform bdc_field using 'BDC_CURSOR'
'itab-NEWBS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF05A' '0700'.
perform bdc_field using 'BDC_CURSOR'
'itab-NEWBS'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
CALL TRANSACTION 'FBS1' USING BDCDATA MODE 'N' UPDATE 'S'
MESSAGES INTO MSG.
DESCRIBE TABLE MSG LINES L.
READ TABLE MSG INDEX L.
write:/ l.
WRITE:/ msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = msg-MSGID
LANG = sy-langu
NO = msg-MSGNR
V1 = msg-MSGV1
V2 = msg-MSGV2
V3 = msg-MSGV3
V4 = msg-MSGV4
IMPORTING
MSG = etab
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.
*ELSE.
write:/ etab.
*CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'FBS1'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
SIMUBATCH = ' '
CTUPARAMS = ' '
TABLES
DYNPROTAB = 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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*ENDIF.
ENDLOOP.
*CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 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.
**
ENDFORM. " ZFBS1_bdc
04-04-2006 3:22 PM
You can not directly assign value to WRBTR. Try this
DATA : L_WRBTR(16).
WRITE ITAB-WRBTR TO L_WRBTR CURRENCY ITAB-WAERS.
PERFORM BDC_FIELD USING 'BSEG-WRBTR' L_WRBTR.
Message was edited by: Ashish Gundawar
04-04-2006 4:36 PM
HI ASISH,
THANK YOU VERY MUCH, THIS HELPED ME A LOT.
CAN U LET ME KNOW HOW TO USE BOTH CALL TRANS AND SESSION.
MY CODE WORKING PROPERLY AND GENERATING DOCUMENT NO IN CALL TRANS METHOD. CAN U LET ME KNOW HOW TO CATCH THAT NO IN BDCMSGCOLL OR IS THERE ANY OTHER TABLE.
THANKS,
CHANDRAMOULI
04-04-2006 4:47 PM
Usually in call transaction method all messages are populated in BDCMSGCALL internal table. Check last message type. If it is Error or Abort, create BDC Sessions using function module BDC_OPEN_GROUP.
Insert BDC data to this session using fm BDC_INSERT. After that close session using fm BDC_CLOSE_GROUP.
open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP
HOLDDATE = HOLDDATE.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = TCODE
TABLES DYNPROTAB = BDCDATA.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
04-04-2006 4:47 PM
Check the code I posted above. It generates a call transaction. If the transaction fails, it generates a session.
Rob
04-04-2006 6:58 PM
Hi Ashish,
I am unable to findout that, can u please help me my sending a simple code. my problem almost over. i already written the code for bdc session but i am unable to link this session to cal trans. i sent one record successfully and i catch the document no too. but i am unable to run session cal trans failed.
thanks,
chandramouli
04-04-2006 7:12 PM
Use this code in your program -
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = msg-MSGID
LANG = sy-langu
NO = msg-MSGNR
V1 = msg-MSGV1
V2 = msg-MSGV2
V3 = msg-MSGV3
V4 = msg-MSGV4
IMPORTING
MSG = etab
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.
*ELSE.
write:/ etab.
if msg-msgtyp = 'E' or
msg-msgtyp = 'A'.
Create a session
data: holddate like sy-datum.
holddate = sy-datum - 1.
open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = <give a variable for a group name>
USER = sy-uname
KEEP = 'X'
HOLDDATE = HOLDDATE.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = 'FBS1'
TABLES DYNPROTAB = BDCDATA.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
Endif.
04-04-2006 7:55 PM
Hi Asish,
Thank you so much, i am working with this , but still i have some doubt like i souldn't keep bdc_open in loop am i right?
how can i call all these outside of loop. if u help in this my prob will be solved.
thanks,
chandramouli
04-04-2006 8:31 PM
You are right, move BDC_OPEN_GROUP before loop.
And BDC_CLOSE_GROUP after loop. This should solve your problem.
data: holddate like sy-datum.
holddate = sy-datum - 1.
open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING CLIENT = SY-MANDT
GROUP = <give a variable for a group name>
USER = sy-uname
KEEP = 'X'
HOLDDATE = HOLDDATE.
LOOP AT ITAB.
.
.
.
CALL FUNCTION 'BDC_INSERT'
EXPORTING TCODE = 'FBS1'
TABLES DYNPROTAB = BDCDATA.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
Message was edited by: Ashish Gundawar
04-04-2006 9:44 PM
HI ASISH,
THANK YOU SO MUCH, FINALLY I MAKE IT WORKING BUT STILL I HAVE SMALL PROB. I CAN CATCH THE DOCUMENT NO IN CALL TRANS METHOD BUT I COULDN'T FINDOUT IN SESSION METHOD. CAN U HELP IN THIS.
THANKS,
CHANDRAMOULI
04-04-2006 10:01 PM
Do you mean to say Document no which gets created after successful riun of FBS1 transaction?
If that is the case, in session method, you will not be able to catch this.
When call transaction is unsuccessful, you are creating sessions in the system which needs to be executed explicilty by using tcode SM35. It will show you the error, which needs to be corrected manually. Once it is corrected you can post document.
Hope this helps.
04-05-2006 12:02 AM
04-05-2006 12:22 AM
Hi Chandra,
I hope your question is answered and issue is solved. In this case pls close the thread and if my suggestion was helpful, reward points.
cheers
ashish
04-05-2006 12:27 AM
Hi Chandra,
I hope your question is answered and issue is solved. In this case pls close the thread and if my suggestion was helpful, reward points.
cheers
ashish
04-04-2006 2:26 PM
Hi Chandra,
Welcome to SDN.
Please check this links and hope this will help you to learn BDC.
http://www.sap-img.com/abap/learning-bdc-programming.htm
http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm
http://www.sap-img.com/abap.htm
http://help.sap.com/saphelp_47x200/helpdata/en/fa/097126543b11d1898e0000e8322d00/frameset.htm
Regards,
Ferry Lianto
04-06-2006 4:51 AM
Hi Ashish,
Can u let me know how to close this thread.
my prob was solved.
thanks,
chandramouli