*&---------------------------------------------------------------------*
*& Include ZFB75_TOP
*&---------------------------------------------------------------------*
DATA: TEXT(4096) TYPE C OCCURS 0.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB TYPE STANDARD TABLE OF BDCMSGCOLL,
GT_MESSTAB TYPE STANDARD TABLE OF BDCMSGCOLL,
GV_STRING TYPE STRING,
LV_CHAR TYPE CHAR1250,
LV_CHAR1 TYPE CHAR1250,
LS_CTU TYPE CTU_PARAMS.
FIELD-SYMBOLS <LS_MESSTAB> TYPE BDCMSGCOLL. "FOR MESSAGE
*&---------------------------------------------------------------------*
*& DATA DECLARATION
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ST_MESSAGE,
SR_NO TYPE I,
LV_MSGTYP TYPE STRING,
LV_CRSTXT TYPE CHAR1250,
END OF ST_MESSAGE.
TYPES: BEGIN OF TY_FB70,
SERIAL TYPE I,
ACCNT TYPE INVFO-ACCNT, "Customer No.
BLDAT(10) TYPE C, "Doc Date
XBLNR TYPE INVFO-XBLNR, "Reference
WAERS TYPE INVFO-WAERS, "Currency Key
BUPLA TYPE INVFO-BUPLA, "Business Place
SECCO TYPE INVFO-SECCO, "Section Code
SGTXT TYPE INVFO-SGTXT, "item text
HKONT TYPE ACGL_ITEM-HKONT, "G/L Account
WRBTR TYPE ACGL_ITEM-WRBTR, "Amount in Document Currency
MWSKZ TYPE ACGL_ITEM-MWSKZ, "Sale Taxes
SGTXT1 TYPE ACGL_ITEM-SGTXT, "Item Text
GSBER1 TYPE ACGL_ITEM-GSBER, "Business Area
PRCTR TYPE ACGL_ITEM-PRCTR, "Profit Center
HSN_SAC TYPE ACGL_ITEM-HSN_SAC, "HSN or SAC Code
END OF TY_FB70.
DATA: IT_FB75 TYPE TABLE OF TY_FB70 WITH HEADER LINE,
WA_FB75 TYPE TY_FB70.
DATA: IT_FB75_0 TYPE TABLE OF TY_FB70 WITH HEADER LINE,
WA_FB75_0 TYPE TY_FB70.
DATA: IT_EXLOAD LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: LV_TABIX TYPE SY-TABIX,
LV_ERR TYPE C.
DATA: GT_MSG TYPE TABLE OF ST_MESSAGE,
GS_MSG TYPE ST_MESSAGE,
GT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
GS_FCAT TYPE SLIS_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: WA_COUNT TYPE N,
WA_COUNT1 TYPE STRING,
LV_TAX_AMOUNT TYPE DMBTR,
TAX_AMOUNT TYPE DMBTR.
DATA: GT_TAX1 TYPE STANDARD TABLE OF RTAX1U15,
GS_TAX1 TYPE RTAX1U15.
DATA LS_CTU_PARAMS TYPE CTU_PARAMS.
LS_CTU_PARAMS-DISMODE = 'A'.
LS_CTU_PARAMS-UPDMODE = 'S'.
LS_CTU_PARAMS-NOBINPT = ' '.
*&---------------------------------------------------------------------*
* SELECTION SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME. "File path
PARAMETERS: W_BEGIN TYPE I OBLIGATORY, "Excel sheet start row
W_END TYPE I OBLIGATORY. "Excel sheet end row
SELECTION-SCREEN: END OF BLOCK B1.
*&---------------------------------------------------------------------*
* SELECTION SCREEN VALIDATION AND INPUT.
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE.
*&---------------------------------------------------------------------*
*& Include ZFB75_FORMS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
* CALL EXCEL SHEET FROM SELECTION SCREEN AND UPLOAD IN INTERNAL TABLE
*----------------------------------------------------------------------*
FORM UPLOAD_FILE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = '0001'
I_BEGIN_ROW = W_BEGIN
I_END_COL = '0012'
I_END_ROW = W_END
TABLES
INTERN = IT_EXLOAD
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF IT_EXLOAD IS NOT INITIAL.
LOOP AT IT_EXLOAD.
CASE IT_EXLOAD-COL.
WHEN '0001'.
IT_FB75-SERIAL = IT_EXLOAD-VALUE.
WHEN '0002'.
IT_FB75-ACCNT = IT_EXLOAD-VALUE.
WHEN '0003'.
IT_FB75-BLDAT = IT_EXLOAD-VALUE.
WHEN '0004'.
IT_FB75-XBLNR = IT_EXLOAD-VALUE.
WHEN '0005'.
IT_FB75-WAERS = IT_EXLOAD-VALUE.
WHEN '0006'.
IT_FB75-SGTXT = IT_EXLOAD-VALUE.
WHEN '0007'.
IT_FB75-HKONT = IT_EXLOAD-VALUE.
WHEN '0008'.
IT_FB75-WRBTR = IT_EXLOAD-VALUE.
WHEN '0009'.
IT_FB75-MWSKZ = IT_EXLOAD-VALUE.
WHEN '0010'.
IT_FB75-SGTXT1 = IT_EXLOAD-VALUE.
WHEN '0011'.
IT_FB75-PRCTR = IT_EXLOAD-VALUE.
WHEN '0012'.
IT_FB75-HSN_SAC = IT_EXLOAD-VALUE.
ENDCASE.
AT END OF ROW.
APPEND IT_FB75.
CLEAR IT_FB75.
ENDAT.
ENDLOOP.
IT_FB75_0[] = IT_FB75[].
SORT IT_FB75 BY ACCNT.
DELETE ADJACENT DUPLICATES FROM IT_FB75 COMPARING ACCNT XBLNR.
ENDIF.
ENDFORM. " UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form CALL_BDC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_BDC .
LOOP AT IT_FB75 INTO WA_FB75.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'RF05A-BUSCS' 'G'.
PERFORM BDC_FIELD USING 'INVFO-ACCNT' WA_FB75-ACCNT.
PERFORM BDC_FIELD USING 'INVFO-BLDAT' WA_FB75-BLDAT.
PERFORM BDC_FIELD USING 'INVFO-XBLNR' WA_FB75-XBLNR.
PERFORM BDC_FIELD USING 'INVFO-WAERS' WA_FB75-WAERS.
PERFORM BDC_FIELD USING 'INVFO-BUPLA' 'NASK'.
PERFORM BDC_FIELD USING 'INVFO-SECCO' 'NASK'.
PERFORM BDC_FIELD USING 'INVFO-SGTXT' WA_FB75-SGTXT.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'ACGL_ITEM-HSN_SAC(01)'.
LOOP AT IT_FB75_0 INTO WA_FB75_0 WHERE ACCNT EQ WA_FB75-ACCNT
AND XBLNR EQ WA_FB75-XBLNR.
WA_COUNT = WA_COUNT + 1.
CONCATENATE 'ACGL_ITEM-HKONT' '(' WA_COUNT ')' INTO WA_COUNT1.
PERFORM BDC_FIELD USING WA_COUNT1 WA_FB75_0-HKONT.
CLEAR WA_COUNT1.
CONCATENATE 'ACGL_ITEM-WRBTR' '(' WA_COUNT ')' INTO WA_COUNT1.
PERFORM BDC_FIELD USING WA_COUNT1 WA_FB75_0-WRBTR.
CLEAR WA_COUNT1.
CONCATENATE 'ACGL_ITEM-MWSKZ' '(' WA_COUNT ')' INTO WA_COUNT1.
PERFORM BDC_FIELD USING WA_COUNT1 WA_FB75_0-MWSKZ.
CLEAR WA_COUNT1.
**** To Tax calculate
IF WA_FB75_0-MWSKZ IS NOT INITIAL.
TAX_AMOUNT = TAX_AMOUNT + WA_FB75_0-WRBTR.
CLEAR GT_TAX1.
CALL FUNCTION 'CALCULATE_TAX_FROM_NET_AMOUNT'
EXPORTING
I_BUKRS = '2012'
I_MWSKZ = WA_FB75_0-MWSKZ
I_WAERS = 'INR'
I_WRBTR = WA_FB75_0-WRBTR
TABLES
T_MWDAT = GT_TAX1.
LOOP AT GT_TAX1 INTO GS_TAX1.
LV_TAX_AMOUNT = LV_TAX_AMOUNT + GS_TAX1-WMWST.
ENDLOOP.
ENDIF.
CONCATENATE 'ACGL_ITEM-SGTXT' '(' WA_COUNT ')' INTO WA_COUNT1.
PERFORM BDC_FIELD USING WA_COUNT1 WA_FB75_0-SGTXT.
CLEAR WA_COUNT1.
CONCATENATE 'ACGL_ITEM-PRCTR' '(' WA_COUNT ')' INTO WA_COUNT1.
PERFORM BDC_FIELD USING WA_COUNT1 WA_FB75_0-PRCTR.
CLEAR WA_COUNT1.
CONCATENATE 'ACGL_ITEM-HSN_SAC' '(' WA_COUNT ')' INTO WA_COUNT1.
PERFORM BDC_FIELD USING WA_COUNT1 WA_FB75_0-HSN_SAC.
CLEAR: WA_FB75_0, WA_COUNT1.
ENDLOOP.
WA_FB75-WRBTR = TAX_AMOUNT + LV_TAX_AMOUNT.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'ACGL_ITEM-HKONT(02)'.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=DUMMY'.
PERFORM BDC_FIELD USING 'RF05A-BUSCS' 'G'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'INVFO-XMWST'.
PERFORM BDC_FIELD USING 'INVFO-ACCNT' WA_FB75-ACCNT.
PERFORM BDC_FIELD USING 'INVFO-XBLNR' WA_FB75-XBLNR.
PERFORM BDC_FIELD USING 'INVFO-BUPLA' 'NASK'.
PERFORM BDC_FIELD USING 'INVFO-SECCO' 'NASK'.
PERFORM BDC_FIELD USING 'INVFO-SGTXT' WA_FB75-SGTXT.
PERFORM BDC_DYNPRO USING 'SAPMF05A' '1200'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BS'.
PERFORM BDC_FIELD USING 'RF05A-BUSCS' 'G'.
PERFORM BDC_FIELD USING 'BDC_CURSOR' 'INVFO-WRBTR'.
PERFORM BDC_FIELD USING 'INVFO-ACCNT' WA_FB75-ACCNT.
PERFORM BDC_FIELD USING 'INVFO-XBLNR' WA_FB75-XBLNR.
PERFORM BDC_FIELD USING 'INVFO-WRBTR' WA_FB75-WRBTR.
PERFORM BDC_FIELD USING 'INVFO-XMWST' 'X'.
PERFORM BDC_FIELD USING 'INVFO-BUPLA' 'NASK'.
PERFORM BDC_FIELD USING 'INVFO-SECCO' 'NASK'.
PERFORM BDC_FIELD USING 'INVFO-SGTXT' WA_FB75-SGTXT.
PERFORM BDC_DYNPRO USING 'SAPMSSY0' '0120'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.
CALL TRANSACTION 'FB75' USING BDCDATA
MODE 'N'
UPDATE 'S'
MESSAGES INTO MESSTAB.
LOOP AT MESSTAB ASSIGNING <LS_MESSTAB>.
IF <LS_MESSTAB>-MSGTYP EQ 'E' OR <LS_MESSTAB>-MSGTYP EQ 'S' .
GS_MSG-SR_NO = WA_FB75-SERIAL.
IF LV_ERR IS INITIAL.
IF <LS_MESSTAB>-MSGTYP EQ 'S' AND <LS_MESSTAB>-MSGNR EQ '060'.
GS_MSG-LV_MSGTYP = 'Error'.
LV_ERR = 'X'.
ELSEIF <LS_MESSTAB>-MSGTYP EQ 'E' .
GS_MSG-LV_MSGTYP = 'Error'.
LV_ERR = 'X'.
ELSEIF <LS_MESSTAB>-MSGTYP EQ 'S'.
GS_MSG-LV_MSGTYP = 'Success'.
ELSE.
GS_MSG-LV_MSGTYP = <LS_MESSTAB>-MSGTYP.
ENDIF.
ENDIF.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = <LS_MESSTAB>-MSGID
LANG = SY-LANGU
NO = <LS_MESSTAB>-MSGNR
V1 = <LS_MESSTAB>-MSGV1
V2 = <LS_MESSTAB>-MSGV2
V3 = <LS_MESSTAB>-MSGV3
V4 = <LS_MESSTAB>-MSGV4
IMPORTING
MSG = LV_CHAR1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATA : CHAR(1) TYPE C VALUE ' '.
CONCATENATE GS_MSG-LV_CRSTXT LV_CHAR1 '/' INTO GS_MSG-LV_CRSTXT SEPARATED BY CHAR.
CLEAR : LV_CHAR1,CHAR.
AT LAST .
APPEND GS_MSG TO GT_MSG.
CLEAR :GS_MSG.
ENDAT.
ENDIF.
ENDLOOP.
CLEAR: GS_MSG ,LS_CTU_PARAMS ,LV_TABIX, LV_ERR,WA_FB75, WA_COUNT, TAX_AMOUNT, LV_TAX_AMOUNT.
REFRESH: BDCDATA , MESSTAB.
ENDLOOP.
DELETE GT_MSG WHERE LV_MSGTYP EQ 'W'.
SORT GT_MSG BY SR_NO.
* PERFORM FCAT USING '1' 'SR_NO' 'Excel Row No' 'GT_MSG' ' '.
PERFORM FCAT USING '2' 'LV_MSGTYP' 'Message Type' 'GT_MSG' ' '.
PERFORM FCAT USING '5' 'LV_CRSTXT' 'Message' 'GET_MSG' ' '.
GS_LAYOUT-ZEBRA = 'X'.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FCAT
TABLES
T_OUTTAB = GT_MSG
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM. "CALL_BDC
"CALL_BDC
*&---------------------------------------------------------------------*
*& Form FCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FCAT USING P_COL
P_FIELDNAME
P_DESCRIPTION
P_TABNAME
P_KEY.
GS_FCAT-COL_POS = P_COL.
GS_FCAT-FIELDNAME = P_FIELDNAME.
GS_FCAT-SELTEXT_L = P_DESCRIPTION.
GS_FCAT-TABNAME = P_TABNAME.
GS_FCAT-KEY = P_KEY.
APPEND GS_FCAT TO GT_FCAT.
CLEAR GS_FCAT.
ENDFORM. "fcat
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
SHIFT BDCDATA-FVAL LEFT DELETING LEADING SPACE.
APPEND BDCDATA.
ENDFORM. "bdc_field