Skip to Content
0
Former Member
Feb 10, 2015 at 05:48 AM

Data is updating on Table LFM1 through BDC for MK01 t-code.

281 Views

In SHDB recording for MK01t-code i have taken 7 fields.... Vendor , Purchasing Org . ,Account group ,Order Currency ,Term of Payment ,Schema Group,Vendor ,GR-Based IV. After saving the data and recording i have create program through SHDB and write the necessary code but while uploading the test data...the data was not getting stored in LFM1 but if i enter the same data through directly t-code the data is getting saved and error log table is working properly ....Please expert help me through this...below is the code.



REPORT ZMM_VMI_C003_MMVMCBDC NO STANDARD PAGE HEADING LINE-SIZE 255.
DATA CTR TYPE I VALUE 0.
TYPE-POOLS : TRUXS.
TABLES : ZMM_VMI_C003_LOG.
*INCLUDE BDCRECX1.

*----------------------------------------------------------------------------*
* STRUCTURE DECLARATION
*----------------------------------------------------------------------------*
TYPES: BEGIN OF FS_FIELD,
LIFNR TYPE LIF16, " Vendor
EKORG TYPE EKORG, " Purchasing Org.
KTOKK TYPE KTOKK, " Account Group
WAERS TYPE CHAR5, " Order Currency
ZTERM TYPE DZTERM, " Term of Payment
KALSK TYPE KALSK, " Schema Group,Vendor
WEBRE TYPE WEBRE, " GR-Based IV
END OF FS_FIELD.

*------------------------------------------------------------------*
* STRUCTURE FOR ERROR RECORDS
*------------------------------------------------------------------*
TYPES : BEGIN OF TY_S_ERROR,
LIFNR TYPE ZMM_VMI_C003_LOG-LIFNR, " Vendor
EKORG TYPE ZMM_VMI_C003_LOG-EKORG, " Purchasing Org.
KTOKK TYPE ZMM_VMI_C003_LOG-KTOKK, " Account Group
WAERS TYPE ZMM_VMI_C003_LOG-WAERS, " Order Currency
ZTERM TYPE ZMM_VMI_C003_LOG-ZTERM, " Term of Payment
KALSK TYPE ZMM_VMI_C003_LOG-KALSK, " Schema Group,Vendor
WEBRE TYPE ZMM_VMI_C003_LOG-WEBRE, " GR-Based IV
MSG_ERR TYPE ZMM_VMI_C003_LOG-MSG_ERR, " ERROR MSG
END OF TY_S_ERROR.
*-----------------------------------------------------------------*
* Data decleration
*-----------------------------------------------------------------*
DATA: T_FIELD TYPE STANDARD TABLE OF FS_FIELD,
W_FIELD TYPE FS_FIELD,
BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
IT_OUTPUT TYPE TABLE OF TY_S_ERROR,
WA_OUTPUT TYPE TY_S_ERROR,
WA_FINAL TYPE ZMM_VMI_C003_LOG,
W_MODE TYPE C ,
W_STRUCT TYPE TRUXS_T_TEXT_DATA,
T_MSG TYPE TABLE OF BDCMSGCOLL, " Collecting Error messages
W_MSG TYPE BDCMSGCOLL,
W_MSG1(60).

*-----------------------------------------------------------------*
*Input Path
*-----------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK VMC WITH FRAME TITLE TEXT-001 .
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME, " File Path
P_MODE TYPE C OBLIGATORY DEFAULT 'A'. " Mode
SELECTION-SCREEN END OF BLOCK VMC.

AT SELECTION-SCREEN.
* Mode 'A' = Foreground mode
* Mode 'N' = Background mode
IF P_MODE = 'A' OR P_MODE = 'N' .
W_MODE = P_MODE.
ELSE.
*Error Message
MESSAGE TEXT-002 TYPE 'E'.
ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.

*-----------------------------------------------------------------*
* Uploading excel file.
*-----------------------------------------------------------------*
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = W_STRUCT
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = T_FIELD[]
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE: / TEXT-003.
ENDIF.

*-----------------------------------------------------------------*
* start of selection event.
*-----------------------------------------------------------------*
START-OF-SELECTION.
LOOP AT T_FIELD INTO W_FIELD .
REFRESH: BDCDATA.
CLEAR BDCDATA.
PERFORM POPULATE_BDCDATA.
PERFORM INSERT_DATA.
ENDLOOP.
*-----------------------------------------------------------------*
* populate_bdcdata
*-----------------------------------------------------------------*
FORM POPULATE_BDCDATA.

* PERFORM OPEN_GROUP.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '0107'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RF02K-KTOKK'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RF02K-LIFNR'
W_FIELD-LIFNR.
PERFORM BDC_FIELD USING 'RF02K-EKORG'
W_FIELD-EKORG.
PERFORM BDC_FIELD USING 'RF02K-KTOKK'
W_FIELD-KTOKK.
PERFORM BDC_DYNPRO USING 'SAPMF02K' '0310'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'LFM1-WEBRE'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=UPDA'.
PERFORM BDC_FIELD USING 'LFM1-WAERS'
W_FIELD-WAERS.
PERFORM BDC_FIELD USING 'LFM1-ZTERM'
W_FIELD-ZTERM.
PERFORM BDC_FIELD USING 'LFM1-KALSK'
W_FIELD-KALSK.
PERFORM BDC_FIELD USING 'LFM1-WEBRE'
W_FIELD-WEBRE.
* PERFORM BDC_TRANSACTION USING 'MK01'.

* PERFORM CLOSE_GROUP.
ENDFORM. "populate_bdcdata
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->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
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM. "bdc_field

*&---------------------------------------------------------------------*
*& Form insert_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM INSERT_DATA.
CALL TRANSACTION 'MK01' USING BDCDATA
UPDATE 'S'
MODE W_MODE
MESSAGES INTO T_MSG.
IF SY-SUBRC EQ 0.
* Uploaded into the database
CTR = CTR + 1.
WRITE :TEXT-004,CTR .
ELSE.
* Error Found
LOOP AT T_MSG INTO W_MSG WHERE MSGTYP EQ 'E'.
* Format Message
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = W_MSG-MSGID
MSGNR = W_MSG-MSGNR
MSGV1 = W_MSG-MSGV1
MSGV2 = W_MSG-MSGV2
MSGV3 = W_MSG-MSGV3
MSGV4 = W_MSG-MSGV4
IMPORTING
MESSAGE_TEXT_OUTPUT = W_MSG1.

WA_OUTPUT = W_FIELD.
WA_OUTPUT-MSG_ERR = W_MSG1.
APPEND WA_OUTPUT TO IT_OUTPUT.
LOOP AT IT_OUTPUT INTO WA_FINAL.
MODIFY ZMM_VMI_C003_LOG FROM WA_FINAL.
ENDLOOP.
CLEAR WA_OUTPUT.
CLEAR WA_FINAL.
ENDLOOP.
ENDIF.
ENDFORM. "INSERT_DATA

Message was edited by: Olga Dolinskaja