Skip to Content
0
Former Member
Aug 17, 2006 at 03:20 PM

EITHER BAPI OR BDC IS BEST FOR F-02

212 Views

Hello Friends,

Iam doing bdc for f-02 even bapi to but iam stuck in middle. i want to upload data for F-02 using posting keys

40 and 50.

iam sending sample code for it can any one rectify and tell me whats wrong with this....

Iam sending both bapi and bdc code...

Regards

Bohra.

REPORT ZBDC_TEST no standard page heading line-size 255.

INCLUDE BDCRECX1.

PARAMETERS: filename LIKE rlgrap-filename.

TYPES : BEGIN OF IT_TAB,

bldat(2), " DOC DATE

blart(2), " DOC TYPE

bukrs(4), " COMPANY CODE

budat(8), " POSTING DATE

waers(5), " CURRENCY

xblnr(16), " HEADER REF

bktxt(50), " HEADER TXT

newbs(2), " POSTING KEY

accnt(16), " ACCOUNT

umskz(1), " SPL GENREAL LEDGER

wrbtr(13), " AMOUNT IN FOR CURRENCY

dmbtr(13), " AMOUNT FOR COMPANY CODE INR

zterm(4), " PAYEMENT TERM

zfbdt(8), " BASELINE DATE

wt_wit(2), " WITH TAX CODE

wt_qs(15), " WITH TAX BASE

wt_qb(15), " WITH TAX AMOUNT

mwskz(2), " TAX CODE

bupla(4), " BUSINESS PLACE

  • bukrs(4),

kostl(10), " COST CENTER

acgl_it(12), " INTERNAL ORDER

acgl_i(10), " PROFIT CENTER

  • acgl_it(8), " PERSONAL NO

zuonr(18), " ASSIGNMENT

xblnr1(16), " REF1

xblnr2(16), " REF2

xblnr3(16), " REF3

sgtxt(50), " LINE TEXT

END OF IT_TAB.

DATA: IT_TAB1 TYPE TABLE OF IT_TAB.

DATA: WA_HEAD LIKE LINE OF IT_TAB1.

data: it_bdcdata like bdcdata occurs 0 with header line.

data: it_bdcmsgcoll like bdcmsgcoll occurs 0 with header line.

data: i_error like itab occurs 0 with header line.

data: i_sucess like itab occurs 0 with header line.

data: v_flag.

data: v_msg(200).

DATA : w_file1 TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = filename.

START-OF-SELECTION.

w_file1 = filename.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = w_file1

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = it_tab1.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = 'F-02'

KEEP = 'X'

USER = SY-UNAME.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'F-02'

TABLES

DYNPROTAB = IT_TAB1.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

  • RECORDING PROGRAM FOR F-02

loop at it_tab1 into wa_head.

perform bdc_dynpro using 'SAPMF05A' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RF05A-NEWKO'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BKPF-BLDAT'

WA_HEAD-BLDAT.

perform bdc_field using 'BKPF-BLART'

'SA'.

perform bdc_field using 'BKPF-BUKRS'

WA_HEAD-BUKRS.

perform bdc_field using 'BKPF-BUDAT'

WA_HEAD-BUDAT.

perform bdc_field using 'BKPF-MONAT'

'3'.

perform bdc_field using 'BKPF-WAERS'

WA_HEAD-WAERS.

perform bdc_field using 'BKPF-XBLNR'

WA_HEAD-XBLNR.

perform bdc_field using 'BKPF-BKTXT'

WA_HEAD-BKTXT.

perform bdc_field using 'FS006-DOCID'

'*'.

perform bdc_field using 'RF05A-NEWBS'

WA_HEAD-NEWBS.

perform bdc_field using 'RF05A-NEWKO'

'100100'.

perform bdc_dynpro using 'SAPMF05A' '0300'.

perform bdc_field using 'BDC_CURSOR'

'RF05A-NEWKO'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BSEG-WRBTR'

WA_HEAD-WRBTR.

perform bdc_field using 'BSEG-VALUT'

'03/27/2006'.

perform bdc_field using 'BSEG-ZUONR'

WA_HEAD-ZUONR.

perform bdc_field using 'BSEG-SGTXT'

WA_HEAD-SGTXT.

perform bdc_field using 'RF05A-NEWBS'

WA_HEAD-NEWBS.

perform bdc_field using 'RF05A-NEWKO'

'574130'.

perform bdc_field using 'DKACB-FMORE'

'X'.

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_CURSOR'

'COBL-GSBER'.

perform bdc_field using 'BDC_OKCODE'

'=ENTE'.

perform bdc_field using 'COBL-GSBER'

'101'.

perform bdc_dynpro using 'SAPMF05A' '0300'.

perform bdc_field using 'BDC_CURSOR'

'BSEG-SGTXT'.

perform bdc_field using 'BDC_OKCODE'

'=BP'.

perform bdc_field using 'BSEG-WRBTR'

