Hi all,
Am getting Error Like material not created can any one help me on this. Am trying to migrate material master using standard bapi.
DATA : WA_HEADDATA TYPE BAPIMATHEAD,
WA_CLIENTDATA TYPE BAPI_MARA,
WA_CLIENTDATAX TYPE BAPI_MARAX.
DATA : IT_MATERIALDESCRIPTION TYPE TABLE OF BAPI_MAKT,
WA_MATERIALDESCRIPTION TYPE BAPI_MAKT.
DATA : IT_RETURN TYPE TABLE OF BAPIRET2,
WA_RETURN TYPE BAPIRET2.
TYPES: BEGIN OF TY_MARA, "internal table as per flat file structure
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
WA_MARA TYPE TY_MARA.
**selection screen
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME. "file input
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. "f4 helop for file input
PERFORM FILE_HELP.
AT SELECTION-SCREEN ON HELP-REQUEST FOR P_FILE. "F1 help for file input
MESSAGE 'Please press f4 to select file' TYPE 'I'.
START-OF-SELECTION.
DATA : LV_FILE TYPE STRING.
LV_FILE = P_FILE. "to avoid type conflict
CALL FUNCTION 'GUI_UPLOAD' "upload flat file
EXPORTING
FILENAME = LV_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_MARA "internal table
* CHANGING
* ISSCANPERFORMED = ' '
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT IT_MARA INTO WA_MARA.
WA_HEADDATA-MATERIAL = WA_MARA-MATNR. "material no
WA_HEADDATA-IND_SECTOR = WA_MARA-MBRSH. "industry sector
WA_HEADDATA-MATL_TYPE = WA_MARA-MTART. "material type
WA_HEADDATA-BASIC_VIEW = 'X'. "basic view
WA_CLIENTDATA-MATL_GROUP = WA_MARA-MATKL. "material group
WA_CLIENTDATA-BASE_UOM = WA_MARA-MEINS. "base Unit Of measure
WA_CLIENTDATAX-MATL_GROUP = 'X'. "passing material group
WA_CLIENTDATAX-BASE_UOM = 'X'. "passing base unit of measure
WA_MATERIALDESCRIPTION-LANGU = 'EN'. "english language
WA_MATERIALDESCRIPTION-LANGU_ISO = 'EN'. "ISO language
WA_MATERIALDESCRIPTION-MATL_DESC = WA_MARA-MAKTX. "material descriptions
APPEND WA_MATERIALDESCRIPTION TO IT_MATERIALDESCRIPTION.
CLEAR WA_MATERIALDESCRIPTION.
**Create/update materials using BAPI_MATERIAL_SAVEDATA
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA = WA_HEADDATA
CLIENTDATA = WA_CLIENTDATA
CLIENTDATAX = WA_CLIENTDATAX
* PLANTDATA = WA_PLANTDATA
* PLANTDATAX = WA_PLANTDATAX
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA = WA_STORAGELOCATIONDATA
* STORAGELOCATIONDATAX = WA_STORAGELOCATIONDATAX
* VALUATIONDATA =
* VALUATIONDATAX =
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA = WA_SALESDATA
* SALESDATAX = WA_SALESDATAX
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '
* NO_DEQUEUE = ' '
* NO_ROLLBACK_WORK = ' '
IMPORTING
RETURN = WA_RETURN
TABLES
MATERIALDESCRIPTION = IT_MATERIALDESCRIPTION
* UNITSOFMEASURE = IT_UNITSOFMEASURE
* UNITSOFMEASUREX = IT_UNITSOFMEASUREX
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT = IT_MATERIALLONGTEXT
* TAXCLASSIFICATIONS = IT_TAXCLASSIFICATIONS
* RETURNMESSAGES = IT_RETURN
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
.
IF WA_RETURN-TYPE = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
WRITE:/ WA_HEADDATA-MATERIAL, 'is not created' COLOR 3.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
IF SY-SUBRC EQ 0.
WRITE:/ WA_HEADDATA-MATERIAL, 'is created' COLOR 5.
ENDIF.
ENDIF.
ENDLOOP.
FORM FILE_HELP .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4' "get file name on F4 help
* EXPORTING
* PROGRAM_NAME = SYST-REPID
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
* STATIC = ' '
* MASK = ' '
* FILEOPERATION = 'R'
* PATH =
CHANGING
FILE_NAME = P_FILE
* LOCATION_FLAG = 'P'
* EXCEPTIONS
* MASK_TOO_LONG = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " FILE_HELP