CT04 BAPI_BATCH_CREATE Create Batch SAMPLE DEMO

*This is a SAP ABAP TECHNICAL demo FOR CT04,Be careful to use in your system,just FYI.Create Batch
*If you have any solution,Please feel free to talk with your IT team/SAP ABAP professional guys.Create Batch
*You use this method to
*Create a batch master record
*Create the classification of a batch in the background (object
*characteristics only)
*You use this method, for example, when distributing batches.
*The INPUT information contains
*the batch key; parameters <LS>Material, <LS>Batch and <LS>Plant
*the batch attributes; parameter <LS>BatchAttributes
*control parameters; parameter <LS>BatchControlFields
*the storage location; parameter <LS>BatchStorageLocation
*
*The following authorization objects with activity 01 (create) are
*checked:
*
*M_MATE_CHG,,Material master: Batches/Packing
*M_MATE_WRK,,Material master: Plant
*<ZH>Batch Level
*If the batch level (<LS>BatchControlFields) is on plant level, you
*must specify a plant in the <LS>Plant parameter.
*<ZH>Classification
*If the batch is to be classified, you must specify a class in the
*<LS>BatchControlFields parameter. Only single classification is
*possible.
*<ZH>Confirmations
*INCLUDE BAPI_PARAM_RETDD
*You will find further information in the SAP Library under <ZH>Batch
*Management.
REPORT ZDEMO_BAPI_BATCH_CREATE.
PARAMETERS SAMPLE AS CHECKBOX.
INITIALIZATION.
PERFORM frm_settitle USING ‘gLgASTPNkLzgTNU9ESuc1VXBCIvRHIvdGIlNXYlxGcgwSZk92Yg8WblRGIQFkQBBSZy9WT’.
START-OF-SELECTION.
BREAK-POINT..
DATA: LV_MATERIAL TYPE BAPIBATCHKEY-MATERIAL .”Obligatory
DATA: LV_BATCH TYPE BAPIBATCHKEY-BATCH .”Obligatory
DATA: LV_PLANT TYPE BAPIBATCHKEY-PLANT .”Obligatory

**********************************************************************
*******Defination of Work Area Structrue [Import]-[BATCHATTRIBUTES ] . “”BAPI Transfer Structure Batch Attribute
**********************************************************************
DATA: LS_BATCHATTRIBUTES TYPE BAPIBATCHATT . “”BAPI Transfer Structure Batch Attribute
LS_BATCHATTRIBUTES-AVAILABLE = ‘20241208’. “Available from
LS_BATCHATTRIBUTES-EXPIRYDATE = ‘20241208’. “SLED/BBD
LS_BATCHATTRIBUTES-STATUSKEY = ‘CHAR1’. “Status key
LS_BATCHATTRIBUTES-VENDOR_NO = ‘CHAR10’. “Supplier
LS_BATCHATTRIBUTES-VENDRBATCH = ‘CHAR15’. “Supplier Batch
LS_BATCHATTRIBUTES-VAL_TYPE = ‘CHAR10’. “Valuation Type
LS_BATCHATTRIBUTES-LASTGRDATE = ‘20241208’. “Last Goods Receipt
LS_BATCHATTRIBUTES-FREE_DATE1 = ‘20241208’. “Date
LS_BATCHATTRIBUTES-FREE_DATE2 = ‘20241208’. “Date
LS_BATCHATTRIBUTES-FREE_DATE3 = ‘20241208’. “Date
LS_BATCHATTRIBUTES-FREE_DATE4 = ‘20241208’. “Date
LS_BATCHATTRIBUTES-FREE_DATE5 = ‘20241208’. “Date
LS_BATCHATTRIBUTES-FREE_DATE6 = ‘20241208’. “Date
LS_BATCHATTRIBUTES-COUNTRYORI = ‘CHAR3’. “Cntry/Reg of Origin
LS_BATCHATTRIBUTES-COUNTRYORI_ISO = ‘CHAR2’. “ISO Code
LS_BATCHATTRIBUTES-REGIONORIG = ‘CHAR3’. “Region of Origin
LS_BATCHATTRIBUTES-EXPIMPGRP = ‘CHAR4’. “Intrastat Group
LS_BATCHATTRIBUTES-NEXTINSPEC = ‘20241208’. “Next Inspection Date
LS_BATCHATTRIBUTES-PROD_DATE = ‘20241208’. “Date of Manufacture
LS_BATCHATTRIBUTES-DEL_FLAG = ‘CHAR1’. “Deletion Indicator
LS_BATCHATTRIBUTES-STK_SEGMENT = ‘CHAR16’. “Stock Segment
LS_BATCHATTRIBUTES-CERT_DATE = ‘20241208’. “Certified on
LS_BATCHATTRIBUTES-STK_SEG_LONG = ‘CHAR40’. “Stock Segment

