Вы находитесь на странице: 1из 9

REPORT ZFI_BAPI_FB01_CUSTOMER.

TYPE-POOLS: TRUXS , SLIS.


TABLES: BSEG.
*&--------------------------------------------------------------------*
* Internal Table
*&--------------------------------------------------------------------*
DATA: BEGIN OF I_FINAL OCCURS 0,
BUKRS
TYPE BUKRS,
" company code
BLDAT(10)
TYPE C,
" document dat
e
BLART
TYPE BLART,
" document typ
e
BUDAT(10)
TYPE C,
" posting date
WAERS
TYPE WAERS,
" currency
XBLNR
TYPE XBLNR,
" reference
BKTXT
TYPE BKTXT,
" doc header t
ext
BSCHL
TYPE BSCHL,
" posting key
KUNNR
TYPE KUNNR,
" CUSTOMER COD
E
REF1
TYPE XREF1,
" REF1
UMSKZ
TYPE ACPI_UMSKZ, " SPL GL INDIC
AOR
REF2
TYPE XREF2,
" REF2
HKONT
TYPE HKONT,
" GL Account
*
DMBTR_A
TYPE BAPIWRBTR, " Amount
DMBTR_LC
TYPE BAPIWRBTR, " Amount in LC
BASE_DT(10) TYPE C,
" BASE LINE DA
TE
PRCTR
TYPE PRCTR
, " Profit Cente
r
ZUONR
TYPE ACPI_ZUONR, " Assignment
SGTXT
TYPE SGTXT,
" line item te
xt
END
OF I_FINAL.
DATA : I_EXCEL LIKE ALSMEX_TABLINE OCCURS 0 WITH HEAD

ER LINE.
DATA : IT_RAW TYPE TRUXS_T_TEXT_DATA.
DATA : PD
TYPE D,
DD
TYPE D,
BD
TYPE D,
KUNNR_N TYPE KUNNR,
HKONT_N TYPE BSEG-HKONT,
IND
TYPE I,
COUNT
TYPE POSNR_ACC.
*************************data declaration for bapi***
****************************************
DATA: DOCUMENTHEADER
LIKE BAPIACHE09 ,
ACCOUNTGL
LIKE BAPIACGL09 OCCURS 0 WIT
H HEADER LINE,
ACCOUNTRECEIVABLE LIKE BAPIACAR09 OCCURS 0 WIT
H HEADER LINE,
CURRENCYAMOUNT
LIKE BAPIACCR09 OCCURS 0 WIT
H HEADER LINE,
RETURN
LIKE BAPIRET2
OCCURS 0 WIT
H HEADER LINE.
DATA: ERROR_FLAG.
*****************************end*********************
****************************************
*********************** Internal Table Declaration fo
r ALV
DATA: IT_FIELDCATALOG TYPE STANDARD TABLE OF SLIS_FIE
LDCAT_ALV.
**************************** Work Area Declaration fo
r ALV
DATA: WA_FIELDCATALOG TYPE SLIS_FIELDCAT_ALV,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
*&--------------------------------------------------------------------*
* selection screen
*&--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BE1 WITH FRAME TITLE
TEXT-003.
PARAMETERS: P_IFILE TYPE RLGRAP-FILENAME.

SELECTION-SCREEN END OF BLOCK BE1.


*--------------------------------------------------------------------*
*-- At Selection Screen
*--------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IFILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MODE
= 'O'
IMPORTING
FILENAME = P_IFILE
EXCEPTIONS
OTHERS
= 1.
*****************************************************
*********************
START-OF-SELECTION.
PERFORM UPLOAD_FILE.
PERFORM BAPI_DATA_ENTRY.
PERFORM RUN_BAPI.
PERFORM ALV_DISPLAY.
*&--------------------------------------------------------------------*
*&
Form UPLOAD_FILE
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
FORM UPLOAD_FILE .
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR
= 'X'
I_LINE_HEADER
= 'X'
I_TAB_RAW_DATA
= IT_RAW
I_FILENAME
= P_IFILE
TABLES
I_TAB_CONVERTED_DATA = I_FINAL[]

EXCEPTIONS
CONVERSION_FAILED
OTHERS

= 1
= 2.

