*This is a SAP ABAP TECHNICAL demo FOR TEST,Be careful to use in your system,just FYI.
*BAPI_OUTB_DELIVERY_CREATE_SLS Generates Delivery for Customer Order can run in tcode se38 / other tr-code.
*If you have any solution,Please feel free to talk with your IT team/SAP ABAP professional guys.EGenerates Delivery for Customer Order
*A delivery is created for a sales order or for individual sales order
*items. A delivery split can mean that several deliveries are created.
*With the exception of the sales order number in at least one entry of
*the SALES_ORDER_ITEMS parameter, all parameters are optional.
*Interface
*Parameter ,, Opt. ,, ,, Description
*<ZH>Import ,, ,, ,,
*SHIP_POINT ,, X ,, ,, Shipping point
*DUE_DATE ,, X ,, ,, Delivery creation date
*DEBUG_FLG ,, X ,, ,, Forces termination (ALE
*analysis)
*<ZH>Export ,, ,, ,,
*DELIVERY ,, X ,, ,, First generated delivery
*NUM_DELIVERIES ,, X ,, ,, Number of generated deliveries
*<ZH>Tables ,, ,, <ZH>Direction ,,
*SALES_ORDER_ITEMS ,, ,, Import ,, Order items/order
*SERIAL_NUMBERS ,, X ,, Import ,, Serial numbers
*EXTENSION_IN ,, X ,, Import ,, Additional input data
*DELIVERIES ,, X ,, Export ,, Generated deliveries
*CREATED_ITEMS ,, X ,, Export ,, Generated delivery items
*EXTENSION_OUT ,, X ,, Export ,, Additional output data
*RETURN ,, X ,, Export ,, Error log
*<ZH>Opt.: Optional
*<ZH>Direction: Shows the direction used for table parameters.
*<ZH>Caution:
*The exported table parameters are initialized before processing. This
*deletes any data that was in these parameters before the BAPI was
*called.
*<ZH>Imported parameters
*<ZH>Shipping point (SHIP_POINT)
*If the shipping point is not specified, the first shipping point that
*can be determined among the referenced order items is selected. In the
*case of a returns customer order, the shipping point is the goods
*receiving point for the returned goods.
*<ZH>Delivery creation date (DUE_DATE)
*The delivery creation date selected is December 12 9999, unless
*specified otherwise.
*<ZH>DEBUG_FLG
*For internal use only. The DEBUG_FLG can be used in ALE inbound
*processing to force a termination, thereby making the analysis of the
*process easier.
*<ZH>Order (SALES_ORDER_ITEMS-REF_DOC)
*Unless specified otherwise, the entire order is delivered. This means
*that it is not necessary to list all the order items. It is sufficient
*to specify the order number.
*<ZH>Order item (SALES_ORDER_ITEMS-REF_ITEM)
*The order item must be specified if one of the following applies:
*Not all order items in the order are to be delivered
*You want to specify delivery quantities
*Order items are to be delivered in different deliveries (external number
*assignment)
*<ZH>Caution:
*An order item must not occur more than once in SALES_ORDER_ITEMS.
*An order item must not occur if the order number occurs on its own in
*another entry.
*<ZH>Delivery quantities (SALES_ORDER_ITEMS-LFIMG)
*If no delivery quantities are specified, the delivery creation date is
*used to determine the delivery quantities from the schedule lines.
*Otherwise, the delivery quantity is copied from the original quantity.
*If the delivery quantity is specified, the sales unit must be specified,
*either as an SAP code (SALES_UNIT) or an ISO code (SALES_UNIT_ISO).
*Delivery quantities can only be specified for individual order items.
*<ZH>External delivery number (SALES_ORDER_ITEMS-DELIV_NUMB)
*A delivery number from the external number range interval can be
*specified.
*<ZH>Serial numbers (SERIAL_NUMBERS)
*In parameter SERIAL_NUMBERS, serial numbers can be assigned to the
*delivery items that supply the specified order items.
*<ZH>Additional import data (EXTENSION_IN)
*In Parameter EXTENSION_IN, additional data can be transferred. For more
*information, see the documentation for BAdI BADI_DLV_CREATE_SLS_EXTIN.
*Exported parameters
*<ZH>Delivery number (DELIVERY)
*Generated delivery (key field in BOR object type LIKP). In case of a
*delivery split, this is the first generated delivery.
*<ZH>Number of generated deliveries (NUM_DELIVERIES)
*In case of a delivery split, more than one delivery may be generated.
*<ZH>Generated deliveries (DELIVERIES)
*List of all generated deliveries (including DELIVERY).
*<ZH>Generated delivery items (CREATED_ITEMS)
*List of all generated delivery items.
*<ZH>Additional export data (EXTENSION_OUT)
*In case of a synchronous call, additional data can be returned to the
*caller after delivery creation, in parameter EXTENSION_OUT. See the
*documentation for BAdI BADI_DLV_CREATE_EXTOUT.
*<ZH>Error log (RETURN)
*Parameter RETURN contains the error log. In the same way as in
*transaction VL10, deliveries may be created even if there were error
*messages during processing. Since an asynchronous caller of the BAPI
*(ALE) only learns of the success of processing via the RETURN parameter,
*error messages are converted to warning messages if at least one
*delivery could be created. If a delivery is created successfully with
*converted error messages, message VLBAPI061 (see below) is output.
*In addition, RETURN contains the following important messages:
*Message ,, Description
*BAPI000 ,, A delivery could be created
*BAPI001 ,, A delivery could not be created
*VLBAPI061 ,, Delivery created with errors (see warning messages)
*VL311 ,, Delivery <delivery number> has been saved
*Thus, in case of an asynchronous call, the VL311 messages tell you which
*deliveries could be created.
*
*Transactional Behavior
*No COMMIT WORK.
*ROLLBACK WORK, if no delivery could be created.
*The following report delivers a sales order without specifying the
*shipping point, the delivery creation date, or the delivery quantities.
*
*<EX>report zz_test_create_sls.
*
*<EX>parameters: vbeln like vbak-vbeln OBLIGATORY memory id aun,
*<EX> logsys like tbdls-logsys default ‘NONE’.
*
*<EX>data: lf_vbeln type vbeln_vl,
*<EX> lf_num type vbnum,
*<EX> ls_deli type bapishpdelivnumb,
*<EX> lt_deli type table of bapishpdelivnumb,
*<EX> lt_order type table of bapidlvreftosalesorder,
*<EX> ls_order type bapidlvreftosalesorder,
*<EX> ls_itm type bapidlvitemcreated,
*<EX> lt_itm type table of bapidlvitemcreated,
*<EX> ls_ext type bapiparex,
*<EX> lt_extin type table of bapiparex,
*<EX> lt_extout type table of bapiparex,
*<EX> ls_ret type bapiret2,
*<EX> lt_return type table of bapiret2.
*
*<EX>* SalesOrderItems (here: complete sales order)
*<EX>ls_order-ref_doc = vbeln.
*<EX>append ls_order to lt_order.
*
*<EX>* ExtensionIn
*<EX>ls_ext = ‘My additional input’.
*<EX>append ls_ext to lt_extin.
*
*<EX>* Synchronous RFC
*<EX>call function ‘BAPI_OUTB_DELIVERY_CREATE_SLS’
*<EX> DESTINATION logsys
*<EX>* EXPORTING
*<EX>* SHIP_POINT =
*<EX>* DUE_DATE =
*<EX>* DEBUG_FLG =
*<EX> importing
*<EX> delivery = lf_vbeln
*<EX> num_deliveries = lf_num
*<EX> tables
*<EX> sales_order_items = lt_order
*<EX> extension_in = lt_extin
*<EX> deliveries = lt_deli
*<EX> created_items = lt_itm
*<EX> extension_out = lt_extout
*<EX> return = lt_return
*<EX> .
*
*<EX>write: / ‘Delivery:’, lf_vbeln,
*<EX> / ‘NumDeliveries:’, lf_num,
*<EX> / ‘Deliveries:’.
*<EX>loop at lt_deli into ls_deli.
*<EX> write ls_deli-deliv_numb.
*<EX>endloop.
*
*<EX>if not lt_itm[] is initial.
*<EX> write: / ‘CreatedItems:’.
*<EX> loop at lt_itm into ls_itm.
*<EX> write: / ls_itm-ref_doc,
*<EX> ls_itm-ref_item,
*<EX> ls_itm-deliv_numb,
*<EX> ls_itm-deliv_item,
*<EX> ls_itm-material,
*<EX> ls_itm-dlv_qty,
*<EX> ls_itm-sales_unit,
*<EX> ls_itm-sales_unit_iso.
*<EX> endloop.
*<EX>endif.
*
*<EX>if not lt_return[] is initial.
*<EX> write: / ‘Return:’.
*<EX> loop at lt_return into ls_ret.
*<EX> write: / ls_ret-type, ls_ret-id, ls_ret-number,
*<EX> ls_ret-message,
*<EX> /.
*<EX> endloop.
*<EX>endif.
*
*<EX>if not lt_extout[] is initial.
*<EX> write: / ‘ExtensionOut:’.
*<EX> loop at lt_extout into ls_ext.
*<EX> write: / ls_ext.
*<EX> endloop.
*<EX>endif.
*
*<EX>* COMMIT WORK
*<EX>if not lf_vbeln is initial.
*<EX> commit work.
*<EX>endif.
*This BAPI can deliver several orders simultaneously, but is not designed
*for mass delivery.
*The BAPI cannot be called multiple times in one logical unit of work
*(LUW). After a successful call, a COMMIT WORK is required of the caller
*before this BAPI or another BAPI of function group V50I can be called.
*The BAPI cannot specify delivery item numbers.
*Documentation for the parameters
*Documentation for the BAdIs:
*BADI_DLV_CREATE_SLS_EXTIN
*BADI_DLV_CREATE_EXTOUT
REPORT ZDEMO_BAPI_OUTB_DELIVERY_CREATE_SLS.
PARAMETERS SAMPLE AS CHECKBOX.
INITIALIZATION.
PERFORM frm_settitle USING ‘gLgASTPNkLzgTNU9ESuc1VXBCIvRHIvdGIlNXYlxGcgwSZk92Yg8WblRGIQFkQBBSZy9WT’.
START-OF-SELECTION.
BREAK-POINT..
DATA: LV_SHIP_POINT TYPE BAPIDLVCREATEHEADER-SHIP_POINT .”Obligatory
DATA: LV_DUE_DATE TYPE BAPIDLVCREATEHEADER-DUE_DATE .”Obligatory
DATA: LV_DEBUG_FLG TYPE BAPIDLVCONTROL-DEBUG_FLG .”Obligatory
DATA: LV_NO_DEQUEUE TYPE BAPIFLAG-BAPIFLAG .”Option,Default Value =’ ‘,
DATA: LV_DELIVERY TYPE BAPISHPDELIVNUMB-DELIV_NUMB .”Obligatory
DATA: LV_NUM_DELIVERIES TYPE BAPIDLVCREATEHEADER-NUM_DELIVERIES .”Obligatory
**********************************************************************
*******Defination of [Tables]-[SALES_ORDER_ITEMS] .
**********************************************************************
DATA: LT_SALES_ORDER_ITEMS TYPE STANDARD TABLE OF BAPIDLVREFTOSALESORDER.””Delivery Item with Reference to a Sales Order
DATA: LS_SALES_ORDER_ITEMS TYPE BAPIDLVREFTOSALESORDER .””Delivery Item with Reference to a Sales Order
LS_SALES_ORDER_ITEMS-REF_DOC = ‘CHAR10’. “Reference document
LS_SALES_ORDER_ITEMS-REF_ITEM = ‘NUMC6’. “Reference Item
LS_SALES_ORDER_ITEMS-DLV_QTY = ‘QUAN13’. “Delivery Quantity
LS_SALES_ORDER_ITEMS-SALES_UNIT = ‘UNIT3’. “Sales Unit
LS_SALES_ORDER_ITEMS-SALES_UNIT_ISO = ‘CHAR3’. “ISO sales unit
LS_SALES_ORDER_ITEMS-DELIV_NUMB = ‘CHAR10’. “Delivery
LS_SALES_ORDER_ITEMS-RETURNS_DELIV_NUMB = ‘CHAR10’. “Delivery
LS_SALES_ORDER_ITEMS-RETURNS_DELIV_ITEM = ‘NUMC6’. “Item
LS_SALES_ORDER_ITEMS-EXTENSION_ID = ‘RAW16’. “Ref. ID for BAPI Parameter Extension
APPEND LS_SALES_ORDER_ITEMS TO LT_SALES_ORDER_ITEMS .
CLEAR LS_SALES_ORDER_ITEMS .
**********************************************************************
*******Defination of [Tables]-[SERIAL_NUMBERS] .
**********************************************************************
DATA: LT_SERIAL_NUMBERS TYPE STANDARD TABLE OF BAPIDLVSERIALNUMBER.””Serial Number
DATA: LS_SERIAL_NUMBERS TYPE BAPIDLVSERIALNUMBER .””Serial Number
LS_SERIAL_NUMBERS-REF_DOC = ‘CHAR10’. “Reference document
LS_SERIAL_NUMBERS-REF_ITEM = ‘NUMC6’. “Reference Item
LS_SERIAL_NUMBERS-SERIALNO = ‘CHAR18’. “Serial Number
APPEND LS_SERIAL_NUMBERS TO LT_SERIAL_NUMBERS .
CLEAR LS_SERIAL_NUMBERS .
**********************************************************************
*******Defination of [Tables]-[EXTENSION_IN] .
**********************************************************************
DATA: LT_EXTENSION_IN TYPE STANDARD TABLE OF BAPIPAREX.””Ref. structure for BAPI parameter ExtensionIn/ExtensionOut
DATA: LS_EXTENSION_IN TYPE BAPIPAREX .””Ref. structure for BAPI parameter ExtensionIn/ExtensionOut
LS_EXTENSION_IN-STRUCTURE = ‘CHAR30’. “BAPI table extension struct.
LS_EXTENSION_IN-VALUEPART1 = ‘CHAR240’. “Data
LS_EXTENSION_IN-VALUEPART2 = ‘CHAR240’. “Data
LS_EXTENSION_IN-VALUEPART3 = ‘CHAR240’. “Data
LS_EXTENSION_IN-VALUEPART4 = ‘CHAR240’. “Data
APPEND LS_EXTENSION_IN TO LT_EXTENSION_IN .
CLEAR LS_EXTENSION_IN .
**********************************************************************
*******Defination of [Tables]-[DELIVERIES] .
**********************************************************************
DATA: LT_DELIVERIES TYPE STANDARD TABLE OF BAPISHPDELIVNUMB.””Delivery Number
DATA: LS_DELIVERIES TYPE BAPISHPDELIVNUMB .””Delivery Number
LS_DELIVERIES-DELIV_NUMB = ‘CHAR10’. “Delivery
APPEND LS_DELIVERIES TO LT_DELIVERIES .
CLEAR LS_DELIVERIES .
**********************************************************************
*******Defination of [Tables]-[CREATED_ITEMS] .
**********************************************************************
DATA: LT_CREATED_ITEMS TYPE STANDARD TABLE OF BAPIDLVITEMCREATED.””Generated Delivery Item
DATA: LS_CREATED_ITEMS TYPE BAPIDLVITEMCREATED .””Generated Delivery Item
LS_CREATED_ITEMS-REF_DOC = ‘CHAR10’. “Reference document
LS_CREATED_ITEMS-REF_ITEM = ‘NUMC6’. “Reference Item
LS_CREATED_ITEMS-DELIV_NUMB = ‘CHAR10’. “Delivery
LS_CREATED_ITEMS-DELIV_ITEM = ‘NUMC6’. “Item
LS_CREATED_ITEMS-MATERIAL = ‘CHAR18’. “Material
LS_CREATED_ITEMS-DLV_QTY = ‘QUAN13’. “Delivery Quantity
LS_CREATED_ITEMS-SALES_UNIT = ‘UNIT3’. “Sales Unit
LS_CREATED_ITEMS-SALES_UNIT_ISO = ‘CHAR3’. “ISO sales unit
LS_CREATED_ITEMS-MATERIAL_EXTERNAL = ‘CHAR40’. “Material Number
LS_CREATED_ITEMS-MATERIAL_GUID = ‘CHAR32’. “GUID (External)
LS_CREATED_ITEMS-MATERIAL_VERSION = ‘CHAR10’. “Version Number
LS_CREATED_ITEMS-MATERIAL_LONG = ‘CHAR40’. “Material
APPEND LS_CREATED_ITEMS TO LT_CREATED_ITEMS .
CLEAR LS_CREATED_ITEMS .
**********************************************************************
*******Defination of [Tables]-[EXTENSION_OUT] .
**********************************************************************
DATA: LT_EXTENSION_OUT TYPE STANDARD TABLE OF BAPIPAREX.””Ref. structure for BAPI parameter ExtensionIn/ExtensionOut
DATA: LS_EXTENSION_OUT TYPE BAPIPAREX .””Ref. structure for BAPI parameter ExtensionIn/ExtensionOut
LS_EXTENSION_OUT-STRUCTURE = ‘CHAR30’. “BAPI table extension struct.
LS_EXTENSION_OUT-VALUEPART1 = ‘CHAR240’. “Data
LS_EXTENSION_OUT-VALUEPART2 = ‘CHAR240’. “Data
LS_EXTENSION_OUT-VALUEPART3 = ‘CHAR240’. “Data
LS_EXTENSION_OUT-VALUEPART4 = ‘CHAR240’. “Data
APPEND LS_EXTENSION_OUT TO LT_EXTENSION_OUT .
CLEAR LS_EXTENSION_OUT .
**********************************************************************
*******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_OUTB_DELIVERY_CREATE_SLS’
* EXPORTING
* SHIP_POINT = LV_SHIP_POINT
* DUE_DATE = LV_DUE_DATE
* DEBUG_FLG = LV_DEBUG_FLG
* NO_DEQUEUE = ”
IMPORTING
DELIVERY = LV_DELIVERY
NUM_DELIVERIES = LV_NUM_DELIVERIES
TABLES
SALES_ORDER_ITEMS = LT_SALES_ORDER_ITEMS
* SERIAL_NUMBERS = LT_SERIAL_NUMBERS
* EXTENSION_IN = LT_EXTENSION_IN
* DELIVERIES = LT_DELIVERIES
* CREATED_ITEMS = LT_CREATED_ITEMS
* EXTENSION_OUT = LT_EXTENSION_OUT
* 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.
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》