‎2007 Jun 08 4:24 AM
hi,
i use BDC for a enhanced t/code, so i think i should use no batch input mode to call the transaction,
could someone give a code example about this ?
thanks!
‎2007 Jun 08 4:26 AM
Hi,
You can use MODE = 'N' which will not display the screens..
CALL TRANSACTION 'ME21' USING T_BDCDATA MODE 'N' UPDATE 'S'
MESSAGES INTO T_MESSAGE.
Thanks,
Naren
‎2007 Jun 08 4:45 AM
hi,
use MODE = 'N' which will not display the screens..
ex:
*CALL TRANSACTION
REPORT ztest_report
NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID ZRASH.
************************************************************************
Internal Table Declarations *
************************************************************************
*--Internal Table for Data Uploading.
DATA : BEGIN OF IT_FFCUST OCCURS 0,
KUNNR(10),
BUKRS(4),
KTOKD(4),
ANRED(15),
NAME1(35),
SORTL(10),
STRAS(35),
ORT01(35),
PSTLZ(10),
LAND1(3),
SPRAS(2),
AKONT(10),
END OF IT_FFCUST.
*--Internal Table to Store Error Records.
DATA : BEGIN OF IT_ERRCUST OCCURS 0,
KUNNR(10),
EMSG(255),
END OF IT_ERRCUST.
*--Internal Table to Store Successful Records.
DATA : BEGIN OF IT_SUCCUST OCCURS 0,
KUNNR(10),
SMSG(255),
END OF IT_SUCCUST.
*--Internal Table for Storing the BDC data.
DATA : IT_CUSTBDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*--Internal Table for storing the messages.
DATA : IT_CUSTMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA : V_FLAG1(1) VALUE ' ',
"Flag used for opening session.
V_TLINES LIKE SY-TABIX,
"For storing total records processed.
V_ELINES LIKE SY-TABIX,
"For storing the no of error records.
V_SLINES LIKE SY-TABIX.
"For storing the no of success records.
************************************************************************
Selection screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1.
PARAMETERS : V_FNAME LIKE RLGRAP-FILENAME,
V_SESNAM LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
Start-of-selection *
************************************************************************
START-OF-SELECTION.
*-- Form to upload flatfile data into the internal table.
PERFORM FORM_UPLOADFF.
************************************************************************
TOP-OF-PAGE *
************************************************************************
TOP-OF-PAGE.
WRITE:/ 'Details of the error and success records for the transaction'.
ULINE.
SKIP.
************************************************************************
End of Selection *
************************************************************************
END-OF-SELECTION.
*-- Form to Generate a BDC from the Uploaded Internal table
PERFORM FORM_BDCGENERATE.
*--To write the totals and the session name.
PERFORM FORM_WRITEOP.
&----
*& Form form_uploadff
&----
Form to upload flatfile data into the internal table.
----
FORM FORM_UPLOADFF .
*--Variable to change the type of the parameter file name.
DATA : LV_FILE TYPE STRING.
LV_FILE = V_FNAME.
*--Function to upload the flat file to the internal table.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = IT_FFCUST
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.
*--Deleting the headings from the internal table.
DELETE IT_FFCUST INDEX 1.
*--Getting the total number of records uploaded.
DESCRIBE TABLE IT_FFCUST LINES V_TLINES.
ENDIF.
ENDFORM. " form_uploadff
&----
*& Form Form_bdcgenerate
&----
Form to Generate a BDC from the Uploaded Internal table
----
FORM FORM_BDCGENERATE .
*--Generating the BDC table for the fields of the internal table.
LOOP AT IT_FFCUST.
PERFORM POPULATEBDC USING :
'X' 'SAPMF02D' '0105',
' ' 'BDC_OKCODE' '/00' ,
' ' 'RF02D-KUNNR' IT_FFCUST-KUNNR,
' ' 'RF02D-BUKRS' IT_FFCUST-BUKRS,
' ' 'RF02D-KTOKD' IT_FFCUST-KTOKD,
'X' 'SAPMF02D' '0110' ,
' ' 'BDC_OKCODE' '/00',
' ' 'KNA1-ANRED' IT_FFCUST-ANRED,
' ' 'KNA1-NAME1' IT_FFCUST-NAME1,
' ' 'KNA1-SORTL' IT_FFCUST-SORTL,
' ' 'KNA1-STRAS' IT_FFCUST-STRAS,
' ' 'KNA1-ORT01' IT_FFCUST-ORT01,
' ' 'KNA1-PSTLZ' IT_FFCUST-PSTLZ,
' ' 'KNA1-LAND1' IT_FFCUST-LAND1,
' ' 'KNA1-SPRAS' IT_FFCUST-SPRAS,
'X' 'SAPMFO2D' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0125',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0340',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0360',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0210',
' ' 'KNB1-AKONT' IT_FFCUST-AKONT,
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0215',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0220',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0230',
' ' 'BDC_OKCODE' '=UPDA'.
*--Calling the transaction 'fd01'.
CALL TRANSACTION 'FD01' USING IT_CUSTBDC MODE 'N' UPDATE 'S'
MESSAGES INTO IT_CUSTMSG.
IF SY-SUBRC <> 0.
*--Populating the error records internal table.
IT_ERRCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_ERRCUST.
CLEAR IT_ERRCUST.
*--Opening a session if there is an error record.
IF V_FLAG1 = ' '.
PERFORM FORM_OPENSESSION.
V_FLAG1 = 'X'.
ENDIF.
*--Inserting the error records into already open session.
IF V_FLAG1 = 'X'.
PERFORM FORM_INSERT.
ENDIF.
*--Populating the Success records internal table.
ELSE.
IT_SUCCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_SUCCUST.
CLEAR IT_SUCCUST.
ENDIF.
*--Displaying the messages.
IF NOT IT_CUSTMSG[] IS INITIAL.
PERFORM FORM_FORMATMSG.
ENDIF.
*--Clearing the message and bdc tables.
CLEAR : IT_CUSTBDC[],IT_CUSTMSG[].
ENDLOOP.
*--Getting the total no of error records.
DESCRIBE TABLE IT_ERRCUST LINES V_ELINES.
*--Getting the total no of successful records.
DESCRIBE TABLE IT_SUCCUST LINES V_SLINES.
*--Closing the session only if it is open.
IF V_FLAG1 = 'X'.
PERFORM FORM_CLOSESESS.
ENDIF.
ENDFORM. " Form_bdcgenerate
&----
*& Form populatebdc
&----
FOrm to Populate the BDC table.
----
FORM POPULATEBDC USING VALUE(P_0178)
VALUE(P_0179)
VALUE(P_0180).
IF P_0178 = 'X'.
IT_CUSTBDC-PROGRAM = P_0179.
IT_CUSTBDC-DYNPRO = P_0180.
IT_CUSTBDC-DYNBEGIN = 'X'.
ELSE.
IT_CUSTBDC-FNAM = P_0179.
IT_CUSTBDC-FVAL = P_0180.
ENDIF.
APPEND IT_CUSTBDC.
CLEAR IT_CUSTBDC.
ENDFORM. " populatebdc
&----
*& Form FORM_OPENSESSION
&----
Form to Open a session.
----
FORM FORM_OPENSESSION .
*--Variable to convert the given session name into reqd type.
DATA : LV_SESNAM(12).
LV_SESNAM = V_SESNAM.
*--Opening a session.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = LV_SESNAM
HOLDDATE = '20040805'
KEEP = 'X'
USER = SY-UNAME
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.
WRITE 😕 'Session not open'.
ENDIF.
ENDFORM. " FORM_OPENSESSION
&----
*& Form FORM_INSERT
&----
fORM TO INSERT ERROR RECOED INTO A SESSION.
----
FORM FORM_INSERT .
*--Inserting the record into session.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'FD01'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
SIMUBATCH = ' '
CTUPARAMS = ' '
TABLES
DYNPROTAB = IT_CUSTBDC
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.
WRITE 😕 'Unable to insert the record'.
ENDIF.
ENDFORM. " FORM_INSERT
&----
*& Form FORM_CLOSESESS
&----
Form to Close the Open Session.
----
FORM FORM_CLOSESESS .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM. " FORM_CLOSESESS
&----
*& Form FORM_FORMATMSG
&----
Form to format messages.
----
FORM FORM_FORMATMSG .
*--Var to store the formatted msg.
DATA : LV_MSG(255).
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = SY-LANGU
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = LV_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE 😕 LV_MSG.
ENDIF.
ULINE.
ENDFORM. " FORM_FORMATMSG
&----
*& Form form_writeop
&----
To write the totals and the session name.
----
FORM FORM_WRITEOP .
WRITE 😕 'Total Records Uploaded :',V_TLINES,
/ 'No of Error Records :',V_ELINES,
/ 'No of Success Records :',V_SLINES,
/ 'Name of the Session :',V_SESNAM.
ULINE.
ENDFORM. " form_writeop
‎2007 Jun 08 4:51 AM
see the simple example code :
************************************************************************
Report : ZMPPC018
Type : Data upload
Author : Seshu Maramreddy
Date : 07/05/2005
Transport : DV3K921247
Transaction: ??
Description: This ABAP/4 Program to Update Rate Routing Material PRT's
for SMI plants using CA22 Transaction.It accepts
tab-delimited spreadsheet input and Run the Call
Transaction Method.
*
************************************************************************
report zmppc018 no standard page heading
line-size 120
line-count 55
message-id zz.
Constants
constants : c_x type c value 'X'," Dynbegin
c_tcode type tstc-tcode value 'CA22'," Transaction Code
c_r(1) type c value 'R'," Task List type
c_O(1) type c value 'O',
c_fh(2) type c value 'FH'.
Variables
data : v_lines_in_xcel like sy-tabix,
v_matnr(18) type c, " Material Number
v_PLNNR like mapl-plnnr," Group
V_DATE(8) type c," System date
v_date1(4) type c,
v_date2(2) type c,
v_date3(2) type c,
V_COUNT TYPE I." Count
Internal table for BDCDATA Structure
data : begin of itab_bdc_tab occurs 0.
include structure bdcdata.
data : end of itab_bdc_tab.
Internal table for File
data : begin of t_file occurs 0,
matnr(18) type c, " Material #
werks(4) type c, " Plant
plnal(2) type n, " Group Counter
vornr(4) type n, " Op #
equnr(18) type c, " PRT Material #
steuf(4) type c, " Control Key
mgvgw(6) type n, " Qty
mgeinh(3) type c, " Qty Unit
end of t_file.
Internal table for Error Log
data : begin of i_error occurs 0,
matnr like mara-matnr,
werks like marc-werks,
vornr like plpo-vornr,
plnnr like plpo-plnnr,
text(90) type c,
end of i_error.
Selection-screen
selection-screen : begin of block blk with frame.
selection-screen: skip 1.
parameters : p_file like rlgrap-filename obligatory,
P_mode type c obligatory Default 'N'.
selection-screen : skip 1.
selection-screen : end of block blk.
at selection-screen on value-request for p_file.
F4 value for Input file
perform filename_get.
main processing
start-of-selection.
To get the data from file to Internal table
perform getdata_fromfile.
loop at t_file.
fill in bdc-data for Routing maintenance screens
perform bdc_build_script.
insert the bdc script as a BDC transaction
perform bdc_submit_transaction.
endloop.
top-of-page.
call function 'Z_HEADER'
EXPORTING
FLEX_TEXT1 =
FLEX_TEXT2 =
FLEX_TEXT3 =
.
skip 1.
write:/2 'Material #',24 'Plant',32 'Group',44 'Op #',
53 'Status Message'.
skip 1.
&----
*& Form filename_get
&----
F4 Value for Input File parameter
----
FORM filename_get.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = 'C:\Temp\ '
MASK = ',.,..'
MODE = 'O'
TITLE = 'Select File '(007)
IMPORTING
FILENAME = p_file
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDFORM. " filename_get
&----
*& Form getdata_fromfile
&----
text
----
FORM getdata_fromfile.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file
FILETYPE = 'DAT'
TABLES
DATA_TAB = t_file
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
if sy-subrc eq 0.
sort t_file by matnr werks plnal vornr .
clear v_lines_in_xcel.
describe table t_file lines v_lines_in_xcel.
if v_lines_in_xcel is initial.
write: / 'No data in input file'.
stop.
endif.
else.
write:/ 'Error reading input file'.
stop.
endif.
ENDFORM. " getdata_fromfile
&----
*& Form bdc_build_script
&----
BDC Script
----
FORM bdc_build_script.
Get the material number from tables ZMSMI_FERR_RAW,
ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
perform get_matnr.
Screen 1010.
perform bdc_screen using 'SAPLCPDI' '1010'.
perform bdc_field using 'BDC_OKCODE' '=VOUE'.
perform bdc_field using 'RC27M-MATNR' SPACE .
perform bdc_field using 'RC27M-WERKS' SPACE.
perform bdc_field using 'RC271-VBELN' SPACE.
perform bdc_field using 'RC271-POSNR' SPACE.
perform bdc_field using 'RC271-PSPNR' SPACE.
Clear v_plnnr.
Get the Group from MAPL Table
select single plnnr from mapl
into v_plnnr
where matnr = t_file-matnr
and werks = t_file-werks
and loekz = space
and plnty = c_r
and plnal = t_file-plnal.
perform bdc_field using 'RC271-PLNNR' v_plnnr.
Current date
MOVE SY-DATUM TO V_DATE.
perform get_date.
perform bdc_field using 'RC271-STTAG' V_DATE.
perform bdc_field using 'RC271-PLNAL' t_file-plnal.
Screen 5400
perform bdc_screen using 'SAPLCPDI' '5400'.
perform bdc_field using 'BDC_OKCODE' '=OSEA'.
Screen 1010
perform bdc_screen using 'SAPLCP02' '1010'.
perform bdc_field using 'BDC_OKCODE' '=ENT1'.
perform bdc_field using 'RC27H-VORNR' T_FILE-VORNR.
Screen 5400
perform bdc_screen using 'SAPLCPDI' '5400'.
perform bdc_field using 'BDC_OKCODE' '=FHUE'.
perform bdc_field using 'RC27X-FLG_SEL(01)' C_X.
Get the no of records from PLAS,PLPO and PLFH Tables
perform get_count.
Screen 0200
IF V_COUNT = 0.
perform bdc_screen using 'SAPLCFDI' '0200'.
perform bdc_field using 'BDC_OKCODE' '/EFIM'.
ELSEif v_count > 0.
Screen 0100
perform bdc_screen using 'SAPLCFDI' '0100'.
perform bdc_field using 'BDC_OKCODE' '/EFIM'.
ENDIF.
Screen 0230
perform bdc_screen using 'SAPLCFDI' '0200'.
perform bdc_field using 'BDC_OKCODE' '=BACK'.
perform bdc_field using 'PLFHD-MATNR' T_FILE-EQUNR.
perform bdc_field using 'PLFHD-STEUF' T_FILE-STEUF.
perform bdc_field using 'PLFHD-MGVGW' T_FILE-mgvgw.
perform bdc_field using 'PLFHD-MGEINH' T_FILE-MGEINH.
Screen 0100
perform bdc_screen using 'SAPLCFDI' '0100'.
perform bdc_field using 'BDC_OKCODE' '=BU'.
ENDFORM. " bdc_build_script
&----
*& Form get_matnr
&----
Get the material number from tables ZMSMI_FERR_RAW,
ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
----
FORM get_matnr.
clear v_matnr.
case t_file-werks.
when '0101'.
select single cmatnr from zmsmi_simp_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
when '0103'.
select single cmatnr from zmsmi_ferr_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
when '0102' or '0110' or '0111' or '0112' or '0113'
or '0114' or '0115' or '0116' or '0117'.
select single cmatnr from zmsmi_snap_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
endcase.
ENDFORM. " get_matnr
&----
*& Form bdc_screen
&----
BDC Script for Screen fields
----
-->P_PROG Program name
-->P_SCRN Screen Number
----
FORM bdc_screen USING p_prog
p_scrn.
clear itab_bdc_tab.
itab_bdc_tab-program = p_prog.
itab_bdc_tab-dynpro = p_scrn.
itab_bdc_tab-dynbegin = c_x.
append itab_bdc_tab.
ENDFORM. " bdc_screen
&----
*& Form bdc_field
&----
BDC Script for Screen fileds
----
-->P_NAM Field name
-->P_VAL Field value
----
FORM bdc_field USING p_nam
p_val.
clear itab_bdc_tab.
itab_bdc_tab-fnam = p_nam.
itab_bdc_tab-fval = p_val.
append itab_bdc_tab.
ENDFORM. " bdc_field
&----
*& Form bdc_submit_transaction
&----
BDC_INSERT Function Module
----
FORM bdc_submit_transaction.
call transaction c_tcode using itab_bdc_tab
mode p_mode update 'S'.
refresh itab_bdc_tab.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = i_error-text
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
i_error-matnr = t_file-matnr.
i_error-werks = t_file-werks.
i_error-plnnr = v_plnnr.
i_error-vornr = t_file-vornr.
append i_error.
clear i_error.
clear t_file.
ENDFORM. " bdc_submit_transaction
&----
*& Form get_date
&----
Converted date as per CA22 Transaction
----
FORM get_date.
clear : v_date,
v_date1,
v_date2,
v_date3.
v_date1 = sy-datum+0(4).
v_date2 = sy-datum+4(2).
v_date3 = sy-datum+6(2).
concatenate v_date2 v_date3 v_date1 into v_date.
ENDFORM. " get_date
&----
*& Form get_count
&----
text
----
FORM get_count.
clear v_count.
select count(*) into v_count
from plas as a inner join plpo as b on aplnty = bplnty
and aplnnr = bplnnr
and aplnkn = bplnkn
inner join plfh as c on cplnty = aplnty
and cplnnr = aplnnr
and cplnal = aplnal
and cplnfl = aplnfl
and cplnkn = bplnkn
where a~plnty = c_r
and a~plnnr = v_plnnr
and a~plnal = t_file-plnal
and c~objct = c_O
and a~loekz = space
and b~vornr = t_file-vornr
and c~objty = c_fh
and c~loekz = space.
ENDFORM. " get_count
end-of-selection.
Displaying Error Log
loop at i_error.
write:/2 i_error-matnr,24 i_error-werks,32 i_error-plnnr,
44 i_error-vornr,50 '-', 53 i_error-text.
endloop.