IF SY-SUBRC <> 0.
MESSAGE 'Please Close the File you are uploading'
TYPE 'E'.
ENDIF.
ENDFORM.
" UPLOAD_FILE
*&--------------------------------------------------------------------*
*&
Form BAPI_DATA_ENTRY
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
FORM BAPI_DATA_ENTRY.
LOOP AT I_FINAL.
IND = SY-TABIX.
**********************************HEADER PART********
****************************************
IF IND = 1.
CONCATENATE I_FINAL-BLDAT+6(4) I_FINALBLDAT+3(2) I_FINAL-BLDAT(2) INTO DD.
CONCATENATE I_FINAL-BUDAT+6(4) I_FINALBUDAT+3(2) I_FINAL-BUDAT(2) INTO PD.
DOCUMENTHEADER-USERNAME
= SY-UNAME.
DOCUMENTHEADER-HEADER_TXT
= I_FINAL-BKTXT.
DOCUMENTHEADER-COMP_CODE
= I_FINAL-BUKRS.
DOCUMENTHEADER-DOC_DATE
= DD.
DOCUMENTHEADER-PSTNG_DATE
= PD.
DOCUMENTHEADER-DOC_TYPE
= I_FINAL-BLART.
DOCUMENTHEADER-REF_DOC_NO
= I_FINAL-XBLNR.
ENDIF.
*******************************ACCOUNT Payble PART**
********************************************
COUNT = COUNT + 1.
IF I_FINAL-BSCHL NE '50'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
INPUT = I_FINAL-KUNNR
IMPORTING
OUTPUT = KUNNR_N.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = I_FINAL-HKONT
IMPORTING
OUTPUT = HKONT_N.
ACCOUNTRECEIVABLE-ITEMNO_ACC = COUNT.
ACCOUNTRECEIVABLE-CUSTOMER
= KUNNR_N.
ACCOUNTRECEIVABLE-GL_ACCOUNT = HKONT_N.
ACCOUNTRECEIVABLE-REF_KEY_1
= I_FINAL-REF1.
ACCOUNTRECEIVABLE-REF_KEY_2
= I_FINAL-REF2.
ACCOUNTRECEIVABLE-COMP_CODE
= I_FINAL-BUKRS.
CONCATENATE I_FINAL-BASE_DT+6(4) I_FINALBASE_DT+3(2) I_FINAL-BASE_DT(2) INTO BD.
ACCOUNTRECEIVABLE-BLINE_DATE = BD.
ACCOUNTRECEIVABLE-ALLOC_NMBR = I_FINAL-ZUONR.
ACCOUNTRECEIVABLE-ITEM_TEXT
= I_FINAL-SGTXT.
IF I_FINAL-BSCHL EQ '19'.
ACCOUNTRECEIVABLE-SP_GL_IND = I_FINAL-UMSKZ.
ENDIF.
APPEND ACCOUNTRECEIVABLE.
CLEAR: ACCOUNTRECEIVABLE , KUNNR_N , HKONT_N ,
BD.
ENDIF.
*************************************Account GL Part*
********************************************
IF I_FINAL-BSCHL EQ '50'.
ACCOUNTGL-ITEMNO_ACC = COUNT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = I_FINAL-HKONT
IMPORTING

OUTPUT = HKONT_N.
ACCOUNTGL-GL_ACCOUNT
= HKONT_N.
ACCOUNTGL-REF_KEY_1
= I_FINAL-REF1.
ACCOUNTGL-REF_KEY_2
= I_FINAL-REF2.
ACCOUNTGL-COMP_CODE
= I_FINAL-BUKRS.
ACCOUNTGL-PSTNG_DATE
= PD.
ACCOUNTGL-DOC_TYPE
= I_FINAL-BLART.
ACCOUNTGL-ALLOC_NMBR
= I_FINAL-ZUONR.
ACCOUNTGL-ITEM_TEXT
= I_FINAL-SGTXT.
ACCOUNTGL-PROFIT_CTR
= I_FINAL-PRCTR.
APPEND ACCOUNTGL.
CLEAR: ACCOUNTGL , HKONT_N.
ENDIF.
*******************************CURRENCY PART*********
***************************************
IF I_FINAL-WAERS EQ 'CNY'.
CURRENCYAMOUNT-ITEMNO_ACC = COUNT.
CURRENCYAMOUNT-CURRENCY
= I_FINAL-WAERS.
CURRENCYAMOUNT-AMT_DOCCUR = I_FINAL-DMBTR_LC.
APPEND CURRENCYAMOUNT.
CLEAR CURRENCYAMOUNT.
*
ELSE.
*
CURRENCYAMOUNT-ITEMNO_ACC = COUNT.
*
CURRENCYAMOUNT-CURRENCY
= I_FINAL-WAERS.
*
CURRENCYAMOUNT-AMT_DOCCUR = I_FINAL-DMBTR_A.
*
IF I_FINAL-DMBTR_A IS NOT INITIAL AND I_FINALDMBTR_LC IS NOT INITIAL.
*
CURRENCYAMOUNT-EXCH_RATE = I_FINALDMBTR_LC / I_FINAL-DMBTR_A .
*
ENDIF.
*
APPEND CURRENCYAMOUNT.
*
CLEAR CURRENCYAMOUNT.
ENDIF.
******************************CURRENCY PART**********
*****************************************

