Skip to Content
0
Feb 15, 2007 at 09:18 AM

BDC UPLOAD

50 Views

Hi ,

I am attaching BDC code for f-02 ,

i want to upload 2 header and there correspomding line items .

i am unable to upload second header .

Here is the code for this upload ..

also check the flat file m using .. its next to code down ..

report ZTESTMAYA

no standard page heading line-size 255.

DATA: BEGIN OF xtab OCCURS 0, " string internal table.

col1(40),

col2(40),

col3(40),

col4(40),

col5(40),

col6(40),

col7(40),

col8(40),

col9(40),

col10(40),

END OF xtab.

DATA: BEGIN OF err1_tab OCCURS 0,

col1(40),

col2(40),

col3(40),

col4(40),

col5(40),

col6(40),

col7(40),

col8(40),

col9(40),

col10(40),

col11(255),

END OF err1_tab.

DATA: x_tab LIKE LINE OF xtab OCCURS 0 WITH HEADER LINE.

DATA: v_afilename(50) .

DATA: tab(255).

DATA : msg1(255),

msg2(255).

DATA: BEGIN OF itab_error OCCURS 0. " error internal table

INCLUDE STRUCTURE bdcmsgcoll.

DATA: END OF itab_error.

DATA: err_tab LIKE err1_tab OCCURS 0 WITH HEADER LINE.

DATA: suc_tab LIKE err1_tab OCCURS 0 WITH HEADER LINE.

DATA: e_tab LIKE LINE OF err_tab OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF itab_h OCCURS 0 ,

bldat(10),

blart(2),

bukrs(4),

budat(10),

monat(2),

waers(5),

kursf(12),

xblnr(16),

bktxt(25),

END OF itab_h .

DATA : BEGIN OF itab_i OCCURS 0 ,

newbs(2),

newko(17),

wrbtr(16),

zuonr(18),

sgtxt(40),

kostl(10),

aufnr(12),

END OF itab_i.

DATA: jtab LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: it_tab TYPE filetable,

gd_subrc TYPE i,

w_temp(50),

h_count TYPE i VALUE 0,

i_count TYPE i ,

bp_count TYPE i,

h42_count TYPE i,

i42_count TYPE i,

bp42_count TYPE i VALUE 0,

chdate(10), " LIKE VEDA-VBEGDAT,

count TYPE i,

w_waers LIKE knvv-waers,

w_waers1 LIKE knvv-waers,

w_flag(1),

w_kunnr(10).

PARAMETERS p_flname TYPE rlgrap-filename

DEFAULT '
sapr3dq\sap_cnv\files\bntest01.txt'.

PARAMETERS p_mode DEFAULT 'N'.

*PARAMETERS p_erfle TYPE rlgrap-filename

  • DEFAULT '
    sapr3dq\sap_cnv\files\bntest01_err.txt'.

*PARAMETERS p_box AS CHECKBOX DEFAULT 'X'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flname.

REFRESH: it_tab.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = 'UPLOAD_FILE'

default_filename = 'P_FILE'

multiselection = ' '

CHANGING

file_table = it_tab

rc = gd_subrc.

LOOP AT it_tab INTO p_flname.

ENDLOOP.

start-of-selection.

*perform open_group.

perform upload_data.

REFRESH jtab.

end-of-selection.

if not xtab[] is initial.

perform create_record.

endif.

----


  • Start new screen *

----


FORM bdc_dynpro USING program dynpro.

CLEAR jtab.

jtab-program = program.

jtab-dynpro = dynpro.

jtab-dynbegin = 'X'.

APPEND jtab.

ENDFORM. "BDC_DYNPRO

**----


**

  • Insert field

**

**----


**

FORM bdc_field USING fnam fval.

IF fval <> ' '.

CLEAR jtab.

jtab-fnam = fnam.

jtab-fval = fval.

APPEND jtab.

ENDIF.

ENDFORM. "BDC_FIELD

&----


*& Form populate_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload_data .

DATA: l_flname TYPE string.

l_flname = p_flname.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_flname

filetype = 'ASC'

has_field_separator = 'X'

  • DAT_MODE = 'X'

TABLES

