#2. バリアント変数
Tr-CD:STVARVC/STVARV
項目定義:Z_MARA_ADD
#2.1 自動更新バリアント
ABAP
DATA:
GDF_STR TYPE CHAR14.
CONSTANTS:
CNS_VARVC_NM TYPE CHAR15 VALUE 'Z_MARA_ADD01'.
MOVE I_ADD_CNT TO GDF_STR.
CONDENSE GDF_STR.
UPDATE TVARVC SET LOW = GDF_STR
HIGH = SPACE WHERE NAME = CNS_VARVC_NM.
ABAP
REPORT Z_BATCH_ADD01.
DATA:
GD_CNT_FOR_SCR TYPE INT4.
SELECT-OPTIONS:
S_CNT FOR GD_CNT_FOR_SCR OBLIGATORY NO-EXTENSION NO INTERVALS .
#3. BatchInput
#3.3 startRecorder
- record:recorder20190110
- Transation code:mm01
#3.4 入力画面
- 品目:
- 産業コード:
- 品目タイプ:
ABAP
report ZSAPN_MM01
no standard page heading line-size 255.
include bdcrecx1.
parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
* data element: MATNR
MATNR_001(018),
* data element: MBRSH
MBRSH_002(001),
* data element: MTART
MTART_003(004),
* data element: XFELD
KZSEL_01_004(001),
* data element: MAKTX
MAKTX_005(040),
* data element: MEINS
MEINS_006(003),
* data element: MTPOS_MARA
MTPOS_MARA_007(004),
end of record.
*** End generated data section ***
start-of-selection.
perform open_dataset using dataset.
perform open_group.
do.
read dataset dataset into record.
if sy-subrc <> 0. exit. endif.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
record-MATNR_001.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_002.
perform bdc_field using 'RMMG1-MTART'
record-MTART_003.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_005.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
record-MEINS_006.
perform bdc_field using 'MARA-MTPOS_MARA'
record-MTPOS_MARA_007.
perform bdc_transaction using 'MM01'.
enddo.
perform close_group.
perform close_dataset using dataset.
#4. BAPI【品目登録】
ABAP
REPORT ZSAPN_MATERIAL_BAPI.
*BAPI declarations
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 = SY-LANGU. "english language
WA_MATERIALDESCRIPTION-LANGU_ISO = 'JA'. "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
mara.txt
SAPNMAT001 MODE W 016 EA Material description1
SAPNMAT002 MODE W 016 EA Material description2
SAPNMAT003 MODE W 016 EA Material description3
SAPNMAT004 MODE W 016 EA Material description4