Skip to Content
0
Former Member
Jul 09, 2012 at 09:29 AM

Values not saved via BDC recording for transaction code 'MASS' (reorder point-MINBE)

476 Views

Hi, I have written a 'Z' program for a BDC recording to update the reorder point in transaction code 'MASS' - SAP-MM. The recording as usual has been incorporated in the 'Z' program. The internal table loads values from the flat file (csv format) successfully. The BDC_OPEN_GROUP is written before the loop of the internal table. The BDC_CLOSE_GROUP is written after the loop. The BDC_INSERT function has been called within the loop - however, it does not call the bdc_insert function at all - due to this the values of the csv file are not saved to the table at all. At the end of the code, the 'SM35' tcode is invoked and the process is run in the foreground which shows the changed values. But after we finish with the program, when we check the values, they have not been changed at all.

The fields in discussion are relating to table MARC (Plant, Material Number and reorder point - werks, matnr and minbe). The same has been tried via call bdc_transaction and call transaction as well without success. In the below 'Z' program, the values have not been taken from the internal table but have been hardcoded instead.

Thanks in advance for all your help.

REPORT ZCATERING_REORDER
NO STANDARD PAGE HEADING LINE-SIZE 255 .

INCLUDE ZBDC_C_REORDER.

***** BEGIN OF ALL DECLARATIONS

DATA : BEGIN OF ITAB OCCURS 15,
WORD(150),
END OF ITAB.

*DATA : SAVE_IND.
DATA : SAVE_RECORD(1) TYPE C VALUE 'N'.
DATA : A LIKE SY-UCOMM.
DATA : COMPNAME LIKE T001-BUTXT.
DATA : FLNAME TYPE STRING.
DATA : MREC_CNT TYPE I.
DATA : WRN_MESS01(35),WRN_MESS02(35),WRN_MESS03(35),WRN_MESS04(35).
DATA : MESSAGE_TXT(85).
DATA : USR_ANSWER(1) TYPE C VALUE 'J'.
DATA : REC_CNT TYPE I VALUE 0.

DATA : BEGIN OF STRING_ITAB OCCURS 0 ,
STRING(255) TYPE C,
END OF STRING_ITAB.

DATA: BEGIN OF ITAB_CATERING OCCURS 0,
PLANT LIKE MARC-WERKS,
* MATERIAL_GROUP LIKE MARC-,
MATNR LIKE MARC-MATNR, "MATERIAL NUMBER
* MINBE LIKE MARC-MINBE, "REORDER POINT
MINBE(16), "REORDER POINT
END OF ITAB_CATERING.

*** End generated data section ***

DATA : AUTH_TEXT(100).
DATA : MBUKRS LIKE BKPF-BUKRS.
DATA : INFILE LIKE RLGRAP-FILENAME.
DATA : FLNM LIKE RLGRAP-FILENAME , FLEXT(3).
DATA : ERRFILE LIKE RLGRAP-FILENAME.
DATA : ERRFLNM LIKE RLGRAP-FILENAME.

*-----------------------------------------------------------------------
* AlV related data declarations
*-----------------------------------------------------------------------
* Type Pools
TYPE-POOLS: SLIS.

CONSTANTS:
GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
GS_PRINT TYPE SLIS_PRINT_ALV,
GT_SORT TYPE SLIS_T_SORTINFO_ALV ,
GT_FILTER TYPE SLIS_T_FILTER_ALV,
GT_SP_GROUP TYPE SLIS_T_SP_GROUP_ALV,
GT_ALV_GRAPHICS TYPE DTC_T_TC,
GT_EXCLUDING TYPE SLIS_T_EXTAB ,
GT_EVENTS TYPE SLIS_T_EVENT .

DATA: G_REPID LIKE SY-REPID.
DATA: GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: G_BOXNAM TYPE SLIS_FIELDNAME VALUE 'BOX',
P_F2CODE LIKE SY-UCOMM VALUE '&ETA',
P_LIGNAM TYPE SLIS_FIELDNAME VALUE 'LIGHTS',
G_SAVE(1) TYPE C,
G_DEFAULT(1) TYPE C,
G_EXIT(1) TYPE C,
GX_VARIANT LIKE DISVARIANT,
G_VARIANT LIKE DISVARIANT.

DATA : G_USER_COMMAND(30) VALUE 'USER_COMMAND'.
DATA : G_STATUS_SET(30) VALUE 'PF_STATUS_SET'.

***** END OF ALL DECLARATIONS

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-003.

