2023 Aug 19 5:19 PM
*********My complete program***********
report ZBAPI_MAT_DATA
no standard page heading line-size 255.
TYPES : BEGIN OF lty_data,
MATNR TYPE MATNR,
MBRSH TYPE mbrsh,
MTART TYPE MTART,
MAKTX TYPE MAKTX,
MEINS TYPE MEINS,
END OF lty_data.
DATA : lt_data TYPE TABLE OF lty_data.
DATA : ls_data TYPE lty_data.
DATA : lv_file TYPE String.
DATA : ls_headdata TYPE BAPIMATHEAD.
DATA : ls_clientdata TYPE BAPI_MARA.
DATA : ls_clientdatax TYPE BAPI_MARA.
DATA : lt_desc TYPE TABLE OF BAPI_MAKT.
DATA : ls_desc TYPE BAPI_MAKT.
DATA : lt_return TYPE TABLE OF BAPIRET2.
DATA : ls_return TYPE BAPIRET2.
PARAMETERS : p_file TYPE Localfile.
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.
.
START-OF-SELECTION.
lv_file = p_file.
CALL FUNCTION 'GUI_UPLOAD'
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 = lt_data
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT lt_data INTO ls_data.
ls_headdata-MATERIAL = ls_data-matnr.
ls_headdata-IND_SECTOR = ls_data-mbrsh.
ls_headdata-MATL_TYPE = ls_data-mtart.
ls_headdata-BASIC_VIEW = 'X'.
ls_clientdata-BASE_UOM = ls_data-meins.
ls_clientdatax-BASE_UOM = 'X'.
ls_desc-LANGU = sy-langu.
ls_desc-MATL_DESC = ls_data-maktx.
APPEND ls_desc TO lt_desc.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA = ls_headdata
CLIENTDATA = ls_clientdata
CLIENTDATAX = ls_clientdatax
* PLANTDATA =
* PLANTDATAX =
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA =
* STORAGELOCATIONDATAX =
* VALUATIONDATA =
* VALUATIONDATAX =
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA =
* SALESDATAX =
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '
* NO_DEQUEUE = ' '
* NO_ROLLBACK_WORK = ' '
IMPORTING
RETURN = ls_return
TABLES
MATERIALDESCRIPTION = lt_desc
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
.
APPEND ls_return TO lt_return.
CLEAR : ls_return,ls_headdata,ls_clientdata,ls_clientdatax.
REFRESH : lt_desc.
ENDLOOP.
END-OF-SELECTION.
LOOP AT lt_return INTO ls_return.
WRITE : / ls_return-message.
ENDLOOP.
2023 Aug 19 6:05 PM
Dear ejazahmed4162,
Looks like the mentioned error 'CX_SY_DYN_CALL_ILLEGAL_TYPE' is coming due to SYST-CPROG and SYST-DYNNR fields in the CALL FUNCTION 'F4_FILENAME' statement. Please try using a fixed program name and screen number instead of dynamic fields.
2023 Aug 21 12:23 PM
Please edit your post and use the CODE button around your code. It will then be nicely formatted and easier to read and people are more likely to help you.
2023 Aug 23 1:08 PM
Don't use those old fashioned FM, better use class CL_GUI_FRONTEND_SERVICES, methods such as FILE_OPEN_DIALOG and GUI_UPLOAD (Use the link to find sap provided samples)