data_tab = xtab.

  • IF sy-subrc <> 0.

  • MESSAGE e999 WITH 'Error in Opening the File'.

  • ENDIF.

ENDFORM. " upload_data

&----


*& Form create_record

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM create_record .

LOOP AT xtab.

IF xtab-col1(1) = 0.

  • IF itab_h-cnum <> space.

IF h_count > 0.

*

*CLEAR jtab.

  • jtab-fnam = fnam.

  • jtab-fval = fval.

  • APPEND jtab.

itab_h-bldat = xtab-col2.

itab_h-blart = xtab-col3.

itab_h-bukrs = xtab-col4.

itab_h-budat = xtab-col5.

itab_h-monat = xtab-col6.

itab_h-waers = xtab-col7.

itab_h-kursf = xtab-col8.

itab_h-xblnr = xtab-col9.

itab_h-bktxt = xtab-col10.

err1_tab = xtab.

APPEND err1_tab.

*CALL TRANSACTION 'F-02' USING jtab

  • MODE p_mode.

*

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-KOSTL'

itab_i-kostl.

perform bdc_field using 'COBL-AUFNR'

itab_i-aufnr.

perform bdc_dynpro using 'SAPMF05A' '0700'.

perform bdc_field using 'BDC_CURSOR'

'RF05A-NEWBS'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'BKPF-XBLNR'

itab_h-xblnr.

perform bdc_field using 'BKPF-BKTXT'

itab_h-bktxt.

CALL TRANSACTION 'F-02' USING jtab

MODE p_mode.

ENDIF.

  • REFRESH jtab.

  • REFRESH itab_h.

  • REFRESH itab_i.

  • clear count.

  • clear itab_H.

itab_h-bldat = xtab-col2.

itab_h-blart = xtab-col3.

itab_h-bukrs = xtab-col4.

itab_h-budat = xtab-col5.

itab_h-monat = xtab-col6.

itab_h-waers = xtab-col7.

itab_h-kursf = xtab-col8.

itab_h-xblnr = xtab-col9.

itab_h-bktxt = xtab-col10.

err1_tab = xtab.

APPEND err1_tab.

h_count = 0.

PERFORM process_f-02_header.

h_count = h_count + 1.

endif.

IF xtab-col1(1) = 1.

CLEAR count.

CLEAR itab_i.

itab_i-newbs = xtab-col2.

itab_i-newko = xtab-col3.

itab_i-wrbtr = xtab-col4.

itab_i-zuonr = xtab-col5.

itab_i-sgtxt = xtab-col6.

itab_i-kostl = xtab-col7.

itab_i-aufnr = xtab-col8.

err1_tab = xtab.

APPEND err1_tab.

PERFORM process_f-02_item.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

  • perform bdc_transaction using 'F-02'.

endif.

ENDLOOP.

endform.

&----


*& Form process_f-02_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process_f-02_header .

if h_count = 0.

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'

itab_h-bldat.

perform bdc_field using 'BKPF-BLART'

itab_h-blart.

perform bdc_field using 'BKPF-BUKRS'

itab_h-bukrs.

perform bdc_field using 'BKPF-BUDAT'

itab_h-budat.

perform bdc_field using 'BKPF-MONAT'

itab_h-monat.

perform bdc_field using 'BKPF-WAERS'

itab_h-waers.

perform bdc_field using 'BKPF-KURSF'

itab_h-kursf.

perform bdc_field using 'BKPF-XBLNR'

itab_h-xblnr.

perform bdc_field using 'BKPF-BKTXT'

itab_h-bktxt.

perform bdc_field using 'FS006-DOCID'

'*'.

  • CALL TRANSACTION 'F-02' USING jtab

  • MODE p_mode.

endif.

*elseif h_count > 0.

*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-KOSTL'

  • itab_i-kostl.

  • perform bdc_field using 'COBL-AUFNR'

  • itab_i-aufnr.

*

*

  • perform bdc_dynpro using 'SAPMF05A' '0700'.

  • perform bdc_field using 'BDC_CURSOR'

  • 'RF05A-NEWBS'.

  • perform bdc_field using 'BDC_OKCODE'

  • '=BU'.

