Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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"

10 REPLIES 10

Former Member
0 Kudos

Hey your code is correct.., DO one thing.. Cross check any 5-10 entries with MARA data. Then you will know .....

0 Kudos

thankX, i've already tried it.... in my flat file i have 10 records out of which 5 are new and 5 already exist in the DB.

Any suggestions ??

~Sid

Former Member
0 Kudos

Hi

Check the below code:

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

IF not l_matnr is initial.

<b>READ TABLE ITAB INTO FAIL_ITAB.</b> not required

APPEND i_itab into FAIL_ITAB.

MESSAGE I307.

endif.

regards

Shiva

0 Kudos

well... its one of the other way that you mentioned...thanx... but issue is L_MATNR remains initial always...i have checked the value of L_MATNR its never initialized....

~:(

~Sid

0 Kudos

experts !! Anyt more thoughts on this

~Sid

0 Kudos

Try this one...

Add the code as shown below for convesion...

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

BEING T/F TO FAIL_ITAB.

* " code for pedding leading zeros...
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
  EXPORTING
    INPUT              = itab-matnr
 IMPORTING
   OUTPUT             = itab-matnr
* EXCEPTIONS
*   LENGTH_ERROR       = 1
*   OTHERS             = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

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

.....

Regards,

Naimesh Patel

0 Kudos

well..already tried that...

thanx anyways...

Former Member
0 Kudos

Hi Sid,

I am not sure what's wrong with your code but I'll try and give another way.


If not itab[] is initial.

Select matnr 
   FROM mara
   for all entries in itab
   into table lt_matnr
   where matnr = itab-matnr.

If sy-subrc eq 0.

Loop at lt_matnr.
Read table itab where matnr = itab-matnr.
If sy-subrc eq 0.
 Move itab to fail_tab.
 append fail_itab.
 Delete itab.   "This will delete that record.
 clear fail_tab.
Endif.
Endloop.

Else.
 Message i000 with 'No value was found in MARA'.
endif.


Loop at itab. "Now this has remaining MATNR.
* Do your BDC operations here.
Endloop.


Else.
Message i000 with 'No value in ITAB'.
Endif.

Hope this resolves your problem.

Regards

Nishant

Also,

If in case it says no value found in MARA. Just debug and see whether value in MATNR field of table ITAB is coming properly or not. It might be that some char is getting cut or there is some space that is coming in.

Message was edited by:

Nishant Rustagi

0 Kudos

HI Nishant,

Sorry I missed to award the points....

Thanks for your help!!

~Sid

Former Member
0 Kudos

Hi,

take two internal tables same as Itab.-say itab1 ,itab2

then use for all entries

first upload data to itab1 using gui_upload.

then write select statement

select matnr

from mara into itab2

for all entries in itab1

where matnr = itab1-matnr.

it will get all the matnrs which are present in DB.

then

loop at itab1.

read table itab2 with key matnr = itab1-matnr.

if sy-subrc <> 0.

Move itab1 to final_tab.

append final_tab.

else.

delete itab1.

endif.

endloop.

Now provide BDC logic for Final_tab which contains records which are not in DB.