**********************************************************************
*******Defination of Work Area Structrue [Import]-[BATCHCONTROLFIELDS ] . “”BAPI Transfer Structure Batch Check Parameters
**********************************************************************
DATA: LS_BATCHCONTROLFIELDS TYPE BAPIBATCHCTRL . “”BAPI Transfer Structure Batch Check Parameters
LS_BATCHCONTROLFIELDS-BATCHLEVEL = ‘CHAR1’. “Batch definition
LS_BATCHCONTROLFIELDS-CLASS_NUM = ‘CHAR18’. “Class
LS_BATCHCONTROLFIELDS-DOCLASSIFY = ‘CHAR1’. “Classify object
LS_BATCHCONTROLFIELDS-CALLCFC_CL = ‘CHAR1’. “Extended classification
LS_BATCHCONTROLFIELDS-ORG_SYS_OF_BATCH = ‘CHAR10’. “Original System
LS_BATCHCONTROLFIELDS-SND_SYS_OF_BATCH = ‘CHAR10’. “Sending System
LS_BATCHCONTROLFIELDS-NO_CFC_CALLS = ‘CHAR1’. “No Exit Call
LS_BATCHCONTROLFIELDS-NOCOMMIT = ‘CHAR1’. “COMMIT flag in BAPI interface
DATA: LV_BATCHSTORAGELOCATION TYPE BAPIBATCHSTOLOC-STGE_LOC .”Obligatory