*

  • perform bdc_field using 'BKPF-XBLNR'

  • itab_h-xblnr.

  • perform bdc_field using 'BKPF-BKTXT'

  • itab_h-bktxt.

*

*

*endif.

ENDFORM. " process_f-02_header

&----


*& Form process_f-02_item

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process_f-02_item .

IF i_count = 0.

perform bdc_field using 'RF05A-NEWBS'

itab_i-newbs.

perform bdc_field using 'RF05A-NEWKO'

itab_i-newko.

perform bdc_dynpro using 'SAPMF05A' '0300'.

perform bdc_field using 'BDC_CURSOR'

itab_i-sgtxt.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BSEG-WRBTR'

itab_i-wrbtr .

perform bdc_field using 'BSEG-ZUONR'

itab_i-zuonr .

perform bdc_field using 'BSEG-SGTXT'

itab_i-sgtxt.

perform bdc_field using 'DKACB-FMORE'

'X'.

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_CURSOR'

'COBL-AUFNR'.

perform bdc_field using 'BDC_OKCODE'

'=ENTE'.

perform bdc_field using 'COBL-KOSTL'

itab_i-kostl.

perform bdc_field using 'COBL-AUFNR'

itab_i-aufnr.

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'

itab_i-wrbtr.

perform bdc_field using 'BSEG-ZUONR'

itab_i-zuonr.

perform bdc_field using 'BSEG-SGTXT'

itab_i-sgtxt.

ELSEIF i_count > 0.

perform bdc_field using 'RF05A-NEWBS'

itab_i-newbs.

perform bdc_field using 'RF05A-NEWKO'

itab_i-newko.

perform bdc_field using 'DKACB-FMORE'

'X'.

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-KOSTL'

itab_i-kostl.

perform bdc_field using 'COBL-AUFNR'

itab_i-aufnr.

perform bdc_dynpro using 'SAPMF05A' '0300'.

perform bdc_field using 'BDC_CURSOR'

'BSEG-SGTXT'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BSEG-WRBTR'

itab_i-wrbtr.

  • perform bdc_field using 'BSEG-VALUT'

  • '14.02.2007'.

perform bdc_field using 'BSEG-ZUONR'

itab_i-zuonr.

perform bdc_field using 'BSEG-SGTXT'

itab_i-sgtxt.

perform bdc_field using 'DKACB-FMORE'

'X'.

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_CURSOR'

'COBL-AUFNR'.

perform bdc_field using 'BDC_OKCODE'

'=ENTE'.

perform bdc_field using 'COBL-AUFNR'

itab_i-aufnr.

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'

  • itab_i-wrbtr.

  • perform bdc_field using 'BSEG-VALUT'

  • '14.02.2007'.

  • perform bdc_field using 'BSEG-ZUONR'

  • itab_i-zuonr.

  • perform bdc_field using 'BSEG-SGTXT'

  • itab_i-sgtxt.

  • *

    • perform bdc_field using 'DKACB-FMORE'

    • 'X'.

    • 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-KOSTL'

    • itab_i-kostl.

    • perform bdc_field using 'COBL-AUFNR'

    • itab_i-aufnr.

    ENDIF.

    i_count = i_count + 1.

    ENDFORM. " process_f-02_item

    -


    flat file :

    0 30.1.2007 sa 100 31.1.2007 9 inr 1 test1 test123

    1 40 3005700 2000 upload upload test1 1000060

    1 40 3005700 3000 upload upload test1 1000060

    1 40 3005700 4000 upload upload test1 1000060

    1 40 3005700 5000 upload upload test1 1000060

    1 40 3005700 6000 upload upload test1 1000060

    1 40 3005700 7000 upload upload test1 1000060

    1 40 3005700 8000 upload upload test1 1000060

    1 40 3005700 9000 upload upload test1 1000060

    1 40 3005700 10000 upload upload test1 1000060

    1 40 3005700 11000 upload upload test1 1000060

    1 50 1150020 65000 text text

    0 01.2.2007 sa 100 4.2.2007 9 inr 1 test2 test345

    1 40 3005700 10 do it do it test1 1000060

    1 50 1150020 10 do it do it

    1 40 3005700 20 do it do it test1 1000060

    1 50 1150020 20s do it do it