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

BDC Program

Hi all,

Can anyone provide any BDC Session method code.

Just I want to keep if for reference.

Thanks,

Shashikanth

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2005 at 01:45 PM

    &----


    *& Report ZNANDHABDC6 *

    *& *

    &----


    *& *

    *& *

    &----


    REPORT ZNANDHABDC6 .

    &----


    *& *

    *& TYPES *

    &----


    TYPES : BEGIN OF X_FF,

    MBRSH(1), "Industry Sector

    MTART(4), "Material Type

    MAKTX(40), "Material Description

    MEINS(3), "Base Unit of Measure

    MATKL(9), "Material Group

    END OF X_FF.

    &----


    • DECLARATIONS

    &----


    • Flat file

    DATA: I_FF TYPE X_FF OCCURS 0 WITH HEADER LINE.

    • BDC Data

    DATA: I_BDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

    *----


    varaible for fomratting messages

    DATA: LV_MSG(255).

    &----


    • START OF SELECTION

    &----


    START-OF-SELECTION.

    • Get Flat file Data

    PERFORM GET_DATA.

    • Create BDC Data

    PERFORM GENERATE.

    &----


    *& Form GET_DATA

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GET_DATA .

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    FILENAME = 'C:\ZNANDHABDC5.TXT'

    FILETYPE = 'ASC'

    HAS_FIELD_SEPARATOR = 'X'

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

    • IMPORTING

    • FILELENGTH =

    • HEADER =

    TABLES

    DATA_TAB = I_FF

    EXCEPTIONS

    FILE_OPEN_ERROR = 1

    FILE_READ_ERROR = 2

    NO_BATCH = 3

    GUI_REFUSE_FILETRANSFER = 4

    INVALID_TYPE = 5

    NO_AUTHORITY = 6

    UNKNOWN_ERROR = 7

    BAD_DATA_FORMAT = 8

    HEADER_NOT_ALLOWED = 9

    SEPARATOR_NOT_ALLOWED = 10

    HEADER_TOO_LONG = 11

    UNKNOWN_DP_ERROR = 12

    ACCESS_DENIED = 13

    DP_OUT_OF_MEMORY = 14

    DISK_FULL = 15

    DP_TIMEOUT = 16

    OTHERS = 17

    .

    IF SY-SUBRC = 0.

    DELETE I_FF INDEX 1.

    ENDIF.

    ENDFORM. " GET_DATA

    &----


    *& Form GENERATE

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GENERATE .

    DATA: LV_MSG(255),

    LV_DATE LIKE SY-DATUM.

    LV_DATE = SY-DATUM - 1.

    CALL FUNCTION 'BDC_OPEN_GROUP'

    EXPORTING

    CLIENT = SY-MANDT

    • DEST = FILLER8

    GROUP = 'T02'

    HOLDDATE = LV_DATE

    KEEP = 'X'

    USER = SY-UNAME

    • RECORD = FILLER1

    • PROG = SY-CPROG

    • IMPORTING

    • QID =

    EXCEPTIONS

    CLIENT_INVALID = 1

    DESTINATION_INVALID = 2

    GROUP_INVALID = 3

    GROUP_IS_LOCKED = 4

    HOLDDATE_INVALID = 5

    INTERNAL_ERROR = 6

    QUEUE_ERROR = 7

    RUNNING = 8

    SYSTEM_LOCK_ERROR = 9

    USER_INVALID = 10

    OTHERS = 11

    .

    IF SY-SUBRC = 0.

    LOOP AT I_FF.

    PERFORM POPULATE USING :'X' 'SAPLMGMM' '0060',

    '' 'BDC_OKCODE' '/00',

    '' 'RMMG1-MBRSH' I_FF-MBRSH,

    '' 'RMMG1-MTART' I_FF-MTART,

    'X' 'SAPLMGMM' '0070',

    '' 'BDC_OKCODE' '=ENTR',

    '' 'MSICHTAUSW-KZSEL(01)' 'X',

    'X' 'SAPLMGMM' '4004',

    '' 'BDC_OKCODE' '=BU',

    '' 'MAKT-MAKTX' I_FF-MAKTX,

    '' 'MARA-MEINS' I_FF-MEINS,

    '' 'MARA-MATKL' I_FF-MATKL,

    '' 'MARA-MTPOS_MARA' 'NORM'.

    CALL FUNCTION 'BDC_INSERT'

    EXPORTING

    TCODE = 'MM01'

    TABLES

    DYNPROTAB = I_BDC

    EXCEPTIONS

    INTERNAL_ERROR = 1

    NOT_OPEN = 2

    QUEUE_ERROR = 3

    TCODE_INVALID = 4

    PRINTING_INVALID = 5

    POSTING_INVALID = 6

    OTHERS = 7.

    CLEAR: I_BDC[].

    ENDLOOP.

    CALL FUNCTION 'BDC_CLOSE_GROUP'

    • EXCEPTIONS

    • NOT_OPEN = 1

    • QUEUE_ERROR = 2

    • OTHERS = 3

    .

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    ENDIF.

    ENDFORM. " GENERATE

    &----


    *& Form POPULATE

    &----


    • text

    ----


    • -->P_0133 text

    • -->P_0134 text

    • -->P_0135 text

    ----


    FORM POPULATE USING VALUE(P_A)

    VALUE(P_B)

    VALUE(P_C).

    IF P_A = 'X'.

    I_BDC-PROGRAM = P_B.

    I_BDC-DYNPRO = P_C.

    I_BDC-DYNBEGIN = 'X'.

    ELSE.

    I_BDC-FNAM = P_B.

    I_BDC-FVAL = P_C.

    ENDIF.

    APPEND I_BDC.

    CLEAR I_BDC.

    ENDFORM. " POPULATE

    Add a comment
    10|10000 characters needed characters exceeded

    • Here is a example of a upload program that exepts a file from the presentation server and does a BDC to update the the standard price of a materail.

      
      
      REPORT ZRICH_0002
             NO STANDARD PAGE HEADING
             LINE-SIZE 132.
      
      TABLES: MARA, MARC.
      
      DATA: BEGIN OF ITAB OCCURS 0,
            MATERIAL(18) TYPE C,
            STDPRICE(7) TYPE C,
      END OF ITAB.
      
      DATA: BEGIN OF PL_ITAB OCCURS 0,
            MATNR TYPE MARA-MATNR,
            WERKS TYPE MARC-WERKS,
            END OF PL_ITAB.
      
      
      DATA: TOTAL(5) TYPE C,
            PROCESSED(5) TYPE C,
            TEXT(50) TYPE C,
            PDATE(10) TYPE C.
      
      DATA: BDCDATA LIKE BDCDATA OCCURS 20 WITH HEADER LINE,
            MODE(1) TYPE C VALUE 'N'.
      
      SELECTION-SCREEN SKIP 1.
      PARAMETERS: P_FILE TYPE LOCALFILE DEFAULT
                  'C:Documents and SettingsrichhDesktopStd_Price.txt'.
      PARAMETERS: P_DATE LIKE SY-DATUM.
      PARAMETERS: P_TEST AS CHECKBOX.
      SELECTION-SCREEN SKIP 1.
      
      AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
        CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
             EXPORTING
                  STATIC    = 'X'
             CHANGING
                  FILE_NAME = P_FILE.
      
      
      START-OF-SELECTION.
      
        CLEAR: ITAB[].
        PERFORM UPLOAD_DATA.
        DESCRIBE TABLE ITAB LINES TOTAL.
        PERFORM CHECK_RECORDS.
      
      
      END-OF-SELECTION.
      
      ************************************************************************
      * Upload_Data
      ************************************************************************
      
      FORM UPLOAD_DATA.
      
        CALL FUNCTION 'WS_UPLOAD'
             EXPORTING
                  FILENAME                = P_FILE
                  FILETYPE                = 'ASC'
             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 NE 0.
      
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          EXIT.
        ENDIF.
      
      ENDFORM.
      
      
      ************************************************************************
      * Check_Records
      ************************************************************************
      
      FORM CHECK_RECORDS.
      
        LOOP AT ITAB.
      
          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
               EXPORTING
                    INPUT  = ITAB-MATERIAL
               IMPORTING
                    OUTPUT = ITAB-MATERIAL.
      
          SELECT SINGLE * FROM MARA
                    WHERE MATNR  = ITAB-MATERIAL.
          IF SY-SUBRC <> 0 OR MARA-LVORM = 'X'.
            WRITE:/ 'E', ITAB-MATERIAL,
                      'material does not exist or is flagged for deletion'.
          ELSE.
      
            IF P_TEST = ' '.
      
              SELECT MATNR WERKS INTO CORRESPONDING FIELDS OF TABLE PL_ITAB
                               FROM MARC WHERE MATNR = ITAB-MATERIAL.
              LOOP AT PL_ITAB.
      
                CONCATENATE P_DATE+4(2) '/' P_DATE+6(2) '/' P_DATE(4)
                        INTO PDATE.
      
                PERFORM BDC_DYNPRO      USING 'SAPRCKM_MR21' '0201'.
                PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                              'MR21HEAD-WERKS'.
                PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                              '=ENTR'.
                PERFORM BDC_FIELD       USING 'MR21HEAD-BUDAT'
                                            PDATE.
                PERFORM BDC_FIELD       USING 'MR21HEAD-BUKRS'
                                              '0010'.
                PERFORM BDC_FIELD       USING 'MR21HEAD-WERKS'
                                            PL_ITAB-WERKS.
                PERFORM BDC_FIELD       USING 'MR21HEAD-SCREEN_VARIANT'
                                              'MR21_LAGERMATERIAL_0250'.
                PERFORM BDC_DYNPRO      USING 'SAPRCKM_MR21' '0201'.
                PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                              '=ENTR'.
                PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                              'CKI_MR21_0250-NEWVALPR(01)'.
                PERFORM BDC_FIELD       USING 'MR21HEAD-SCREEN_VARIANT'
                                              'MR21_LAGERMATERIAL_BWKEY_0250'.
                PERFORM BDC_FIELD       USING 'CKI_MR21_0250-MATNR(01)'
                                            PL_ITAB-MATNR.
                PERFORM BDC_FIELD       USING 'CKI_MR21_0250-NEWVALPR(01)'
                                            ITAB-STDPRICE.
                PERFORM BDC_DYNPRO      USING 'SAPRCKM_MR21' '0201'.
                PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                              '=SAVE'.
                PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                              'CKI_MR21_0250-MATNR(02)'.
                PERFORM BDC_FIELD       USING 'MR21HEAD-SCREEN_VARIANT'
                                              'MR21_LAGERMATERIAL_BWKEY_0250'.
      
                CALL TRANSACTION 'MR21' USING BDCDATA MODE MODE
                        UPDATE 'S'.
      
                IF SY-SUBRC = 0.
                  WRITE:/ 'S', ITAB-MATERIAL, PL_ITAB-WERKS,
                  'updated successfully'.
                ELSE.
                  WRITE:/ 'E', ITAB-MATERIAL, PL_ITAB-WERKS,
                           'error trying to update'.
                ENDIF.
      
                CLEAR BDCDATA.
                REFRESH BDCDATA.
                COMMIT WORK AND WAIT.
      
              ENDLOOP.
            ELSE.
              WRITE:/ 'S', ITAB-MATERIAL,
                      'Test Mode - Material will be updated successfully'.
            ENDIF.
          ENDIF.
      
          PERFORM SHOW_STATUS.
      
        ENDLOOP.
      
      ENDFORM.
      
      ************************************************************************
      *      Form  BDC_DYNPRO
      ************************************************************************
      
      FORM BDC_DYNPRO USING  PROGRAM DYNPRO.
      
        CLEAR BDCDATA.
        BDCDATA-PROGRAM = PROGRAM.
        BDCDATA-DYNPRO = DYNPRO.
        BDCDATA-DYNBEGIN = 'X'.
        APPEND BDCDATA.
      
      ENDFORM.                    " BDC_DYNPRO
      
      ************************************************************************
      *      Form  BDC_FIELD
      ************************************************************************
      
      FORM BDC_FIELD USING FNAM FVAL.
      
        CLEAR BDCDATA.
        BDCDATA-FNAM = FNAM.
        BDCDATA-FVAL = FVAL.
        APPEND BDCDATA.
      
      ENDFORM.                    " BDC_FIELD
      
      ************************************************************************
      * SHOW_STATUS
      ************************************************************************
      
      FORM SHOW_STATUS.
      
        PROCESSED = PROCESSED + 1.
        TEXT = TEXT-001.
        REPLACE '&1' WITH PROCESSED INTO TEXT.
        REPLACE '&2' WITH TOTAL INTO TEXT.
        CONDENSE TEXT.
        CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
             EXPORTING
                  TEXT = TEXT.
      
      ENDFORM.
      
      

      Regards,

      Rich Heilman

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2005 at 01:54 PM

    Hi shashi,

    check this it may help you...

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

    regards,

    venu.

    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.