Register Login

Call transaction and Batch input - Example

Updated May 18, 2018

This example shows how to use Call Transaction. If Call Transaction fails,
a batch input session is created.


DATA: BEGIN OF BDC_TAB OCCURS 0.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.



FORM Create_Transaction.
* Table for messages from call transaction. The table is automatically
filled with messags from call transaction.
DATA BEGIN OF messtab OCCURS 10.
INCLUDE STRUCTURE bdcmsgcoll.
DATA END OF messtab.

REFRESH bdc_tab.

* Create new dynpro
PERFORM bdc_newdynpro USING 'SAPML03T' '101'.


* Insert fields
PERFORM bdc_field USING 'LTAK-BWLVS' w_screen1000-io_bwls.

PERFORM bdc_field USING 'LTAP-MATNR' w_screen1000-io_matnr.

PERFORM bdc_field USING 'RL03T-ANFME' w_tmpstr.

PERFORM bdc_field USING 'LTAP-CHARG' w_screen1000-io_charg.

PERFORM bdc_field USING 'BDC_OKCODE' '=TAM'.


................. And much more of the same ..................


**** Use this part if you want to use call transaction
* Call the transaction. Messages from Call Transaction are stored in the
* internal table messtab
CALL TRANSACTION 'LT01' USING bdc_tab MODE 'N' UPDATE 'S'
MESSAGES INTO messtab.

IF sy-subrc = 0.
* Call transaction successfull, get the number of the Transfer Order that
* was created

LOOP AT messtab.
IF messtab-dynumb = '0104' AND messtab-msgnr = '016'.
w_transportorderno = messtab-msgv1.
ENDIF.
ENDLOOP.
ELSE.
* Call transaction failed, create a batch input session instead.
PERFORM open_group.
PERFORM bdc_insert USING 'LT01'.
PERFORM close_group.
ENDIF.



ENDFORM.


Here are the strandard forms used for call transaction and batch input


*******************************************************************
* Starts a new screen
*******************************************************************
FORM bdc_newdynpro USING program dynpro.
CLEAR bdc_tab.
bdc_tab-program = program.
bdc_tab-dynpro = dynpro.
bdc_tab-dynbegin = 'X'.
APPEND bdc_tab.
ENDFORM.

*******************************************************************
* Inserts a field in bdc_tab
*******************************************************************
FORM bdc_field USING fnam fval.
CLEAR bdc_tab.
bdc_tab-fnam = fnam.
bdc_tab-fval = fval.
APPEND bdc_tab.
ENDFORM.


*******************************************************************
* Opens group
*******************************************************************
FORM open_group.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
* DEST = FILLER8
group = 'ZSM02'
* HOLDDATE = FILLER8

keep = 'X'
user = sy-uname
* RECORD = FILLER1
* 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.
ENDFORM.

*******************************************************************
* Closes group
*******************************************************************
FORM close_group.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.
ENDFORM.

*******************************************************************
* BDC_INSERT
*******************************************************************
FORM bdc_insert USING tcode.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
TABLES
dynprotab = bdc_tab

EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4

printing_invalid = 5
posting_invalid = 6
OTHERS = 7.
ENDFORM.


×