Application Development and Automation 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: 
Read only

bdc mm01

Former Member
0 Likes
505

hi gurus,

i create a programm for bdc using call transaction to extend the plant from one plant to another plant

plz check my codes when i diosplay the error record it would show the only single record 4 times print in displaying errors.

in my flat file there is 3 records

and show the error only flat file last record

and it is like t0096 it print it 4 times but there is only 3 records

why it can not print others record of internal table

plz chk my programm

REPORT zsgg

NO STANDARD PAGE HEADING LINE-SIZE 255.

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

  • TABLES *

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

TABLES: mara, marc,mard.

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

  • INTERNAL TABLE *

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

TYPES: BEGIN OF lt_data,

matnr TYPE mara-matnr, "Material

werks TYPE marc-werks, "Plant

lgort TYPE mard-lgort, "Storage Location

  • maktx TYPE makt-maktx, "Material Description

  • iprkz TYPE mara-iprkz, "Period indicator

  • maktx1 TYPE makt-maktx, "Material Description

err_msg(200) TYPE c,

  • succ_msg(100) TYPE c,

END OF lt_data.

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

    • D A T A *

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

DATA: it_data TYPE TABLE OF lt_data. "Internal table for store data

DATA: wa_data LIKE LINE OF it_data. " work area for store data

DATA: it_bdc TYPE TABLE OF bdcdata. " Internal table for bdc data

DATA: wa_bdc LIKE LINE OF it_bdc. " work area for store data

DATA: it_messtab LIKE TABLE OF bdcmsgcoll. " Internal table message

DATA: wa_messtab LIKE LINE OF it_messtab. " work area for message

*DATA: it_success TYPE TABLE OF lt_data, "Internal table success

  • wa_success LIKE LINE OF it_success. "work area for success

DATA: it_err TYPE TABLE OF lt_data, "Internal table error record

wa_err LIKE LINE OF it_err. "work area for error record

DATA: v_file TYPE string.

DATA: v_index TYPE i.

DATA: v_text(100) TYPE c.

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

  • S E L E C T I O N S C R E E N *

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

SELECTION-SCREEN BEGIN OF BLOCK b .

PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b.

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

  • AT SELECTION-SCREEN *

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM get_file USING p_file.

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

  • START-OF-SELECTION *

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

START-OF-SELECTION.

v_file = p_file.

*upload flat file

PERFORM upload_file USING v_file .

PERFORM bdc_upload.

PERFORM write_message.

&----


*& Form get_file

&----


  • Getting the file

----


FORM get_file USING p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

program_name = syst-repid

field_name = 'P_FILE'

CHANGING

file_name = p_file.

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. " get_file

&----


*& Form upload_file

&----


  • populating the file into the internal table

----


  • -->P_V_FILE text

  • <--P_IT_DATA text

----


FORM upload_file USING p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = it_data.

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_file

&----


*& Form bdc_upload

&----


  • Updating MM01 using the intenal table

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload .

*POPULATING THE BDCDATA

LOOP AT it_data INTO wa_data.

  • REFRESH it_bdc.

  • CLEAR it_bdc.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060' 'X'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE' '=AUSW'.

PERFORM bdc_field USING 'RMMG1-MATNR' wa_data-matnr.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070' 'X'.

PERFORM bdc_field USING 'BDC_CURSOR' 'USRM1-SISEL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.

PERFORM bdc_field USING 'USRM1-SISEL' 'X'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(15)' 'X'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(16)' 'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0080' 'X'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RMMG1-LGORT'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.

PERFORM bdc_field USING 'RMMG1-WERKS' wa_data-werks.

PERFORM bdc_field USING 'RMMG1-LGORT' wa_data-lgort.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000' 'X'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SP20'.

PERFORM bdc_field USING 'MAKT-MAKTX' 'test for change'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MARA-MEINS'.

PERFORM bdc_field USING 'MARA-MEINS' 'EA'.

PERFORM bdc_field USING 'MARA-IPRKZ' 'D'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000' 'X'.

PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MAKT-MAKTX'.

PERFORM bdc_field USING 'MAKT-MAKTX' 'test for change'.

CALL TRANSACTION 'MM01' USING it_bdc

MODE 'N' UPDATE 'S'

MESSAGES INTO it_messtab.

ENDLOOP.

REFRESH it_bdc.

CLEAR it_bdc.

ENDFORM. " bdc_upload

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P1 text

  • -->P2 text

----


FORM bdc_dynpro USING program

dynpro

dynbegin .

wa_bdc-program = program.

wa_bdc-dynpro = dynpro.

wa_bdc-dynbegin = dynbegin.

APPEND wa_bdc TO it_bdc.

CLEAR wa_bdc.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P3 text

  • -->P4 text

----


FORM bdc_field USING fnam

fval .

wa_bdc-fnam = fnam.

wa_bdc-fval = fval.

APPEND wa_bdc TO it_bdc.

