Skip to Content
author's profile photo
Former Member

Flat files in BDC

hi......to everybody.....

i am working on session method with two application(transaction)s.

i have the data in two flat files separate related to those applications in presentation server.

how to update the data into the data base?

Message was edited by:

Alvaro Tejada Galindo

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Aug 15, 2007 at 04:52 PM

    HI,

    there is no difference as far as the code is concerned for the BDC.. only change is u use bdc_open_group,bdc_insert and bdc_close_group function modules instead of call transaction..

    See the example

    REPORT Z_PCA_PL

    MESSAGE-ID ZYFI

    NO STANDARD PAGE HEADING

    LINE-SIZE 100.

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

    • Progname : ZF_BDCP_PCPLANE_01 *

    • Request no : RTDK905785

    • Description : Profit center plan data upload for KIMO dates

    ----


    • LOGICAL DB : VERSION OF : *

    ----


    • AUTHOR : Krishna M

    • DATE : 28/04/2004

    ----


    • MODIFICATION LOG (latest change first): *

    ----


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

    • TABLES

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

    *-- Imternal table declaration.

    DATA : BEGIN OF IT_UPLOAD OCCURS 0,

    YEAR(4), " Year Variable

    PROFIT(10), " Profit Center Variable

    GLACCOUNT(13), " GL account Variable

    AMOUNT(10), " Amount Variable

    END OF IT_UPLOAD.

    *-- Declaration of bdc data.

    DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

    *-Internal table for message control

    *data : msgtab like bdcmsgcoll occurs 0 with header line.

    *--Selection screen declaration

    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

    PARAMETERS: P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.

    SELECTION-SCREEN END OF BLOCK B1.

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

    • A T S E L E C T I O N - S C R E E N .

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

    *--Value request for the file.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

    PERFORM VALUE_REQUEST.

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

    • S T A R T - O F - S E L E C T I O N

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

    START-OF-SELECTION.

    *-- Upload data into internal table it_upload.

    PERFORM UPLOAD.

    PERFORM PROFIT_CENTER.

    PERFORM BDC_OPEN_GROUP.

    PERFORM CALL_TRANSACTION.

    *-- Close the bdc group

    PERFORM BDC_CLOSE_GROUP.

    &----


    *& Form upload

    &----


    • Uploading of the flat file into the internal table

    *----


    FORM UPLOAD.

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = P_FILE

    FILETYPE = 'DAT'

    TABLES

    DATA_TAB = IT_UPLOAD

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TABLE_WIDTH = 4

    INVALID_TYPE = 5

    NO_BATCH = 6

    UNKNOWN_ERROR = 7

    OTHERS = 8.

    IF SY-SUBRC <> 0 .

    MESSAGE E999 WITH TEXT-002. "File cannot be Uploaded

    ENDIF.

    ENDFORM. " upload

    &----


    *& Form value_request

    &----


    • IN PUT HEPL REQUEST

    ----


    FORM VALUE_REQUEST.

    CALL FUNCTION 'WS_FILENAME_GET'

    EXPORTING

    DEF_FILENAME = ' '

    DEF_PATH = 'C:\'

    MASK = ',.txt,.*.'

    MODE = 'S'

    TITLE = TEXT-003 "'Upload'

    IMPORTING

    FILENAME = P_FILE

    EXCEPTIONS

    INV_WINSYS = 1

    NO_BATCH = 2

    SELECTION_CANCEL = 3

    SELECTION_ERROR = 4

    OTHERS = 5.

    CASE SY-SUBRC.

    WHEN 3.

    MESSAGE I999 WITH TEXT-004. "Selection Cancel

    WHEN 4.

    MESSAGE I999 WITH TEXT-005. "Selection Error'.

    ENDCASE.

    ENDFORM. " value_request

    *----


    • form call_transaction.

    *----


    FORM CALL_TRANSACTION.

    IF NOT IT_UPLOAD[] IS INITIAL.

    LOOP AT IT_UPLOAD. " loop at it_upload

    PERFORM FILL_BDC.

    ENDLOOP.

    ELSE.

    MESSAGE E999 WITH TEXT-010. " 'No records found'.

    ENDIF.

    ENDFORM.

    &----


    *& Form fill_bdc

    &----


    • This form is used to fill the bdcdata & call the transaction *

    ----


    FORM FILL_BDC.

    PERFORM PROFIT_CENTER_UPLOAD.

    ENDFORM.

    &----


    *& Form Profit_Center_Upload.

    &----


    FORM PROFIT_CENTER_UPLOAD.

    PERFORM FILL_BDCDATA USING:

    'SAPLKPP0' '1000' 'X',

    'bdc_cursor' 'kpp0b-value(03)' ' ',

    'kpp0b-value(03)' IT_UPLOAD-YEAR ' ',

    'bdc_cursor' 'kpp0b-value(06)' ' ',

    'kpp0b-value(06)' IT_UPLOAD-PROFIT ' ',

    'bdc_cursor' 'kpp0b-value(09)' ' ',

    'kpp0b-value(09)' IT_UPLOAD-GLACCOUNT ' ',

    'bdc_okcode' '/00' ' ',

    'BDC_OKCODE' '=CSUB' ' ',

    'SAPLKPP2' '0103' 'X',

    'bdc_cursor' 'BDC03(01)' ' ',

    'BDC03(01)' IT_UPLOAD-AMOUNT ' ',

    'BDC_OKCODE' '/00' ' ',

    'BDC_OKCODE' '=CBUC' ' '.

    PERFORM BDC_INSERT.

    ENDFORM.

    &----


    *& Form fill_bdcdata

    &----


    • This form is used to fill the IT_BDCDATA table *

    ----


    FORM FILL_BDCDATA USING PROGRAM TYPE C

    DYNPRO TYPE ANY

    DYNBEGIN TYPE C.

    IF DYNBEGIN = 'X'.

    IT_BDCDATA-PROGRAM = PROGRAM.

    IT_BDCDATA-DYNPRO = DYNPRO.

    IT_BDCDATA-DYNBEGIN = DYNBEGIN.

    ELSE.

    IT_BDCDATA-FNAM = PROGRAM.

    IT_BDCDATA-FVAL = DYNPRO.

    ENDIF.

    APPEND IT_BDCDATA.

    CLEAR IT_BDCDATA.

    ENDFORM. " fill_bdcdata

    *----


    • form profit_center

    *----


    FORM PROFIT_CENTER.

    PERFORM FILL_BDCDATA USING:

    'SAPLSPO4' '0300' 'X',

    'SVALD-VALUE(01)' '0100' ' ',

    'BDC_OKCODE' '=FURT' ' ',

    'SAPLKPP6' '1007' 'X',

    'RKPP6-PLPROF' 'RTA-PC-K' ' ',

    'BDC_OKCODE' '=CWEI' ' '.

    ENDFORM.

    *----


    • form bdc_open_group.

    *----


    FORM BDC_OPEN_GROUP.

    CALL FUNCTION 'BDC_OPEN_GROUP'

    EXPORTING

    CLIENT = SY-MANDT

    GROUP = '7KE1'

    KEEP = 'X'

    USER = SY-UNAME.

    IF SY-SUBRC NE 0. "Error in Opening error session

    *---

    MESSAGE E999 WITH TEXT-007. "'Unable to open BDC Group'.

    ELSE.

    MESSAGE S999 WITH TEXT-008. "Session created successfully"

    ENDIF.

    ENDFORM.

    *----


    • form bdc_insert

    *----


    FORM BDC_INSERT.

    CALL FUNCTION 'BDC_INSERT'

    EXPORTING

    TCODE = '7KE1'

    TABLES

    DYNPROTAB = IT_BDCDATA[]

    EXCEPTIONS

    INTERNAL_ERROR = 1

    NOT_OPEN = 2

    QUEUE_ERROR = 3

    TCODE_INVALID = 4

    PRINTING_INVALID = 5

    POSTING_INVALID = 6

    OTHERS = 7.

    IF SY-SUBRC <> 0.

    MESSAGE E999 WITH TEXT-006.

    • 'Unable to Insert using Transaction 7KE1'.

    ENDIF.

    REFRESH IT_BDCDATA.

    CLEAR IT_BDCDATA.

    ENDFORM.

    &----


    *& Form BDC_CLOSE_GROUP

    &----


    • This form is used to close the group that is opend.

    ----


    FORM BDC_CLOSE_GROUP.

    CALL FUNCTION 'BDC_CLOSE_GROUP'

    EXCEPTIONS

    NOT_OPEN = 1

    QUEUE_ERROR = 2

    OTHERS = 3.

    ENDFORM. " BDC_CLOSE_GROUP

    Thanks

    Mahesh

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 15, 2007 at 04:53 PM

    One more example

    for two files just call the gui_download two times.

    REPORT ZTAPAS2

    NO STANDARD PAGE HEADING LINE-SIZE 255.

    *INCLUDE ZBDCRECX.

    DATA: BEGIN OF RECORD OCCURS 0,

    BLDAT_001(010),

    BLART_002(002),

    BUKRS_003(004),

    BUDAT_004(010),

    MONAT_005(002),

    WAERS_006(005),

    • DOCID_007(010),

    NEWBS_008(002),

    NEWKO_009(017),

    WRBTR_010(016),

    • MWSKZ_011(002),

    GSBER_012(004),

    ZTERM_013(004),

    • ZFBDT_014(010),

    SGTXT_015(050),

    NEWBS_016(002),

    NEWKO_017(017),

    WRBTR_018(016),

    FMORE_019(001),

    GSBER_020(004),

    END OF RECORD.

    PARAMETERS : P_GRP(12) TYPE C OBLIGATORY.

    START-OF-SELECTION.

    PERFORM UPLOAD_DATA TABLES RECORD.

    PERFORM OPEN_GROUP USING P_GRP.

    LOOP AT RECORD.

    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'

    RECORD-BLDAT_001.

    PERFORM BDC_FIELD USING 'BKPF-BLART'

    RECORD-BLART_002.

    PERFORM BDC_FIELD USING 'BKPF-BUKRS'

    RECORD-BUKRS_003.

    PERFORM BDC_FIELD USING 'BKPF-BUDAT'

    RECORD-BUDAT_004.

    PERFORM BDC_FIELD USING 'BKPF-MONAT'

    RECORD-MONAT_005.

    PERFORM BDC_FIELD USING 'BKPF-WAERS'

    RECORD-WAERS_006.

    *perform bdc_field using 'FS006-DOCID'

    • record-DOCID_007.

    PERFORM BDC_FIELD USING 'RF05A-NEWBS'

    RECORD-NEWBS_008.

    PERFORM BDC_FIELD USING 'RF05A-NEWKO'

    RECORD-NEWKO_009.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '0301'.

    PERFORM BDC_FIELD USING 'BDC_CURSOR'

    'RF05A-NEWUM'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '/00'.

    PERFORM BDC_FIELD USING 'BSEG-WRBTR'

    RECORD-WRBTR_010.

    *perform bdc_field using 'BSEG-MWSKZ'

    • record-MWSKZ_011.

    PERFORM BDC_FIELD USING 'BSEG-GSBER'

    RECORD-GSBER_012.

    PERFORM BDC_FIELD USING 'BSEG-ZTERM'

    RECORD-ZTERM_013.

    *perform bdc_field using 'BSEG-ZFBDT'

    • record-ZFBDT_014.

    PERFORM BDC_FIELD USING 'BSEG-SGTXT'

    RECORD-SGTXT_015.

    PERFORM BDC_FIELD USING 'RF05A-NEWBS'

    RECORD-NEWBS_016.

    PERFORM BDC_FIELD USING 'RF05A-NEWKO'

    RECORD-NEWKO_017.

    PERFORM BDC_DYNPRO USING 'SAPMF05A' '0300'.

    PERFORM BDC_FIELD USING 'BDC_CURSOR'

    'BSEG-WRBTR'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '=BU'.

    PERFORM BDC_FIELD USING 'BSEG-WRBTR'

    RECORD-WRBTR_018.

    PERFORM BDC_FIELD USING 'DKACB-FMORE'

    RECORD-FMORE_019.

    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'

    RECORD-GSBER_020.

    PERFORM BDC_TRANSACTION USING 'F-22'.

    ENDLOOP.

    PERFORM CLOSE_GROUP.

    DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

    BDCMODE TYPE C.

    ----


    • FORM OPEN_GROUP *

    ----


    FORM OPEN_GROUP USING P_GROUP.

    SKIP.

    WRITE: /(20) 'Create group'(I01), P_GROUP.

    SKIP.

    • open batchinput group

    CALL FUNCTION 'BDC_OPEN_GROUP'

    EXPORTING

    CLIENT = SY-MANDT

    GROUP = P_GROUP

    USER = SY-UNAME

    KEEP = 'X'.

    • holddate = holddate.

    WRITE: /(30) 'BDC_OPEN_GROUP'(I02),

    (12) 'returncode:'(I05),

    SY-SUBRC.

    ENDFORM. "open_group

    ----


    • FORM BDC_TRANSACTION *

    ----


    FORM BDC_TRANSACTION USING TCODE.

    DATA: L_MSTRING(480).

    DATA: L_SUBRC LIKE SY-SUBRC.

    CALL FUNCTION 'BDC_INSERT'

    EXPORTING

    TCODE = TCODE

    TABLES

    DYNPROTAB = BDCDATA

    EXCEPTIONS

    INTERNAL_ERROR = 1

    NOT_OPEN = 2

    QUEUE_ERROR = 3

    TCODE_INVALID = 4

    PRINTING_INVALID = 5

    POSTING_INVALID = 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.

    • batch input session

    WRITE: / 'BDC_INSERT'(I03), TCODE,

    'returncode:'(I05), SY-SUBRC,

    'RECORD:', SY-INDEX.

    ENDFORM. "bdc_transaction

    ----


    • CLOSE GROUP *

    ----


    FORM CLOSE_GROUP.

    • close batchinput group

    CALL FUNCTION 'BDC_CLOSE_GROUP'.

    WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),

    (12) 'returncode:'(I05),

    SY-SUBRC.

    ENDFORM. "close_group

    ----


    • Start new screen *

    ----


    FORM BDC_DYNPRO USING PROGRAM DYNPRO.

    CLEAR BDCDATA.

    BDCDATA-PROGRAM = PROGRAM.

    BDCDATA-DYNPRO = DYNPRO.

    BDCDATA-DYNBEGIN = 'X'.

    APPEND BDCDATA.

    ENDFORM. "bdc_dynpro

    ----


    • Insert field *

    ----


    FORM BDC_FIELD USING FNAM FVAL.

    CLEAR BDCDATA.

    BDCDATA-FNAM = FNAM.

    BDCDATA-FVAL = FVAL.

    APPEND BDCDATA.

    ENDFORM. "bdc_field

    &----


    *& Form UPLOAD_DATA

    &----


    FORM UPLOAD_DATA TABLES T_ITAB.

    REFRESH: RECORD.

    CLEAR : RECORD.

    CALL FUNCTION 'UPLOAD'

    EXPORTING

    • CODEPAGE = ' '

    FILENAME = 'C:\'

    FILETYPE = 'DAT'

    • 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 = RECORD

    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.

    ENDFORM. " UPLOAD_DATA

    Thanks

    Mahesh

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 15, 2007 at 05:04 PM

    Please try to use better post titles....Using "BDC", doesn't give us the idea of the main problem...And that also makes harder for the "Search" engine to gather the related questions.

    Greetings,

    Blag.

    Add comment
    10|10000 characters needed characters exceeded