*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 1(13) TEXT-004.
*PARAMETERS: COMP_CD LIKE BKPF-BUKRS OBLIGATORY DEFAULT '9WIN'. " Company Code
*SELECTION-SCREEN COMMENT 61(25) COMP_NM.
*SELECTION-SCREEN END OF LINE.

*SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN COMMENT 1(75) FILTXT FOR FIELD P_FILE.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.
* DEFAULT '9999_SYSTEMGLD.DAT' OBLIGATORY.
SELECTION-SCREEN SKIP 1.

PARAMETERS: P_PLANT LIKE MARC-WERKS OBLIGATORY.
SELECTION-SCREEN SKIP 1.

PARAMETERS P_RUN AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK B1.
* END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
* STATIC = ' '
* MASK = ' '
CHANGING
FILE_NAME = P_FILE
EXCEPTIONS
MASK_TOO_LONG = 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.

IF SY-UCOMM = 'ONLI'. " When Click the Execute (F8) Button.

P_FILE = INFILE.

TRANSLATE P_FILE TO UPPER CASE.

SPLIT P_FILE AT '.' INTO FLNM FLEXT.

CONCATENATE 'Upload Error File Location & Name - >'
FLNM '.ERR' INTO FILTXT.

CONCATENATE FLNM '.ERR' INTO ERRFLNM.
CONCATENATE FLNM '.ERR' INTO ERRFILE.

ENDIF.

START-OF-SELECTION.
* BREAK-POINT.

IF P_RUN = 'X' .
* ONLY FOR ACTUAL RUN
* PERFORM OPEN_GROUP.
ENDIF.

* UPLOAD FROM FLAT FILE TO INTERNAL TABLE (ITAB_CATERING)
PERFORM UPLOAD_CSV.

BREAK-POINT.
* TAKE THE DATA FROM INTERNAL TABLE (ITAB_CATERING) TO THE 'MASS' TRANSACTION
PERFORM ITAB_TO_TABLE.

IF P_RUN = 'X' .
* ONLY FOR ACTUAL RUN
* PERFORM CLOSE_GROUP.
* CALL TRANSACTION 'SM35' AND SKIP FIRST SCREEN.
ENDIF.

*&---------------------------------------------------------------------*
*& Form UPLOAD_CSV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_CSV .

FLNAME = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = FLNAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ','
* HAS_FIELD_SEPARATOR = 'X'

HEADER_LENGTH = 0
TABLES
DATA_TAB = STRING_ITAB.

PERFORM CHK_UPLOAD_REC.

LOOP AT STRING_ITAB.
SPLIT STRING_ITAB-STRING AT ',' INTO TABLE ITAB.

LOOP AT ITAB.

CASE SY-TABIX.
WHEN 1.
ITAB_CATERING-PLANT = ITAB-WORD. " PLANT
WHEN 2.
ITAB_CATERING-MATNR = ITAB-WORD. " MATERIAL NUMBER
WHEN 3.
ITAB_CATERING-MINBE = ITAB-WORD. " REORDER POINT
ENDCASE.

ENDLOOP.

* APPEND ITAB_BOB.
* CLEAR: ITAB_BOB, ITAB.

IF ITAB_CATERING-PLANT = P_PLANT.
APPEND ITAB_CATERING.
ENDIF.
CLEAR: ITAB_CATERING, ITAB.

A(5) = SY-TABIX. A+5 = 'Line Items Processed'.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = SY-INDEX
TEXT = A.

ENDLOOP.
ENDFORM. " UPLOAD_CSV

*&---------------------------------------------------------------------*
*& Form CHK_UPLOAD_REC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHK_UPLOAD_REC .

CLEAR MREC_CNT.
DESCRIBE TABLE STRING_ITAB LINES MREC_CNT.

IF MREC_CNT = 0.
CONCATENATE 'The file ->' P_FILE
INTO WRN_MESS01. " INFILE
WRN_MESS02 = 'contains ZERO records.'.
WRN_MESS03 = 'Do you want to record this'.
WRN_MESS04 = 'as an uploaded file ??'.
CALL FUNCTION 'POPUP_TO_DECIDE_WITH_MESSAGE'
EXPORTING
DEFAULTOPTION = '1'
DIAGNOSETEXT1 = WRN_MESS01
DIAGNOSETEXT2 = WRN_MESS02
TEXTLINE1 = WRN_MESS03
TEXTLINE2 = WRN_MESS04
TEXT_OPTION1 = 'No'
TEXT_OPTION2 = 'Yes'
TITEL = 'EMPTY FILE UPLOAD WARNING'
START_COLUMN = 25
START_ROW = 6
CANCEL_DISPLAY = ''
IMPORTING
ANSWER = USR_ANSWER
EXCEPTIONS
OTHERS = 1.