CLEAR wa_bdc.

ENDFORM. "bdc_field

&----


*& Form write_message

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_message .

  • Get the BDC error messages

LOOP AT it_messtab INTO wa_messtab.

CLEAR v_text.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = wa_messtab-msgid

lang = 'EN'

no = wa_messtab-msgnr

v1 = wa_messtab-msgv1

v2 = wa_messtab-msgv2

v3 = wa_messtab-msgv3

v4 = wa_messtab-msgv4

IMPORTING

msg = v_text.

IF sy-subrc = 0.

CASE wa_messtab-msgtyp.

********Display Report When Records are extend

  • WHEN 'S'.

  • write:/ v_text.

********Display Report When Error in Records

WHEN 'E'.

wa_err = wa_data.

wa_err-err_msg = v_text.

APPEND wa_err TO it_err.

CLEAR: wa_err.

ENDCASE.

ENDIF.

ENDLOOP.

REFRESH it_messtab.

CLEAR wa_messtab.

*********Error be printed

IF NOT it_err[] IS INITIAL.

WRITE:2 ' Error Report ' COLOR COL_NEGATIVE.

SKIP.

WRITE:2 'The following records failed during update:'.

WRITE:/ sy-uline(150).

FORMAT COLOR COL_HEADING.

WRITE:/ sy-vline,

(15) 'Material Number', sy-vline,

(6) 'Plant', sy-vline,

(16) 'Storage Location',sy-vline,

(100) 'Error Message', sy-vline.

WRITE:/ sy-uline(150).

FORMAT COLOR COL_NORMAL.

LOOP AT it_err INTO wa_err.

WRITE:/ sy-vline,

(15) wa_err-matnr, sy-vline,

(6) wa_err-werks, sy-vline,

(16) wa_err-lgort, sy-vline,

(100) wa_err-err_msg, sy-vline.

ENDLOOP.

ENDIF.

WRITE:/ sy-uline(150).

REFRESH: it_err.

ENDFORM. "write_message

plz help me .

its very urgent

thanks

jayant

hi gurus,

i create a programm for bdc using call transaction to extend the plant from one plant to another plant

plz check my codes when i diosplay the error record it would show the only single record 4 times print in displaying errors.

in my flat file there is 3 records

and show the error only flat file last record

and it is like t0096 it print it 4 times but there is only 3 records

why it can not print others record of internal table

plz chk my programm

REPORT zsgg

NO STANDARD PAGE HEADING LINE-SIZE 255.

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

  • TABLES *

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

TABLES: mara, marc,mard.

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

  • INTERNAL TABLE *

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

TYPES: BEGIN OF lt_data,

matnr TYPE mara-matnr, "Material

werks TYPE marc-werks, "Plant

lgort TYPE mard-lgort, "Storage Location

  • maktx TYPE makt-maktx, "Material Description

  • iprkz TYPE mara-iprkz, "Period indicator

  • maktx1 TYPE makt-maktx, "Material Description

err_msg(200) TYPE c,

  • succ_msg(100) TYPE c,

END OF lt_data.

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

    • D A T A *

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

DATA: it_data TYPE TABLE OF lt_data. "Internal table for store data

DATA: wa_data LIKE LINE OF it_data. " work area for store data

DATA: it_bdc TYPE TABLE OF bdcdata. " Internal table for bdc data

DATA: wa_bdc LIKE LINE OF it_bdc. " work area for store data

DATA: it_messtab LIKE TABLE OF bdcmsgcoll. " Internal table message

DATA: wa_messtab LIKE LINE OF it_messtab. " work area for message

*DATA: it_success TYPE TABLE OF lt_data, "Internal table success

  • wa_success LIKE LINE OF it_success. "work area for success

DATA: it_err TYPE TABLE OF lt_data, "Internal table error record

wa_err LIKE LINE OF it_err. "work area for error record

DATA: v_file TYPE string.

DATA: v_index TYPE i.

DATA: v_text(100) TYPE c.

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

  • S E L E C T I O N S C R E E N *

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

SELECTION-SCREEN BEGIN OF BLOCK b .

PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b.

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

  • AT SELECTION-SCREEN *

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM get_file USING p_file.

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

  • START-OF-SELECTION *

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

START-OF-SELECTION.

v_file = p_file.

*upload flat file

PERFORM upload_file USING v_file .

PERFORM bdc_upload.

PERFORM write_message.

&----


*& Form get_file

&----


  • Getting the file

----


FORM get_file USING p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

program_name = syst-repid

field_name = 'P_FILE'

CHANGING

file_name = p_file.

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. " get_file

&----


*& Form upload_file

&----


  • populating the file into the internal table

----


  • -->P_V_FILE text

  • <--P_IT_DATA text

----


FORM upload_file USING p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = it_data.

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_file

&----


*& Form bdc_upload

&----


  • Updating MM01 using the intenal table

----


  • --> p1 text

  • <-- p2 text

