Sei sulla pagina 1di 64

*&---------------------------------------------------------------------*

*& Report ZFBV1_VENDOR


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZFI_DOC_PARK2.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: IT_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA: FCAT TYPE TABLE OF SLIS_FIELDCAT_ALV WITH NON-UNIQUE DEFAULT KEY WITH H
EADER LINE INITIAL SIZE 0.
DATA: L_INTERN LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: FILENAME_EXL TYPE RLGRAP-FILENAME.
TYPES: BEGIN OF TY_ITAB,
SNO(03),
BUKRS(004),""COMPANY CODE
BLDAT(010),""DOC DATE
BUDAT(010),"" POSTING DATE
BLART(002),"" DOC TYPE
WAERS(005),"" CURR
XBLNR(016),""REFERENCE
BKTXT(025),""DOC.HEADER TEXT
NEWBS(02),""PKEY
NEWKO(017),""ACCOUNT
WRBTR(016)," TYPE p DECIMALS 2, "(013)," TYPE bseg-wrbtr, "(016),"""AMOU
NT
MWSKZ(002),""TAX
ZUONR(018),""ASSIGNMENT
SGTXT(050),"" TEXT
GSBER(004),""BUS AREA
KOSTL(010),"" COST CENTER
AUFNR(010),"" ORDER
PRCTR(010),"" PROFIT CENTER
END OF TY_ITAB.
DATA: IT_ITAB TYPE TABLE OF TY_ITAB,
WA_ITAB TYPE TY_ITAB,
WA_ITAB_T TYPE TY_ITAB,
IT_ITAB2 TYPE TABLE OF TY_ITAB,
IT_ITAB3 TYPE TABLE OF TY_ITAB,
WA_ITAB2 TYPE TY_ITAB,
WA_ITAB3 TYPE TY_ITAB.
DATA:GV_SNO(3) TYPE C.
TYPES : BEGIN OF TY_MSG,
SNO TYPE NUMC3,
MSGTYP(1) TYPE C,
TEXT TYPE CHAR100,
END OF TY_MSG.
DATA:IT_MSG TYPE TABLE OF TY_MSG,
WA_MSG TYPE TY_MSG.
FIELD-SYMBOLS : <FS>.
DATA : L_INDEX TYPE I,
CTR TYPE I VALUE 0,
LV_DOCTYPE(2) TYPE C.
.
SELECTION-SCREEN: BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME,
* P_TMODE TYPE MODE DEFAULT 'N',"NO-DISPLAY. " FILE
PATH
RADIO_KR RADIOBUTTON GROUP RA1 MODIF ID M1,"1
RADIO_KG RADIOBUTTON GROUP RA1 MODIF ID M1,"2
RADIO_KZ RADIOBUTTON GROUP RA1 MODIF ID M1,"3
RADIO_KA RADIOBUTTON GROUP RA1 MODIF ID M1,"4
RADIO_SA RADIOBUTTON GROUP RA1 MODIF ID M1,"5
RADIO_AB RADIOBUTTON GROUP RA1 MODIF ID M1,"6
RADIO_DG RADIOBUTTON GROUP RA1 MODIF ID M1,"7
RADIO_DA RADIOBUTTON GROUP RA1 MODIF ID M1,"8
RADIO_DZ RADIOBUTTON GROUP RA1 MODIF ID M1,"9
radio_dr RADIOBUTTON GROUP ra1 MODIF ID m1.
SELECTION-SCREEN: END OF BLOCK A1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM UPLOAD_FILE.
START-OF-SELECTION.
PERFORM FILL_TABLE.
IT_ITAB2 = IT_ITAB.
REFRESH IT_ITAB.
SORT IT_ITAB2 BY SNO.
LOOP AT IT_ITAB2 INTO WA_ITAB2.
APPEND WA_ITAB2 TO IT_ITAB.
LV_DOCTYPE = WA_ITAB2-BLART.
CLEAR:WA_ITAB2.
AT END OF SNO.
IF LV_DOCTYPE = 'KR' AND RADIO_KR = 'X'.
PERFORM GET_DATA_KR.
ENDIF.
IF LV_DOCTYPE = 'KZ' AND RADIO_KZ = 'X'.
PERFORM GET_DATA_KZ_ITAB.
ENDIF.
IF LV_DOCTYPE = 'KG' AND RADIO_KG = 'X'.
PERFORM GET_DATA_KG_ITAB.
ENDIF.
IF LV_DOCTYPE = 'KA' AND RADIO_KA = 'X'.
PERFORM GET_DATA_KA_ITAB.
ENDIF.
IF LV_DOCTYPE = 'SA' AND RADIO_SA = 'X'.
PERFORM GET_DATA_SA_ITAB.
ENDIF.

IF LV_DOCTYPE = 'AB' AND RADIO_AB = 'X'.


PERFORM GET_DATA_AB_ITAB.
ENDIF.
IF LV_DOCTYPE = 'DG' AND RADIO_DG = 'X'.
PERFORM GET_DATA_DG_ITAB.
ENDIF.
IF LV_DOCTYPE = 'DA' AND RADIO_DA = 'X'.
PERFORM GET_DATA_DA_ITAB.
ENDIF.
IF LV_DOCTYPE = 'DZ' AND RADIO_DZ = 'X'.
PERFORM GET_DATA_DZ_ITAB.
ENDIF.
IF LV_DOCTYPE = 'DR' AND RADIO_DR = 'X'.
PERFORM GET_DATA_DR_ITAB.
ENDIF.
REFRESH IT_ITAB.
CLEAR:LV_DOCTYPE.
ENDAT.
CLEAR :WA_ITAB2.
ENDLOOP.

CALL FUNCTION 'HR_IT_SHOW_ANY_TABLE_ON_ALV'


TABLES
TABLE = it_msg
* EXCEPTIONS
* FB_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

FORM UPLOAD_FILE .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
ENDFORM.
FORM FILL_TABLE .
MOVE P_FILE TO FILENAME_EXL.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = FILENAME_EXL
I_BEGIN_COL = '1'
I_BEGIN_ROW = '2'
I_END_COL = '256'
I_END_ROW = '10000'
TABLES
INTERN = L_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC NE 0.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE : / 'FILE ERROR'.
EXIT.
ELSE.
SORT L_INTERN BY ROW COL.
LOOP AT L_INTERN.
MOVE L_INTERN-COL TO L_INDEX.
ASSIGN COMPONENT L_INDEX OF STRUCTURE WA_ITAB TO <FS>.
MOVE L_INTERN-VALUE TO <FS>.
AT END OF ROW.
APPEND WA_ITAB TO IT_ITAB.
CLEAR WA_ITAB.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " FILL_TABLE
FORM GET_DATA_KR.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
* FS006_FB01 TYPE FS006.

TABLES: WITH_ITEM.
DATA : H_LFBW TYPE LFBW OCCURS 0 WITH HEADER LINE,
H_T001WT TYPE T001WT OCCURS 0 WITH HEADER LINE,
T_BSEZ TYPE BSEZ OCCURS 0 WITH HEADER LINE,
FS006_FB01 TYPE FS006,
T_BKPF TYPE BKPF OCCURS 0 WITH HEADER LINE,
T_BSEG TYPE BSEG OCCURS 0 WITH HEADER LINE,
I_WITH_ITEM TYPE WITH_ITEMX OCCURS 0 WITH HEADER LINE,
T_BSEC TYPE TABLE OF BSEC,
T_BSET TYPE TABLE OF BSET,
LV_BELNR TYPE VBKPF-BELNR,
* LV_BUKRS TYPE VBKPF-BUKRS VALUE '1001',
* LV_GJAHR TYPE VBKPF-GJAHR,
* LV_LIFNR TYPE BSEG-LIFNR VALUE 'MAS1022',
* XMSG LIKE FIMSG1 OCCURS 0 WITH HEADER LINE,
* XVBKPF TYPE VBKPF OCCURS 0 WITH HEADER LINE,
* LV_BUDAT TYPE BKPF-BUDAT,
LV_SLNO TYPE NUMC4.

DATA: ET_RETURN LIKE TABLE OF BAPIRET2, "Return Table


WA_RETURN TYPE BAPIRET2, "Return work area
* lv_belnr TYPE belnr_d, "Document number
LV_TEXT TYPE BAPI_MSG,
* E_BELNR TYPE BELNR_D,
T_RETURN LIKE TABLE OF BAPIRET2, "Document number.
"Message
* DATA : LV_BELNR TYPE VBKPF-BELNR,
* LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
E_BELNR TYPE CHAR10,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE.

SORT IT_ITAB BY NEWBS.


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1 ."WA_ITAB-NEWBS = '31'.
WA_BKPF-BUKRS = WA_ITAB-BUKRS.
WA_BKPF-GJAHR = SY-DATUM+0(4).
WA_BKPF-BLART = 'KR'.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

* WA_BKPF-BLDAT = SY-DATUM.
* WA_BKPF-BUDAT = SY-DATUM.
WA_BKPF-MONAT = FISCAL_PERIOD.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBU'.
WA_BKPF-HWAER = 'INR'.
WA_BKPF-XMWST = 'X'.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '31' OR WA_ITAB-NEWBS = '40'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.

* WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '31'.
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-ZUONR.

WA_BSEG-ZUONR = WA_ITAB-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-LIFNR. "wa_bseg-hkont

* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.

IF WA_ITAB-NEWBS = '40'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
* wa_bseg-zuonr = wa_itab-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
* wa_bseg-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
* wa_bseg-XKRES = 'X'.
* wa_bseg-XOPVW = 'X'.
* CLEAR:lv_hkont.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-HKONT.

LV_HKONT = WA_ITAB-NEWKO.
* SELECT SINGLE akont INTO lv_akont FROM lfb1 WHERE lifnr = wa_itab-NEWKO A
ND bukrs = wa_itab-bukrs.
* wa_mseg-saknr = lv_akont.
* wa_bseg-hkont = lv_hkont.
* wa_mseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.
CLEAR:WA_BSEG.
ENDLOOP.
*
* CALL FUNCTION 'FI_WT_READ_T001WT'
* EXPORTING
* I_BUKRS = 'SAFF'
** I_TYPE =
* TABLES
* T_T001WT = H_T001WT
* EXCEPTIONS
* NOT_FOUND = 1
* OTHERS = 2.
*
*
* CALL FUNCTION 'FI_WT_READ_LFBW'
* EXPORTING
* I_LIFNR = '0001000003'
* I_BUKRS = 'SAFF'
** I_TYPE =
* TABLES
* T_LFBW = H_LFBW
* EXCEPTIONS
* NOT_FOUND = 1
* OTHERS = 2.
*
*
* LOOP AT H_LFBW.
**--- vendor subjected to wt type
* IF H_LFBW-WT_SUBJCT = 'X'.
*
* READ TABLE H_T001WT WITH KEY
* WITHT = H_LFBW-WITHT.
*
* IF SY-SUBRC EQ 0.
* IF H_T001WT-WT_AGENT = 'X' AND
* H_T001WT-WT_AGTDF LE lv_BUDAT AND
* H_T001WT-WT_AGTDT GE lv_BUDAT.
*
* MOVE-CORRESPONDING H_LFBW TO I_WITH_ITEM.
* I_WITH_ITEM-WT_WTEXMN = H_LFBW-WT_EXNR.
* I_WITH_ITEM-BUZEI = '1'. " <---- Vendor Item No
* I_WITH_ITEM-WT_QSSHH = '2000'. "<--- Line item 2 amount
* APPEND I_WITH_ITEM.
* ENDIF.
* ENDIF.
* ENDIF.
*ENDLOOP.
*
*CALL FUNCTION 'FI_WT_PUT_X_WITH_ITEM'
* TABLES
* T_WITH_ITEM = I_WITH_ITEM.

CALL FUNCTION 'PRELIMINARY_POSTING_FB01'


EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
** I_UF05A =
I_XCMPL = ' '
* FS006_FB01 = FS006_FB01
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT = 'F-02'
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
T_BKORM = IT_BKORM
T_THEAD = IT_THEAD
T_SPLTTAB = IT_SPLTTAB
T_SPLTWT = IT_SPLTWT
T_MANDATE = IT_MANDATE
EXCEPTIONS
ERROR_MESSAGE = 1.
IF SY-SUBRC = 0.
* Document parked successfully
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
WA_MSG-SNO = LV_SLNO. "E_BELNR."TYPE NUMC3,
WA_MSG-MSGTYP = 'S'."(1) TYPE C,
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR WA_MSG.

ELSE.
* Error message capturing
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
*Return error messages back to Mulesoft
* T_RETURN[] = ET_RETURN[].
ENDIF.

ENDFORM.
FORM GET_DATA_KZ.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
DATA : LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD.
WA_BKPF-BUKRS = 'SAFF'. "WA_ITAB-BUKRS.
WA_BKPF-GJAHR = SY-DATUM+0(4).
WA_BKPF-BLART = 'KZ'."WA_ITAB-BLART.
WA_BKPF-BLDAT = SY-DATUM.
WA_BKPF-BUDAT = SY-DATUM.
WA_BKPF-MONAT = '05' ."FISCAL_PERIOD ."'04'.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = 'Test'. "WA_ITAB-XBLNR.
WA_BKPF-WAERS = 'INR'."WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBV'.
WA_BKPF-HWAER = 'INR'.
* WA_BKPF-XMWST = 'X'.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.

WA_BSEG-BUKRS = 'SAFF'. "WA_ITAB-BUKRS.


WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = '001'.
WA_BSEG-BSCHL = '50'."WA_ITAB-NEWBS.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = 'ADTD'."WA_I41200001TAB-GSBER.
WA_BSEG-HKONT = '0041200001'.
WA_BSEG-DMBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-WRBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWBT = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWSL = 'INR'."WA_ITAB-WAERS.
WA_BSEG-SGTXT = 'Test1'."WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
WA_BSEG-XZAHL = 'X'.
WA_BSEG-XBILK = 'X'.
WA_BSEG-KOSTL = 'CFATCTOS'.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
WA_BSEG-BUKRS = 'SAFF'. "WA_ITAB-BUKRS.
WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = '002'.
WA_BSEG-BSCHL = '25'."WA_ITAB-NEWBS.
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = 'ADTD'."WA_I41200001TAB-GSBER.
WA_BSEG-DMBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-WRBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWBT = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWSL = 'INR'."WA_ITAB-WAERS.
WA_BSEG-SGTXT = 'Test2'."WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
CLEAR:LV_AKONT,LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND BUKRS =
WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-LIFNR. "wa_bseg-hkont
WA_BSEG-SAKNR = '0020110001'.
WA_BSEG-HKONT = '0020110001'.
WA_BSEG-LIFNR = '0001000002'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
WA_BSEG-XZAHL = 'X'.
WA_BSEG-XBILK = 'X'.
WA_BSEG-KOSTL = 'CFATCTOS'.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.

CALL FUNCTION 'PRELIMINARY_POSTING_FB01'


EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
* I_UF05A =
I_XCMPL = 'X'
* FS006_FB01 =
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT =
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
* T_BKORM =
* T_THEAD =
* T_SPLTTAB =
* T_SPLTWT =
* T_MANDATE =
.

* SORT IT_ITAB BY NEWBS DESCENDING.


* CLEAR:LV_CNT.
* REFRESH: IT_BKPF,IT_BSEG.
* LOOP AT IT_ITAB INTO WA_ITAB.
* LV_SLNO = WA_ITAB-SNO.
* LV_CNT = LV_CNT + 1.
* IF WA_ITAB-NEWBS = '50'.
* WA_BKPF-BUKRS = WA_ITAB-BUKRS.
** WA_BKPF-GJAHR = SY-DATUM+0(4).
* WA_BKPF-BLART = WA_ITAB-BLART.
* WA_BKPF-BLDAT = SY-DATUM.
* WA_BKPF-BUDAT = SY-DATUM.
*
* CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* EXPORTING
* COMPANYCODEID = 'SAFF'
* POSTING_DATE = SY-DATUM
* IMPORTING
* FISCAL_YEAR = FISCAL_YEAR
* FISCAL_PERIOD = FISCAL_PERIOD
** RETURN =
* .
*
* WA_BKPF-GJAHR = FISCAL_YEAR. "SY-DATUM+0(4).
*
*
* WA_BKPF-MONAT = FISCAL_PERIOD ."'04'.
* WA_BKPF-WWERT = SY-DATUM.
* WA_BKPF-USNAM = SY-UNAME.
* WA_BKPF-TCODE = 'FB01'.
* WA_BKPF-XBLNR = WA_ITAB-XBLNR.
* WA_BKPF-WAERS = WA_ITAB-WAERS.
* WA_BKPF-GLVOR = 'RFBU'.
* WA_BKPF-HWAER = 'INR'.
* WA_BKPF-XMWST = 'X'.
* WA_BKPF-KUTY2 = 'M'.
* APPEND WA_BKPF TO IT_BKPF.
* CLEAR WA_BKPF.
* ENDIF.
*
* IF WA_ITAB-NEWBS = '50' OR WA_ITAB-NEWBS = '25'.
* WA_BSEG-BUKRS = WA_ITAB-BUKRS.
* WA_BSEG-GJAHR = SY-DATUM+0(4).
* WA_BSEG-BUZEI = LV_CNT.
* WA_BSEG-BSCHL = WA_ITAB-NEWBS.
* IF WA_ITAB-NEWBS = '50'.
* WA_BSEG-KOART = 'S'.
* WA_BSEG-SHKZG = 'H'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
** WA_BSEG-PRCTR = WA_ITAB-PRCTR.
** WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
* WA_BSEG-DMBTR = WA_ITAB-WRBTR.
* WA_BSEG-WRBTR = WA_ITAB-WRBTR.
* WA_BSEG-PSWBT = WA_ITAB-WRBTR.
* WA_BSEG-PSWSL = WA_ITAB-WAERS.
** WA_BSEG-ZUONR = WA_ITAB-NEWKO.
* WA_BSEG-SGTXT = WA_ITAB-SGTXT.
* WA_BSEG-VORGN = 'RFBU'.
** WA_BSEG-XUMSW = 'X'.
** WA_BSEG-XHRES = 'X'.
* WA_BSEG-XKRES = 'X'.
* WA_BSEG-XOPVW = 'X'.
* WA_BSEG-XZAHL = 'X'.
* WA_BSEG-XBILK = 'X'.
** CLEAR:LV_AKONT,LV_NEWKO.
** LV_NEWKO = WA_ITAB-NEWKO.
** SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND
BUKRS = WA_ITAB-BUKRS.
** WA_BSEG-SAKNR = LV_AKONT.
** WA_BSEG-HKONT = LV_AKONT.
**
** CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
** EXPORTING
** INPUT = WA_ITAB-NEWKO
** IMPORTING
** OUTPUT = WA_BSEG-LIFNR. "wa_bseg-hkont
*
*
*
*
*
** wa_bseg-lifnr = wa_itab-newko.
* WA_BSEG-ZFBDT = SY-DATUM.
* ENDIF.
*
*
* IF WA_ITAB-NEWBS = '25'.
* WA_BSEG-KOART = 'K'.
* WA_BSEG-SHKZG = 'S'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
* WA_BSEG-PRCTR = WA_ITAB-PRCTR.
* WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
* WA_BSEG-DMBTR = WA_ITAB-WRBTR.
* WA_BSEG-WRBTR = WA_ITAB-WRBTR.
* WA_BSEG-PSWBT = WA_ITAB-WRBTR.
* WA_BSEG-PSWSL = WA_ITAB-WAERS.
* WA_BSEG-ZUONR = WA_ITAB-NEWKO.
* WA_BSEG-SGTXT = WA_ITAB-SGTXT.
* WA_BSEG-VORGN = 'RFBU'.
* WA_BSEG-KOSTL = WA_ITAB-KOSTL.
** wa_bseg-XUMSW = 'X'.
* WA_BSEG-XHRES = 'X'.
* WA_BSEG-XKRES = 'X'.
* WA_BSEG-XOPVW = 'X'.
* WA_BSEG-XZAHL = 'X'.
* WA_BSEG-XBILK = 'X'.
** CLEAR:lv_hkont.
* CLEAR:LV_AKONT,LV_NEWKO.
* LV_NEWKO = WA_ITAB-NEWKO.
* SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND
BUKRS = WA_ITAB-BUKRS.
* WA_BSEG-SAKNR = LV_AKONT.
* WA_BSEG-HKONT = LV_AKONT.
*
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = WA_ITAB-NEWKO
* IMPORTING
* OUTPUT = WA_BSEG-LIFNR. "wa_bseg-hkont
*
*
** CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
** EXPORTING
** INPUT = WA_ITAB-NEWKO
** IMPORTING
** OUTPUT = WA_BSEG-HKONT.
**
**
** LV_HKONT = WA_ITAB-NEWKO.
*
*
*
** CLEAR:lv_akont .
** SELECT SINGLE akont INTO lv_akont FROM lfb1 WHERE lifnr = wa_itab-NEWKO
AND bukrs = wa_itab-bukrs.
** wa_mseg-saknr = lv_akont.
** wa_bseg-hkont = lv_hkont.
**
**
** CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
** EXPORTING
** INPUT = WA_ITAB-NEWKO
** IMPORTING
** OUTPUT = WA_BSEG-LIFNR. "wa_bseg-hkont
*
*
*
** wa_mseg-lifnr = wa_itab-newko.
** wa_bseg-prctr = wa_itab-prctr.
* WA_BSEG-ZFBDT = SY-DATUM.
* ENDIF.
* APPEND WA_BSEG TO IT_BSEG.
*
* ENDIF.
* CLEAR:WA_BSEG.
* ENDLOOP.
*
**
** CALL FUNCTION 'FI_WT_READ_T001WT'
** EXPORTING
** I_BUKRS = 'SAFF'
*** I_TYPE =
** TABLES
** T_T001WT = H_T001WT
** EXCEPTIONS
** NOT_FOUND = 1
** OTHERS = 2.
**
**
** CALL FUNCTION 'FI_WT_READ_LFBW'
** EXPORTING
** I_LIFNR = '0001000003'
** I_BUKRS = 'SAFF'
*** I_TYPE =
** TABLES
** T_LFBW = H_LFBW
** EXCEPTIONS
** NOT_FOUND = 1
** OTHERS = 2.
**
**
** LOOP AT H_LFBW.
***--- vendor subjected to wt type
** IF H_LFBW-WT_SUBJCT = 'X'.
**
** READ TABLE H_T001WT WITH KEY
** WITHT = H_LFBW-WITHT.
**
** IF SY-SUBRC EQ 0.
** IF H_T001WT-WT_AGENT = 'X' AND
** H_T001WT-WT_AGTDF LE lv_BUDAT AND
** H_T001WT-WT_AGTDT GE lv_BUDAT.
**
** MOVE-CORRESPONDING H_LFBW TO I_WITH_ITEM.
** I_WITH_ITEM-WT_WTEXMN = H_LFBW-WT_EXNR.
** I_WITH_ITEM-BUZEI = '1'. " <---- Vendor Item No
** I_WITH_ITEM-WT_QSSHH = '2000'. "<--- Line item 2 amount
** APPEND I_WITH_ITEM.
** ENDIF.
** ENDIF.
** ENDIF.
**ENDLOOP.
**
**CALL FUNCTION 'FI_WT_PUT_X_WITH_ITEM'
** TABLES
** T_WITH_ITEM = I_WITH_ITEM.
*
*
*
*
*
*
*
*
*
*
* CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
* EXPORTING
* TEXT_UPDATE = 'X'
** TEXT_ITEM_UPDATE = ' '
*** I_UF05A =
* I_XCMPL = ' '
** FS006_FB01 = FS006_FB01
* I_TCODE = 'FB01'
** I_PARGB =
** I_TCODE_INT = 'F-02'
** IMPORTING
** XEPBBP =
* TABLES
* T_BKPF = IT_BKPF
* T_BSEG = IT_BSEG
* T_BSEC = IT_BSEC
* T_BSET = IT_BSET
* T_BSEZ = IT_BSEZ
* T_BKORM = IT_BKORM
* T_THEAD = IT_THEAD
* T_SPLTTAB = IT_SPLTTAB
* T_SPLTWT = IT_SPLTWT
* T_MANDATE = IT_MANDATE
* EXCEPTIONS
* ERROR_MESSAGE = 1.
*
* IF SY-SUBRC = 0.
** Document parked successfully
* CLEAR: LV_BELNR.
* GET PARAMETER ID 'BLP' FIELD LV_BELNR.
* E_BELNR = LV_BELNR.
*
* WA_MSG-SNO = E_BELNR."TYPE NUMC3,
* WA_MSG-MSGTYP = 'S'."(1) TYPE C,
* CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
* APPEND WA_MSG TO IT_MSG.
* CLEAR WA_MSG.
*
*
*
*
* ELSE.
** Error message capturing
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* INTO LV_TEXT
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
*
* APPEND WA_RETURN TO ET_RETURN.
**Return error messages back to Mulesoft
* T_RETURN[] = ET_RETURN[].
*
* ENDIF.
ENDFORM.

FORM GET_DATA_KZ_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
DATA : LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
E_BELNR TYPE CHAR10,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.

SORT IT_ITAB BY NEWBS DESCENDING.


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1.
WA_BKPF-BUKRS = WA_ITAB-BUKRS."SAFF
WA_BKPF-BLART = 'KZ'."WA_ITAB-BLART.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

* WA_BKPF-BLDAT = WA_ITAB-BLDAT.
* WA_BKPF-BUDAT = WA_ITAB-BUDAT.
* CLEAR:POSTING_DATE.
* CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
*
*
* CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* EXPORTING
* COMPANYCODEID = 'SAFF'
* POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
* IMPORTING
* FISCAL_YEAR = FISCAL_YEAR
* FISCAL_PERIOD = FISCAL_PERIOD
** RETURN =
* .
WA_BKPF-MONAT = FISCAL_PERIOD."FISCAL_PERIOD ."'04'.
WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-CPUDT = SY-DATUM.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBV'.
WA_BKPF-HWAER = WA_ITAB-WAERS.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '50'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
CLEAR:LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-HKONT = LV_NEWKO.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.
IF WA_ITAB-NEWBS = '40'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
CLEAR:LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-HKONT = LV_NEWKO.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.

IF WA_ITAB-NEWBS = '25'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
CLEAR:LV_AKONT,LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-LIFNR = LV_NEWKO.
CLEAR:LV_AKONT.
SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND BUK
RS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.
CLEAR:WA_ITAB.
ENDLOOP.
CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
* I_UF05A =
I_XCMPL = 'X'
* FS006_FB01 =
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT =
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
* T_BKORM =
* T_THEAD =
* T_SPLTTAB =
* T_SPLTWT =
* T_MANDATE =
EXCEPTIONS
ERROR_MESSAGE = 1
.
IF SY-SUBRC = 0.
WA_MSG-SNO = LV_SLNO.
WA_MSG-MSGTYP = 'S'.
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR:WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
*Return error messages back to Mulesoft
* T_RETURN[] = ET_RETURN[].

ENDIF.
ENDFORM.
FORM GET_DATA_KG.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
DATA : LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD.
WA_BKPF-BUKRS = 'SAFF'. "WA_ITAB-BUKRS.
WA_BKPF-GJAHR = SY-DATUM+0(4).
WA_BKPF-BLART = 'KG'."WA_ITAB-BLART.
WA_BKPF-BLDAT = SY-DATUM.
WA_BKPF-BUDAT = SY-DATUM.
WA_BKPF-MONAT = '05' ."FISCAL_PERIOD ."'04'.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = 'Test'. "WA_ITAB-XBLNR.
WA_BKPF-WAERS = 'INR'."WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBV'.
WA_BKPF-HWAER = 'INR'.
* WA_BKPF-XMWST = 'X'.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
WA_BSEG-BUKRS = 'SAFF'. "WA_ITAB-BUKRS.
WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = '001'.
WA_BSEG-BSCHL = '21'."WA_ITAB-NEWBS.
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = 'ADTD'."WA_I41200001TAB-GSBER.
WA_BSEG-DMBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-WRBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWBT = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWSL = 'INR'."WA_ITAB-WAERS.
WA_BSEG-SGTXT = 'Test2'."WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
CLEAR:LV_AKONT,LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND BUKRS =
WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-LIFNR. "wa_bseg-hkont
WA_BSEG-SAKNR = '0020110001'.
WA_BSEG-HKONT = '0020110001'.
WA_BSEG-LIFNR = '0001000002'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
WA_BSEG-XZAHL = 'X'.
WA_BSEG-XBILK = 'X'.
WA_BSEG-KOSTL = 'CFATCTOS'.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.

WA_BSEG-BUKRS = 'SAFF'. "WA_ITAB-BUKRS.


WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = '001'.
WA_BSEG-BSCHL = '50'."WA_ITAB-NEWBS.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = 'ADTD'."WA_I41200001TAB-GSBER.
WA_BSEG-HKONT = '0041200001'.
WA_BSEG-DMBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-WRBTR = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWBT = '1000.00'."WA_ITAB-WRBTR.
WA_BSEG-PSWSL = 'INR'."WA_ITAB-WAERS.
WA_BSEG-SGTXT = 'Test1'."WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
WA_BSEG-XZAHL = 'X'.
WA_BSEG-XBILK = 'X'.
WA_BSEG-KOSTL = 'CFATCTOS'.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
* I_UF05A =
I_XCMPL = 'X'
* FS006_FB01 =
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT =
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
* T_BKORM =
* T_THEAD =
* T_SPLTTAB =
* T_SPLTWT =
* T_MANDATE =
.
ENDFORM.
FORM GET_DATA_KG_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
DATA : LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
E_BELNR TYPE CHAR10,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.

SORT IT_ITAB BY NEWBS DESCENDING.


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1.
WA_BKPF-BUKRS = WA_ITAB-BUKRS."SAFF
WA_BKPF-BLART = 'KG'."WA_ITAB-BLART.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

* WA_BKPF-BLDAT = SY-DATUM.
* WA_BKPF-BUDAT = SY-DATUM.
* WA_BKPF-MONAT = FISCAL_PERIOD.
* WA_BKPF-BLDAT = WA_ITAB-BLDAT.
* WA_BKPF-BUDAT = WA_ITAB-BUDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BKPF-MONAT = FISCAL_PERIOD."FISCAL_PERIOD ."'04'.
WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-CPUDT = SY-DATUM.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBU'.
WA_BKPF-HWAER = WA_ITAB-WAERS.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '21'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
CLEAR:LV_AKONT,LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-LIFNR = LV_NEWKO.
CLEAR:LV_AKONT.
SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND BUK
RS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.
IF WA_ITAB-NEWBS = '50'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
CLEAR:LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-HKONT = LV_NEWKO.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.
CLEAR:WA_ITAB.
ENDLOOP.
CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
* I_UF05A =
I_XCMPL = 'X'
* FS006_FB01 =
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT =
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
* T_BKORM =
* T_THEAD =
* T_SPLTTAB =
* T_SPLTWT =
* T_MANDATE =
EXCEPTIONS
ERROR_MESSAGE = 1
.
IF SY-SUBRC = 0.
WA_MSG-SNO = LV_SLNO.
WA_MSG-MSGTYP = 'S'.
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR:WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
*Return error messages back to Mulesoft
ENDIF.
ENDFORM.
* FORM GET_DATA_KG_ITAB.
* DATA: IT_BKPF TYPE TABLE OF BKPF,
* WA_BKPF TYPE BKPF,
* IT_BSEG TYPE TABLE OF BSEG,
* WA_BSEG TYPE BSEG,
* LV_CNT TYPE NUMC3,
* LV_AKONT TYPE AKONT,
* IT_BSEC TYPE TABLE OF BSEC,
* IT_BSET TYPE TABLE OF BSET,
* IT_BSEZ TYPE TABLE OF BSEZ,
* IT_BKORM TYPE TABLE OF BKORM,
* IT_THEAD TYPE TABLE OF THEAD,
* IT_SPLTTAB TYPE TABLE OF ACSPLT,
* IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
* IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
* LV_NEWKO TYPE NUMC10,
* LV_HKONT TYPE SAKNR.
*
* DATA : LV_BELNR TYPE VBKPF-BELNR,
* LV_SLNO TYPE NUMC4,
* FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
* FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
* E_BELNR TYPE char10,
* posting_date TYPE BAPI0002_4-POSTING_DATE.
*
*
* SORT IT_ITAB BY NEWBS DESCENDING.
* CLEAR:LV_CNT.
* REFRESH: IT_BKPF,IT_BSEG.
* LOOP AT IT_ITAB INTO WA_ITAB.
* LV_SLNO = WA_ITAB-SNO.
* LV_CNT = LV_CNT + 1.
* IF LV_CNT = 1.
* WA_BKPF-BUKRS = WA_ITAB-BUKRS."SAFF
* WA_BKPF-BLART = 'KG'."WA_ITAB-BLART.
* WA_BKPF-BLDAT = WA_ITAB-BLDAT.
* WA_BKPF-BUDAT = WA_ITAB-BUDAT.
*
* CLEAR:POSTING_DATE.
* CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
*
*
* CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* EXPORTING
* COMPANYCODEID = 'SAFF'
* POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
* IMPORTING
* FISCAL_YEAR = FISCAL_YEAR
* FISCAL_PERIOD = FISCAL_PERIOD
** RETURN =
* .
* WA_BKPF-MONAT = FISCAL_PERIOD."FISCAL_PERIOD ."'04'.
* WA_BKPF-GJAHR = FISCAL_YEAR.
* WA_BKPF-WWERT = SY-DATUM.
* WA_BKPF-USNAM = SY-UNAME.
* WA_BKPF-CPUDT = SY-DATUM.
* WA_BKPF-TCODE = 'FB01'.
* WA_BKPF-XBLNR = WA_ITAB-XBLNR.
* WA_BKPF-WAERS = WA_ITAB-WAERS.
* WA_BKPF-GLVOR = 'RFBU'.
* WA_BKPF-HWAER = WA_ITAB-WAERS.
* WA_BKPF-KUTY2 = 'M'.
* APPEND WA_BKPF TO IT_BKPF.
* CLEAR WA_BKPF.
* ENDIF.
*
* IF WA_ITAB-NEWBS = '21'.
* WA_BSEG-BUKRS = WA_ITAB-BUKRS.
* CLEAR:POSTING_DATE.
* CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
*
*
* CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* EXPORTING
* COMPANYCODEID = 'SAFF'
* POSTING_DATE = POSTING_DATE
* IMPORTING
* FISCAL_YEAR = FISCAL_YEAR
* FISCAL_PERIOD = FISCAL_PERIOD
** RETURN =
* .
* WA_BSEG-GJAHR = FISCAL_YEAR.
* WA_BSEG-BUZEI = lv_cnt.
* WA_BSEG-BSCHL = WA_ITAB-NEWBS.
* WA_BSEG-KOART = 'K'.
* WA_BSEG-SHKZG = 'S'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
* WA_BSEG-DMBTR = WA_ITAB-WRBTR.
* WA_BSEG-WRBTR = WA_ITAB-WRBTR.
* WA_BSEG-PSWBT = WA_ITAB-WRBTR.
* WA_BSEG-PSWSL = WA_ITAB-WAERS.
* WA_BSEG-SGTXT = WA_ITAB-SGTXT.
* WA_BSEG-VORGN = 'RFBU'.
*
* CLEAR:LV_AKONT,LV_NEWKO.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = WA_ITAB-NEWKO
* IMPORTING
* OUTPUT = LV_NEWKO.
*
* wa_bseg-lifnr = LV_NEWKO.
* CLEAR:LV_AKONT.
* SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND BU
KRS = WA_ITAB-BUKRS.
* WA_BSEG-SAKNR = LV_AKONT.
* WA_BSEG-HKONT = LV_AKONT.
* WA_BSEG-KOSTL = wa_itab-kostl.
* WA_BSEG-ZFBDT = SY-DATUM.
* APPEND WA_BSEG TO IT_BSEG.
* CLEAR:WA_BSEG.
* ENDIF.
*
* IF WA_ITAB-NEWBS = '50'.
* WA_BSEG-BUKRS = WA_ITAB-BUKRS.
* CLEAR:POSTING_DATE.
* CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
*
* CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* EXPORTING
* COMPANYCODEID = 'SAFF'
* POSTING_DATE = POSTING_DATE
* IMPORTING
* FISCAL_YEAR = FISCAL_YEAR
* FISCAL_PERIOD = FISCAL_PERIOD
** RETURN =
* .
* WA_BSEG-GJAHR = FISCAL_YEAR.
*
* WA_BSEG-BUZEI = LV_CNT.
* WA_BSEG-BSCHL = WA_ITAB-NEWBS.
* WA_BSEG-KOART = 'S'.
* WA_BSEG-SHKZG = 'H'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
* CLEAR:LV_NEWKO.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = WA_ITAB-NEWKO
* IMPORTING
* OUTPUT = LV_NEWKO.
*
* WA_BSEG-HKONT = LV_NEWKO.
* WA_BSEG-DMBTR = WA_ITAB-WRBTR.
* WA_BSEG-WRBTR = WA_ITAB-WRBTR.
* WA_BSEG-PSWBT = WA_ITAB-WRBTR.
* WA_BSEG-PSWSL = WA_ITAB-WAERS.
* WA_BSEG-SGTXT = WA_ITAB-SGTXT.
* WA_BSEG-VORGN = 'RFBU'.
* WA_BSEG-KOSTL = WA_ITAB-KOSTL.
* WA_BSEG-ZFBDT = SY-DATUM.
* APPEND WA_BSEG TO IT_BSEG.
* CLEAR:WA_BSEG.
* ENDIF.
*
* CLEAR:wa_itab.
*ENDLOOP.
*
* CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
* EXPORTING
* TEXT_UPDATE = 'X'
** TEXT_ITEM_UPDATE = ' '
** I_UF05A =
* I_XCMPL = 'X'
** FS006_FB01 =
* I_TCODE = 'FB01'
** I_PARGB =
** I_TCODE_INT =
** IMPORTING
** XEPBBP =
* TABLES
* T_BKPF = IT_BKPF
* T_BSEG = IT_BSEG
* T_BSEC = IT_BSEC
* T_BSET = IT_BSET
* T_BSEZ = IT_BSEZ
** T_BKORM =
** T_THEAD =
** T_SPLTTAB =
** T_SPLTWT =
** T_MANDATE =
* .
*
* if sy-subrc = 0.
* wa_msg-sno = LV_SLNO.
* wa_msg-msgtyp = 'S'.
* CLEAR: LV_BELNR.
* GET PARAMETER ID 'BLP' FIELD LV_BELNR.
* E_BELNR = LV_BELNR.
* CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
* APPEND wa_msg to it_msg.
* CLEAR:wa_msg.
* ENDIF.
* ENDFORM.
*
* FORM GET_DATA_KA_ITAB.
* DATA: IT_BKPF TYPE TABLE OF BKPF,
* WA_BKPF TYPE BKPF,
* IT_BSEG TYPE TABLE OF BSEG,
* WA_BSEG TYPE BSEG,
* LV_CNT TYPE NUMC3,
* LV_AKONT TYPE AKONT,
* IT_BSEC TYPE TABLE OF BSEC,
* IT_BSET TYPE TABLE OF BSET,
* IT_BSEZ TYPE TABLE OF BSEZ,
* IT_BKORM TYPE TABLE OF BKORM,
* IT_THEAD TYPE TABLE OF THEAD,
* IT_SPLTTAB TYPE TABLE OF ACSPLT,
* IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
* IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
* LV_NEWKO TYPE NUMC10,
* LV_HKONT TYPE SAKNR.
*
* DATA : LV_BELNR TYPE VBKPF-BELNR,
* LV_SLNO TYPE NUMC4,
* FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
* FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
* E_BELNR TYPE char10,
* posting_date TYPE BAPI0002_4-POSTING_DATE.
*
*
* SORT IT_ITAB BY NEWBS DESCENDING.
* CLEAR:LV_CNT.
* REFRESH: IT_BKPF,IT_BSEG.
* LOOP AT IT_ITAB INTO WA_ITAB.
* LV_SLNO = WA_ITAB-SNO.
* LV_CNT = LV_CNT + 1.
* IF LV_CNT = 1.
* WA_BKPF-BUKRS = WA_ITAB-BUKRS."SAFF
* WA_BKPF-BLART = 'KA'."WA_ITAB-BLART.
* CLEAR:POSTING_DATE.
* CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
*
*
* WA_BKPF-BLDAT = POSTING_DATE.
*
*
* CLEAR:POSTING_DATE.
* CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
* WA_BKPF-BUDAT = POSTING_DATE.
*
* CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* EXPORTING
* COMPANYCODEID = 'SAFF'
* POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
* IMPORTING
* FISCAL_YEAR = FISCAL_YEAR
* FISCAL_PERIOD = FISCAL_PERIOD
** RETURN =
* .
* WA_BKPF-MONAT = FISCAL_PERIOD."FISCAL_PERIOD ."'04'.
* WA_BKPF-GJAHR = FISCAL_YEAR.
* WA_BKPF-WWERT = SY-DATUM.
* WA_BKPF-USNAM = SY-UNAME.
* WA_BKPF-CPUDT = SY-DATUM.
* WA_BKPF-TCODE = 'FB01'.
* WA_BKPF-XBLNR = WA_ITAB-XBLNR.
* WA_BKPF-WAERS = WA_ITAB-WAERS.
* WA_BKPF-GLVOR = 'RFBU'.
* WA_BKPF-HWAER = WA_ITAB-WAERS.
* WA_BKPF-KUTY2 = 'M'.
* APPEND WA_BKPF TO IT_BKPF.
* CLEAR WA_BKPF.
* ENDIF.
*
* IF WA_ITAB-NEWBS = '21'.
* WA_BSEG-BUKRS = WA_ITAB-BUKRS.
* CLEAR:POSTING_DATE.
* CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
*
*
* CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
* EXPORTING
* COMPANYCODEID = 'SAFF'
* POSTING_DATE = POSTING_DATE
* IMPORTING
* FISCAL_YEAR = FISCAL_YEAR
* FISCAL_PERIOD = FISCAL_PERIOD
** RETURN =
* .
* WA_BSEG-GJAHR = FISCAL_YEAR.
* WA_BSEG-BUZEI = lv_cnt.
* WA_BSEG-BSCHL = WA_ITAB-NEWBS.
* WA_BSEG-KOART = 'K'.
* WA_BSEG-SHKZG = 'S'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
* WA_BSEG-DMBTR = WA_ITAB-WRBTR.
* WA_BSEG-WRBTR = WA_ITAB-WRBTR.
* WA_BSEG-PSWBT = WA_ITAB-WRBTR.
* WA_BSEG-PSWSL = WA_ITAB-WAERS.
* WA_BSEG-SGTXT = WA_ITAB-SGTXT.
* WA_BSEG-VORGN = 'RFBU'.
*
* CLEAR:LV_AKONT,LV_NEWKO.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = WA_ITAB-NEWKO
* IMPORTING
* OUTPUT = LV_NEWKO.
*
* wa_bseg-lifnr = LV_NEWKO.
* CLEAR:LV_AKONT.
* SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND BU
KRS = WA_ITAB-BUKRS.
* WA_BSEG-SAKNR = LV_AKONT.
* WA_BSEG-HKONT = LV_AKONT.
* WA_BSEG-KOSTL = wa_itab-kostl.
* WA_BSEG-ZFBDT = SY-DATUM.
* APPEND WA_BSEG TO IT_BSEG.
* CLEAR:WA_BSEG.
* ENDIF.
* CLEAR:wa_itab.
*ENDLOOP.
*
* CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
* EXPORTING
* TEXT_UPDATE = 'X'
** TEXT_ITEM_UPDATE = ' '
** I_UF05A =
* I_XCMPL = 'X'
** FS006_FB01 =
* I_TCODE = 'FB01'
** I_PARGB =
** I_TCODE_INT =
** IMPORTING
** XEPBBP =
* TABLES
* T_BKPF = IT_BKPF
* T_BSEG = IT_BSEG
* T_BSEC = IT_BSEC
* T_BSET = IT_BSET
* T_BSEZ = IT_BSEZ
** T_BKORM =
** T_THEAD =
** T_SPLTTAB =
** T_SPLTWT =
** T_MANDATE =
* .
*
* if sy-subrc = 0.
* wa_msg-sno = LV_SLNO.
* wa_msg-msgtyp = 'S'.
* CLEAR: LV_BELNR.
* GET PARAMETER ID 'BLP' FIELD LV_BELNR.
* E_BELNR = LV_BELNR.
* CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
* APPEND wa_msg to it_msg.
* CLEAR:wa_msg.
* ENDIF.
* ENDFORM.

FORM GET_DATA_KA_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
DATA : LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
E_BELNR TYPE CHAR10,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.

SORT IT_ITAB BY NEWBS .


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1.
WA_BKPF-BUKRS = WA_ITAB-BUKRS."SAFF
WA_BKPF-BLART = 'KA'."WA_ITAB-BLART.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.

WA_BKPF-BLDAT = POSTING_DATE.

CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE "WA_ITAB-BUDAT
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BKPF-MONAT = FISCAL_PERIOD."FISCAL_PERIOD ."'04'.
WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-CPUDT = SY-DATUM.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBU'.
WA_BKPF-HWAER = WA_ITAB-WAERS.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '21' OR WA_ITAB-NEWBS = '31'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '21' .
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'S'.
ENDIF.
IF WA_ITAB-NEWBS = '31' .
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'H'.
ENDIF.

WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
CLEAR:LV_AKONT,LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-LIFNR = LV_NEWKO.
CLEAR:LV_AKONT.
SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND BUK
RS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.
IF WA_ITAB-NEWBS = '50' OR WA_ITAB-NEWBS = '40'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_BSEG-BSCHL = '40'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
ENDIF.
IF WA_BSEG-BSCHL = '50'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
ENDIF.
WA_BSEG-GSBER = WA_ITAB-GSBER.
CLEAR:LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-HKONT = LV_NEWKO.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.

CLEAR:WA_ITAB.
ENDLOOP.
CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
* I_UF05A =
I_XCMPL = 'X'
* FS006_FB01 =
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT =
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
* T_BKORM =
* T_THEAD =
* T_SPLTTAB =
* T_SPLTWT =
* T_MANDATE =
EXCEPTIONS
ERROR_MESSAGE = 1
.
IF SY-SUBRC = 0.
WA_MSG-SNO = LV_SLNO.
WA_MSG-MSGTYP = 'S'.
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR:WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
ENDIF.
ENDFORM.

FORM GET_DATA_SA_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
DATA : LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
E_BELNR TYPE CHAR10,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.

SORT IT_ITAB BY NEWBS.


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1.
WA_BKPF-BUKRS = WA_ITAB-BUKRS."SAFF
WA_BKPF-BLART = 'SA'."WA_ITAB-BLART.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE." WA_ITAB-BLDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE." WA_ITAB-BUDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BKPF-MONAT = FISCAL_PERIOD."FISCAL_PERIOD ."'04'.
WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-CPUDT = SY-DATUM.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBV'.
WA_BKPF-HWAER = WA_ITAB-WAERS.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '50' OR WA_ITAB-NEWBS = '40'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_BSEG-BSCHL = '40'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
ENDIF.
IF WA_BSEG-BSCHL = '50'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
ENDIF.
WA_BSEG-GSBER = WA_ITAB-GSBER.
CLEAR:LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-HKONT = LV_NEWKO.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.
IF WA_ITAB-NEWBS = '31' .
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
* WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '31'.
WA_BSEG-KOART = 'K'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-ZUONR.

WA_BSEG-ZUONR = WA_ITAB-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM LFB1 WHERE LIFNR = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-LIFNR. "wa_bseg-hkont

* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.

* IF WA_ITAB-NEWBS = '40'.
* WA_BSEG-KOART = 'S'.
* WA_BSEG-SHKZG = 'S'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
* WA_BSEG-PRCTR = WA_ITAB-PRCTR.
* WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
* WA_BSEG-DMBTR = WA_ITAB-WRBTR.
* WA_BSEG-WRBTR = WA_ITAB-WRBTR.
* WA_BSEG-PSWBT = WA_ITAB-WRBTR.
* WA_BSEG-PSWSL = WA_ITAB-WAERS.
** wa_bseg-zuonr = wa_itab-NEWKO.
* WA_BSEG-SGTXT = WA_ITAB-SGTXT.
* WA_BSEG-VORGN = 'RFBU'.
* WA_BSEG-KOSTL = WA_ITAB-KOSTL.
** wa_bseg-XUMSW = 'X'.
* WA_BSEG-XHRES = 'X'.
** wa_bseg-XKRES = 'X'.
** wa_bseg-XOPVW = 'X'.
** CLEAR:lv_hkont.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = WA_ITAB-NEWKO
* IMPORTING
* OUTPUT = WA_BSEG-HKONT.
*
*
* LV_HKONT = WA_ITAB-NEWKO.
** SELECT SINGLE akont INTO lv_akont FROM lfb1 WHERE lifnr = wa_itab-NEWKO
AND bukrs = wa_itab-bukrs.
** wa_mseg-saknr = lv_akont.
** wa_bseg-hkont = lv_hkont.
** wa_mseg-lifnr = wa_itab-newko.
* WA_BSEG-ZFBDT = SY-DATUM.
* ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.
IF WA_ITAB-NEWBS = '01'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '01'.
WA_BSEG-KOART = 'D'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-ZUONR = WA_ITAB-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM knb1 WHERE kunnr = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-kunnr. "wa_bseg-hkont
* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.

* IF WA_ITAB-NEWBS = '50'.
* WA_BSEG-KOART = 'S'.
* WA_BSEG-SHKZG = 'H'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
* WA_BSEG-PRCTR = WA_ITAB-PRCTR.
* WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
* WA_BSEG-DMBTR = WA_ITAB-WRBTR.
* WA_BSEG-WRBTR = WA_ITAB-WRBTR.
* WA_BSEG-PSWBT = WA_ITAB-WRBTR.
* WA_BSEG-PSWSL = WA_ITAB-WAERS.
* WA_BSEG-SGTXT = WA_ITAB-SGTXT.
* WA_BSEG-VORGN = 'RFBU'.
* WA_BSEG-KOSTL = WA_ITAB-KOSTL.
* WA_BSEG-XHRES = 'X'.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = WA_ITAB-NEWKO
* IMPORTING
* OUTPUT = WA_BSEG-HKONT.
* WA_BSEG-ZFBDT = SY-DATUM.
* ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.

CLEAR:WA_ITAB,WA_BSEG.
ENDLOOP.
CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
* I_UF05A =
I_XCMPL = 'X'
* FS006_FB01 =
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT =
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
* T_BKORM =
* T_THEAD =
* T_SPLTTAB =
* T_SPLTWT =
* T_MANDATE =
EXCEPTIONS
ERROR_MESSAGE = 1
.
IF SY-SUBRC = 0.
WA_MSG-SNO = LV_SLNO.
WA_MSG-MSGTYP = 'S'.
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR:WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.

ENDIF.
ENDFORM.
FORM GET_DATA_AB_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR.
DATA : LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
E_BELNR TYPE CHAR10,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.
SORT IT_ITAB BY NEWBS.
CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1.
WA_BKPF-BUKRS = WA_ITAB-BUKRS."SAFF
WA_BKPF-BLART = 'AB'."WA_ITAB-BLART.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE." WA_ITAB-BLDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE." WA_ITAB-BUDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BKPF-MONAT = FISCAL_PERIOD."FISCAL_PERIOD ."'04'.
WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-CPUDT = SY-DATUM.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBV'.
WA_BKPF-HWAER = WA_ITAB-WAERS.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '50' OR WA_ITAB-NEWBS = '40'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_BSEG-BSCHL = '40'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
ENDIF.
IF WA_BSEG-BSCHL = '50'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
ENDIF.
WA_BSEG-GSBER = WA_ITAB-GSBER.
CLEAR:LV_NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = LV_NEWKO.
WA_BSEG-HKONT = LV_NEWKO.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-ZFBDT = SY-DATUM.
APPEND WA_BSEG TO IT_BSEG.
CLEAR:WA_BSEG.
ENDIF.
CLEAR:WA_ITAB.
ENDLOOP.
CALL FUNCTION 'PRELIMINARY_POSTING_FB01'
EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
* I_UF05A =
I_XCMPL = 'X'
* FS006_FB01 =
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT =
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
* T_BKORM =
* T_THEAD =
* T_SPLTTAB =
* T_SPLTWT =
* T_MANDATE =
EXCEPTIONS
ERROR_MESSAGE = 1
.
IF SY-SUBRC = 0.
WA_MSG-SNO = LV_SLNO.
WA_MSG-MSGTYP = 'S'.
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR:WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
ENDIF.
ENDFORM.

FORM GET_DATA_DG_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR,
LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
E_BELNR TYPE BELNR_D,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.

SORT IT_ITAB BY NEWBS.


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1 .
WA_BKPF-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE." WA_ITAB-BLDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE." WA_ITAB-BUDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-MONAT = FISCAL_PERIOD.
WA_BKPF-BLART = 'DG'.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBU'.
WA_BKPF-HWAER = 'INR'.
* WA_BKPF-XMWST = 'X'.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '11' OR WA_ITAB-NEWBS = '40'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.

CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '11'.
WA_BSEG-KOART = 'D'.
WA_BSEG-SHKZG = 'H'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-ZUONR. "wa_

* WA_BSEG-ZUONR = WA_ITAB-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM knb1 WHERE kunnr = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-kunnr. "wa_bseg-hkont
* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.

IF WA_ITAB-NEWBS = '40'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-XHRES = 'X'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-HKONT.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.
CLEAR:WA_BSEG.
ENDLOOP.

CALL FUNCTION 'PRELIMINARY_POSTING_FB01'


EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
** I_UF05A =
I_XCMPL = ' '
* FS006_FB01 = FS006_FB01
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT = 'F-02'
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
T_BKORM = IT_BKORM
T_THEAD = IT_THEAD
T_SPLTTAB = IT_SPLTTAB
T_SPLTWT = IT_SPLTWT
T_MANDATE = IT_MANDATE
EXCEPTIONS
ERROR_MESSAGE = 1.
IF SY-SUBRC = 0.
* Document parked successfully
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
WA_MSG-SNO = LV_SLNO."TYPE NUMC3,
WA_MSG-MSGTYP = 'S'."(1) TYPE C,
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
* Error message capturing
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* INTO LV_TEXT
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
*
* APPEND WA_RETURN TO ET_RETURN.
**Return error messages back to Mulesoft
* T_RETURN[] = ET_RETURN[].
ENDIF.
ENDFORM.
FORM GET_DATA_DA_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR,
LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
E_BELNR TYPE BELNR_D,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.

SORT IT_ITAB BY NEWBS.


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1 .
WA_BKPF-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE." WA_ITAB-BLDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE." WA_ITAB-BUDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-MONAT = FISCAL_PERIOD.
WA_BKPF-BLART = 'DA'.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBU'.
WA_BKPF-HWAER = 'INR'.
* WA_BKPF-XMWST = 'X'.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '04' OR WA_ITAB-NEWBS = '50' or WA_ITAB-NEWBS = '01' or W
A_ITAB-NEWBS = '11'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
WA_BSEG-GJAHR = SY-DATUM+0(4).
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '04' or WA_ITAB-NEWBS = '01'.
WA_BSEG-KOART = 'D'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-ZUONR = WA_ITAB-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM knb1 WHERE kunnr = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-kunnr. "wa_bseg-hkont
* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.

IF WA_ITAB-NEWBS = '50' or WA_ITAB-NEWBS = '11'.


WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-XHRES = 'X'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-HKONT.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.
IF WA_ITAB-NEWBS = '40' OR WA_ITAB-NEWBS = '15'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '40'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-XHRES = 'X'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-HKONT.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
IF WA_ITAB-NEWBS = '15'.
WA_BSEG-KOART = 'D'.
WA_BSEG-SHKZG = 'H'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-ZUONR = WA_ITAB-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM knb1 WHERE kunnr = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-kunnr. "wa_bseg-hkont
* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.
CLEAR:WA_BSEG.
ENDLOOP.

CALL FUNCTION 'PRELIMINARY_POSTING_FB01'


EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
** I_UF05A =
I_XCMPL = ' '
* FS006_FB01 = FS006_FB01
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT = 'F-02'
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
T_BKORM = IT_BKORM
T_THEAD = IT_THEAD
T_SPLTTAB = IT_SPLTTAB
T_SPLTWT = IT_SPLTWT
T_MANDATE = IT_MANDATE
EXCEPTIONS
ERROR_MESSAGE = 1.
IF SY-SUBRC = 0.
* Document parked successfully
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
WA_MSG-SNO = LV_SLNO."TYPE NUMC3,
WA_MSG-MSGTYP = 'S'."(1) TYPE C,
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
* Error message capturing
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* INTO LV_TEXT
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
*
* APPEND WA_RETURN TO ET_RETURN.
**Return error messages back to Mulesoft
* T_RETURN[] = ET_RETURN[].
ENDIF.
ENDFORM.
FORM GET_DATA_DZ_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR,
LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
E_BELNR TYPE BELNR_D,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.
SORT IT_ITAB BY NEWBS DESCENDING.
CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1 .
WA_BKPF-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE." WA_ITAB-BLDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE." WA_ITAB-BUDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-MONAT = FISCAL_PERIOD.
WA_BKPF-BLART = 'DZ'.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBU'.
WA_BKPF-HWAER = 'INR'.
* WA_BKPF-XMWST = 'X'.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '40' OR WA_ITAB-NEWBS = '15'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.
WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '40'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-XHRES = 'X'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-HKONT.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
IF WA_ITAB-NEWBS = '15'.
WA_BSEG-KOART = 'D'.
WA_BSEG-SHKZG = 'H'.
* WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-ZUONR = WA_ITAB-NEWKO.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM knb1 WHERE kunnr = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-kunnr. "wa_bseg-hkont
* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.
CLEAR:WA_BSEG.
ENDLOOP.

CALL FUNCTION 'PRELIMINARY_POSTING_FB01'


EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
** I_UF05A =
I_XCMPL = ' '
* FS006_FB01 = FS006_FB01
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT = 'F-02'
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
T_BKORM = IT_BKORM
T_THEAD = IT_THEAD
T_SPLTTAB = IT_SPLTTAB
T_SPLTWT = IT_SPLTWT
T_MANDATE = IT_MANDATE
EXCEPTIONS
ERROR_MESSAGE = 1.
IF SY-SUBRC = 0.
* Document parked successfully
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
WA_MSG-SNO = LV_SLNO."TYPE NUMC3,
WA_MSG-MSGTYP = 'S'."(1) TYPE C,
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
* Error message capturing
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* INTO LV_TEXT
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
*
* APPEND WA_RETURN TO ET_RETURN.
**Return error messages back to Mulesoft
* T_RETURN[] = ET_RETURN[].
ENDIF.
ENDFORM.
FORM GET_DATA_DR_ITAB.
DATA: IT_BKPF TYPE TABLE OF BKPF,
WA_BKPF TYPE BKPF,
IT_BSEG TYPE TABLE OF BSEG,
WA_BSEG TYPE BSEG,
LV_CNT TYPE NUMC3,
LV_AKONT TYPE AKONT,
IT_BSEC TYPE TABLE OF BSEC,
IT_BSET TYPE TABLE OF BSET,
IT_BSEZ TYPE TABLE OF BSEZ,
IT_BKORM TYPE TABLE OF BKORM,
IT_THEAD TYPE TABLE OF THEAD,
IT_SPLTTAB TYPE TABLE OF ACSPLT,
IT_SPLTWT TYPE TABLE OF WITH_ITEMX,
IT_MANDATE TYPE TABLE OF SEPA_MANDATE,
LV_NEWKO TYPE NUMC10,
LV_HKONT TYPE SAKNR,
LV_BELNR TYPE VBKPF-BELNR,
LV_SLNO TYPE NUMC4,
E_BELNR TYPE BELNR_D,
FISCAL_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
FISCAL_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
POSTING_DATE TYPE BAPI0002_4-POSTING_DATE,
LV_TEXT TYPE BAPI_MSG.

SORT IT_ITAB BY NEWBS.


CLEAR:LV_CNT.
REFRESH: IT_BKPF,IT_BSEG.
LOOP AT IT_ITAB INTO WA_ITAB.
LV_SLNO = WA_ITAB-SNO.
LV_CNT = LV_CNT + 1.
IF LV_CNT = 1 .
WA_BKPF-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BLDAT+6(4) WA_ITAB-BLDAT+3(2) WA_ITAB-BLDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BLDAT = POSTING_DATE." WA_ITAB-BLDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
WA_BKPF-BUDAT = POSTING_DATE." WA_ITAB-BUDAT.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.

CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'


EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

WA_BKPF-GJAHR = FISCAL_YEAR.
WA_BKPF-MONAT = FISCAL_PERIOD.
WA_BKPF-BLART = 'DR'.
WA_BKPF-WWERT = SY-DATUM.
WA_BKPF-USNAM = SY-UNAME.
WA_BKPF-TCODE = 'FB01'.
WA_BKPF-XBLNR = WA_ITAB-XBLNR.
WA_BKPF-WAERS = WA_ITAB-WAERS.
WA_BKPF-GLVOR = 'RFBU'.
WA_BKPF-HWAER = 'INR'.
* WA_BKPF-XMWST = 'X'.
WA_BKPF-KUTY2 = 'M'.
APPEND WA_BKPF TO IT_BKPF.
CLEAR WA_BKPF.
ENDIF.
IF WA_ITAB-NEWBS = '01' OR WA_ITAB-NEWBS = '50'.
WA_BSEG-BUKRS = WA_ITAB-BUKRS.
CLEAR:POSTING_DATE.
CONCATENATE WA_ITAB-BUDAT+6(4) WA_ITAB-BUDAT+3(2) WA_ITAB-BUDAT+0(2) INTO
POSTING_DATE.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
COMPANYCODEID = 'SAFF'
POSTING_DATE = POSTING_DATE
IMPORTING
FISCAL_YEAR = FISCAL_YEAR
FISCAL_PERIOD = FISCAL_PERIOD
* RETURN =
.

WA_BSEG-GJAHR = FISCAL_YEAR.
WA_BSEG-BUZEI = LV_CNT.
WA_BSEG-BSCHL = WA_ITAB-NEWBS.
IF WA_ITAB-NEWBS = '01'.
WA_BSEG-KOART = 'D'.
WA_BSEG-SHKZG = 'S'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-ZUONR = WA_ITAB-NEWKO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-ZUONR. "

WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-XUMSW = 'X'.
WA_BSEG-XHRES = 'X'.
WA_BSEG-XKRES = 'X'.
WA_BSEG-XOPVW = 'X'.
CLEAR:LV_AKONT,LV_NEWKO.
LV_NEWKO = WA_ITAB-NEWKO.
SELECT SINGLE AKONT INTO LV_AKONT FROM knb1 WHERE kunnr = LV_NEWKO AND B
UKRS = WA_ITAB-BUKRS.
WA_BSEG-SAKNR = LV_AKONT.
WA_BSEG-HKONT = LV_AKONT.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-kunnr. "wa_bseg-hkont
* wa_bseg-lifnr = wa_itab-newko.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.

IF WA_ITAB-NEWBS = '50'.
WA_BSEG-KOART = 'S'.
WA_BSEG-SHKZG = 'H'.
WA_BSEG-GSBER = WA_ITAB-GSBER.
WA_BSEG-PRCTR = WA_ITAB-PRCTR.
WA_BSEG-MWSKZ = WA_ITAB-MWSKZ.
WA_BSEG-DMBTR = WA_ITAB-WRBTR.
WA_BSEG-WRBTR = WA_ITAB-WRBTR.
WA_BSEG-PSWBT = WA_ITAB-WRBTR.
WA_BSEG-PSWSL = WA_ITAB-WAERS.
WA_BSEG-SGTXT = WA_ITAB-SGTXT.
WA_BSEG-VORGN = 'RFBU'.
WA_BSEG-KOSTL = WA_ITAB-KOSTL.
WA_BSEG-XHRES = 'X'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_ITAB-NEWKO
IMPORTING
OUTPUT = WA_BSEG-HKONT.
WA_BSEG-ZFBDT = SY-DATUM.
ENDIF.
APPEND WA_BSEG TO IT_BSEG.
ENDIF.
CLEAR:WA_BSEG.
ENDLOOP.

CALL FUNCTION 'PRELIMINARY_POSTING_FB01'


EXPORTING
TEXT_UPDATE = 'X'
* TEXT_ITEM_UPDATE = ' '
** I_UF05A =
I_XCMPL = ' '
* FS006_FB01 = FS006_FB01
I_TCODE = 'FB01'
* I_PARGB =
* I_TCODE_INT = 'F-02'
* IMPORTING
* XEPBBP =
TABLES
T_BKPF = IT_BKPF
T_BSEG = IT_BSEG
T_BSEC = IT_BSEC
T_BSET = IT_BSET
T_BSEZ = IT_BSEZ
T_BKORM = IT_BKORM
T_THEAD = IT_THEAD
T_SPLTTAB = IT_SPLTTAB
T_SPLTWT = IT_SPLTWT
T_MANDATE = IT_MANDATE
EXCEPTIONS
ERROR_MESSAGE = 1.
IF SY-SUBRC = 0.
* Document parked successfully
CLEAR: LV_BELNR.
GET PARAMETER ID 'BLP' FIELD LV_BELNR.
E_BELNR = LV_BELNR.
WA_MSG-SNO = LV_SLNO."TYPE NUMC3,
WA_MSG-MSGTYP = 'S'."(1) TYPE C,
CONCATENATE 'Document' E_BELNR 'Parked successfully' INTO WA_MSG-TEXT.
APPEND WA_MSG TO IT_MSG.
CLEAR WA_MSG.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
INTO LV_TEXT
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
wa_msg-sno = LV_SLNO.
wa_msg-msgtyp = SY-MSGTY.
wa_msg-text = LV_TEXT.
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
* APPEND WA_RETURN TO ET_RETURN.
APPEND wa_msg to it_msg.
CLEAR wa_msg.
* Er
* Error message capturing
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* INTO LV_TEXT
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*
* WA_RETURN-TYPE = SY-MSGTY. "Message type: S Success, E Error, W Warning,
I Info, A Abort
* WA_RETURN-ID = SY-MSGID. "Message Class
* WA_RETURN-NUMBER = SY-MSGNO. "Message Number
* WA_RETURN-MESSAGE = LV_TEXT. "Message Text
*
* APPEND WA_RETURN TO ET_RETURN.
**Return error messages back to Mulesoft
* T_RETURN[] = ET_RETURN[].
ENDIF.
ENDFORM.