IF USR_ANSWER NE '2'.
MESSAGE ID 'A5' TYPE 'E' NUMBER '221' WITH P_FILE.
EXIT.
ENDIF.
ENDIF.

ENDFORM. " CHK_UPLOAD_REC

*&---------------------------------------------------------------------*
*& Form ITAB_TO_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ITAB_TO_TABLE .
*&---------------------------------------------------------------------*
*& Form ITAB_TO_FI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
perform open_group.

LOOP AT ITAB_CATERING.

perform bdc_dynpro using 'SAPMMSDL' '0100'.
perform bdc_field using 'BDC_CURSOR'
'MASSSCREEN-OBJECT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MASSSCREEN-OBJECT'
'BUS1001'.
perform bdc_dynpro using 'SAPMMSDL' '0100'.
perform bdc_field using 'BDC_CURSOR'
'MASSSCREEN-OBJECT'.
perform bdc_field using 'BDC_OKCODE'
'=NEXT'.
perform bdc_field using 'MASSSCREEN-OBJECT'
'BUS1001'.
perform bdc_dynpro using 'SAPMMSDL' '0200'.
perform bdc_field using 'BDC_CURSOR'
'MASSSCREEN-VARNAME'.
perform bdc_field using 'BDC_OKCODE'
'=TAB2'.
perform bdc_dynpro using 'SAPMMSDL' '0200'.
perform bdc_field using 'BDC_CURSOR'
'MASSSCREEN-VARNAME'.
perform bdc_field using 'BDC_OKCODE'
'=FIND'.
perform bdc_dynpro using 'SAPLSPO4' '0300'.
perform bdc_field using 'BDC_CURSOR'
'SVALD-VALUE(01)'.
perform bdc_field using 'BDC_OKCODE'
'=FURT'.
perform bdc_field using 'SVALD-VALUE(01)'
'MINBE'.
perform bdc_dynpro using 'SAPMMSDL' '0200'.
perform bdc_field using 'BDC_OKCODE'
'=NEXT'.
perform bdc_field using 'BDC_CURSOR'
'MASSFVIEW-FIELDTEXT(01)'.
perform bdc_field using 'MASSFVIEW-CHECKBOX(01)'
'X'.
perform bdc_dynpro using 'SAPLMASS_SEL_DIALOG' '0100'.
perform bdc_field using 'BDC_OKCODE'
'=NEXT'.
perform bdc_field using 'BDC_CURSOR'
'MASSFREESEL-LOW(01)'.
perform bdc_field using 'MASSFREESEL-LOW(01)'
'NFLT0110010'.
perform bdc_dynpro using 'SAPLMASS_SEL_DIALOG' '0100'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_CURSOR'
'MASSFREESEL-LOW(02)'.
perform bdc_field using 'MASSFREESEL-LOW(02)'
'1011'.
perform bdc_dynpro using 'SAPLMASS_SEL_DIALOG' '0100'.
perform bdc_field using 'BDC_OKCODE'
'=CRET'.
perform bdc_field using 'BDC_CURSOR'
'MASSFREESEL-LOW(01)'.
perform bdc_dynpro using 'SAPLMASSINTERFACE' '0200'.
perform bdc_field using 'BDC_OKCODE'
'=CRET'.
perform bdc_field using 'BDC_CURSOR'
'STRUC-FIELD3-VALUE-RIGHT(01)'.
perform bdc_field using 'STRUC-FIELD3-VALUE-RIGHT(01)'
' 260'.
perform bdc_dynpro using 'SAPLMASSINTERFACE' '0200'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'BDC_CURSOR'
'STRUC-FIELD3-VALUE-RIGHT(01)'.
* perform bdc_transaction using 'MASS'.

AT LAST.
BREAK-POINT.
IF P_RUN = 'X'. " If actual run
PERFORM BDC_TRANSACTION USING 'MASS'.
SAVE_RECORD = 'Y' .
ELSE.
CALL TRANSACTION 'MASS' USING BDCDATA
MODE CTUMODE MESSAGES INTO MESSTAB.
SAVE_RECORD = 'N' .
ENDIF.

CLEAR BDCDATA.
REFRESH BDCDATA.
ENDAT.
ENDLOOP .