----


FORM bdc_upload .

*POPULATING THE BDCDATA

LOOP AT it_data INTO wa_data.

  • REFRESH it_bdc.

  • CLEAR it_bdc.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060' 'X'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE' '=AUSW'.

PERFORM bdc_field USING 'RMMG1-MATNR' wa_data-matnr.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070' 'X'.

PERFORM bdc_field USING 'BDC_CURSOR' 'USRM1-SISEL'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.

PERFORM bdc_field USING 'USRM1-SISEL' 'X'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(15)' 'X'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(16)' 'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0080' 'X'.

PERFORM bdc_field USING 'BDC_CURSOR' 'RMMG1-LGORT'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.

PERFORM bdc_field USING 'RMMG1-WERKS' wa_data-werks.

PERFORM bdc_field USING 'RMMG1-LGORT' wa_data-lgort.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000' 'X'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SP20'.

PERFORM bdc_field USING 'MAKT-MAKTX' 'test for change'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MARA-MEINS'.

PERFORM bdc_field USING 'MARA-MEINS' 'EA'.

PERFORM bdc_field USING 'MARA-IPRKZ' 'D'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000' 'X'.

PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.

PERFORM bdc_field USING 'BDC_CURSOR' 'MAKT-MAKTX'.

PERFORM bdc_field USING 'MAKT-MAKTX' 'test for change'.

CALL TRANSACTION 'MM01' USING it_bdc

MODE 'N' UPDATE 'S'

MESSAGES INTO it_messtab.

ENDLOOP.

REFRESH it_bdc.

CLEAR it_bdc.

ENDFORM. " bdc_upload

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P1 text

  • -->P2 text

----


FORM bdc_dynpro USING program

dynpro

dynbegin .

wa_bdc-program = program.

wa_bdc-dynpro = dynpro.

wa_bdc-dynbegin = dynbegin.

APPEND wa_bdc TO it_bdc.

CLEAR wa_bdc.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P3 text

  • -->P4 text

----


FORM bdc_field USING fnam

fval .

wa_bdc-fnam = fnam.

wa_bdc-fval = fval.

APPEND wa_bdc TO it_bdc.

CLEAR wa_bdc.

ENDFORM. "bdc_field

&----


*& Form write_message

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_message .

  • Get the BDC error messages

LOOP AT it_messtab INTO wa_messtab.

CLEAR v_text.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = wa_messtab-msgid

lang = 'EN'

no = wa_messtab-msgnr

v1 = wa_messtab-msgv1

v2 = wa_messtab-msgv2

v3 = wa_messtab-msgv3

v4 = wa_messtab-msgv4

IMPORTING

msg = v_text.

IF sy-subrc = 0.

CASE wa_messtab-msgtyp.

********Display Report When Records are extend

  • WHEN 'S'.

  • write:/ v_text.

********Display Report When Error in Records

WHEN 'E'.

wa_err = wa_data.

wa_err-err_msg = v_text.

APPEND wa_err TO it_err.

CLEAR: wa_err.

ENDCASE.

ENDIF.

ENDLOOP.

REFRESH it_messtab.

CLEAR wa_messtab.

*********Error be printed

IF NOT it_err[] IS INITIAL.

WRITE:2 ' Error Report ' COLOR COL_NEGATIVE.

SKIP.

WRITE:2 'The following records failed during update:'.

WRITE:/ sy-uline(150).

FORMAT COLOR COL_HEADING.

WRITE:/ sy-vline,

(15) 'Material Number', sy-vline,

(6) 'Plant', sy-vline,

(16) 'Storage Location',sy-vline,

(100) 'Error Message', sy-vline.

WRITE:/ sy-uline(150).

FORMAT COLOR COL_NORMAL.

LOOP AT it_err INTO wa_err.

WRITE:/ sy-vline,

(15) wa_err-matnr, sy-vline,

(6) wa_err-werks, sy-vline,

(16) wa_err-lgort, sy-vline,

(100) wa_err-err_msg, sy-vline.

ENDLOOP.

ENDIF.

WRITE:/ sy-uline(150).

REFRESH: it_err.

ENDFORM. "write_message

plz help me .

its very urgent

thanks

jayant

2 REPLIES 2
Read only

Former Member
0 Likes
463

Hi Jayant,

According to ur logic u can see the error records only for the last loop pass of internal table IT_DATA.

You have to call the PERFORM write_message before ENDLOOP statement of the internal table IT_DATA.

sample code.

LOOP at IT_DATA.

call transaction....

if sy-subrc = 0.

read table it_messtab with key msgtyp = 'E'

if sy-subrc = 0.

append all the error msgs to another internal table ITAB

else.

success records.

endif.

endif.

Endloop.

Finally display all the error messages after Endlloop by looping on the table ITAB.

If this is helpful reward the points

With Regards,

Dwarakanath.S

Read only

Former Member
0 Likes
463