Advanced shipping
Overview
To use the full API functionality of Carrier Cloud for SAP, use this class: /AEB/CL_PA_PB_CARRIER_BF
This class enables you to call every API function of Carrier Cloud and change every field value and parameter. For a detailed documentation of this API see here: .
To support you building up the required data structures in SAP, there are some complementary features, which will be explained in this guide step by step:
Task | Class |
---|---|
Determination of the org unit | Freight order: /AE1/CL_PA_PB_FRO_OU_RULE_BC Delivery: /AEB/CL_PA_PB_DLV_OU_RULE_BC Shipment: /AEB/CL_PA_PB_SHP_OU_RULE_BC |
Determination of connection parms | /AEB/CL_PA_PB_ENGN_PRM_BC |
Collecting data for a shipping order (Collector) This function provides the basic data based on the settings in the configuration. It runs also through the "AFTER_STD_FILLING"-method of the according BAdI for each object. | Freight order: /AE1/CL_PA_PB_FRO_SHP_COLL_BC Delivery: /AEB/CL_PA_PB_DLV_SHP_COLL_BC Shipment: /AEB/CL_PA_PB_SHP_SHP_COLL_BC |
Determination of the reference number | Freight order: /AE1/CL_PA_PB_FRO_SHP_REF_BC Delivery: /AEB/CL_PA_PB_DLV_SHP_REF_BC Shipment: /AEB/CL_PA_PB_SHP_SHP_REF_BC |
Determination of the workstation ID | /AEB/CL_PA_PB_WSTA_ID_BC |
The naming of the classes is structured like this:
- /AEB/CL_PA_PB - Class is for public usage in customer implementations of Carrier Cloud for SAP
- DLV , SHP, FRO - the SAP document the class is applicable for: delivery, shipment or freight order
- OU_RULE_BC, SHP_COLL_BC, SHP_REF_BC, WSTA_ID_BC - the functionality the class can be used for: organizational unit rule (OU_RULE), collect shipping data (SHIP_COLL), get reference (REF) or get workstation data (WSTA).
In this part of the guide we will walk through a reference implementation that combines all those functions.
All examples are based on an outbound delivery, but you can adapt them to other supported SAP business objects using the according class as listed above. Regardless of the SAP business object you're transferring, the result will be a "shipping order" in Carrier Cloud.
1. Organizational unit
First step is to determine the AEB specific organizational unit for a business object. The org unit is helpful to separate data access and read certain data from the configuration. This program determines the organizational unit for a delivery and writes it to the screen:
REPORT zaeb_create_first_shipment.
PARAMETERS: vbeln TYPE likp-vbeln.
DATA:
likp TYPE likp,
lipss TYPE STANDARD TABLE OF lips,
vbpas TYPE STANDARD TABLE OF vbpa,
vekps TYPE STANDARD TABLE OF vekp,
org_unit_rule_bc TYPE REF TO /aeb/cl_pa_pb_dlv_ou_rule_bc,
org_unit TYPE string.
SELECT SINGLE * FROM likp INTO likp WHERE vbeln = vbeln.
SELECT * FROM lips INTO TABLE lipss WHERE vbeln = vbeln.
SELECT * FROM vbpa INTO TABLE vbpas WHERE vbeln = vbeln.
SELECT * FROM vekp INTO TABLE vekps WHERE vpobjkey = vbeln.
org_unit_rule_bc = /aeb/cl_pa_pb_dlv_ou_rule_bc=>new_for(
im_likp = likp
im_lipss = lipss ).
org_unit = org_unit_rule_bc->get_org_unit( ).
WRITE: 'OrgUnit: ' , org_unit.
WRITE /.
2. Connection parameters
The next step is to read the connection parameters linked to this organizational unit. The connection is used to call the endpoint (Carrier Cloud for SAP) accordingly.
REPORT zaeb_create_first_shipment.
PARAMETERS: vbeln TYPE likp-vbeln.
DATA:
likp TYPE likp,
lipss TYPE STANDARD TABLE OF lips,
vbpas TYPE STANDARD TABLE OF vbpa,
vekps TYPE STANDARD TABLE OF vekp,
org_unit_rule_bc TYPE REF TO /aeb/cl_pa_pb_dlv_ou_rule_bc,
org_unit TYPE /aeb/01_char20,
engn_prm_bc TYPE REF TO /aeb/cl_pa_pb_engn_prm_bc,
engn_prm_mo TYPE REF TO /aeb/if_pa_pb_engn_prm_mo.
SELECT SINGLE * FROM likp INTO likp WHERE vbeln = vbeln.
SELECT * FROM lips INTO TABLE lipss WHERE vbeln = vbeln.
SELECT * FROM vbpa INTO TABLE vbpas WHERE vbeln = vbeln.
SELECT * FROM vekp INTO TABLE vekps WHERE vpobjkey = vbeln AND xyz -> select the right HUs here using further criteria...
org_unit_rule_bc = /aeb/cl_pa_pb_dlv_ou_rule_bc=>new_for( im_likp = likp im_lipss = lipss ).
org_unit = org_unit_rule_bc->get_org_unit( ).
WRITE: 'OrgUnit: ' , org_unit.
WRITE /.
engn_prm_bc = /aeb/cl_pa_pb_engn_prm_bc=>get_instance( ).
engn_prm_mo = engn_prm_bc->get_engn_prm_do_for( org_unit ).
WRITE: 'Destination: ' , engn_prm_mo->get_destination( ).
WRITE: 'Engine client: ' , engn_prm_mo->get_engine_client( ).s
If you run the report again the destination and client for Carrier Cloud for SAP will be shown.
3. Collect data for a shipping order
Next, we need the data for the shipping order that we want to send to Carrier Cloud. Use the "collector"-class for the according business object (see table on top). It provides the data based on the standard logic and configuration of the AEB add-on.
REPORT zaeb_create_first_shipment.
PARAMETERS: vbeln TYPE likp-vbeln.
DATA:
likp TYPE likp,
lipss TYPE STANDARD TABLE OF lips,
vbpas TYPE STANDARD TABLE OF vbpa,
vekps TYPE STANDARD TABLE OF vekp,
org_unit_rule_bc TYPE REF TO /aeb/cl_pa_pb_dlv_ou_rule_bc,
org_unit TYPE /aeb/01_char20,
engn_prm_bc TYPE REF TO /aeb/cl_pa_pb_engn_prm_bc,
engn_prm_mo TYPE REF TO /aeb/if_pa_pb_engn_prm_mo,
collector_bc TYPE REF TO /aeb/cl_pa_pb_dlv_shp_coll_bc,
shipment TYPE /aeb/pa_pb_dl_shp_req_do.
SELECT SINGLE * FROM likp INTO likp WHERE vbeln = vbeln.
SELECT * FROM lips INTO TABLE lipss WHERE vbeln = vbeln.
SELECT * FROM vbpa INTO TABLE vbpas WHERE vbeln = vbeln.
SELECT * FROM vekp INTO TABLE vekps WHERE vpobjkey = vbeln AND xyz -> select the right HUs here using further criteria...
org_unit_rule_bc = /aeb/cl_pa_pb_dlv_ou_rule_bc=>new_for( im_likp = likp im_lipss = lipss ).
org_unit = org_unit_rule_bc->get_org_unit( ).
WRITE: 'OrgUnit: ' , org_unit.
WRITE /.
engn_prm_bc = /aeb/cl_pa_pb_engn_prm_bc=>get_instance( ).
engn_prm_mo = engn_prm_bc->get_engn_prm_do_for( org_unit ).
WRITE: 'Destination: ' , engn_prm_mo->get_destination( ).
WRITE /.
WRITE: 'Engine client: ' , engn_prm_mo->get_engine_client( ).
WRITE /.
collector_bc = /aeb/cl_pa_pb_dlv_shp_coll_bc=>new_for( im_likp = likp
im_lipss = lipss
im_vbpas = vbpas
im_vekps = vekps ).
shipment = collector_bc->create_shipment( org_unit ).
write shipment-referencenumber1.
WRITE /.
With this example you have collected the shipping data of the SAP delivery, e.g. the ship-to address and the carrier.
To change or add the collected data, you can implement the "AFTER_STD_FILLING"-method of the according BAdI: BAdIs to change data .
4. Determine the workstation
The workstation ID is mandatory for creating a shipping order and printing labels. Just add the following code lines to the program:
DATA: workstation_id TYPE string.
workstation_id = /aeb/cl_pa_pb_wsta_id_bc=>new( )->get_workstation_id( ).
write: workstation_id.
write /.
5. Create the first shipping order
With the first steps we have collected all required data. Now let's use it with the class /AEB/CL_PA_PB_CARRIER_BF. This will create your first shipping order in Carrier Connect.
Add the following code to your program:
DATA:
request TYPE REF TO /aeb/cl_pa_pb_cr_shp_req_do,
result_language_iso_codes TYPE /aeb/01_char2s,
result TYPE REF TO /aeb/cl_pa_pb_cr_shp_res_do,
exc TYPE REF TO /aeb/cx_01_pb_bf_inv_sc,
msg TYPE REF TO /aeb/cl_01_pb_res_msg_do,
text TYPE REF TO /aeb/cl_01_pb_til_do,
creation_parms TYPE REF TO /aeb/cl_pa_pb_cr_prm_do,
process_parms TYPE REF TO /aeb/cl_pa_pb_shp_prp_do,
output_mode TYPE REF TO /aeb/cl_pa_pb_doc_outm_do,
prepare_scope TYPE REF TO /aeb/cl_pa_pb_doc_scope_do,
process_mode TYPE /aeb/pa_pb_dl_pmode_do,
output_scope TYPE REF TO /aeb/cl_pa_pb_doc_scope_do,
carrier_bf TYPE REF TO /aeb/cl_pa_pb_carrier_bf.
CREATE OBJECT request.
request->set_client_identcode( engn_prm_mo->get_engine_client( ) ).
request->set_client_system_id( sy-sysid && '_' && sy-mandt ).
request->set_shipment( shipment ).
request->set_username( sy-uname ).
APPEND 'DE' TO result_language_iso_codes.
APPEND 'EN' TO result_language_iso_codes.
request->set_result_language_iso_codes( result_language_iso_codes ).
CREATE OBJECT creation_parms.
creation_parms->set_creation_mode( 'ALWAYS' ).
request->set_creation_parms( creation_parms ).
CREATE OBJECT process_parms.
process_parms->set_do_completion( 'X' ).
process_parms->set_workstation_id( workstation_id ).
CREATE OBJECT output_mode.
output_mode->set_mode( 'NONE' ).
process_parms->set_document_output_mode( output_mode ).
process_mode-mode = 'EXTENDED'.
process_parms->set_process_mode( process_mode ).
CREATE OBJECT prepare_scope.
prepare_scope->set_scope( 'ALL' ).
process_parms->set_document_prepare_scope( prepare_scope ).
CREATE OBJECT output_scope.
output_scope->set_scope( 'ALL' ).
process_parms->set_document_output_scope( output_scope ).
request->set_process_parms( process_parms ).
TRY.
carrier_bf = /aeb/cl_pa_pb_carrier_bf=>new_for( im_engn_prm = engn_prm_mo
im_org_unit = org_unit ).
result = carrier_bf->create_shipment( request ).
IF result->get_has_errors( ) = 'X'.
LOOP AT result->get_messages( ) INTO msg.
LOOP AT msg->get_message_texts( ) INTO text.
WRITE text->get_text( ).
WRITE /.
ENDLOOP.
ENDLOOP.
ELSE.
WRITE result->get_shipment_number( ).
ENDIF.
CATCH /aeb/cx_01_pb_bf_inv_sc INTO exc.
WRITE exc->/aeb/if_01_cx_message~get_msg_as_str( ).
ENDTRY.
Run the report. You should see the number of the created shipping order on the screen.
6. Further subsequent functionality
Based on an existing shipping order you can make use of further functionality:
Upddate shipping order (Process Shipment)
Read shipping order data (Get Shipments)
Updated 5 days ago