Skip to Content
author's profile photo Former Member
Former Member

FLATFILE structure for bdc using table control(BOM)

hi,

the format of the flatfile is :

matnr werks stlan idnrk menge postp idnrk menge postp

300000232 UN02 1 200000345 100 L 200000347 300 L

300000232 UN02 1 200000346 200 L

THE FLATFILE SRUCTURE IS THE MAIN PROBLEM....

COZ the line items can either be in the same line or in the next line....

so my pgm should be able to run in both the situations...

would b best if u provide me with code.....

My second issue is what to use for primary recording.....shdb or sm35.....which one's better?

hav tried d pgm.....

1] http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm

2] the one given in d forum.......given below....

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA : w_auart(4) TYPE c,

w_vkorg(4) TYPE c,

w_vtweg(2) TYPE c,

w_spart(2) TYPE c,

w_kunnr(10) TYPE c,

w_kunrg(10) TYPE c,

w_bstkd(35) TYPE c,

w_bstdk(10) TYPE c,

w_kwmeng(18) TYPE c,

w_zterm(4) TYPE c,

w_inco1(3) TYPE c,

w_inco2(28) TYPE c,

w_augru(3) TYPE c.

DATA : var1 TYPE string,

var2 TYPE c VALUE '(',

var3 TYPE c VALUE ')',

num(2) TYPE c,

flag(1) TYPE c.

DATA : BEGIN OF it_order, " Internal table Structure

auart(4) TYPE c, " Sales Order Type

vkorg(4) TYPE c, " Sales Organization

vtweg(2) TYPE c, " Distribution Channel

spart(2) TYPE c, " Division

kunnr(10) TYPE c, " Sold-to-Party

kunrg(10) TYPE c, " Ship-to-Party

bstkd(35) TYPE c, " Purchase Order No

bstdk(10) TYPE c, " Purchase Order Date

zterm(4) TYPE c, " Payment Terms

inco1(3) TYPE c, " Inco Terms1

inco2(20) TYPE c, " Inco Terms2

augru(3) TYPE c, " Order Reason

mabnr(18) TYPE c, " Material No

kwmeng(18) TYPE c, " Quantity

END OF it_order,

itab LIKE STANDARD TABLE OF it_order WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETER filename LIKE rlgrap-filename.

PARAMETER session LIKE apqi-groupid.

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

************************************************************************

Get the file path

************************************************************************

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = filename

def_path = ' '

mask = ',.,..'

mode = 'O'

title = 'Select File'

IMPORTING

filename = filename

EXCEPTIONS

selection_cancel = 1.

CHECK sy-subrc = 0.

START-OF-SELECTION.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

codepage = ' '

filename = filename

filetype = 'ASC'

headlen = ' '

line_exit = ' '

trunclen = ' '

user_form = ' '

user_prog = ' '

dat_d_format = ' '

IMPORTING

FILELENGTH =

TABLES

data_tab = itab

EXCEPTIONS

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10.

IF sy-subrc 0.

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

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

ENDIF.

PERFORM open_group.

LOOP AT itab.

CLEAR : w_auart,w_vkorg,w_vtweg,w_spart,w_kunnr,w_kunrg,

w_bstkd,w_bstdk,w_zterm,w_inco1,w_inco2,w_augru.

w_auart = itab-auart.

w_vkorg = itab-vkorg.

w_vtweg = itab-vtweg.

w_spart = itab-spart.

w_kunnr = itab-kunnr.

w_kunrg = itab-kunrg.

w_bstkd = itab-bstkd.

w_bstdk = itab-bstdk.

w_zterm = itab-zterm.

w_inco1 = itab-inco1.

w_inco2 = itab-inco2.

w_augru = itab-augru.

ON CHANGE OF itab-kunnr OR itab-kunrg OR itab-bstkd .

flag = 0.

num = 1.

PERFORM bdc_dynpro USING 'SAPMV45A' '0101'.

PERFORM bdc_field USING 'BDC_CURSOR'

'VBAK-AUART'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'VBAK-AUART' " Order Type

itab-auart.

PERFORM bdc_field USING 'VBAK-VKORG' " Sales Organization

itab-vkorg.

PERFORM bdc_field USING 'VBAK-VTWEG' " Distribution Channel

itab-vtweg.

PERFORM bdc_field USING 'VBAK-SPART' " Division

itab-spart.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'VBKD-BSTKD' " PO Number

itab-bstkd.

PERFORM bdc_field USING 'VBKD-BSTDK' " PO Date

itab-bstdk.

PERFORM bdc_field USING 'KUAGV-KUNNR' " Sold to Party

itab-kunnr.

PERFORM bdc_field USING 'KUWEV-KUNNR' " Ship to Party

itab-kunrg.

PERFORM bdc_field USING 'VBKD-ZTERM' " Payment Terms

itab-zterm.

PERFORM bdc_field USING 'VBKD-INCO1' " Inco Terms1

itab-inco1.

PERFORM bdc_field USING 'VBKD-INCO2' " Inco Terms2

itab-inco2.

PERFORM bdc_field USING 'VBAK-AUGRU' " Order Reason

itab-augru.

ENDON.

IF flag = 0.

LOOP AT itab WHERE bstkd = itab-bstkd AND kunnr = itab-kunnr .

var1 = 'RV45A-MABNR'.

CONCATENATE var1 var2 num var3 INTO var1.

PERFORM bdc_field USING var1

itab-mabnr.

var1 = 'RV45A-KWMENG'.

CONCATENATE var1 var2 num var3 INTO var1.

PERFORM bdc_field USING var1

itab-kwmeng.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

num = 2.

ENDLOOP.

ELSE.

CONTINUE.

ENDIF.

flag = 1.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=SICH'.

PERFORM bdc_transaction USING 'VA01'.

ENDLOOP.

PERFORM close_group.

WRITE : / 'Session',session, 'was Created'.

FORM open_group.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = session

user = sy-uname

keep = 'X'.

ENDFORM.

FORM close_group.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDFORM.

FORM bdc_transaction USING tcode.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = tcode

TABLES

dynprotab = bdcdata.

ENDFORM.

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM.

FORM bdc_field USING fnam fval.

IF fval ' '.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDIF.

ENDFORM.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 11, 2008 at 02:42 PM

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    codepage = ' '

    filename = filename

    filetype = 'ASC'

    headlen = ' '

    line_exit = ' '

    trunclen = ' '

    user_form = ' '

    user_prog = ' '

    dat_d_format = ' '

    IMPORTING

    FILELENGTH =

    TABLES

    data_tab = itab

    EXCEPTIONS

    conversion_error = 1

    file_open_error = 2

    file_read_error = 3

    invalid_type = 4

    no_batch = 5

    unknown_error = 6

    invalid_table_width = 7

    gui_refuse_filetransfer = 8

    customer_error = 9

    OTHERS = 10.

    IF sy-subrc 0.

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

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

    ENDIF.

    After using this function module yoyr getting the data into internal table itab.

    then you can use the below code.

    you can split your data based on delimeter. delimeter like , # |

    now now problem items can either be in the same line or in the next line...

    based on your internal table fileds its going to split...

    loop at lt_itab into wa_itab.

    SPLIT wa_itab AT gc_comm INTO

    wa_itab1-matnr

    wa_itab1-werks

    wa_itab1-stlan like

    apeend to one more internal table.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.