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

BDC for MM02 - MRP area

Hello everyone!

I have developed a BDC program to batch input data into MM02 / MRP area.

It's working perfectly fine when I use mode 'A' in CALL TRANSACTION statement, but when I change it to 'N', so I can give this for the customer to test, it stops working, giving me an error in one of the screens, saying the "MRP area is not assigned to plant CH01" (when running with mode "E" it also gives me the error).

Here's my coding:

REPORT zload_mrp_areas.

  • Data and variables definition

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF t_header OCCURS 0,

link LIKE mara-matnr,

matnr LIKE mara-matnr,

werks LIKE marc-werks,

mstae(2) TYPE c,

perkz(2) TYPE c,

END OF t_header.

DATA: BEGIN OF t_details OCCURS 0,

muvbr(5) TYPE c,

unvbr(5) TYPE c,

matnr LIKE mara-matnr,

priod(6) TYPE c,

gsvbr(5) TYPE c,

END OF t_details.

DATA: v_count(3) TYPE n,

v_week LIKE scal-week,

v_week1(6) TYPE n,

v_week2(6) TYPE n,

v_page(5) TYPE p DECIMALS 2,

v_index(3) TYPE n,

v_field(19) TYPE c,

v_mode TYPE c,

v_date1 LIKE sy-datum,

v_date2 LIKE sy-datum,

v_date3 TYPE i.

  • Screen definition

SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE text-001.

PARAMETERS: headfile LIKE rfpdo1-febauszf OBLIGATORY,

detsfile LIKE rfpdo1-febauszf OBLIGATORY.

SELECTION-SCREEN END OF BLOCK 1.

  • File selection

AT SELECTION-SCREEN ON VALUE-REQUEST FOR headfile.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

mask = ',Multicash,*.txt'

static = 'X'

CHANGING

file_name = headfile.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR detsfile.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

mask = ',Multicash,*.txt'

static = 'X'

CHANGING

file_name = detsfile.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

  • Load files

PERFORM load_files.

PERFORM process_file.

&----


*& Form LOAD_FILES

&----


  • Load files from network to SAP

----


FORM load_files .

  • File upload

DATA: l_filename TYPE string.

l_filename = headfile.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_filename

filetype = 'ASC'

TABLES

data_tab = t_header.

IF sy-subrc <> 0.

*

ENDIF.

l_filename = detsfile.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_filename

filetype = 'ASC'

TABLES

data_tab = t_details.

IF sy-subrc <> 0.

*

ENDIF.

ENDFORM. " LOAD_FILES

&----


*& Form process_file

&----


  • Load files into Material Master

----


FORM process_file .

LOOP AT t_header.

REFRESH bdcdata.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

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

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SELA'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '0080'.

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

PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SP12'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.

PERFORM bdc_field USING 'BDC_OKCODE' '=PB42'.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0010'.

  • PERFORM bdc_field USING 'SMDMA-BERID(01)' 'X'.

PERFORM bdc_field USING 'BDC_OKCODE' '=AEND'.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '=SP04'.

CLEAR v_week.

CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'

EXPORTING

date = sy-datum

IMPORTING

week = v_week.

CALL FUNCTION 'WEEK_GET_FIRST_DAY'

EXPORTING

week = v_week

IMPORTING

date = v_date1.

LOOP AT t_details WHERE matnr = t_header-matnr.

CLEAR: v_week1, v_week2.

v_week1 = v_week.

v_week = t_details-priod.

CALL FUNCTION 'WEEK_GET_FIRST_DAY'

EXPORTING

week = v_week

IMPORTING

date = v_date2.

v_date3 = v_date1 - v_date2.

v_page = v_date3 / 7.

IF v_page > 11.

v_index = v_page MOD 11.

v_page = v_page / 11.

COMPUTE v_count = TRUNC( v_page ).

ELSE.

v_index = v_page.

ENDIF.

IF v_index IS INITIAL.

v_index = 11.

v_count = v_count - 1.

ELSE.

v_index = v_index + 1.

ENDIF.

  • Paging

IF v_count NE 0.

v_count = v_count + 1.

DO v_count TIMES.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '=P-'.

ENDDO.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '=P++'.

v_count = v_count - 1.

DO v_count TIMES.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '=P-'.

ENDDO.

ENDIF.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

v_field = 'RM03M_DB-KOVBW(*)'.

REPLACE '*' WITH v_index INTO v_field.

PERFORM bdc_field USING v_field t_details-muvbr.

v_field = 'RM03M_DB-VBWRT(*)'.

REPLACE '*' WITH v_index INTO v_field.

PERFORM bdc_field USING v_field t_details-unvbr.

  • PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '=WEIT'.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '/00'.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '=P++'.

ENDLOOP.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0020'.

PERFORM bdc_field USING 'BDC_OKCODE' '=UEBE'.

PERFORM bdc_dynpro USING 'SAPLMD_MGD1' '0010'.

PERFORM bdc_field USING 'BDC_OKCODE' '=UEBE'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.

PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.

DATA: ITAB TYPE TABLE OF BDCMSGCOLL.

v_mode = 'N'.

CALL TRANSACTION 'MM02' USING bdcdata

MODE v_mode

UPDATE 'S'

MESSAGES INTO ITAB.

if sy-subrc is initial.

endif.

ENDLOOP.

ENDFORM. " process_file

&----


*& Form BDC_DYNPRO

&----


  • text

----


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

Can anyone help? Please!

Thanks and regards,

Fernanda

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Nov 20, 2007 at 03:27 PM

    You are trying to access one of the MRP area which is not yet assigned to CH01 plant. You need to make sure wheather the MRP view was already created for that material for CH01 plant.

    So, first check your data against the MARC for material and plant. If you don't fine any material for that plant than don't run BDC for that plant.

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 03:27 PM

    Hi Fernanada,

    If your program is working in mode 'A' and not working in 'N'..means somewhere you are missing 'ENTER' stroke in your recording... in mode 'A' we'll press enter key manually... in mode 'N' system should pass appropriate code thru BDC.. please try to check your recording again and check is there any 'Enter' code is missing...

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks everyone for the answer...

      I was trying to mark the wrong field in a table control, and that's why it was not working!!

      Line: PERFORM bdc_field USING 'SMDMA-MARKED(01)' 'X'.

      Thanks guys!

      Regards,

      Fernanda

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.