REPORT zfbs1_mass_upload.
INCLUDE zfbs1_mass_upload_top.
INCLUDE zfbs1_mass_upload_sel.
INCLUDE zfbs1_mass_upload_sub.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_p_file.
START-OF-SELECTION.
IF p_file IS NOT INITIAL.
PERFORM upload_data.
ENDIF.
IF lt_upload[] IS NOT INITIAL.
PERFORM run_bapi.
PERFORM call_fm.
ENDIF.
*&---------------------------------------------------------------------*
*& Include ZFBS1_MASS_UPLOAD_TOP
*&---------------------------------------------------------------------*
TYPES : BEGIN OF ty_upload,
srno TYPE string,
header_text TYPE bktxt,
comp_code TYPE bukrs,
doc_date TYPE bldat,
post_date TYPE budat,
doc_type TYPE blart,
ref_no TYPE xblnr,
rev_reason TYPE acpi_stgrd,
rev_date TYPE rbdat,
gl_line_num TYPE posnr_acc,
gl_account TYPE hkont,
line_text TYPE sgtxt,
busi_area TYPE gsber,
plant TYPE werks_d,
bupla TYPE bupla,
assignment_no TYPE dzuonr,
cost_center TYPE kostl,
profit_center TYPE prctr,
dist_chan TYPE vtweg,
division TYPE spart,
sales_org TYPE vkorg,
kndnr TYPE kunnr,
sales_grp TYPE vkgrp,
doc_currency TYPE bkpf-waers,
doc_amount TYPE bapidoccur,
END OF ty_upload.
TYPES : BEGIN OF ty_log,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
gjahr TYPE bkpf-gjahr,
type TYPE char1,
message TYPE char100,
END OF ty_log.
TYPES: BEGIN OF ty_header1,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
rbdat TYPE rbdat,
END OF ty_header1.
*
TYPES : BEGIN OF ty_message,
srno TYPE string,
type TYPE string,
belnr TYPE bkpf-belnr,
message TYPE c LENGTH 1000,
END OF ty_message.
DATA :it_message TYPE TABLE OF ty_message,
wa_message TYPE ty_message,
lv_message TYPE c LENGTH 1000, "string,
lv_type TYPE string.
********Field catalog declaration
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_fieldcat TYPE slis_fieldcat_alv,
gs_layo TYPE slis_layout_alv.
DATA: ls_documentheader1 TYPE ty_header1,
lt_documentheader1 TYPE TABLE OF ty_header1.
DATA : lt_upload TYPE STANDARD TABLE OF ty_upload,
ls_upload TYPE ty_upload,
ls_data TYPE ty_upload,
lv_hkont TYPE hkont,
lv_kostl TYPE kostl,
lv_prctr TYPE prctr,
lv_kunnr TYPE kunnr.
DATA it_type TYPE truxs_t_text_data.
***** Declaration for application log
DATA: gt_return_log TYPE bapiret2_t.
****************** Class/Objects***************************
DATA: gcl_app_log TYPE REF TO zca_cl_application_log_revised,
****************** Internal Structure *********************
gs_log_handle TYPE balloghndl.
*&---------------------------------------------------------------------*
*& Include ZFBS1_MASS_UPLOAD_SEL
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_file TYPE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*& Include ZFBS1_MASS_UPLOAD_SUB
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form F4_P_FILE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM F4_P_FILE .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM UPLOAD_DATA .
IF P_FILE IS NOT INITIAL .
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = IT_TYPE
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = LT_UPLOAD
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
MESSAGE E000(38) WITH TEXT-100.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form RUN_BAPI
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM RUN_BAPI .
IF LT_UPLOAD[] IS NOT INITIAL.
DATA: LV_ERROR,
LV_COUNT TYPE BAPIACGL09-ITEMNO_ACC,
LS_DOCUMENTHEADER TYPE BAPIACHE09,
LT_ACCOUNTGL TYPE TABLE OF BAPIACGL09,
LS_ACCOUNTGL TYPE BAPIACGL09,
LT_CRITERIA TYPE TABLE OF BAPIACKEC9,
LS_CRITERIA TYPE BAPIACKEC9,
LT_CURRENCYAMOUNT TYPE TABLE OF BAPIACCR09,
LS_CURRENCYAMOUNT TYPE BAPIACCR09,
LS_EXTENSION TYPE BAPIPAREX,
LT_EXTENSION TYPE STANDARD TABLE OF BAPIPAREX,
LS_RETURN TYPE BAPIRET2,
LT_RETURN TYPE TABLE OF BAPIRET2,
LV_OBJ_KEY TYPE BAPIACHE09-OBJ_KEY,
LV_BUPER TYPE T009B-POPER,
LV_GJAHR TYPE T009B-BDATJ,
LV_BSSUBST TYPE BSSUBST.
LOOP AT LT_UPLOAD ASSIGNING FIELD-SYMBOL(<FS_UPLOAD>).
LS_DATA = <FS_UPLOAD>.
AT NEW SRNO.
CLEAR: LV_COUNT,LV_BUPER,LV_GJAHR.
FREE: LT_ACCOUNTGL,LT_CURRENCYAMOUNT.
LS_DOCUMENTHEADER-USERNAME = SY-UNAME.
LS_DOCUMENTHEADER-HEADER_TXT = LS_DATA-HEADER_TEXT.
LS_DOCUMENTHEADER-COMP_CODE = LS_DATA-COMP_CODE.
LS_DOCUMENTHEADER-DOC_DATE = LS_DATA-DOC_DATE.
LS_DOCUMENTHEADER-PSTNG_DATE = LS_DATA-POST_DATE.
LS_DOCUMENTHEADER-DOC_TYPE = LS_DATA-DOC_TYPE.
LS_DOCUMENTHEADER-REF_DOC_NO = LS_DATA-REF_NO.
LS_DOCUMENTHEADER-REASON_REV = LS_DATA-REV_REASON .
LS_DOCUMENTHEADER1-RBDAT = LS_DATA-REV_DATE .
ENDAT.
LS_ACCOUNTGL-ITEMNO_ACC = LS_DATA-GL_LINE_NUM .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_DATA-GL_ACCOUNT
IMPORTING
OUTPUT = LS_DATA-GL_ACCOUNT.
LS_ACCOUNTGL-GL_ACCOUNT = LS_DATA-GL_ACCOUNT.
LS_ACCOUNTGL-ITEM_TEXT = LS_DATA-LINE_TEXT .
LS_ACCOUNTGL-BUS_AREA = LS_DATA-BUSI_AREA.
LS_ACCOUNTGL-PLANT = LS_DATA-PLANT..
LS_ACCOUNTGL-ALLOC_NMBR = LS_DATA-ASSIGNMENT_NO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_DATA-PROFIT_CENTER
IMPORTING
OUTPUT = LS_DATA-PROFIT_CENTER.
LS_ACCOUNTGL-PROFIT_CTR = LS_DATA-PROFIT_CENTER.
LS_ACCOUNTGL-DISTR_CHAN = LS_DATA-DIST_CHAN....
LS_ACCOUNTGL-DIVISION = LS_DATA-DIVISION...
LS_ACCOUNTGL-SALESORG = LS_DATA-SALES_ORG.
LS_CURRENCYAMOUNT-ITEMNO_ACC = LS_DATA-GL_LINE_NUM.
LS_CURRENCYAMOUNT-CURRENCY = LS_DATA-DOC_CURRENCY.
LS_CURRENCYAMOUNT-AMT_DOCCUR = LS_DATA-DOC_AMOUNT.
APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
CLEAR : LV_BSSUBST .
SELECT SINGLE BSSUBST INTO LV_BSSUBST
FROM TKA3A
WHERE BUKRS = LS_DATA-COMP_CODE
AND KSTAR = LS_DATA-GL_ACCOUNT .
IF LS_DATA-COST_CENTER IS NOT INITIAL AND LV_BSSUBST IS NOT INITIAL..
LS_CRITERIA-ITEMNO_ACC = LS_DATA-GL_LINE_NUM.
LS_CRITERIA-FIELDNAME = 'COPA_KOSTL'.
CLEAR:LV_KOSTL.
LS_CRITERIA-CHARACTER = LS_DATA-COST_CENTER. "copa_kostl.
APPEND LS_CRITERIA TO LT_CRITERIA.
CLEAR LS_CRITERIA.
ELSEIF LS_DATA-COST_CENTER IS NOT INITIAL
AND LV_BSSUBST IS INITIAL.
LS_ACCOUNTGL-COSTCENTER = LS_DATA-COST_CENTER.
ENDIF.
APPEND LS_ACCOUNTGL TO LT_ACCOUNTGL.
**********COMMENTED BY JAYASHREE ON 02.08.2023
* LS_CRITERIA-ITEMNO_ACC = LS_DATA-GL_LINE_NUM.
* LS_CRITERIA-FIELDNAME = 'KNDNR'. "CUSTOMER
* CLEAR LV_KUNNR.
*********EOC
**************ADDED BY JAYASHREE ON 02.08.2023
IF LS_DATA-KNDNR IS NOT INITIAL.
LS_CRITERIA-ITEMNO_ACC = LS_DATA-GL_LINE_NUM.
LS_CRITERIA-FIELDNAME = 'KNDNR'. "CUSTOMER
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_DATA-KNDNR
IMPORTING
OUTPUT = LS_DATA-KNDNR.
LS_CRITERIA-CHARACTER = LS_DATA-KNDNR.
APPEND LS_CRITERIA TO LT_CRITERIA.
CLEAR LS_CRITERIA.
ENDIF.
*****EOC
CLEAR LV_KUNNR.
***********COMMENTED BY JAYASHREE ON 03.08.2023
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = LS_DATA-KNDNR
* IMPORTING
* OUTPUT = LS_DATA-KNDNR.
* LS_CRITERIA-CHARACTER = LS_DATA-KNDNR.
* APPEND LS_CRITERIA TO LT_CRITERIA.
* CLEAR LS_CRITERIA.
*****eoc
IF LS_DATA-SALES_GRP IS NOT INITIAL.
LS_CRITERIA-ITEMNO_ACC = LS_DATA-GL_LINE_NUM.
LS_CRITERIA-FIELDNAME = 'VKGRP'. "SALES GROUP
LS_CRITERIA-CHARACTER = LS_DATA-SALES_GRP.
APPEND LS_CRITERIA TO LT_CRITERIA.
CLEAR LS_CRITERIA.
ENDIF.
LS_EXTENSION-STRUCTURE = 'ACCIT'.
IF LS_DATA-BUPLA IS NOT INITIAL.
LS_EXTENSION-VALUEPART1 = LS_DATA-BUPLA.
LS_EXTENSION-VALUEPART2 = LS_DATA-GL_LINE_NUM.
APPEND LS_EXTENSION TO LT_EXTENSION.
CLEAR LS_EXTENSION.
ENDIF.
AT END OF SRNO.
CHECK LT_CURRENCYAMOUNT IS NOT INITIAL.
CLEAR LV_OBJ_KEY.
FREE LT_RETURN.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = LS_DOCUMENTHEADER
IMPORTING
OBJ_KEY = LV_OBJ_KEY
TABLES
ACCOUNTGL = LT_ACCOUNTGL
CURRENCYAMOUNT = LT_CURRENCYAMOUNT
CRITERIA = LT_CRITERIA
EXTENSION2 = LT_EXTENSION
RETURN = LT_RETURN.
READ TABLE LT_RETURN WITH KEY TYPE = 'E' TRANSPORTING NO FIELDS.
IF SY-SUBRC <> 0.
DATA : LV TYPE CHAR10,
LV1 TYPE BKPF-BELNR,
LV2 TYPE BKPF-BUKRS,
LV3 TYPE BKPF-GJAHR.
LOOP AT LT_RETURN INTO LS_RETURN WHERE MESSAGE_V2 IS NOT INITIAL.
MOVE LS_RETURN-MESSAGE_V2+0(10) TO LV1.
MOVE LS_RETURN-MESSAGE_V2+10(14) TO LV2.
MOVE LS_RETURN-MESSAGE_V2+14(18) TO LV3.
LS_DOCUMENTHEADER1-BELNR = LV1.
LS_DOCUMENTHEADER1-BUKRS = LV2.
LS_DOCUMENTHEADER1-GJAHR = LV3.
LS_DOCUMENTHEADER1-RBDAT = LS_DATA-REV_DATE.
APPEND LS_DOCUMENTHEADER1 TO LT_DOCUMENTHEADER1.
WA_MESSAGE-MESSAGE = LS_RETURN-MESSAGE.
WA_MESSAGE-TYPE = LS_RETURN-TYPE.
IF LS_RETURN-TYPE EQ 'S'.
WA_MESSAGE-BELNR = LV1.
ENDIF.
WA_MESSAGE-SRNO = LS_DATA-SRNO.
APPEND WA_MESSAGE TO IT_MESSAGE.
CLEAR : LV_MESSAGE,LV_TYPE.
ENDLOOP.
CLEAR WA_MESSAGE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = '3'.
COMMIT WORK AND WAIT.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ELSE.
CLEAR WA_MESSAGE.
LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = 'E'.
IF SY-SUBRC = 0.
WA_MESSAGE-SRNO = LS_DATA-SRNO.
WA_MESSAGE-MESSAGE = LS_RETURN-MESSAGE.
WA_MESSAGE-TYPE = LS_RETURN-TYPE.
CLEAR LV_MESSAGE.
WA_MESSAGE-BELNR = ' '.
APPEND WA_MESSAGE TO IT_MESSAGE.
ENDIF.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
REFRESH : LT_RETURN[] , LT_CURRENCYAMOUNT[] , LT_ACCOUNTGL[].
REFRESH : LT_CRITERIA[], LT_EXTENSION.
CLEAR : LS_DOCUMENTHEADER, LV_COUNT.
ENDAT.
CLEAR LV_KOSTL.
CLEAR: LS_DATA-COST_CENTER,LS_ACCOUNTGL.
ENDLOOP.
ENDIF.
ENDFORM.
FORM CALL_FM.
LOOP AT LT_DOCUMENTHEADER1 INTO LS_DOCUMENTHEADER1.
CALL FUNCTION 'TSTOR_INSERT'
EXPORTING
BELNR = LS_DOCUMENTHEADER1-BELNR
BUKRS = LS_DOCUMENTHEADER1-BUKRS
GJAHR = LS_DOCUMENTHEADER1-GJAHR
RBDAT = LS_DOCUMENTHEADER1-RBDAT
EXCn
EPTIONS
KEY_CONTAINS_SPACE = 1
RBDAT_INITIAL = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
***********fieldcat log *******************
ENDLOOP.
GS_FIELDCAT-COL_POS = '1'.
GS_FIELDCAT-FIELDNAME = 'SRNO'.
GS_FIELDCAT-SELTEXT_L = 'Serial Number'.
GS_FIELDCAT-OUTPUTLEN = '10'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
GS_FIELDCAT-COL_POS = '2'.
GS_FIELDCAT-FIELDNAME = 'BELNR'.
GS_FIELDCAT-SELTEXT_L = 'Document Number'.
GS_FIELDCAT-OUTPUTLEN = '10'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = '3'.
GS_FIELDCAT-FIELDNAME = 'TYPE'.
GS_FIELDCAT-SELTEXT_L = 'Type'.
GS_FIELDCAT-OUTPUTLEN = '10'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-COL_POS = '4'.
GS_FIELDCAT-FIELDNAME = 'MESSAGE'.
GS_FIELDCAT-SELTEXT_L = 'Message'.
GS_FIELDCAT-OUTPUTLEN = '1000'.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
*****************************************display_output*******************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = GS_LAYO
IT_FIELDCAT = GT_FIELDCAT
* IT_EXCLUDING =
TABLES
T_OUTTAB = IT_MESSAGE.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
output:
No comments:
Post a Comment