Skip to Content
0
Former Member
Nov 02, 2007 at 09:48 AM

BDC : Checking records before they are updated into DB. ERROR !!!

146 Views

HI EXPERTS,

IM RUNNING A BDC PROGRAM BUT BEFORE THAT I AM CHECKING IF THE RECORD ALREADY EXISTS INTO THE DATABASE, IF YES, THEN THAT RECORD WILL NOT BE UPDATED. But its not working. With every record it says that record exists. DO WE NEED any kind of conversion to be done using any conversion FMs.

PLEASE HELP!!!

Following is the code.

REPORT ZFIRST_MM01 NO STANDARD PAGE HEADING LINE-SIZE 255 MESSAGE-ID M3.

TABLES MARA.

DATA L_MATNR LIKE MARA-MATNR.

DATA : BEGIN OF ITAB OCCURS 0,

MATNR LIKE RMMG1-MATNR,

MBRSH LIKE RMMG1-MBRSH,

MTART LIKE RMMG1-MTART,

MAKTX LIKE MAKT-MAKTX,

MEINS LIKE MARA-MEINS,

END OF ITAB.

DATA : BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

  • Internal table to hold existing records.

DATA FAIL_ITAB LIKE ITAB OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF WA_ITAB,

MATNR LIKE RMMG1-MATNR,

MBRSH LIKE RMMG1-MBRSH,

MTART LIKE RMMG1-MTART,

MAKTX LIKE MAKT-MAKTX,

MEINS LIKE MARA-MEINS,

END OF WA_ITAB.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = 'C:\Documents and Settings\Administrator\Desktop\BDC1.TXT'

FILETYPE = 'DAT'

  • 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

  • NO_AUTHORITY = 10

  • OTHERS = 11

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

*LOOP AT ITAB.

*CALL FUNCTION 'CONVERSION_EXIT_MATN1_RANGE_I'

  • EXPORTING

  • INPUT = ITAB-MATNR

  • IMPORTING

  • OUTPUT = ITAB-MATNR

  • TABLES

  • RANGE_INT = ITAB

  • RANGE_EXT = ITAB

  • .

*

  • WRITE : / ITAB-MATNR.

*

  • CALL FUNCTION 'CONVERSION_EXIT_MATN1_RANGE_O'

  • EXPORTING

  • INPUT = ITAB-MATNR

  • IMPORTING

  • OUTPUT =

  • TABLES

  • RANGE_INT = ITAB

  • RANGE_EXT = ITAB

  • .

  • *

    • WRITE : / ITAB-MATNR.

    *

    *ENDLOOP.

    LOOP AT ITAB.

    **COMPARING THE ITAB RECORD WITH THE DATABASE TABLE IF IT ALREADY EXISTS IT IS

    BEING T/F TO FAIL_ITAB.

    SELECT SINGLE MATNR INTO L_MATNR FROM MARA WHERE MATNR = ITAB-MATNR.

    *

    • WRITE : / SY-TABIX, '. WA_ITAB-MATNR: ', WA_ITAB-MATNR.

    IF SY-SUBRC EQ 0.

    READ TABLE ITAB INTO FAIL_ITAB.

    APPEND FAIL_ITAB.

    MESSAGE I307.

    ELSE.

    REFRESH BDCDATA.

    PERFORM RECORDING.

    CALL TRANSACTION 'MM01' USING BDCDATA MODE 'A' MESSAGES INTO BDCMSGCOLL.

    ENDIF.

    LOOP AT BDCMSGCOLL WHERE MSGID EQ '307'.

    WRITE : / 'This record did not get updated'.

    READ TABLE ITAB INDEX SY-TABIX INTO FAIL_ITAB.

    APPEND FAIL_ITAB.

    ENDLOOP.

    *

    ENDLOOP.

    *

    • WRITE : 'Msg Typ', 'Msg ID', 'MSG NO'.

    • LOOP AT BDCMSGCOLL.

    • WRITE : / BDCMSGCOLL-MSGTYP UNDER 'Msg Typ', BDCMSGCOLL-MSGID UNDER 'Msg ID',

    BDCMSGCOLL-MSGNR UNDER 'MSG NO'.

    • ENDLOOP.

    *IF FAIL_ITAB IS INITIAL.

    • WRITE : 'NO RECORDS IN FAILED ITAB.'.

    *ELSE.

    • LOOP AT FAIL_ITAB.

    • WRITE: / FAIL_ITAB-MATNR, FAIL_ITAB-MBRSH, FAIL_ITAB-MTART, FAIL_ITAB-MAKTX,

    FAIL_ITAB-MEINS.

    • ENDLOOP.

    *ENDIF.

    &----


    *& Form RECORDING

    &----


    • text

    ----


    FORM RECORDING.

    PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.

    PERFORM BDC_FIELD USING 'BDC_CURSOR'

    'RMMG1-MTART'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '/00'.

    PERFORM BDC_FIELD USING 'RMMG1-MATNR'

    ITAB-MATNR.

    PERFORM BDC_FIELD USING 'RMMG1-MBRSH'

    ITAB-MBRSH.

    PERFORM BDC_FIELD USING 'RMMG1-MTART'

    ITAB-MTART.

    PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0070'.

    PERFORM BDC_FIELD USING 'BDC_CURSOR'

    'MSICHTAUSW-DYTXT(01)'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '=ENTR'.

    PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(01)'

    'X'.

    PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '/00'.

    PERFORM BDC_FIELD USING 'MAKT-MAKTX'

    ITAB-MAKTX.

    PERFORM BDC_FIELD USING 'BDC_CURSOR'

    'MARA-SPART'.

    PERFORM BDC_FIELD USING 'MARA-MEINS'

    ITAB-MEINS.

    PERFORM BDC_FIELD USING 'MARA-MTPOS_MARA'

    'NORM'.

    PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0300'.

    PERFORM BDC_FIELD USING 'BDC_OKCODE'

    '=YES'.

    *perform bdc_transaction using 'MM01'.

    *

    *perform close_group.

    ENDFORM. "RECORDING

    ----


    • 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.

    IF FVAL <> SPACE.

    CLEAR BDCDATA.

    BDCDATA-FNAM = FNAM.

    BDCDATA-FVAL = FVAL.

    APPEND BDCDATA.

    ENDIF.

    ENDFORM. "BDC_FIELD

    ThankX

    ~Sid

    "Max points on precise guidelines"