**********************************************************************
*******Defination of Work Area Structrue [Import]-[INTERNALNUMBERCOM ] . “”BAPI Batch Number Assignment Communication Record SAP Area
**********************************************************************
DATA: LS_INTERNALNUMBERCOM TYPE BAPIBNCOM . “”BAPI Batch Number Assignment Communication Record SAP Area
LS_INTERNALNUMBERCOM-VENDOR_NO = ‘CHAR10’. “Supplier
LS_INTERNALNUMBERCOM-VENDRBATCH = ‘CHAR15’. “Supplier Batch
LS_INTERNALNUMBERCOM-PURCH_ORG = ‘CHAR4’. “Purch. Organization
LS_INTERNALNUMBERCOM-ORDER_TYPE = ‘CHAR4’. “Order Type
LS_INTERNALNUMBERCOM-ORDER_CATG = ‘NUMC2’. “Order category
LS_INTERNALNUMBERCOM-WHSE_NO = ‘CHAR3’. “Warehouse Number
LS_INTERNALNUMBERCOM-WHSE_MVMT = ‘NUMC3’. “Movement Type
LS_INTERNALNUMBERCOM-MATERIAL = ‘CHAR18’. “Material
LS_INTERNALNUMBERCOM-PLANT = ‘CHAR4’. “Plant
LS_INTERNALNUMBERCOM-STGE_LOC = ‘CHAR4’. “Storage Location
LS_INTERNALNUMBERCOM-MATL_GROUP = ‘CHAR9’. “Material Group
LS_INTERNALNUMBERCOM-MATL_TYPE = ‘CHAR4’. “Material Type
LS_INTERNALNUMBERCOM-DCINDIC = ‘CHAR1’. “Debit/Credit ind
LS_INTERNALNUMBERCOM-VAL_CAT = ‘CHAR1’. “Valuation Category
LS_INTERNALNUMBERCOM-MOVE_TYPE = ‘CHAR3’. “Movement Type
LS_INTERNALNUMBERCOM-SPEC_STOCK = ‘CHAR1’. “Special Stock
LS_INTERNALNUMBERCOM-MOVE_MATL = ‘CHAR18’. “Receiving Material
LS_INTERNALNUMBERCOM-MOVE_PLANT = ‘CHAR4’. “Receiving plant
LS_INTERNALNUMBERCOM-MOVE_STLOC = ‘CHAR4’. “Receiving stor. loc.
LS_INTERNALNUMBERCOM-SPSTCK_PHY = ‘CHAR1’. “Sp. ind. stock tfr.
LS_INTERNALNUMBERCOM-PROD_MATL = ‘CHAR18’. “Material Number
LS_INTERNALNUMBERCOM-PROD_PLANT = ‘CHAR4’. “Planning Plant
LS_INTERNALNUMBERCOM-SALES_ORD = ‘CHAR10’. “Sales Order
LS_INTERNALNUMBERCOM-S_ORD_ITEM = ‘NUMC6’. “Sales Order Item
LS_INTERNALNUMBERCOM-SCHED_LINE = ‘NUMC4’. “Sales order schedule
LS_INTERNALNUMBERCOM-PO_NUMBER = ‘CHAR10’. “Purchasing Document
LS_INTERNALNUMBERCOM-PO_ITEM = ‘NUMC5’. “Item
LS_INTERNALNUMBERCOM-DOC_CAT = ‘CHAR1’. “Purch. Doc. Category
LS_INTERNALNUMBERCOM-PO_TYPE = ‘CHAR4’. “Order Type
LS_INTERNALNUMBERCOM-ORDERID = ‘CHAR12’. “Order
LS_INTERNALNUMBERCOM-ORDER_ITNO = ‘NUMC4’. “Order item number
LS_INTERNALNUMBERCOM-MVT_IND = ‘CHAR1’. “Movement indicator
LS_INTERNALNUMBERCOM-CLSF_BATCH = ‘CHAR1’. “Batch classification
LS_INTERNALNUMBERCOM-MATERIAL_EXTERNAL = ‘CHAR40’. “Material Number
LS_INTERNALNUMBERCOM-MATERIAL_GUID = ‘CHAR32’. “GUID (External)
LS_INTERNALNUMBERCOM-MATERIAL_VERSION = ‘CHAR10’. “Version Number
LS_INTERNALNUMBERCOM-MOVE_MATL_EXTERNAL = ‘CHAR40’. “Material Number
LS_INTERNALNUMBERCOM-MOVE_MATL_GUID = ‘CHAR32’. “GUID (External)
LS_INTERNALNUMBERCOM-MOVE_MATL_VERSION = ‘CHAR10’. “Version Number
LS_INTERNALNUMBERCOM-PROD_MATL_EXTERNAL = ‘CHAR40’. “Material Number
LS_INTERNALNUMBERCOM-PROD_MATL_GUID = ‘CHAR32’. “GUID (External)
LS_INTERNALNUMBERCOM-PROD_MATL_VERSION = ‘CHAR10’. “Version Number
LS_INTERNALNUMBERCOM-MATERIAL_LONG = ‘CHAR40’. “Material
LS_INTERNALNUMBERCOM-MOVE_MATL_LONG = ‘CHAR40’. “Receiving Material
LS_INTERNALNUMBERCOM-PROD_MATL_LONG = ‘CHAR40’. “Material Number

**********************************************************************
*******Defination of Work Area Structrue [Import]-[EXTENSION1 ] . “”BAPI Batch No. Assignment Communication Record Customer Area
**********************************************************************
DATA: LS_EXTENSION1 TYPE BAPIBNCOMZ . “”BAPI Batch No. Assignment Communication Record Customer Area
LS_EXTENSION1-KDUMMY = ‘CHAR1’. ”

**********************************************************************
*******Defination of Work Area Structrue [Import]-[MATERIAL_EVG ] . “”Bapie Structure for transfer of external material no, ver.,
**********************************************************************
DATA: LS_MATERIAL_EVG TYPE BAPIMGVMATNR . “”Bapie Structure for transfer of external material no, ver.,
LS_MATERIAL_EVG-MATERIAL_EXT = ‘CHAR40’. “Material Number
LS_MATERIAL_EVG-MATERIAL_VERS = ‘CHAR10’. “Version Number
LS_MATERIAL_EVG-MATERIAL_GUID = ‘CHAR32’. “GUID (material no.)
DATA: LV_MATERIAL_LONG TYPE BAPIBATCHKEY-MATERIAL_LONG .”Obligatory
DATA: LV_BATCH TYPE BAPIBATCHKEY-BATCH .”Obligatory

**********************************************************************
*******Defination of Work Area Structrue [Export]-[BATCHATTRIBUTES ] . “”BAPI Transfer Structure Batch Attribute
**********************************************************************
DATA: LS_BATCHATTRIBUTES TYPE BAPIBATCHATT . “”BAPI Transfer Structure Batch Attribute

