2007 Jul 20 5:15 PM
2007 Jul 20 5:20 PM
hi,
chk this sample code...
&----
*& Report ZP_CALL_TRANS_TAB1 *
*& *
&----
*& *
*& *
&----
REPORT ZP_CALL_TRANS_TAB1 .
TABLES: LFA1,LFBK,lfb1.
&----
*& internal table declaration
**&----
data: BEGIN OF it_vendor occurs 0,
LIFNR LIKE LFA1-LIFNR,
bukrs like lfb1-bukrs,
END OF it_vendor.
DATA: BEGIN OF IT_BANK occurs 0,
LIFNR LIKE LFA1-LIFNR,
BANKS LIKE LFBK-BANKS,
BANKL LIKE LFBK-BANKL,
BANKN LIKE LFBK-BANKN,
koinh like lfbk-koinh,
END OF IT_BANK.
data: it_bdcdata like bdcdata occurs 0 with header line.
data: it_messages like bdcmsgcoll occurs 0 with header line.
***************************************************
*selection screen.
***************************************************
selection-screen: begin of block b1 with frame.
parameters: p_file like rlgrap-filename default 'c:/vendor.txt'
obligatory.
parameters: p_file1 like rlgrap-filename default 'c:/xyz.txt'
obligatory.
selection-screen: end of block b1.
***************************************************
*at selection screen.
***************************************************
at selection-screen on value-request for p_file.
perform f4_help using p_file.
at selection-screen on value-request for p_file1.
perform f4_help1 using p_file1.
***************************************************
*start of selection
***************************************************
start-of-selection.
*******uploading file
perform upload_file using p_file P_FILE1.
******open session.
perform populate_data.
&----
*& Form f4_help
&----
text
----
-->P_P_FILE text
----
form f4_help using p_p_file.
data: l_file type ibipparms-path.
call function 'F4_FILENAME'
importing
file_name = l_file.
p_file = l_file.
endform. " f4_help
&----
*& Form POPULATE_DATA
&----
text
----
--> p1 text
<-- p2 text
----
form populate_data .
DATA: L_STRING TYPE STRing.
DATA: L_COUNTER(2) TYPE n.
loop at it_vendor.
perform bdc_dynpro using 'SAPMF02K' '0106'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-D0130'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
it_vendor-lifnr.
perform bdc_field using 'RF02K-BUKRS'
it_vendor-bukrs.
perform bdc_field using 'RF02K-D0130'
'X'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-bankn(03)'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
******CALL TRANSACTION.
call transaction 'FK02' using it_bdcdata mode 'A'
messages into it_messages.
write:/ sy-subrc.
perform format_messages.
clear it_bdcdata.
refresh it_bdcdata.
endloop.
endform. " POPULATE_DATA
&----
*& Form FORMAT_MESSAGES
&----
text
----
--> p1 text
<-- p2 text
----
form format_messages .
data: l_msg(100).
loop at it_messages.
call function 'FORMAT_MESSAGE'
exporting
id = it_messages-msgid
lang = sy-langu
no = it_messages-msgnr
v1 = it_messages-msgv1
v2 = it_messages-msgv2
v3 = it_messages-msgv3
v4 = it_messages-msgv4
importing
msg = l_msg
exceptions
not_found = 1
others = 2
.
write:/ l_msg.
endloop.
endform. " FORMAT_MESSAGES
&----
*& Form bdc_dynpro
&----
text
----
-->P_0173 text
-->P_0174 text
----
form bdc_dynpro using value(p_program)
value(p_screen).
it_bdcdata-program = p_program.
it_bdcdata-dynpro = p_screen.
it_bdcdata-dynbegin = 'X'.
append it_bdcdata.
clear it_bdcdata.
endform. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->P_0178 text
-->P_0179 text
----
form bdc_field using value(p_fnam)
value(p_fval).
it_bdcdata-fnam = p_fnam.
it_bdcdata-fval = p_fval.
append it_bdcdata.
clear it_bdcdata.
endform. " bdc_field
&----
*& Form upload_file
&----
text
----
-->P_P_FILE text
-->P_P_FILE1 text
----
form upload_file using p_p_file
p_p_file1.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = P_P_FILE
FILETYPE = 'DAT'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = IT_VENDOR
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
NO_AUTHORITY = 10
OTHERS = 11
.
IF sy-subrc <> 0.
MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.
STOP.
ENDIF.
*******UPLOADING BANK DETAILS
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = P_P_FILE1
FILETYPE = 'DAT'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = IT_BANK
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
NO_AUTHORITY = 10
OTHERS = 11
.
IF sy-subrc <> 0.
MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.
STOP.
ENDIF.
endform. " upload_file
&----
*& Form f4_help1
&----
text
----
-->P_P_FILE1 text
----
form f4_help1 using p_p_file1.
data:l_file1 type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = l_file1.
p_file1 = l_file1.
endform. " f4_help1
do reward if it helps,
priya.
2007 Jul 20 5:20 PM
when you call transaction , give messages into internal table.Check F1 on call transaction.
Call transaction messages into IT_TABLE .
Please reward points if useful
2007 Jul 20 5:20 PM
HI ,
check for the bold part..
REPORT ZCONCUR_UPLOAD_TO_SAP NO STANDARD PAGE HEADING
LINE-SIZE 170
LINE-COUNT 58
MESSAGE-ID ZM.
***********************************************************************
Internal Table *
***********************************************************************
*-Internal table for the Header input data from the Comma Delimited file
DATA: BEGIN OF IT_DATA_HEADER OCCURS 0,
ID TYPE C, "Identifier
BUKRS(6), "Company Code
WAERS(7), "Currency
NEWKO(12), "Vendor
XBLNR(16), "First Name
XBLNR1(16), "Last Name
BLDAT(12), "Document/Posting date
PK(15), "Reference
WRBTR(15), "Amount
BKTXT(27), "Doc.header text
BKTXT1(27), "Item text
SELNO(8), "Serial No
END OF IT_DATA_HEADER.
*-Internal table for the item input data from the Comma Delimited file
DATA: BEGIN OF IT_DATA_ITEM OCCURS 0,
ID TYPE C, "Identifier
NEWKO(19), "Vendor
BUKRS(6), "Company Code
KOSTL(12), "Cost center
WRBTR(15), "Amount
SGTXT(50), "Text
SELNO(8), "Serial No Header
SELNO1(8), "Serial No item
END OF IT_DATA_ITEM .
*-Internal table for the Header input data from the Comma Delimited file
*-Removing " " From Comma Delimited file
DATA: BEGIN OF IT_FINAL_HEADER OCCURS 0,
ID TYPE C, "Identifier
BUKRS LIKE BKPF-BUKRS, "Company Code
WAERS LIKE BKPF-WAERS, "Currency
NEWKO TYPE RF05A-NEWKO, "Vendor
XBLNR LIKE BKPF-XBLNR,
XBLNR1 LIKE BKPF-XBLNR,
BLDAT(10), " LIKE BKPF-BLDAT, "Date
PK(15), "Reference
WRBTR(15), "Amount
BKTXT LIKE BKPF-BKTXT, "Doc.header text
BKTXT1 LIKE BKPF-BKTXT, "Item text
SELNO TYPE I, "Serial No
FLAG TYPE C,
END OF IT_FINAL_HEADER.
*-Internal table for the Item input data from the Comma Delimited file
*-Removing " " From Comma Delimited file
DATA: BEGIN OF IT_FINAL_ITEM OCCURS 0,
ID TYPE C, "Identifier
NEWKO TYPE RF05A-NEWKO, "Account
BUKRS LIKE BKPF-BUKRS, "Company Code
KOSTL LIKE BSEG-KOSTL, "Cost Center
WRBTR(15), "Amount
SGTXT LIKE BSEG-SGTXT, "Text
SELNO TYPE I, "Serial No
SELNO1 TYPE I, "Serial No
END OF IT_FINAL_ITEM.
**-Internal table for the input data from the file
DATA : BEGIN OF P_DOWNLOAD OCCURS 0,
V_FILEREC(1000) TYPE C,
END OF P_DOWNLOAD.
*--- Internal Table for Success messages
DATA : BEGIN OF I_SUCC OCCURS 0,
HEADER(50),
MSG(100), "SUCCESS message
END OF I_SUCC.
*--- Internal Table for error messages
DATA : BEGIN OF I_ERROR_LOG OCCURS 0,
HEADER(50),
MSG(100), "Error message
END OF I_ERROR_LOG.
*--- Internal table for getting the BDC data
DATA : BEGIN OF IT_BDCDATA OCCURS 0.
INCLUDE STRUCTURE BDCDATA. " Table to hold BDC data
DATA : END OF IT_BDCDATA.
*--- Internal table for reading the messages of call transaction
DATA : BEGIN OF IT_MESSAGE_TAB OCCURS 0.
INCLUDE STRUCTURE BDCMSGCOLL. "Table to hold messages
DATA : END OF IT_MESSAGE_TAB.
************************************************************************
DATA DECLARATIONS *
************************************************************************
DATA:
V_ERROR_COUNTER TYPE I, " error records counter
V_MSG(100), " used for Error message
V_LINES TYPE I, " used for format message
V_HEAD LIKE SY-CPROG, " Heading for report
XMODE VALUE 'N', " EXECUTION MODE
V_SUCCESS_COUNTER TYPE I, " Success records counter
V_UNAME LIKE APQI-USERID, " User Name
V_TOTAL TYPE I. " Total records uploaded
DATA : V_SELNO TYPE I.
DATA : V_CHECK TYPE I.
DATA : V_HEADER(50) TYPE C. "Header Information
DATA : V_SUCC_MSG LIKE BDCMSGCOLL-MSGV1."Success Message
DATA : V_ZERO(4) VALUE '0.00'. "Checking Zero
DATA : V_CHECK_ZERO LIKE BSEG-WRBTR. "Checking Zero
DATA : V_CHECK_ZERO1 LIKE BSEG-WRBTR. "Checking Zero
DATA : V_SYSTEMDATE LIKE BKPF-BUDAT.
DATA : V_VALUE TYPE I.
DATA : V_VALUE1 TYPE I.
DATA : V_VALUE2 TYPE I.
*----
Flags
*----
DATA:
F_BDC_OPEN, " BDC session open check.
F_CONTINUE_PROCESSING. " To continue further processing
************************************************************************
CONSTANTS *
************************************************************************
CONSTANTS:
C_SESSION_NAME LIKE APQI-GROUPID VALUE 'F-43', "Session
C_X VALUE 'X'. " Used for falgs
************************************************************************
SELECTION SCREEN *
************************************************************************
*--- Selection Screen with Block and title
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-038.
PARAMETER: P_FNAME LIKE RLGRAP-FILENAME DEFAULT
'C:\Concur.txt'.
SELECTION-SCREEN END OF BLOCK B1.
----
AT SELECTION SCREEN ON VALUE-REQUEST
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = P_FNAME
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
MESSAGE E999 WITH 'Error in opening a file'(009).
ENDIF.
************************************************************************
Top-of-page *
************************************************************************
TOP-OF-PAGE .
*---perform to display the standard header
PERFORM STANDARD_HEADER.
************************************************************************
--
************************************************************************
START-OF-SELECTION.
Upload data
PERFORM UPLOAD_DATA.
move data to bdcdata internal table
PERFORM MOVE_DATA_F43.
*--- Posting the valid data to F-43
IF F_BDC_OPEN = C_X.
*---perform to close bdc group
PERFORM CLOSE_GROUP.
ENDIF.
************************************************************************
END OF SELECTION *
************************************************************************
END-OF-SELECTION.
CHECK F_CONTINUE_PROCESSING IS INITIAL.
PERFORM DISPLAY_REPORT.
&----
*& Form MESSAGE_FORMAT
&----
MESSAGE FORMAT
----
FORM MESSAGE_FORMAT.
CLEAR V_MSG.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = IT_MESSAGE_TAB-MSGID
LANG = 'EN'
NO = IT_MESSAGE_TAB-MSGNR
V1 = IT_MESSAGE_TAB-MSGV1
V2 = IT_MESSAGE_TAB-MSGV2
V3 = IT_MESSAGE_TAB-MSGV3
V4 = IT_MESSAGE_TAB-MSGV4
IMPORTING
MSG = V_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
V_MSG = SPACE.
ENDIF.
ENDFORM. " MESSAGE_FORMAT
&----
*& Form F4_HELP
&----
FORM F4_HELP.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = ' '
DEF_PATH = 'C:\'
MODE = 'O'
TITLE = TEXT-025 "'Upload File'
IMPORTING
FILENAME = P_FNAME
EXCEPTIONS
SELECTION_CANCEL = 3
SELECTION_ERROR = 4.
CASE SY-SUBRC.
WHEN 3.
MESSAGE I000 WITH TEXT-007. " Selection Cancel.
WHEN 4.
MESSAGE I000 WITH TEXT-008. " Selection Error.
ENDCASE.
ENDFORM. " F4_HELP
&----
*& Form STANDARD_HEADER
&----
STANDARD_HEADER
----
FORM STANDARD_HEADER.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
CASE V_HEAD.
WHEN 'Summary Report'(001).
WHEN 'SUCC_REPORT'.
**---To display the field headings for Success report.
ULINE (154).
WRITE : /001 SY-VLINE,
002 'Header Details '(011),
052 SY-VLINE,
053 'Document Number'(036),
154 SY-VLINE.
ULINE (154).
WHEN 'Error Report'.
**---To display the field headings for error report.
ULINE (154).
WRITE : /001 SY-VLINE,
002 'Header Details '(011),
052 SY-VLINE,
053 'Error Message/Text'(035),
154 SY-VLINE.
ULINE (154).
ENDCASE.
ENDFORM. " STANDARD_HEADER
&----
*& Form DISPLAY_REPORT
&----
Display Report Details
----
FORM DISPLAY_REPORT.
PERFORM SUMMARY_REPORT.
PERFORM SUCC_REPORT.
PERFORM ERROR_REPORT.
ENDFORM. " DISPLAY_REPORT
&----
*& Form SUMMARY_REPORT
&----
Success & Error Count Number
----
FORM SUMMARY_REPORT.
WRITE : /030 SY-TITLE.
SKIP 1.
WRITE : /005 'Program Name : '(032),
024 SY-REPID,
080 'Date :'(033),
088 SY-DATUM.
SKIP 1.
V_HEAD = 'Summary Report'(001).
ULINE (132).
WRITE : /1 SY-VLINE,
5 'No. of Records read from the Data file'(014),
45 ':', V_TOTAL LEFT-JUSTIFIED,
132 SY-VLINE,
/1 SY-VLINE,
5 'No. of Records successfully posted'(015),
45 ':', V_SUCCESS_COUNTER LEFT-JUSTIFIED,
132 SY-VLINE,
/1 SY-VLINE,
5 'No. of Records Failed'(023),
45 ':'(031), V_ERROR_COUNTER LEFT-JUSTIFIED,
132 SY-VLINE.
IF NOT F_BDC_OPEN IS INITIAL.
WRITE: /1 SY-VLINE,
5 'Session Name'(022),
45 ':'(031), C_SESSION_NAME LEFT-JUSTIFIED,
132 SY-VLINE.
ENDIF.
ULINE (132).
IF NOT F_BDC_OPEN IS INITIAL.
WRITE: /1 SY-VLINE,
5 'Session Name'(022),
45 ':'(031), C_SESSION_NAME LEFT-JUSTIFIED,
132 SY-VLINE.
ENDIF.
ULINE (132).
ENDFORM. " SUMMARY_REPORT
&----
*& Form ERROR_REPORT
&----
Error Report
----
FORM ERROR_REPORT.
IF NOT I_ERROR_LOG[] IS INITIAL.
SORT I_ERROR_LOG. " by tcode.
V_HEAD = 'Error Report'(013).
NEW-PAGE.
LOOP AT I_ERROR_LOG.
WRITE: /001 SY-VLINE,
002 I_ERROR_LOG-HEADER,
052 SY-VLINE,
053 I_ERROR_LOG-MSG,
154 SY-VLINE.
ULINE (154).
ENDLOOP.
ENDIF.
ENDFORM. " ERROR_REPORT
&----
*& Form ERROR_REPORT
&----
Success Report
----
FORM SUCC_REPORT.
IF NOT I_SUCC[] IS INITIAL.
SORT I_SUCC. " by tcode.
V_HEAD = 'SUCC_REPORT'(034).
NEW-PAGE.
LOOP AT I_SUCC.
WRITE: /001 SY-VLINE,
002 I_SUCC-HEADER,
052 SY-VLINE,
053 I_SUCC-MSG,
154 SY-VLINE.
ULINE (154).
ENDLOOP.
ENDIF.
ENDFORM. " SUCC_REPORT
&----
*& Form OPEN_SESSION
&----
FORM OPEN_SESSION.
DATA : V_DATE LIKE SY-DATUM. " For Hold Date.
V_DATE = SY-DATUM - 1. " Hold date
V_UNAME = SY-UNAME. " User name
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = C_SESSION_NAME
HOLDDATE = V_DATE
KEEP = 'X'
USER = V_UNAME
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 I000 WITH 'Session can not be opened'(019).
STOP.
ENDIF.
F_BDC_OPEN = 'X'.
ENDFORM. " OPEN_SESSION
&----
*& Form BDC_INSERT
&----
FORM BDC_INSERT USING P_TCODE TYPE ANY.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = P_TCODE
TABLES
DYNPROTAB = IT_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 I000 WITH 'Unable to insert, Error record'(037).
STOP.
ENDIF.
ENDFORM. " BDC_INSERT
&----
*& Form CLOSE_GROUP
&----
FORM CLOSE_GROUP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE I000 WITH 'Session can not be closed'(021).
STOP.
ENDIF.
ENDFORM. " CLOSE_GROUP
&----
*& Form UPLOAD_DATA
&----
Upload Data From the text file
----
FORM UPLOAD_DATA.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_FNAME
FILETYPE = 'DAT'
TABLES
DATA_TAB = P_DOWNLOAD
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
OTHERS = 10.
IF SY-SUBRC NE 0.
MESSAGE E000 WITH 'File does not Exist'(003).
ELSEIF P_DOWNLOAD[] IS INITIAL.
MESSAGE E000 WITH 'Input file is empty'(004).
ENDIF.
DATA: V_INDEX LIKE SY-TABIX.
IF NOT P_DOWNLOAD[] IS INITIAL.
LOOP AT P_DOWNLOAD.
V_INDEX = SY-TABIX.
*Removing double quotes
DO.
REPLACE '"' WITH '' INTO P_DOWNLOAD.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
ENDDO.
MODIFY P_DOWNLOAD INDEX V_INDEX.
CONDENSE P_DOWNLOAD.
IF P_DOWNLOAD(1) = '1'.
*Finding the header information, creating key field
V_SELNO = SY-TABIX.
ENDIF.
WE ARE NOT HAVING KEY FIELD IN HEADER/ITEM IN THE FILE.
SO WE ARE CREATING MANUAL KEY FIELD IN INTERNAL TABLE (SELNO).
IF P_DOWNLOAD(1) = '1'.
Moving header information into IT_DATA_HEADER Internal Table
SPLIT P_DOWNLOAD AT ',' INTO
IT_DATA_HEADER-ID
IT_DATA_HEADER-BUKRS
IT_DATA_HEADER-WAERS
IT_DATA_HEADER-NEWKO
IT_DATA_HEADER-XBLNR
IT_DATA_HEADER-XBLNR1
IT_DATA_HEADER-BLDAT
IT_DATA_HEADER-PK
IT_DATA_HEADER-WRBTR
IT_DATA_HEADER-BKTXT
IT_DATA_HEADER-BKTXT1.
IT_DATA_HEADER-SELNO = V_SELNO.
CONDENSE : IT_DATA_HEADER-ID, IT_DATA_HEADER-BUKRS,
IT_DATA_HEADER-WAERS, IT_DATA_HEADER-NEWKO,
IT_DATA_HEADER-XBLNR, IT_DATA_HEADER-XBLNR1,
IT_DATA_HEADER-BLDAT, IT_DATA_HEADER-PK,
IT_DATA_HEADER-WRBTR, IT_DATA_HEADER-BKTXT,
IT_DATA_HEADER-BKTXT1, IT_DATA_HEADER-SELNO.
APPEND IT_DATA_HEADER.
CLEAR IT_DATA_HEADER.
ELSEIF P_DOWNLOAD(1) = '2'.
Moving header information into IT_DATA_ITEM Internal Table
SPLIT P_DOWNLOAD AT ',' INTO
IT_DATA_ITEM-ID
IT_DATA_ITEM-NEWKO
IT_DATA_ITEM-BUKRS
IT_DATA_ITEM-KOSTL
IT_DATA_ITEM-WRBTR
IT_DATA_ITEM-SGTXT.
IT_DATA_ITEM-SELNO = V_SELNO.
IT_DATA_ITEM-SELNO1 = SY-TABIX.
CONDENSE: IT_DATA_ITEM-ID,IT_DATA_ITEM-NEWKO,IT_DATA_ITEM-BUKRS,
IT_DATA_ITEM-KOSTL,IT_DATA_ITEM-WRBTR,
IT_DATA_ITEM-SGTXT,IT_DATA_ITEM-SELNO,
IT_DATA_ITEM-SELNO1.
APPEND IT_DATA_ITEM.
CLEAR IT_DATA_ITEM.
ENDIF.
ENDLOOP.
*SORT HEADER & ITEM INTERNAL Table
SORT IT_DATA_HEADER BY SELNO.
SORT IT_DATA_ITEM BY SELNO SELNO1.
*Header Information
LOOP AT IT_DATA_HEADER.
IT_FINAL_HEADER-ID = IT_DATA_HEADER-ID.
IT_FINAL_HEADER-BUKRS = IT_DATA_HEADER-BUKRS.
IT_FINAL_HEADER-WAERS = IT_DATA_HEADER-WAERS.
IT_FINAL_HEADER-NEWKO = IT_DATA_HEADER-NEWKO.
CONCATENATE IT_DATA_HEADER-XBLNR IT_DATA_HEADER-XBLNR1
INTO IT_FINAL_HEADER-XBLNR.
IT_FINAL_HEADER-BLDAT = IT_DATA_HEADER-BLDAT.
IT_FINAL_HEADER-PK = IT_DATA_HEADER-PK.
IT_FINAL_HEADER-WRBTR = IT_DATA_HEADER-WRBTR.
IT_FINAL_HEADER-BKTXT = IT_DATA_HEADER-BKTXT.
IT_FINAL_HEADER-BKTXT1 = IT_DATA_HEADER-BKTXT1.
IT_FINAL_HEADER-SELNO = IT_DATA_HEADER-SELNO.
APPEND IT_FINAL_HEADER.
CLEAR IT_FINAL_HEADER.
ENDLOOP.
*Item Information
LOOP AT IT_DATA_ITEM.
CHECKING ZERO IN THE IT_DATA_ITEM-WRBTR FIELD
It will not append the IT_FINAL_ITEM
V_CHECK_ZERO = IT_DATA_ITEM-WRBTR.
IF V_CHECK_ZERO NE V_CHECK_ZERO1. "V_ZERO.
IT_FINAL_ITEM-ID = IT_DATA_ITEM-ID.
IT_FINAL_ITEM-NEWKO = IT_DATA_ITEM-NEWKO.
IT_FINAL_ITEM-BUKRS = IT_DATA_ITEM-BUKRS.
IT_FINAL_ITEM-KOSTL = IT_DATA_ITEM-KOSTL.
IT_FINAL_ITEM-WRBTR = IT_DATA_ITEM-WRBTR.
IT_FINAL_ITEM-SGTXT = IT_DATA_ITEM-SGTXT.
IT_FINAL_ITEM-SELNO = IT_DATA_ITEM-SELNO.
IT_FINAL_ITEM-SELNO1 = IT_DATA_ITEM-SELNO1.
APPEND IT_FINAL_ITEM.
CLEAR IT_FINAL_ITEM.
CLEAR : V_CHECK_ZERO,V_CHECK_ZERO1.
ENDIF.
ENDLOOP.
SORT IT_FINAL_HEADER BY SELNO.
SORT IT_FINAL_ITEM BY SELNO.
ENDIF.
ENDFORM. " UPLOAD_DATA
&----
*& Form MOVE_DATA_F43
&----
Call Transaction F-43
----
FORM MOVE_DATA_F43.
*MOVE THE SYSTEM DATE TO
CLEAR V_SYSTEMDATE.
V_SYSTEMDATE = SY-DATUM.
LOOP AT IT_FINAL_HEADER.
CLEAR V_CHECK.
V_CHECK = IT_FINAL_HEADER-SELNO.
MOVE HEADER DATA TO BDCDATA INTERNAL TABLE
PERFORM BDC_BUILD_HEADER.
MOVE ITEM DATA TO BDCDATA INTERNAL TABLE
PERFORM BDC_BUILD_ITEM.
<b>* Call Transcation (F-43)
CALL TRANSACTION 'F-43' USING IT_BDCDATA
MODE XMODE
UPDATE 'S'
MESSAGES INTO IT_MESSAGE_TAB.</b>
IF error record found, it will move to batch Input session
IF SY-SUBRC <> 0.
V_ERROR_COUNTER = V_ERROR_COUNTER + 1. " Inc the counter
CLEAR V_LINES.
DESCRIBE TABLE IT_MESSAGE_TAB LINES V_LINES.
READ TABLE IT_MESSAGE_TAB INDEX V_LINES.
*--- <b>Perform to read the messages
PERFORM MESSAGE_FORMAT.</b>*--- Appending the error records into error table
CONDENSE IT_FINAL_HEADER-BUKRS.
CONDENSE IT_FINAL_HEADER-NEWKO.
CONDENSE IT_FINAL_HEADER-XBLNR.
CONDENSE IT_FINAL_HEADER-BLDAT.
CONCATENATE IT_FINAL_HEADER-BUKRS ','
IT_FINAL_HEADER-NEWKO ','
IT_FINAL_HEADER-XBLNR ','
IT_FINAL_HEADER-BLDAT
INTO V_HEADER.
I_ERROR_LOG-HEADER = V_HEADER.
I_ERROR_LOG-MSG = V_MSG.
APPEND I_ERROR_LOG.
CLEAR I_ERROR_LOG.
*-- Posting the error record to Session
IF F_BDC_OPEN IS INITIAL.
PERFORM OPEN_SESSION.
ENDIF.
PERFORM BDC_INSERT USING 'F-43'.
ELSE.
V_SUCCESS_COUNTER = V_SUCCESS_COUNTER + 1.
*-- READING ONLY SUCCESS MESSAGE(MSGNR 312)
LOOP AT IT_MESSAGE_TAB WHERE MSGNR = '312'.
V_SUCC_MSG = IT_MESSAGE_TAB-MSGV1.
ENDLOOP.
*--- Perform to read the messages
PERFORM MESSAGE_FORMAT.
*--- Appending the Success records into Success table
CONDENSE IT_FINAL_HEADER-BUKRS.
CONDENSE IT_FINAL_HEADER-NEWKO.
CONDENSE IT_FINAL_HEADER-PK.
CONDENSE IT_FINAL_HEADER-XBLNR.
CONDENSE IT_FINAL_HEADER-BLDAT.
CONCATENATE IT_FINAL_HEADER-BUKRS ','
IT_FINAL_HEADER-NEWKO ','
IT_FINAL_HEADER-PK ','
IT_FINAL_HEADER-XBLNR ','
IT_FINAL_HEADER-BLDAT
INTO V_HEADER.
I_SUCC-HEADER = V_HEADER.
I_SUCC-MSG = V_SUCC_MSG.
APPEND I_SUCC.
CLEAR I_SUCC.
ENDIF.
V_TOTAL = V_TOTAL + 1.
REFRESH: IT_BDCDATA,
IT_MESSAGE_TAB.
CLEAR: IT_BDCDATA,
IT_MESSAGE_TAB.
ENDLOOP.
ENDFORM. " MOVE_DATA_F43
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR IT_BDCDATA.
IT_BDCDATA-PROGRAM = PROGRAM.
IT_BDCDATA-DYNPRO = DYNPRO.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDFORM.
&----
*& Form BDC_BUILD_HEADER
&----
Header Information
----
FORM BDC_BUILD_HEADER.
Header Details
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'BKPF-BLDAT'
IT_FINAL_HEADER-BLDAT.
PERFORM BDC_FIELD USING 'BKPF-BLART'
'KR'.
PERFORM BDC_FIELD USING 'BKPF-BUKRS'
IT_FINAL_HEADER-BUKRS.
Moveing System date to Posting date in the document
CLEAR IT_FINAL_HEADER-BLDAT.
CONCATENATE V_SYSTEMDATE4(4) V_SYSTEMDATE0(4)
INTO IT_FINAL_HEADER-BLDAT.
PERFORM BDC_FIELD USING 'BKPF-BUDAT'
IT_FINAL_HEADER-BLDAT.
PERFORM BDC_FIELD USING 'BKPF-WAERS'
IT_FINAL_HEADER-WAERS.
PERFORM BDC_FIELD USING 'BKPF-XBLNR'
IT_FINAL_HEADER-PK.
PERFORM BDC_FIELD USING 'BKPF-BKTXT'
IT_FINAL_HEADER-BKTXT.
PERFORM BDC_FIELD USING 'FS006-DOCID' '*'.
IF IT_FINAL_HEADER-WRBTR CA '-'.
REPLACE '-' WITH SPACE INTO IT_FINAL_HEADER-WRBTR.
CONDENSE IT_FINAL_HEADER-WRBTR.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '25'.
ELSE.
PERFORM BDC_FIELD USING 'RF05A-NEWBS' '31'.
ENDIF.
PERFORM BDC_FIELD USING 'RF05A-NEWKO'
IT_FINAL_HEADER-NEWKO.
*-- Item Vendor Details
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'BSEG-WRBTR'
IT_FINAL_HEADER-WRBTR.
PERFORM BDC_FIELD USING 'BSEG-SGTXT'
IT_FINAL_HEADER-BKTXT1.
ENDFORM. " BDC_BUILD_HEADER
&----
*& Form BDC_BUILD_ITEM
&----
Item Information
----
FORM BDC_BUILD_ITEM.
DATA L_FIRST TYPE C.
LOOP AT IT_FINAL_ITEM WHERE SELNO = V_CHECK.
IF L_FIRST IS INITIAL.
L_FIRST = C_X.
Line Item ( PstKy,Account & New Company Code)
CONDENSE IT_FINAL_HEADER-BLDAT.
IF IT_FINAL_ITEM-WRBTR CA '-'.
REPLACE '-' WITH SPACE INTO IT_FINAL_ITEM-WRBTR.
CONDENSE IT_FINAL_ITEM-WRBTR.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'RF05A-NEWBS' '50',
'RF05A-NEWKO' IT_FINAL_ITEM-NEWKO,
'RF05A-NEWBK' IT_FINAL_ITEM-BUKRS.
ELSE.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0302'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'RF05A-NEWBS' '40',
'RF05A-NEWKO' IT_FINAL_ITEM-NEWKO,
'RF05A-NEWBK' IT_FINAL_ITEM-BUKRS.
ENDIF.
Amount & Text
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'BSEG-WRBTR' IT_FINAL_ITEM-WRBTR,
'BSEG-SGTXT' IT_FINAL_ITEM-SGTXT,
'DKACB-FMORE' 'X'.
Cost Center
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' 'ENTE',
'COBL-KOSTL' IT_FINAL_ITEM-KOSTL.
ELSE.
Line Item ( PstKy,Account & New Company Code)
IF IT_FINAL_ITEM-WRBTR CA '-'.
REPLACE '-' WITH SPACE INTO IT_FINAL_ITEM-WRBTR.
CONDENSE IT_FINAL_ITEM-WRBTR.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'RF05A-NEWBS' '50',
'RF05A-NEWKO' IT_FINAL_ITEM-NEWKO,
'RF05A-NEWBK' IT_FINAL_ITEM-BUKRS.
ELSE.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'RF05A-NEWBS' '40',
'RF05A-NEWKO' IT_FINAL_ITEM-NEWKO,
'RF05A-NEWBK' IT_FINAL_ITEM-BUKRS.
ENDIF.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' 'ENTE'.
Amount & Text
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' '/00',
'BSEG-WRBTR' IT_FINAL_ITEM-WRBTR,
'BSEG-SGTXT' IT_FINAL_ITEM-SGTXT,
'DKACB-FMORE' 'X'.
Cost Center
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' 'ENTE',
'COBL-KOSTL' IT_FINAL_ITEM-KOSTL.
ENDIF.
ENDLOOP.
*Save Details
PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_DYNPRO USING 'SAPLKACB' '0002'.
PERFORM BDC_FIELD USING: 'BDC_OKCODE' 'ENTE'.
ENDFORM. " BDC_BUILD_ITEM
Thanks
Mahesh