WA_HEAD-WRBTR.

perform bdc_field using 'BSEG-VALUT'

'03/27/2006'.

perform bdc_field using 'BSEG-ZUONR'

WA_HEAD-ZUONR.

perform bdc_field using 'BSEG-SGTXT'

WA_HEAD-SGTXT.

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_CURSOR'

'COBL-KOSTL'.

perform bdc_field using 'BDC_OKCODE'

'=ENTE'.

perform bdc_field using 'COBL-GSBER'

'101'.

perform bdc_field using 'COBL-KOSTL'

WA_HEAD-KOSTL.

ENDLOOP.

-


BAPI PROGRAM----


&----


*& Report ZBAPI_TEST

*&

&----


*&

*&

&----


REPORT ZBAPI_TEST.

DATA: BEGIN OF i_data OCCURS 0,

text(255),

END OF i_data.

DATA: i_fico TYPE BAPIACHE09.

*DATA: I_FICO1 TYPE BAPIACCR08.

DATA: I_FICO1 TYPE BAPIACGL09.

DATA: I_FICO3 TYPE BAPIACCR09.

DATA: I_FICO2 TYPE BAPIACTX09.

DATA: P_KEY TYPE BBSEG.

*DATA: it_TAB LIKE TABLE OF i_fico INITIAL SIZE 0 WITH HEADER LINE.

  • HEADER DETAILS FROM BAPI STRUCUTE BAPIACHE09

DATA: BEGIN OF it_TAB1 OCCURS 0, " BAPIACHE09

bldat(8), " DOC DATE

blart(2), " DOC TYPE

bukrs(4), " COMPANY CODE

BUDAT(8), " POSTING DATE

XBLNR(16), " HEADER REF

BKTXT(50), " HEADER TXT

END OF IT_TAB1.

DATA: it_TAB LIKE TABLE OF BAPIACHE09 INITIAL SIZE 0 WITH HEADER LINE .

  • ITEM DETAILS FROM STRUCTURE OF BAPI G/L ACCOUNT ITEM BAPIACGL09.

DATA: BEGIN OF IT_ITAB3 OCCURS 0, " BAPIACGL09.

HKONT(10), " General Ledger Account

SGTXT(50), " ITEM TXT

BUKRS(4), " Company Code

KOSTL(10), " COST CENTER

PRCTR(10), " PROFIT CENTER

END OF IT_ITAB3.

  • DETIALS OF CURRENCY ITEMS FROM STRUCTURE OF BAPI BAPIACCR09

DATA: BEGIN OF IT_iTAB4 OCCURS 0, " BAPIACCR09

WAERS(5), " CURRENCY

BAPIWRBTR(23), " Amount in document currency

BAPIFWBAS(23), " Tax Base Amount in Document Currency

END OF IT_ITAB4.

  • TAX ITEM DETAILS FROM BAPI STRUCUTE BAPIACTX09.

DATA: BEGIN OF IT_ITAB5 OCCURS 0, " BAPIACTX09.

MWSKZ(2), " Sales Tax Code

TXJCD(15), " Tax Jurisdiction

ACPI_TXJCD_DEEP(15), " Tax jurisdiction code - jurisdiction for lowest level tax

END OF IT_ITAB5.

  • THIS IS FROM STRUCTURE BBSEG.

DATA: BEGIN OF IT_TAB6 OCCURS 0,

NEWBS(2), " Posting Key for the Next Line Item

NEWUM(1), " Special G/L Indicator for the Next Line Item

DMBTR(16), " Amount in local currency (batch input field)

AUFNR(12), " Order Number

DZUONR(18), " Assignment number

ZTERM(4), " Terms of payment key

ZFBDT(8), " Baseline Date.

END OF IT_TAB6.

DATA: v_index TYPE i.

DATA: return TYPE TABLE OF bapiret2 INITIAL SIZE 0 WITH HEADER LINE.

START-OF-SELECTION.

CALL FUNCTION 'UPLOAD'

  • EXPORTING

  • CODEPAGE = ' '

  • FILENAME = ' '

  • FILETYPE = ' '

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

TABLES

data_tab = i_data

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • CALL FUNCTION 'BAPI_ACC_GL_POSTING_CHECK'

  • EXPORTING

  • DOCUMENTHEADER =

  • TABLES

  • ACCOUNTGL = it_tab1

    • CURRENCYAMOUNT =

  • RETURN = return.

  • CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

    EXPORTING

    DOCUMENTHEADER = it_tab

    TABLES

    ACCOUNTGL = it_Itab3

    ACCOUNTRECEIVABLE = it_Itab4

    • ACCOUNTPAYABLE =

    ACCOUNTTAX = it_Itab5

    • CURRENCYAMOUNT =

    • CRITERIA =

    • VALUEFIELD =

    • EXTENSION1 =

    RETURN = return.

    loop at return.

    write:/ return-message,return-type.

    endloop.