Valuable source:https://wiki.scn.sap.com/wiki/display/ABAP/Batch+Input+FAQ
Sample coding - call of IW31:
*&---------------------------------------------------------------------**& Form run_iw31
*&---------------------------------------------------------------------*
* Run IW31 using BDC - stop on the second screen
*----------------------------------------------------------------------*
FORM run_iw31.
" run BDC call
DATA: lr_bdc TYPE REF TO /yournamespace/cl_bdc,
lv_val TYPE bdc_fval,
lx_msg TYPE REF TO /yournamespace/cx_message.
IF lr_bdc IS NOT BOUND.
CREATE OBJECT lr_bdc.
ENDIF.
lr_bdc->init( ).
lr_bdc->add_param( iv_dynbegin = 'T'
iv_name = 'IW31'
).
" The first screen
lr_bdc->add_dynpro( iv_program = 'SAPLCOIH'
iv_dynpro = '0100'
iv_dynrbegin = 'X'
).
" Order type - mandatory
CLEAR lv_val.
lv_val = aufpar-pm_aufart.
lr_bdc->add_param( iv_name = 'AUFPAR-PM_AUFART'
iv_value = lv_val
).
" Planning plant - mandatory
CLEAR lv_val.
lv_val = caufvd-iwerk.
lr_bdc->add_param( iv_name = 'CAUFVD-IWERK'
iv_value = lv_val
).
" Reference date
IF caufvd-addat IS NOT INITIAL.
CLEAR lv_val.
lv_val = caufvd-addat.
lr_bdc->add_param( iv_name = 'CAUFVD-ADDAT'
iv_value = lv_val
).
ENDIF.
" Priority
IF caufvd-priok IS NOT INITIAL.
CLEAR lv_val.
lv_val = caufvd-priok.
lr_bdc->add_param( iv_name = 'CAUFVD-PRIOK'
iv_value = lv_val
).
ENDIF.
" Bus. area
IF caufvd-gsber IS NOT INITIAL.
CLEAR lv_val.
lv_val = caufvd-gsber.
lr_bdc->add_param( iv_name = 'CAUFVD-GSBER'
iv_value = lv_val
).
ENDIF.
" Subscreen elements:
" Functional location
IF caufvd-tplnr IS NOT INITIAL.
CLEAR lv_val.
lv_val = caufvd-tplnr.
lr_bdc->add_param( iv_name = 'CAUFVD-TPLNR'
iv_value = lv_val
).
ENDIF.
" Equipment
IF caufvd-equnr IS NOT INITIAL.
CLEAR lv_val.
lv_val = caufvd-equnr.
lr_bdc->add_param( iv_name = 'CAUFVD-EQUNR'
iv_value = lv_val
).
ENDIF.
" Assembly
IF caufvd-bautl IS NOT INITIAL.
CLEAR lv_val.
lv_val = caufvd-bautl.
lr_bdc->add_param( iv_name = 'CAUFVD-BAUTL'
iv_value = lv_val
).
ENDIF.
" Subscreen
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLCOIH 7120OBJECT'
).
lr_bdc->send_enter( ).
" BDA OK-code command has to be send before next screen to be displayed
lr_bdc->send_bda( ).
" The second screen
lr_bdc->add_dynpro( iv_program = 'SAPLCOIH'
iv_dynpro = '3000'
iv_dynrbegin = 'X'
).
" Subscreens
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLCOIH 3001SUB_ALL'
).
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLCOIH 1100SUB_LEVEL'
).
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLCOIH 1102SUB_KOPF'
).
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLCOIH 1105SUB_BTN'
).
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLCOIH 1104SUB_TEXT'
).
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLCOIH 1120SUB_AUFTRAG'
).
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLIPAR 0415SUB_ADRESSE'
).
lr_bdc->add_param( iv_name = 'BDC_SUBSCR'
iv_value = 'SAPLIPAR 0415SUB_ADDR_PM'
).
TRY .
lr_bdc->call_transaction(
EXPORTING
iv_transaction = 'IW31'
iv_mode = 'E' " A - foreground / E - errors only / N - no display
).
CATCH /yournamespace/cx_message INTO lx_msg.
MESSAGE lx_msg TYPE lx_msg->msgty.
ENDTRY.
ENDFORM. "run_iw31
Repository custom class contains methods as:
SEND_BDA Instance Method Public Works with display mode E (display errors) only - switch
ADD_PARAM Instance Method Public Adds parameter to internal table bdcdata
INIT Instance Method Public Clear internal variables
SEND_END Instance Method Public Send END command to GUI
SEND_ENTER Instance Method Public Send ENTER key command to GUI
SEND_EXECUTE Instance Method Public Send EXECUTE command to GUI
SEND_SELECT_ALL Instance Method Public Send select ALL items command to GUI
SEND_UPDATE Instance Method Public Send UPDATE/COMMIT command to GUI
ADD_DYNPRO Instance Method Public Adds dynpro to internal table bdcdata
CALL_TRANSACTION Instance Method Public Call transaction with parameters
Methods source code:
METHOD send_bda.
" Change the screen Processing from Error only mode (display mode = E) to all display mode (Foreground processing) (display mode = A)
" It works only when you call BDA command just before next screen after ENTER key command of previous screen
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '/bda').
ENDMETHOD.
" Change the screen Processing from Error only mode (display mode = E) to all display mode (Foreground processing) (display mode = A)
" It works only when you call BDA command just before next screen after ENTER key command of previous screen
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '/bda').
ENDMETHOD.
METHOD add_param.
CLEAR s_bdcdata.
s_bdcdata-program = iv_program.
s_bdcdata-dynpro = iv_dynpro.
s_bdcdata-dynbegin = iv_dynbegin.
s_bdcdata-fnam = iv_name.
s_bdcdata-fval = iv_value.
CONDENSE s_bdcdata-fval.
APPEND s_bdcdata TO t_bdcdata.
ENDMETHOD.
CLEAR s_bdcdata.
s_bdcdata-program = iv_program.
s_bdcdata-dynpro = iv_dynpro.
s_bdcdata-dynbegin = iv_dynbegin.
s_bdcdata-fnam = iv_name.
s_bdcdata-fval = iv_value.
CONDENSE s_bdcdata-fval.
APPEND s_bdcdata TO t_bdcdata.
ENDMETHOD.
METHOD init.
CLEAR s_bdcdata.
REFRESH t_bdcdata.
ENDMETHOD.
CLEAR s_bdcdata.
REFRESH t_bdcdata.
ENDMETHOD.
METHOD send_end.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '/EECAN'). "iv_value = '/EENDE').
ENDMETHOD.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '/EECAN'). "iv_value = '/EENDE').
ENDMETHOD.
METHOD send_enter.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '/00').
ENDMETHOD.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '/00').
ENDMETHOD.
METHOD send_execute.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '=ONLI').
ENDMETHOD.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '=ONLI').
ENDMETHOD.
METHOD send_select_all.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
"iv_value = '/EENDE').
iv_value = '=&ALL').
ENDMETHOD.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
"iv_value = '/EENDE').
iv_value = '=&ALL').
ENDMETHOD.
METHOD send_update.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '=COMMIT').
ENDMETHOD.
me->add_param(
EXPORTING
iv_name = 'BDC_OKCODE'
iv_value = '=COMMIT').
ENDMETHOD.
METHOD ADD_DYNPRO.
CLEAR s_bdcdata.
s_bdcdata-program = iv_program.
s_bdcdata-dynpro = iv_dynpro.
s_bdcdata-dynbegin = iv_dynrbegin.
APPEND s_bdcdata TO t_bdcdata.
ENDMETHOD.
CLEAR s_bdcdata.
s_bdcdata-program = iv_program.
s_bdcdata-dynpro = iv_dynpro.
s_bdcdata-dynbegin = iv_dynrbegin.
APPEND s_bdcdata TO t_bdcdata.
ENDMETHOD.
METHOD call_transaction.
DATA: lt_msg TYPE TABLE OF bdcmsgcoll, " Collecting Error messages
ls_msg TYPE scx_t100key.
FIELD-SYMBOLS: <fs_msg> TYPE bdcmsgcoll.
IF cv_update IS INITIAL.
cv_update = 'S'. " Synchronous/Asynchronous/Local update task
ENDIF.
* CALL TRANSACTION iv_transaction AND SKIP FIRST SCREEN.
CALL TRANSACTION iv_transaction
USING me->t_bdcdata
MODE iv_mode
UPDATE cv_update
MESSAGES INTO lt_msg.
IF sy-subrc NE 0.
* Error Found - fire the first one
LOOP AT lt_msg ASSIGNING <fs_msg> WHERE ( msgtyp EQ 'E' ) OR ( msgtyp EQ 'A' ).
ls_msg-msgid = <fs_msg>-msgid.
ls_msg-msgno = <fs_msg>-msgnr.
ls_msg-attr1 = <fs_msg>-msgv1.
ls_msg-attr2 = <fs_msg>-msgv2.
ls_msg-attr3 = <fs_msg>-msgv3.
ls_msg-attr4 = <fs_msg>-msgv4.
" fire exception
RAISE EXCEPTION TYPE /yournamespace/cx_message
DATA: lt_msg TYPE TABLE OF bdcmsgcoll, " Collecting Error messages
ls_msg TYPE scx_t100key.
FIELD-SYMBOLS: <fs_msg> TYPE bdcmsgcoll.
IF cv_update IS INITIAL.
cv_update = 'S'. " Synchronous/Asynchronous/Local update task
ENDIF.
* CALL TRANSACTION iv_transaction AND SKIP FIRST SCREEN.
CALL TRANSACTION iv_transaction
USING me->t_bdcdata
MODE iv_mode
UPDATE cv_update
MESSAGES INTO lt_msg.
IF sy-subrc NE 0.
* Error Found - fire the first one
LOOP AT lt_msg ASSIGNING <fs_msg> WHERE ( msgtyp EQ 'E' ) OR ( msgtyp EQ 'A' ).
ls_msg-msgid = <fs_msg>-msgid.
ls_msg-msgno = <fs_msg>-msgnr.
ls_msg-attr1 = <fs_msg>-msgv1.
ls_msg-attr2 = <fs_msg>-msgv2.
ls_msg-attr3 = <fs_msg>-msgv3.
ls_msg-attr4 = <fs_msg>-msgv4.
" fire exception
RAISE EXCEPTION TYPE /yournamespace/cx_message
EXPORTING
textid = ls_msg
msgty = <fs_msg>-msgtyp.
ENDLOOP.
ENDIF.
ENDMETHOD.
textid = ls_msg
msgty = <fs_msg>-msgtyp.
ENDLOOP.
ENDIF.
ENDMETHOD.
Class Types:
public section.
types:
ty_bdcdata type standard table of bdcdata .
types:
ty_bdcdata type standard table of bdcdata .
Class attributes:
T_BDCDATA Instance Attribute Public Type TY_BDCDATA
S_BDCDATA Instance Attribute Public Type BDCDATA Batch input: New table field structure