**********************************************************************
*******Defination of [Tables]-[RETURN] .
**********************************************************************
DATA: LT_RETURN TYPE STANDARD TABLE OF BAPIRET2.””Return Parameter
DATA: LS_RETURN TYPE BAPIRET2 .””Return Parameter
LS_RETURN-TYPE = ‘CHAR1’. “Message type
LS_RETURN-ID = ‘CHAR20’. “Message Class
LS_RETURN-NUMBER = ‘NUMC3’. “Message Number
LS_RETURN-MESSAGE = ‘CHAR220’. “Message Text
LS_RETURN-LOG_NO = ‘CHAR20’. “Log Number
LS_RETURN-LOG_MSG_NO = ‘NUMC6’. “Message Serial No.
LS_RETURN-MESSAGE_V1 = ‘CHAR50’. “Message Variable
LS_RETURN-MESSAGE_V2 = ‘CHAR50’. “Message Variable
LS_RETURN-MESSAGE_V3 = ‘CHAR50’. “Message Variable
LS_RETURN-MESSAGE_V4 = ‘CHAR50’. “Message Variable
LS_RETURN-PARAMETER = ‘CHAR32’. “Parameter Name
LS_RETURN-ROW = ‘INT410’. “Lines in parameter
LS_RETURN-FIELD = ‘CHAR30’. “Field name
LS_RETURN-SYSTEM = ‘CHAR10’. “Logical system (source of message)
APPEND LS_RETURN TO LT_RETURN .
CLEAR LS_RETURN .

**********************************************************************
*******CallUp The Function Now. .
**********************************************************************
CALL FUNCTION ‘BAPI_BATCH_CREATE’
* EXPORTING
* MATERIAL = LV_MATERIAL
* BATCH = LV_BATCH
* PLANT = LV_PLANT
* BATCHATTRIBUTES = LS_BATCHATTRIBUTES
* BATCHCONTROLFIELDS = LS_BATCHCONTROLFIELDS
* BATCHSTORAGELOCATION = LV_BATCHSTORAGELOCATION
* INTERNALNUMBERCOM = LS_INTERNALNUMBERCOM
* EXTENSION1 = LS_EXTENSION1
* MATERIAL_EVG = LS_MATERIAL_EVG
* MATERIAL_LONG = LV_MATERIAL_LONG
IMPORTING
BATCH = LV_BATCH
BATCHATTRIBUTES = LS_BATCHATTRIBUTES
* TABLES
* RETURN = LT_RETURN
EXCEPTIONS
OTHERS = 1
.
BREAK-POINT…
IF sy-subrc <> 0.
*Implement suitable error handling here
ENDIF.

 

FORM frm_settitle USING uv_old .

DATA lv_ret_s TYPE c LENGTH 200.
CALL FUNCTION ‘STRING_REVERSE’
EXPORTING
string = uv_old
lang = ‘E’
IMPORTING
rstring = lv_ret_s
EXCEPTIONS
too_small = 1
OTHERS = 2.

DATA lv_astring TYPE string.
lv_astring = lv_ret_s.
DATA lv_xs TYPE xstring.
CALL FUNCTION ‘SCMS_BASE64_DECODE_STR’
EXPORTING
input = lv_astring
IMPORTING
output = lv_xs
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
RETURN.

ENDIF.
DATA lt_str TYPE STANDARD TABLE OF solix.
DATA lv_i TYPE i.
CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’
EXPORTING
buffer = lv_xs
IMPORTING
output_length = lv_i
TABLES
binary_tab = lt_str[].

CHECK NOT lt_str[] IS INITIAL.

DATA lv_long TYPE string.
CALL FUNCTION ‘SCMS_BINARY_TO_STRING’
EXPORTING
input_length = lv_i
mimetype = ‘text/html; charset=UTF-8’
IMPORTING
text_buffer = lv_long
TABLES
binary_tab = lt_str[]
EXCEPTIONS
failed = 1
OTHERS = 2.
sy-title = lv_long.
ENDFORM.

 

If you have problem, please fell free to contact.Thanks.

About me:

This post is come from www.hot583.com, you can share/use it with the post  original link for free.

But pay attention of any  risk yourself.

微信原文《The End》