SAP ABAP - Uploading Excel Sheet Data & Saving It To FB01 Transaction Using BDC Session Or Call Transaction Method.

This is a sample program on uploading FI documents into SAP system. Also this program shows how to upload multiple line items through BDC sessions.

Upload the financial documents from a legacy system (excel file) into SAP using transaction code FB01. The file to be uploaded is specified on the selection screen by the user. The same file is displayed on the output screen in ALV Format (grid display) along with status details (success/failure).Also, the successful transaction is uploaded into the SAP system.

ALSO this program download all the error message and success messages in excel sheets.

SAMPLE PROGRAM:

REPORT ztest_fi_bdc_fb01_upload MESSAGE-ID zfimessages.

TYPE-POOLS: truxs,slis.

* STRUCTURE FOR INTERNAL TABLE
TYPES:BEGIN OF x_file,
documentreferencenumber TYPE augbl, "Variable name for document reference number.
documentdate(10) TYPE c, "Variable name for document date.
documenttype TYPE blart, "Variable name for document type.
companycode TYPE bukrs, "Variable name for company code.
postingdate(10) TYPE c, "Variable name for posting date.
period TYPE monat, "Variable name for fiscal period.
currency TYPE waers, "Variable name for currency code.
reference TYPE xblnr1, "Variable name for reference.
postingkey TYPE newbs, "Variable name for posting key.
account TYPE newko, "Variable name for account number.
amount(16) TYPE c, "Variable name for amount.
taxcode TYPE mwskx, "Variable name for taxcode.
businessarea TYPE gsber, "Variable name for business area.
profitcenter TYPE prctr, "Variable name for profit center.
valuedate(10) TYPE c, "Variable name for value date.
status(1) TYPE c, "Variable name for status.
description TYPE string, "Variable name for description.
END OF x_file.

* STRUCTURE FOR MESSAGE STATUS
TYPES: BEGIN OF x_mess,
documentreferencenumber TYPE augbl, "Variable name for document reference number.
status(1) TYPE c, "Variable name for status of the message.
description TYPE string, "Variable name for description of the message.
END OF x_mess.


TYPES: BEGIN OF x_header,
field1(20) TYPE c,
END OF x_header.

TYPES: BEGIN OF x_down,
documentreferencenumber TYPE n,
END OF x_down.

DATA: v_statusd TYPE n,
it_check TYPE STANDARD TABLE OF x_file,
wa_check TYPE x_file.

DATA: it_header TYPE STANDARD TABLE OF x_header,
wa_header TYPE x_header,
p_filee TYPE string,
p_files TYPE string.

* DATA DECLARATION FOR INTERNAL TABLES, WORKAREAS, VARIABLES

DATA: it_upload TYPE STANDARD TABLE OF x_file," IT To Store Data From Excel Sheet
wa_upload TYPE x_file,
wa_upload1 TYPE x_file,
it_type TYPE truxs_t_text_data,
it_successmess TYPE STANDARD TABLE OF x_file,
wa_successmess TYPE x_file,
it_errormess TYPE STANDARD TABLE OF x_file,
wa_errormess TYPE x_file,
it_bdcdata TYPE STANDARD TABLE OF bdcdata, :" IT To Store Data Field Names & Values Of Each Screen.
wa_bdcdata TYPE bdcdata,
it_messagelog TYPE STANDARD TABLE OF bdcmsgcoll, " IT To Store Messages
wa_messagelog TYPE bdcmsgcoll,
v_itirate TYPE c,
v_msg TYPE string VALUE ' is missing.',
v_finalmsg TYPE string VALUE '',
it_success TYPE STANDARD TABLE OF x_mess,
wa_success TYPE x_mess,
v_validate_fg TYPE c,
v_temp TYPE c.


* DATA DECLARATION FOR ALV GRID DISPLAY

DATA: it_alv_fieldcat TYPE slis_t_fieldcat_alv,
wa_alv_fieldcat TYPE slis_fieldcat_alv,
it_alv_layout TYPE slis_layout_alv.


* DATA DECLARATION FOR VALIDATION OF BDC SESSION METHOD