perform close_group.
CALL TRANSACTION 'SM35' AND SKIP FIRST SCREEN.

*&---------------------------------------------------------------------*
*& Include ZBDC_C_REORDER
*&---------------------------------------------------------------------*
* for programs doing a data transfer by creating a batch-input session
* and for programs doing a data transfer by CALL TRANSACTION USING

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS SESSION RADIOBUTTON GROUP CTU. "create session
SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.
selection-screen position 45.
PARAMETERS CTU RADIOBUTTON GROUP CTU. "call transaction
SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.
selection-screen position 25.
PARAMETERS GROUP(12). "group name of session
SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.
selection-screen position 70.
PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.
selection-screen position 25.
PARAMETERS: USER(12) DEFAULT SY-UNAME. "user for session in batch
SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.
selection-screen position 70.
PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.
"S: synchronously
"A: asynchronously
"L: local
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.
selection-screen position 25.
PARAMETERS: KEEP AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.
selection-screen position 70.
parameters E_GROUP(12). "group name of error-session
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.
selection-screen position 25.
PARAMETERS: HOLDDATE LIKE SY-DATUM.
SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.
selection-screen position 70.
PARAMETERS: E_USER(12) DEFAULT SY-UNAME. "user for error-session
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.
selection-screen position 70.
PARAMETERS: E_KEEP AS CHECKBOX. "' ' = delete session if finished
"'X' = keep session if finished
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.
selection-screen position 70.
PARAMETERS: E_HDATE LIKE SY-DATUM.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.
PARAMETERS: NODATA DEFAULT '/' LOWER CASE. "nodata
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) FOR FIELD SMALLLOG.
PARAMETERS: SMALLLOG as checkbox. "' ' = log all transactions
"'X' = no transaction logging
SELECTION-SCREEN END OF LINE.

*----------------------------------------------------------------------*
* data definition
*----------------------------------------------------------------------*
* Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
* error session opened (' ' or 'X')
DATA: E_GROUP_OPENED.
* message texts
TABLES: T100.


*----------------------------------------------------------------------*
* at selection screen *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* group and user must be filled for create session
IF SESSION = 'X' AND
GROUP = SPACE OR USER = SPACE.
MESSAGE E613(MS).
ENDIF.

*----------------------------------------------------------------------*
* open dataset *
*----------------------------------------------------------------------*
FORM OPEN_DATASET USING P_DATASET.
OPEN DATASET P_DATASET
FOR INPUT IN TEXT MODE
ENCODING DEFAULT.
IF SY-SUBRC <> 0.
WRITE: / TEXT-E00, SY-SUBRC.
STOP.
ENDIF.
ENDFORM. "OPEN_DATASET

*----------------------------------------------------------------------*
* close dataset *
*----------------------------------------------------------------------*
FORM CLOSE_DATASET USING P_DATASET.
CLOSE DATASET P_DATASET.
ENDFORM. "CLOSE_DATASET

*----------------------------------------------------------------------*
* create batchinput session *
* (not for call transaction using...) *
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
IF SESSION = 'X'.
SKIP.
WRITE: /(20) 'Create group'(I01), GROUP.
SKIP.
* open batchinput group
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = GROUP
USER = USER
KEEP = KEEP
HOLDDATE = HOLDDATE.
WRITE: /(30) 'BDC_OPEN_GROUP'(I02),
(12) 'returncode:'(I05),
SY-SUBRC.
ENDIF.
ENDFORM. "OPEN_GROUP

*----------------------------------------------------------------------*
* end batchinput session *
* (call transaction using...: error session) *
*----------------------------------------------------------------------*
FORM CLOSE_GROUP.
IF SESSION = 'X'.
* close batchinput group
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
(12) 'returncode:'(I05),
SY-SUBRC.
ELSE.
IF E_GROUP_OPENED = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
E_GROUP_OPENED = ' '.
ENDIF.
ENDIF.
ENDFORM. "CLOSE_GROUP

*----------------------------------------------------------------------*
* Start new transaction according to parameters *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = TCODE
TABLES
DYNPROTAB = BDCDATA.
IF SMALLLOG <> 'X'.
WRITE: /(25) 'BDC_INSERT'(I03),
TCODE,
(12) 'returncode:'(I05),
SY-SUBRC,
'RECORD:',
SY-INDEX.
ENDIF.
REFRESH BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
* 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 <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
* SHIFT BDCDATA-FVAL LEFT DELETING LEADING space.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM. "BDC_FIELD