ENDLOOP.

ENDFORM.

"BAPI_DATA_ENTRY

**&--------------------------------------------------------------------*
**&
Form RUN_BAPI
**&--------------------------------------------------------------------*
**
text
**---------------------------------------------------------------------*
FORM RUN_BAPI.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER
= DOCUMENTHEADER
*
CUSTOMERCPD
=
*
CONTRACTHEADER
=
*
IMPORTING
*
OBJ_TYPE
=
*
OBJ_KEY
=
*
OBJ_SYS
=
TABLES
ACCOUNTGL
= ACCOUNTGL[]
ACCOUNTRECEIVABLE
= ACCOUNTRECEIVABLE[]
*
ACCOUNTPAYABLE
=
*
ACCOUNTTAX
=
CURRENCYAMOUNT
= CURRENCYAMOUNT[]
*
CRITERIA
=
*
VALUEFIELD
=
*
EXTENSION1
=
RETURN
= RETURN[]
*
PAYMENTCARD
=
*
CONTRACTITEM
=
*
EXTENSION2
=
*
REALESTATE
=
*
ACCOUNTWT
=
.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING

*
*

WAIT
IMPORTING
RETURN
.

= 'X'
=

ENDIF.
ENDFORM.

"RUN_BAPI

*&--------------------------------------------------------------------*
*&
Form ALV_DISPLAY
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
FORM ALV_DISPLAY.
WA_FIELDCATALOG-FIELDNAME = 'TYPE'.
WA_FIELDCATALOG-SELTEXT_M = 'TYPE'.
WA_FIELDCATALOG-TABNAME
= 'RETURN'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME
WA_FIELDCATALOG-SELTEXT_M
WA_FIELDCATALOG-TABNAME
APPEND WA_FIELDCATALOG TO
CLEAR WA_FIELDCATALOG.

= 'MESSAGE'.
= 'MESSAGE'.
= 'RETURN'.
IT_FIELDCATALOG.

WA_FIELDCATALOG-FIELDNAME
WA_FIELDCATALOG-SELTEXT_M
WA_FIELDCATALOG-TABNAME
APPEND WA_FIELDCATALOG TO
CLEAR WA_FIELDCATALOG.

= 'MESSAGE_V1'.
= 'MESSAGE_V1'.
= 'RETURN'.
IT_FIELDCATALOG.

WA_FIELDCATALOG-FIELDNAME
WA_FIELDCATALOG-SELTEXT_M
WA_FIELDCATALOG-TABNAME
APPEND WA_FIELDCATALOG TO
CLEAR WA_FIELDCATALOG.

= 'MESSAGE_V2'.
= 'MESSAGE_V2'.
= 'RETURN'.
IT_FIELDCATALOG.

WA_FIELDCATALOG-FIELDNAME
WA_FIELDCATALOG-SELTEXT_M
WA_FIELDCATALOG-TABNAME
APPEND WA_FIELDCATALOG TO
CLEAR WA_FIELDCATALOG.

= 'MESSAGE_V3'.
= 'MESSAGE_V3'.
= 'RETURN'.
IT_FIELDCATALOG.

WA_FIELDCATALOG-FIELDNAME
WA_FIELDCATALOG-SELTEXT_M
WA_FIELDCATALOG-TABNAME
APPEND WA_FIELDCATALOG TO
CLEAR WA_FIELDCATALOG.

= 'MESSAGE_V4'.
= 'MESSAGE_V4'.
= 'RETURN'.
IT_FIELDCATALOG.

WA_LAYOUT-NO_INPUT = 'X'.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
WA_LAYOUT-ZEBRA = 'X'.

*
*

*
*

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_CALLBACK_PROGRAM
= SY-REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
i_callback_user_command = 'USER_COMMAND'
IS_LAYOUT
= WA_LAYOUT
IT_FIELDCAT
= IT_FIELDCATALOG[]
it_sort
= i_sort
I_SAVE
= 'A'
TABLES
T_OUTTAB
= RETURN[]
EXCEPTIONS
PROGRAM_ERROR
= 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.

ENDFORM.

"ALV_DISPLAY