CONSTANTS: c_documentdate TYPE c LENGTH 20 VALUE 'Document date',
c_documenttype TYPE c LENGTH 20 VALUE 'Document type',
c_companycode TYPE c LENGTH 20 VALUE 'Company code',
c_postingdate TYPE c LENGTH 20 VALUE 'Posting date',
c_period TYPE c LENGTH 20 VALUE 'Fiscal period',
c_currency TYPE c LENGTH 20 VALUE 'Currency code',
c_postingkey TYPE c LENGTH 20 VALUE 'Posting key',
c_account TYPE c LENGTH 20 VALUE 'Account',
c_amount TYPE c LENGTH 20 VALUE 'Amount',

c_documentreferenceno TYPE c LENGTH 20 VALUE 'Document reference #',
c_x TYPE c VALUE 'X',
c_comma TYPE c VALUE ',',
c_session(12) TYPE c VALUE 'FB01_SESSION',
c_transaction TYPE tstc-tcode VALUE 'FB01',
c_mode TYPE c VALUE 'N',
c_update TYPE c VALUE 'S',
c_y TYPE c VALUE 'Y'.



* BLOCK 1 FOR FILE NAME & BLOCK 2 FOR TYPE OF PROCESS.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME
TITLE text-001.
PARAMETERS: p_fname TYPE rlgrap-filename OBLIGATORY,
p_error TYPE rlgrap-filename,
p_succes TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME
TITLE text-002.
PARAMETERS: rb_sessi RADIOBUTTON GROUP grp1 USER-COMMAND flag,
rb_trans RADIOBUTTON GROUP grp1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME.
PARAMETERS: p_sname TYPE apqi-groupid obligatory.
SELECTION-SCREEN END OF BLOCK b3.

p_files = p_succes.
p_filee = p_error.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
PERFORM get1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_succes.
PERFORM get2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_error.
PERFORM get3.


AT SELECTION-SCREEN OUTPUT.
PERFORM modify_screen.

START-OF-SELECTION.
PERFORM alv_setup.

* TRANSFER DATA FROM EXCEL SHEET TO INTERNAL TABLE


CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_line_header = c_x
i_tab_raw_data = it_type
i_filename = p_fname
TABLES
i_tab_converted_data = it_upload[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.

* IF FILE OTHER THAN EXCEL, THROW ERROR "Excel File Conversion Failed".
IF sy-subrc <> 0.
v_validate_fg = c_x.
MESSAGE i003.
STOP.
ENDIF.

* IF FILE IS EMPTY, THROW ERROR "Excel File Is Empty".
IF it_upload IS INITIAL.
v_validate_fg = c_x.
MESSAGE i004.
STOP.
ENDIF.

* SELECT A PROCESS : SESSION OR CALL TRANSACTION
CHECK v_validate_fg <> c_x.

IF rb_sessi = c_x.
PERFORM session.

ELSE.
PERFORM transaction.
ENDIF.

*&---------------------------------------------------------------------*
*& Form session
*&---------------------------------------------------------------------*
* Using Session method
*----------------------------------------------------------------------*

FORM session.
*VALIDATION FOR SESSION METHOD

LOOP AT it_upload INTO wa_upload.

wa_upload1 = wa_upload.
AT NEW documentreferencenumber.
IF wa_upload1-documentreferencenumber IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_documentreferenceno v_msg INTO v_msg.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-documentdate IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_documentdate v_msg INTO v_msg.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-documenttype IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_documenttype v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-companycode IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_companycode v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-postingdate IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_postingdate v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-period IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_period v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-currency IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_currency v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.
ENDAT.

IF wa_upload1-postingkey IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_postingkey v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-account IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_account v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.

IF wa_upload1-amount IS INITIAL.
wa_upload1-status = text-003.
CONCATENATE c_amount v_msg INTO v_msg SEPARATED BY c_comma.
wa_upload1-description = v_msg.
ENDIF.

IF v_msg CO ' is missing.'.

wa_upload1-status = text-004.
wa_upload1-description = ''.
ENDIF.

MODIFY it_upload FROM wa_upload1.
CLEAR wa_upload1.
v_msg = text-005.
ENDLOOP.

* OPEN BDC GROUP

PERFORM bdc_open_grp.

LOOP AT it_upload INTO wa_upload.
v_itirate = c_x.
wa_upload1 = wa_upload.

AT NEW documentreferencenumber.
v_itirate = c_y.

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'
wa_upload1-documentdate.

PERFORM bdc_field USING 'BKPF-BLART'
wa_upload1-documenttype.

PERFORM bdc_field USING 'BKPF-BUKRS'
wa_upload1-companycode.

PERFORM bdc_field USING 'BKPF-BUDAT'
wa_upload1-postingdate.

PERFORM bdc_field USING 'BKPF-MONAT'
wa_upload1-period.

PERFORM bdc_field USING 'BKPF-WAERS'
wa_upload1-currency.

PERFORM bdc_field USING 'FS006-DOCID'
'*'.

PERFORM bdc_field USING 'RF05A-NEWBS'
wa_upload1-postingkey.

PERFORM bdc_field USING 'RF05A-NEWKO'
wa_upload1-account.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'
'BSEG-VALUT'.

PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.

PERFORM bdc_field USING 'BSEG-WRBTR'
wa_upload1-amount.

PERFORM bdc_field USING 'BSEG-VALUT'
wa_upload1-valuedate.

PERFORM bdc_field USING 'DKACB-FMORE'
'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-PRCTR'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

PERFORM bdc_field USING 'COBL-GSBER'
wa_upload1-businessarea.

PERFORM bdc_field USING 'COBL-PRCTR'
wa_upload1-profitcenter.

ENDAT.

CHECK v_itirate = c_x.
IF sy-tabix <> 1.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'
'RF05A-NEWKO'.

PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.

PERFORM bdc_field USING 'RF05A-NEWBS'
wa_upload1-postingkey.

PERFORM bdc_field USING 'RF05A-NEWKO'
wa_upload1-account.

PERFORM bdc_field USING 'DKACB-FMORE'
'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-GSBER'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

PERFORM bdc_field USING 'COBL-GSBER'
wa_upload1-businessarea.

PERFORM bdc_field USING 'COBL-PRCTR'
wa_upload1-profitcenter.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'
'RF05A-NEWKO'.

PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.

PERFORM bdc_field USING 'BSEG-WRBTR'
wa_upload1-amount.

PERFORM bdc_field USING 'BSEG-VALUT'
wa_upload1-valuedate.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-GSBER'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

ENDIF.

AT END OF documentreferencenumber.

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'
wa_upload1-amount.

PERFORM bdc_field USING 'BSEG-VALUT'
wa_upload1-valuedate.

PERFORM bdc_field USING 'DKACB-FMORE'
'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-PRCTR'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

PERFORM bdc_field USING 'COBL-GSBER'
wa_upload1-businessarea.

PERFORM bdc_field USING 'COBL-PRCTR'
wa_upload1-profitcenter.

* CREATE BDC SESSION
PERFORM bdc.
REFRESH it_bdcdata.

ENDAT.
ENDLOOP.

* CLOSE BDC GROUP
PERFORM bdc_close_grp.

ENDFORM. "End of form Session

*&---------------------------------------------------------------------*
*& Form transaction
*&---------------------------------------------------------------------*
* Using CALL TRANSACTION method
*----------------------------------------------------------------------*
FORM transaction.

LOOP AT it_upload INTO wa_upload.
v_itirate = c_x.
wa_upload1 = wa_upload.

AT NEW documentreferencenumber.
v_itirate = c_y.

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'
wa_upload1-documentdate.

PERFORM bdc_field USING 'BKPF-BLART'
wa_upload1-documenttype.

PERFORM bdc_field USING 'BKPF-BUKRS'
wa_upload1-companycode.

PERFORM bdc_field USING 'BKPF-BUDAT'
wa_upload1-postingdate.

PERFORM bdc_field USING 'BKPF-MONAT'
wa_upload1-period.

PERFORM bdc_field USING 'BKPF-WAERS'
wa_upload1-currency.

PERFORM bdc_field USING 'FS006-DOCID'
'*'.

PERFORM bdc_field USING 'RF05A-NEWBS'
wa_upload1-postingkey.

PERFORM bdc_field USING 'RF05A-NEWKO'
wa_upload1-account.


PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'
'BSEG-VALUT'.

PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.

PERFORM bdc_field USING 'BSEG-WRBTR'
wa_upload1-amount.

PERFORM bdc_field USING 'BSEG-VALUT'
wa_upload1-valuedate.

PERFORM bdc_field USING 'DKACB-FMORE'
'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-PRCTR'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

PERFORM bdc_field USING 'COBL-GSBER'
wa_upload1-businessarea.

PERFORM bdc_field USING 'COBL-PRCTR'
wa_upload1-profitcenter.

ENDAT.

CHECK v_itirate = c_x.

IF sy-tabix <> 1.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'
'RF05A-NEWKO'.

PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.

PERFORM bdc_field USING 'RF05A-NEWBS'
wa_upload1-postingkey.

PERFORM bdc_field USING 'RF05A-NEWKO'
wa_upload1-account.

PERFORM bdc_field USING 'DKACB-FMORE'
'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-GSBER'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

PERFORM bdc_field USING 'COBL-GSBER'
wa_upload1-businessarea.

PERFORM bdc_field USING 'COBL-PRCTR'
wa_upload1-profitcenter.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'
'RF05A-NEWKO'.

PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.

PERFORM bdc_field USING 'BSEG-WRBTR'
wa_upload1-amount.

PERFORM bdc_field USING 'BSEG-VALUT'
wa_upload1-valuedate.


PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-GSBER'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

ENDIF.

AT END OF documentreferencenumber.


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'
wa_upload1-amount.

PERFORM bdc_field USING 'BSEG-VALUT'
wa_upload1-valuedate.

PERFORM bdc_field USING 'DKACB-FMORE'
'X'.


PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'
'COBL-PRCTR'.

PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTE'.

PERFORM bdc_field USING 'COBL-GSBER'
wa_upload1-businessarea.

PERFORM bdc_field USING 'COBL-PRCTR'
wa_upload1-profitcenter.

* CALL TRANSACTION

CALL TRANSACTION c_transaction USING it_bdcdata MODE c_mode UPDATE c_update MESSAGES INTO it_messagelog.

IF sy-subrc <> 0.
v_temp = text-003.
ENDIF.
LOOP AT it_messagelog INTO wa_messagelog.

CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_messagelog-msgid
lang = wa_messagelog-msgspra
no = wa_messagelog-msgnr
v1 = wa_messagelog-msgv1
v2 = wa_messagelog-msgv2
v3 = wa_messagelog-msgv3
v4 = wa_messagelog-msgv4
IMPORTING
msg = v_msg.

IF v_temp IS NOT INITIAL.
wa_messagelog-msgtyp = v_temp.
ENDIF.

IF v_finalmsg = ''.
v_finalmsg = v_msg.

ELSE.
CONCATENATE v_finalmsg v_msg INTO v_finalmsg SEPARATED BY c_comma.
ENDIF.

wa_success-documentreferencenumber = wa_upload1-documentreferencenumber.
wa_success-status = wa_messagelog-msgtyp.
wa_success-description = v_finalmsg.
APPEND wa_success TO it_success.

IF wa_success-documentreferencenumber = wa_upload1-documentreferencenumber.
MOVE wa_success-status TO wa_upload1-status.
MOVE wa_success-description TO wa_upload1-description.
MODIFY it_upload FROM wa_upload1.
ENDIF.

ENDLOOP.
CLEAR v_temp.
CLEAR v_finalmsg.
REFRESH it_messagelog.


* LOOP AT IT_SUCCESS INTO WA_SUCCESS
REFRESH it_bdcdata.
ENDAT.
ENDLOOP.
ENDFORM. " End of Form transaction

END-OF-SELECTION.

wa_header-field1 = 'doc_no'.
APPEND wa_header TO it_header.
CLEAR wa_header..

wa_header-field1 = 'doc_date'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'doc_type'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'companycode'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'postingdate'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'period'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'currency'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'reference'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'postingkey'.
APPEND wa_header TO it_header.
CLEAR wa_header..

wa_header-field1 = 'account'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'amount'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'taxcode'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'businessarea'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'profitcenter'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'valuedate'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'status'.
APPEND wa_header TO it_header.
CLEAR wa_header.

wa_header-field1 = 'description'.
APPEND wa_header TO it_header.
CLEAR wa_header.

CHECK v_validate_fg <> c_x.

***********************************
* WRITING TO THE LOG FILES.
***************************************

IF rb_sessi = c_x.

LOOP AT it_upload INTO wa_upload.
wa_upload1 = wa_upload.
IF wa_upload1-status = text-003 OR wa_upload1-documentreferencenumber = v_statusd.
APPEND wa_upload1 TO it_errormess.
v_statusd = wa_upload1-documentreferencenumber.
APPEND wa_upload1 TO it_check.

ELSE.
IF wa_upload1-documentreferencenumber <> v_statusd.
APPEND wa_upload1 TO it_successmess.

ENDIF.

LOOP AT it_check INTO wa_check.
LOOP AT it_successmess INTO wa_successmess.

IF wa_successmess-documentreferencenumber = wa_check-documentreferencenumber.
DELETE it_successmess.
ENDIF.

ENDLOOP.
ENDLOOP.
ENDIF.

AT END OF documentreferencenumber.
CLEAR v_statusd.
ENDAT.
ENDLOOP.

PERFORM file_download.

ELSE.
LOOP AT it_upload INTO wa_upload.
wa_upload1 = wa_upload.
APPEND wa_upload1 TO it_check.

AT END OF documentreferencenumber.
IF wa_upload1-status = text-004.

LOOP AT it_check INTO wa_check.
APPEND wa_check TO it_successmess.
ENDLOOP.
REFRESH it_check.

ELSE.
LOOP AT it_check INTO wa_check.
APPEND wa_check TO it_errormess.
ENDLOOP.
REFRESH it_check.

ENDIF.
ENDAT.

ENDLOOP.

PERFORM file_download.
ENDIF.

PERFORM display_alv.

FREE: it_upload,
it_type,
it_bdcdata,
it_messagelog,
it_success,
it_alv_fieldcat,
it_alv_layout.

CLEAR: wa_upload,
wa_upload1,
wa_bdcdata,
wa_messagelog,
wa_success,
wa_alv_fieldcat.

DATA fcode TYPE TABLE OF sy-ucomm.

*&---------------------------------------------------------------------*
*& Form file_download
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM file_download.

IF p_files IS NOT INITIAL.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = p_files
filetype = 'DAT'
append = 'X'
TABLES
data_tab = it_successmess
fieldnames = it_header
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.

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.

IF p_filee IS NOT INITIAL.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = p_filee
filetype = 'DAT'
append = 'X'
TABLES
data_tab = it_errormess
fieldnames = it_header
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.

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.
ENDFORM. "file_download

*&---------------------------------------------------------------------*
*& Form set_pf_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.

IF rb_sessi = 'X'.
SET PF-STATUS 'ZSTATUS'.
ELSE.
APPEND 'DISP' TO fcode.
APPEND 'PROCESS' TO fcode.

SET PF-STATUS 'ZSTATUS' EXCLUDING fcode.
ENDIF.

ENDFORM. "set_pf_status


*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->SY-UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
IF r_ucomm EQ 'PROCESS'.
SUBMIT rsbdcsub AND RETURN

WITH mappe = p_sname
WITH z_verarb = 'X'
WITH logall = 'X'.
ELSEIF r_ucomm EQ 'DISP'.
CALL TRANSACTION 'SM35'.
ENDIF.
ENDFORM. "user_command


*&---------------------------------------------------------------------*
*& Form alv_setup
*&---------------------------------------------------------------------*
* Layout for ALV
*----------------------------------------------------------------------*


FORM alv_setup.

CLEAR wa_alv_fieldcat.
REFRESH it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'DOCUMENTREFERENCENUMBER'.
wa_alv_fieldcat-seltext_l = 'Document Reference Number'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'DOCUMENTDATE'.
wa_alv_fieldcat-seltext_l = 'Document Date'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'DOCUMENTTYPE'.
wa_alv_fieldcat-seltext_l = 'Document Type'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'COMPANYCODE'.
wa_alv_fieldcat-seltext_l = 'Company Code'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'POSTINGDATE'.
wa_alv_fieldcat-seltext_l = 'Posting Date'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'PERIOD'.
wa_alv_fieldcat-seltext_l = 'Period'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'CURRENCY'.
wa_alv_fieldcat-seltext_l = 'Currency'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'REFERENCE'.
wa_alv_fieldcat-seltext_l = 'Reference'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'POSTINGKEY'.
wa_alv_fieldcat-seltext_l = 'Posting Key'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'ACCOUNT'.
wa_alv_fieldcat-seltext_l = 'Account'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'AMOUNT'.
wa_alv_fieldcat-seltext_l = 'Amount'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'TAXCODE'.
wa_alv_fieldcat-seltext_l = 'Tax code'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'BUSINESSAREA'.
wa_alv_fieldcat-seltext_l = 'Business Area'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'PROFITCENTER'.
wa_alv_fieldcat-seltext_l = 'Profit Center'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'VALUEDATE'.
wa_alv_fieldcat-seltext_l = 'Value Date'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'STATUS'.
wa_alv_fieldcat-seltext_l = 'Status'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

wa_alv_fieldcat-fieldname = 'DESCRIPTION'.
wa_alv_fieldcat-seltext_l = 'Description'. "#EC NOTEXT
APPEND wa_alv_fieldcat TO it_alv_fieldcat.

ENDFORM. "alv_setup


*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM display_alv.
it_alv_layout-colwidth_optimize = c_x.
it_alv_layout-zebra = c_x.
SET PF-STATUS 'TEST'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
is_layout = it_alv_layout
it_fieldcat = it_alv_fieldcat
TABLES
t_outtab = it_upload.

ENDFORM. "display_alv

**&---------------------------------------------------------------------*
**& Form bdc_open_grp
**&---------------------------------------------------------------------*
** -->Group Session name
**----------------------------------------------------------------------*
FORM bdc_open_grp.

CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_sname
keep = c_x
user = sy-uname.
.
ENDFORM. "bdc_open_grp


*&---------------------------------------------------------------------*
*& Form bdc
*&---------------------------------------------------------------------*
* -->TCODE Transaction code for which session to be created
* -->DYNPROTAB Intenal table that is passed
*----------------------------------------------------------------------*
FORM bdc.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = c_transaction
TABLES
dynprotab = it_bdcdata.

ENDFORM. "bdc

*&---------------------------------------------------------------------*
*& Form bdc_close_grp
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM bdc_close_grp.

CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1.
.
IF sy-subrc <> 0.
MESSAGE i017.
ELSE.
MESSAGE s016.
ENDIF.
ENDFORM. "bdc_close_grp

*&---------------------------------------------------------------------*
*& Form get1
*&---------------------------------------------------------------------*
* Browse for a file on the presentation server
*----------------------------------------------------------------------*
FORM get1.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'p_fname'
IMPORTING
file_name = p_fname.

ENDFORM. "get1

*&---------------------------------------------------------------------*
*& Form get2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get2.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'p_succes'
IMPORTING
file_name = p_succes.

ENDFORM. "get2

*&---------------------------------------------------------------------*
*& Form get3
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get3.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = 'p_error'
IMPORTING
file_name = p_error.

ENDFORM. "get3

*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
* -->PROGRAM Program name
* -->DYNPRO Screen #
* -->DYNBEGIN Beginning of new screen
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR wa_bdcdata.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = c_x.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM. "BDC_DYNPRO
*
**&---------------------------------------------------------------------*
**& Form BDC_FIELD
**&---------------------------------------------------------------------*
**
**----------------------------------------------------------------------*
** -->FNAM Field name
** -->FVAL Field value
**----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR wa_bdcdata.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM. "BDC_FIELD

*&---------------------------------------------------------------------*
*& Form modify_screen
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM modify_screen.
LOOP AT SCREEN.
IF rb_sessi <> 'X'.
IF screen-name CS 'p_sname'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDIF.

ENDLOOP.
ENDFORM. "modify_screen


MORE PROGRAMS ON REPORT PROGRAMMING:

- Upload Excel Sheet Data Into Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE.

- Uploading Large Data From Excel Sheet To Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE

- Send an excel sheet to the concerned person in an email format via SAP System.

- Generate PDF from ABAP List Output.

- Edit / Create Customer Specific Message / Text On Login Screen Via SE61.

- ...Back To Index On Report Programming.



Your suggestions and comments are welcome in this section.

Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.

No comments:

Post a Comment