09-01-2015 5:41 AM
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
09-01-2015 10:56 PM
had you ever done such task before?
Looking at your code and the question I wonder if you even tried the baby steps of an ABAPer to help yourself: debugging
You did not even add some coding for error handling, no wonder that you do not know where the programm fails, whether it is already in the upload step or when it comes to the material creation.
And what do you actually call "material migration"? this coding has almost all views on comments.
Just a hint, a material basic data is only able to work if it has unit of measure data (which is still on comment in your coding)
09-02-2015 11:12 AM
Hi Jurgen
Can you correct the code and send back to me so that it will be helpful for me.
09-02-2015 7:34 PM
09-03-2015 6:12 AM
Hi Jurgen,
I am just learner am just doing my practice on the bapi.. If you are willing to help me you can help...
I am not doing for money sake am doing to gain the knowledge.
09-03-2015 12:04 PM
See, if I just amend your code then I doubt that you learn much.
There are so many things unconsidered in your code that it is even difficult to know where to start.
Do you had an ABAP training at all?
Do you know debugging?
Can you read the code?
Did you ever create a material master with its standard transaction?
Do you have a fundamental understanding of material masters?
I am certainly willing to help people over a hurdle, but you actually asked i shall send you the corrected code, and this is not my goal and is not the purpose of SCN either.
The bapi is pretty much structured according to the tables used to store material master information.
if you understand ABAP coding then you can see that almost anything is commented, which means will not be processed. What kind of material do you expect to create?
It might not be a bad approach to start small on one side, but you are actually fighting against a problem which you probably would not see if you tried to migrate a real material, which has all kind of plant views etc.
Back to your coding. You just cared about MARA the general data of a material. Goto MM01 and maintain the same values in the screen, then check the tables, MARA, MAKT, MARM (just to give you one more hint)
do all 3 tables have entries or only MARA?
If you see values in all three tables, then your coding just for MARA is to less to create a material. Would you share this opinion?
09-04-2015 8:20 AM
Hi jurgen,
I am just beginner of ABAP. Am practicing the ABAP scenarios by seeing in saptechnical website.
As you said i did the debugging am not getting y it is taking return type as E.
As you said i observe the tcode MM01 it is updating MARA and MARM.
Can you share your email id or skype id so that i can share my views.
09-04-2015 7:37 PM
It is interesting that you are following scenarios posted in another website and seeking then for help in SCN. Wouldn't it be logical to contact the author of the article in the other website if his stuff doesn't work?
That is actually exact what I initially meant, just following unexplained scenarios by retyping of some code does not really get you anywhere.
It is very important to understand interrelations and to think beyond. So you already found that SAP updated table MARM when you create the material master. What is your conclusion from this experience? What does that mean for your code? Do you have any such values in your data template as you could see in MARM? Do you have any coding that would enable the update of table MARM in your BAPI?
What is MARM about? Answer: units of measures
What is the part in the parameters/tables of the BAPI that care about that?
This one eventually?:
* UNITSOFMEASURE = IT_UNITSOFMEASURE
* UNITSOFMEASUREX = IT_UNITSOFMEASUREX
09-02-2015 1:03 PM
First read Top 10 ABAP crimes and add some error monitoring (at least write the error message text RETURN-MESSAGE and not a meaningless generic failure message)
Also you should (must) also
Regards,
Raymond