Difference between revisions of "SAP SD BAPI TRANSPORTE"

From SapWiki
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Ejemplo 1 ==
 
== Ejemplo 1 ==
  <nowiki> REPORT ztest_bapi_shipment_create2 .
+
  <nowiki>REPORT ztest_bapi_shipment_create2 .
***************************************************************
+
***************************************************************
* This report is provided to help understanding the interface *
+
* This report is provided to help understanding the interface *
* of function module 'BAPI_SHIPMENT_CREATE' with regard to    *
+
* of function module 'BAPI_SHIPMENT_CREATE' with regard to    *
* its ability to fill the different shipment-deadlines        *
+
* its ability to fill the different shipment-deadlines        *
* With running this report, new shipments are created        *
+
* With running this report, new shipments are created        *
* see note 531207
+
* see note 531207
***************************************************************
+
***************************************************************
  
* fill the interface for bapi
+
* fill the interface for bapi
DATA: headerdata LIKE bapishipmentheader,
+
DATA: headerdata LIKE bapishipmentheader,
        headerdeadline LIKE bapishipmentheaderdeadline
+
        headerdeadline LIKE bapishipmentheaderdeadline
                    OCCURS 0 WITH HEADER LINE,
+
                  OCCURS 0 WITH HEADER LINE,
        itemdata LIKE bapishipmentitem  OCCURS 0 WITH HEADER LINE,
+
        itemdata LIKE bapishipmentitem  OCCURS 0 WITH HEADER LINE,
        stagedata LIKE bapishipmentstage OCCURS 0 WITH HEADER LINE,
+
        stagedata LIKE bapishipmentstage OCCURS 0 WITH HEADER LINE,
        stagedeadline LIKE bapishipmentstagedeadline
+
        stagedeadline LIKE bapishipmentstagedeadline
                          OCCURS 0 WITH HEADER LINE,
 
        itemonstage LIKE bapishipmentitemonstage
 
 
                           OCCURS 0 WITH HEADER LINE,
 
                           OCCURS 0 WITH HEADER LINE,
        address LIKE bapishipmentaddress
+
        itemonstage LIKE bapishipmentitemonstage
                          OCCURS 0 WITH HEADER LINE,
+
                        OCCURS 0 WITH HEADER LINE,
        hdunheader LIKE bapishipmenthdunheader
+
        address LIKE bapishipmentaddress
                          OCCURS 0 WITH HEADER LINE,
+
                        OCCURS 0 WITH HEADER LINE,
        hdunitem LIKE bapishipmenthdunitem
+
        hdunheader LIKE bapishipmenthdunheader
                          OCCURS 0 WITH HEADER LINE,
+
                        OCCURS 0 WITH HEADER LINE,
        return LIKE bapiret2  OCCURS 0 WITH HEADER LINE.
+
        hdunitem LIKE bapishipmenthdunitem
 +
                        OCCURS 0 WITH HEADER LINE,
 +
        return LIKE bapiret2  OCCURS 0 WITH HEADER LINE.
  
  
SELECTION-SCREEN COMMENT /1(83) com1.
+
SELECTION-SCREEN COMMENT /1(83) com1.
SELECTION-SCREEN COMMENT /1(83) com2.
+
SELECTION-SCREEN COMMENT /1(83) com2.
SELECTION-SCREEN COMMENT /1(83) com3.
+
SELECTION-SCREEN COMMENT /1(83) com3.
SELECTION-SCREEN COMMENT /1(83) com4.
+
SELECTION-SCREEN COMMENT /1(83) com4.
SELECTION-SCREEN COMMENT /1(83) com5.
+
SELECTION-SCREEN COMMENT /1(83) com5.
SELECTION-SCREEN COMMENT /1(83) com6.
+
SELECTION-SCREEN COMMENT /1(83) com6.
SELECTION-SCREEN COMMENT /1(83) com7.
+
SELECTION-SCREEN COMMENT /1(83) com7.
SELECTION-SCREEN SKIP 1.
+
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN ULINE.
+
SELECTION-SCREEN ULINE.
  
  
SELECTION-SCREEN BEGIN OF BLOCK header WITH FRAME TITLE text-hrd.
+
SELECTION-SCREEN BEGIN OF BLOCK header WITH FRAME TITLE text-hrd.
* Headerdate - obligatory
+
* Headerdate - obligatory
SELECTION-SCREEN COMMENT /1(79) com8 FOR FIELD tplst.
+
SELECTION-SCREEN COMMENT /1(79) com8 FOR FIELD tplst.
PARAMETER: tplst LIKE vttk-tplst.
+
PARAMETER: tplst LIKE vttk-tplst.
SELECTION-SCREEN COMMENT /1(79) com9 FOR FIELD tplst.
+
SELECTION-SCREEN COMMENT /1(79) com9 FOR FIELD tplst.
PARAMETER: shtyp LIKE vttk-shtyp.
+
PARAMETER: shtyp LIKE vttk-shtyp.
SELECTION-SCREEN END OF BLOCK header.
+
SELECTION-SCREEN END OF BLOCK header.
  
SELECTION-SCREEN ULINE.
+
SELECTION-SCREEN ULINE.
  
SELECTION-SCREEN BEGIN OF BLOCK status WITH FRAME TITLE com10.
+
SELECTION-SCREEN BEGIN OF BLOCK status WITH FRAME TITLE com10.
* Plan
+
* Plan
PARAMETER:  plan LIKE  bapishipmentheader-status_plan.
+
PARAMETER:  plan LIKE  bapishipmentheader-status_plan.
*checkin
+
*checkin
PARAMETER:  check LIKE  bapishipmentheader-status_checkin.
+
PARAMETER:  check LIKE  bapishipmentheader-status_checkin.
*load start
+
*load start
PARAMETER:  load_s LIKE  bapishipmentheader-status_load_start.
+
PARAMETER:  load_s LIKE  bapishipmentheader-status_load_start.
*load end
+
*load end
PARAMETER:  load_e LIKE  bapishipmentheader-status_load_end.
+
PARAMETER:  load_e LIKE  bapishipmentheader-status_load_end.
*Completion
+
*Completion
PARAMETER:  compl LIKE  bapishipmentheader-status_compl.
+
PARAMETER:  compl LIKE  bapishipmentheader-status_compl.
* tra begin
+
* tra begin
PARAMETER:  ship_s LIKE  bapishipmentheader-status_shpmnt_start.
+
PARAMETER:  ship_s LIKE  bapishipmentheader-status_shpmnt_start.
* tra end
+
* tra end
PARAMETER:  ship_e LIKE  bapishipmentheader-status_shpmnt_end.
+
PARAMETER:  ship_e LIKE  bapishipmentheader-status_shpmnt_end.
SELECTION-SCREEN END OF BLOCK status.
+
SELECTION-SCREEN END OF BLOCK status.
  
* Headerdeadline
+
* Headerdeadline
SELECTION-SCREEN BEGIN OF BLOCK h_deadline WITH FRAME TITLE com11.
+
SELECTION-SCREEN BEGIN OF BLOCK h_deadline WITH FRAME TITLE com11.
PARAMETERS: ttype(10)
+
PARAMETERS: ttype(10)
            DEFAULT 'HDRSTPLDT', "= End of planning
+
          DEFAULT 'HDRSTPLDT', "= End of planning
            utc LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone LIKE bapishipmentheaderdeadline-time_zone.
+
          zone LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype2(10)
+
PARAMETERS: ttype2(10)
            DEFAULT 'HDRSTCIPDT',"= planned date of check-in
+
          DEFAULT 'HDRSTCIPDT',"= planned date of check-in
            utc2 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc2 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone2 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone2 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype3(10)
+
PARAMETERS: ttype3(10)
            DEFAULT 'HDRSTCIADT',"= actual date of check-in
+
          DEFAULT 'HDRSTCIADT',"= actual date of check-in
            utc3 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc3 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone3 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone3 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype4(10)
+
PARAMETERS: ttype4(10)
            DEFAULT 'HDRSTLSPDT',"= planned date f. start loading
+
          DEFAULT 'HDRSTLSPDT',"= planned date f. start loading
            utc4 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc4 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone4 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone4 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype5(10)
+
PARAMETERS: ttype5(10)
            DEFAULT 'HDRSTLSADT',"= current date f. start loading
+
          DEFAULT 'HDRSTLSADT',"= current date f. start loading
            utc5 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc5 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone5 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone5 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype6(10)
+
PARAMETERS: ttype6(10)
            DEFAULT 'HDRSTLEPDT',"= planned date f. end loading
+
          DEFAULT 'HDRSTLEPDT',"= planned date f. end loading
            utc6 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc6 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone6 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone6 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype7(10)
+
PARAMETERS: ttype7(10)
            DEFAULT 'HDRSTLEADT',"= actual date f. end loading
+
          DEFAULT 'HDRSTLEADT',"= actual date f. end loading
            utc7 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc7 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone7 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone7 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype8(10)
+
PARAMETERS: ttype8(10)
            DEFAULT 'HDRSTCPDT',"= planned date f. shpmnt completion
+
          DEFAULT 'HDRSTCPDT',"= planned date f. shpmnt completion
            utc8 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc8 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone8 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone8 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype9(10)
+
PARAMETERS: ttype9(10)
            DEFAULT 'HDRSTCADT',"= actual date f. shpmnt completion
+
          DEFAULT 'HDRSTCADT',"= actual date f. shpmnt completion
            utc9 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc9 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone9 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone9 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype10(10)
+
PARAMETERS: ttype10(10)
            DEFAULT 'HDRSTSSPDT',"= planned date f. start shpmnt
+
          DEFAULT 'HDRSTSSPDT',"= planned date f. start shpmnt
            utc10 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc10 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone10 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone10 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype11(10)
+
PARAMETERS: ttype11(10)
            DEFAULT 'HDRSTSSADT',"= actual date f. start shpmnt
+
          DEFAULT 'HDRSTSSADT',"= actual date f. start shpmnt
            utc11 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc11 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone11 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone11 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype12(10)
+
PARAMETERS: ttype12(10)
            DEFAULT 'HDRSTSEPDT',"= planned date f. end shpmnt
+
          DEFAULT 'HDRSTSEPDT',"= planned date f. end shpmnt
            utc12 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc12 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone12 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone12 LIKE bapishipmentheaderdeadline-time_zone.
  
PARAMETERS: ttype13(10)
+
PARAMETERS: ttype13(10)
            DEFAULT 'HDRSTSEADT',"= actual date f. end shpmnt
+
          DEFAULT 'HDRSTSEADT',"= actual date f. end shpmnt
            utc13 LIKE bapishipmentheaderdeadline-time_stamp_utc,
+
          utc13 LIKE bapishipmentheaderdeadline-time_stamp_utc,
            zone13 LIKE bapishipmentheaderdeadline-time_zone.
+
          zone13 LIKE bapishipmentheaderdeadline-time_zone.
  
SELECTION-SCREEN END OF BLOCK h_deadline.
+
SELECTION-SCREEN END OF BLOCK h_deadline.
  
***********************************************************************
+
***********************************************************************
* Format the select-options                                          *
+
* Format the select-options                                          *
***********************************************************************
+
***********************************************************************
INITIALIZATION.
+
INITIALIZATION.
  com1 = 'This report was provided to help understanding the behaviour'.
+
com1 = 'This report was provided to help understanding the behaviour'.
  com2 = 'of function module BAPI_SHIPMENT_CREATE with regard to its '.
+
com2 = 'of function module BAPI_SHIPMENT_CREATE with regard to its '.
  com3 = 'ability to fill the new shipments deadlines: '.
+
com3 = 'ability to fill the new shipments deadlines: '.
  com4 = 'Planning, Check-In, Loading Start, Loading end, '.
+
com4 = 'Planning, Check-In, Loading Start, Loading end, '.
  com5 = 'Shpmnt completion, Shipment start and shipment end.'.
+
com5 = 'Shpmnt completion, Shipment start and shipment end.'.
  com6 = 'This report creates new shipments which can be '.
+
com6 = 'This report creates new shipments which can be '.
  com7 = 'viewed e.g. with transaction VT03n'.
+
com7 = 'viewed e.g. with transaction VT03n'.
  com8 = 'Transportation Planning Point (obligatory)'.
+
com8 = 'Transportation Planning Point (obligatory)'.
  com9 = 'Shipment type (obligatory)'.
+
com9 = 'Shipment type (obligatory)'.
  com10 = 'BAPISHIPMENTHEADER-Flags --> see note 531207 '.
+
com10 = 'BAPISHIPMENTHEADER-Flags --> see note 531207 '.
  com11 = 'HEADERDEADLINE-Structure --> see note 531207 '.
+
com11 = 'HEADERDEADLINE-Structure --> see note 531207 '.
***********************************************************************
+
***********************************************************************
  
  
START-OF-SELECTION.
+
START-OF-SELECTION.
******************head begin***********************************
+
******************head begin***********************************
  headerdata-trans_plan_pt = tplst.
+
headerdata-trans_plan_pt = tplst.
  headerdata-shipment_type = shtyp.
+
headerdata-shipment_type = shtyp.
  
* change Plan status
+
* change Plan status
*  HEADERDATA-SHIPMENT_NUM = tknum.
+
*  HEADERDATA-SHIPMENT_NUM = tknum.
  IF plan <> space.
+
IF plan <> space.
    headerdata-status_plan = plan.
+
  headerdata-status_plan = plan.
  ENDIF.
+
ENDIF.
* Change Check_in status
+
* Change Check_in status
  IF check <> space.
+
IF check <> space.
    headerdata-status_checkin = check.
+
  headerdata-status_checkin = check.
  ENDIF.
+
ENDIF.
*load beginn
+
*load beginn
  IF load_s <> space .
+
IF load_s <> space .
    headerdata-status_load_start = load_s.
+
  headerdata-status_load_start = load_s.
  ENDIF.
+
ENDIF.
* load end
+
* load end
  IF load_e <> space .
+
IF load_e <> space .
    headerdata-status_load_end = load_e.
+
  headerdata-status_load_end = load_e.
  ENDIF.
+
ENDIF.
* completion
+
* completion
  IF compl <> space.
+
IF compl <> space.
    headerdata-status_compl = compl.
+
  headerdata-status_compl = compl.
  ENDIF.
+
ENDIF.
*tra beginn
+
*tra beginn
  IF ship_s <> space.
+
IF ship_s <> space.
    headerdata-status_shpmnt_start = ship_s.
+
  headerdata-status_shpmnt_start = ship_s.
  ENDIF.
+
ENDIF.
*tra beginn
+
*tra beginn
  IF ship_e <> space.
+
IF ship_e <> space.
    headerdata-status_shpmnt_end = ship_e.
+
  headerdata-status_shpmnt_end = ship_e.
  ENDIF.
+
ENDIF.
  
***** HEADERDEADLINE END OF PLANNING
+
***** HEADERDEADLINE END OF PLANNING
  IF ttype <> space.
+
IF ttype <> space.
    headerdeadline-time_type = ttype.
+
  headerdeadline-time_type = ttype.
    headerdeadline-time_stamp_utc = utc.
+
  headerdeadline-time_stamp_utc = utc.
    headerdeadline-time_zone = zone.
+
  headerdeadline-time_zone = zone.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE PLANNED DATE OF CHECK-IN
+
***** HEADERDEADLINE PLANNED DATE OF CHECK-IN
  IF ttype2 <> space.
+
IF ttype2 <> space.
    headerdeadline-time_type = ttype2.
+
  headerdeadline-time_type = ttype2.
    headerdeadline-time_stamp_utc = utc2.
+
  headerdeadline-time_stamp_utc = utc2.
    headerdeadline-time_zone = zone2.
+
  headerdeadline-time_zone = zone2.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE ACTUAL DATE OF CHECK-IN
+
***** HEADERDEADLINE ACTUAL DATE OF CHECK-IN
  IF ttype3 <> space.
+
IF ttype3 <> space.
    headerdeadline-time_type = ttype3.
+
  headerdeadline-time_type = ttype3.
    headerdeadline-time_stamp_utc = utc3.
+
  headerdeadline-time_stamp_utc = utc3.
    headerdeadline-time_zone = zone3.
+
  headerdeadline-time_zone = zone3.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE PLANNED D START OF LOADING
+
***** HEADERDEADLINE PLANNED D START OF LOADING
  IF ttype4 <> space.
+
IF ttype4 <> space.
    headerdeadline-time_type = ttype4.
+
  headerdeadline-time_type = ttype4.
    headerdeadline-time_stamp_utc = utc4.
+
  headerdeadline-time_stamp_utc = utc4.
    headerdeadline-time_zone = zone4.
+
  headerdeadline-time_zone = zone4.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE CURRENT D START OF LOADING
+
***** HEADERDEADLINE CURRENT D START OF LOADING
  IF ttype5 <> space.
+
IF ttype5 <> space.
    headerdeadline-time_type = ttype5.
+
  headerdeadline-time_type = ttype5.
    headerdeadline-time_stamp_utc = utc5.
+
  headerdeadline-time_stamp_utc = utc5.
    headerdeadline-time_zone = zone5.
+
  headerdeadline-time_zone = zone5.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE PLANNED D END OF LOADING
+
***** HEADERDEADLINE PLANNED D END OF LOADING
  IF ttype6 <> space.
+
IF ttype6 <> space.
    headerdeadline-time_type = ttype6.
+
  headerdeadline-time_type = ttype6.
    headerdeadline-time_stamp_utc = utc6.
+
  headerdeadline-time_stamp_utc = utc6.
    headerdeadline-time_zone = zone6.
+
  headerdeadline-time_zone = zone6.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE ACTUAL D END OF LOADING
+
***** HEADERDEADLINE ACTUAL D END OF LOADING
  IF ttype7 <> space.
+
IF ttype7 <> space.
    headerdeadline-time_type = ttype7.
+
  headerdeadline-time_type = ttype7.
    headerdeadline-time_stamp_utc = utc7.
+
  headerdeadline-time_stamp_utc = utc7.
    headerdeadline-time_zone = zone7.
+
  headerdeadline-time_zone = zone7.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE PLANNED D SHIPMENT COMPLETION
+
***** HEADERDEADLINE PLANNED D SHIPMENT COMPLETION
  IF ttype8 <> space.
+
IF ttype8 <> space.
    headerdeadline-time_type = ttype8.
+
  headerdeadline-time_type = ttype8.
    headerdeadline-time_stamp_utc = utc8.
+
  headerdeadline-time_stamp_utc = utc8.
    headerdeadline-time_zone = zone8.
+
  headerdeadline-time_zone = zone8.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE ACTUAL D SHIPMENT COMPLETION
+
***** HEADERDEADLINE ACTUAL D SHIPMENT COMPLETION
  IF ttype9 <> space.
+
IF ttype9 <> space.
    headerdeadline-time_type = ttype9.
+
  headerdeadline-time_type = ttype9.
    headerdeadline-time_stamp_utc = utc9.
+
  headerdeadline-time_stamp_utc = utc9.
    headerdeadline-time_zone = zone9.
+
  headerdeadline-time_zone = zone9.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE PLANNED D START OF SHIPMENT
+
***** HEADERDEADLINE PLANNED D START OF SHIPMENT
  IF ttype10 <> space.
+
IF ttype10 <> space.
    headerdeadline-time_type = ttype10.
+
  headerdeadline-time_type = ttype10.
    headerdeadline-time_stamp_utc = utc10.
+
  headerdeadline-time_stamp_utc = utc10.
    headerdeadline-time_zone = zone10.
+
  headerdeadline-time_zone = zone10.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE ACTUAL D START OF SHIPMENT
+
***** HEADERDEADLINE ACTUAL D START OF SHIPMENT
  IF ttype11 <> space.
+
IF ttype11 <> space.
    headerdeadline-time_type = ttype11.
+
  headerdeadline-time_type = ttype11.
    headerdeadline-time_stamp_utc = utc11.
+
  headerdeadline-time_stamp_utc = utc11.
    headerdeadline-time_zone = zone11.
+
  headerdeadline-time_zone = zone11.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE PLANNED D END OF SHIPMENT
+
***** HEADERDEADLINE PLANNED D END OF SHIPMENT
  IF ttype12 <> space.
+
IF ttype12 <> space.
    headerdeadline-time_type = ttype12.
+
  headerdeadline-time_type = ttype12.
    headerdeadline-time_stamp_utc = utc12.
+
  headerdeadline-time_stamp_utc = utc12.
    headerdeadline-time_zone = zone12.
+
  headerdeadline-time_zone = zone12.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
***** HEADERDEADLINE CURRENT D END OF SHIPMENT
+
***** HEADERDEADLINE CURRENT D END OF SHIPMENT
  IF ttype13 <> space.
+
IF ttype13 <> space.
    headerdeadline-time_type = ttype13.
+
  headerdeadline-time_type = ttype13.
    headerdeadline-time_stamp_utc = utc13.
+
  headerdeadline-time_stamp_utc = utc13.
    headerdeadline-time_zone = zone13.
+
  headerdeadline-time_zone = zone13.
    APPEND headerdeadline.
+
  APPEND headerdeadline.
  ENDIF.
+
ENDIF.
  
************************************************************
+
************************************************************
************************************************************
+
************************************************************
  CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
+
CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
      EXPORTING
+
      EXPORTING
            headerdata    = headerdata
+
          headerdata    = headerdata
      TABLES
+
      TABLES
            headerdeadline = headerdeadline
+
          headerdeadline = headerdeadline
            itemdata      = itemdata
+
          itemdata      = itemdata
            stagedata      = stagedata
+
          stagedata      = stagedata
            stagedeadline  = stagedeadline
+
          stagedeadline  = stagedeadline
            itemonstage    = itemonstage
+
          itemonstage    = itemonstage
            address        = address
+
          address        = address
            hdunheader    = hdunheader
+
          hdunheader    = hdunheader
            hdunitem      = hdunitem
+
          hdunitem      = hdunitem
            return        = return.
+
          return        = return.
  
  LOOP AT return.
+
LOOP AT return.
  
    WRITE: return.
+
  WRITE: return.
  
  ENDLOOP.
+
ENDLOOP.
  
*Colocar commit work para grabar</nowiki>
+
*Colocar commit work para grabar</nowiki>
  
 
== Ejemplo 2 ==
 
== Ejemplo 2 ==
  <nowiki> FORM CREAR_TRANSPORTE  CHANGING o_TKNUM type TKNUM
+
  <nowiki>FORM CREAR_TRANSPORTE  CHANGING o_TKNUM type TKNUM
                                o_SUBRC.
+
                              o_SUBRC.
  data: lt_return type TABLE OF bapiret2,
+
data: lt_return type TABLE OF bapiret2,
      ls_return like LINE OF lt_return.
+
    ls_return like LINE OF lt_return.
  
  data: ls_headerdata LIKE  BAPISHIPMENTHEADER,
+
data: ls_headerdata LIKE  BAPISHIPMENTHEADER,
        ls_itemdata type BAPISHIPMENTITEM,
+
      ls_itemdata type BAPISHIPMENTITEM,
        lt_itemdata type TABLE OF BAPISHIPMENTITEM,
+
      lt_itemdata type TABLE OF BAPISHIPMENTITEM,
        ls_HEADERDEADLINE  type BAPISHIPMENTHEADERDEADLINE,
+
      ls_HEADERDEADLINE  type BAPISHIPMENTHEADERDEADLINE,
        lt_HEADERDEADLINE  type table of BAPISHIPMENTHEADERDEADLINE.
+
      lt_HEADERDEADLINE  type table of BAPISHIPMENTHEADERDEADLINE.
  
  ls_headerdata-SHIPMENT_TYPE = 'ZDT'.
+
ls_headerdata-SHIPMENT_TYPE = 'ZDT'.
  ls_headerdata-TRANS_PLAN_PT = vttk-tplst.
+
ls_headerdata-TRANS_PLAN_PT = vttk-tplst.
  ls_headerdata-SHIPPING_COND = vttk-vsbed.
+
ls_headerdata-SHIPPING_COND = vttk-vsbed.
  ls_headerdata-SHIPMENT_ROUTE = vttk-route.
+
ls_headerdata-SHIPMENT_ROUTE = vttk-route.
  ls_headerdata-SERVICE_AGENT_ID = vttk-tdlnr.
+
ls_headerdata-SERVICE_AGENT_ID = vttk-tdlnr.
  ls_headerdata-CONTAINER_ID = vttk-signi.
+
ls_headerdata-CONTAINER_ID = vttk-signi.
  ls_headerdata-EXTERNAL_ID_1 = vttk-exti1.
+
ls_headerdata-EXTERNAL_ID_1 = vttk-exti1.
  ls_headerdata-status_plan = 'X'.
+
ls_headerdata-status_plan = 'X'.
  
  loop at gt_likp into gs_likp where vbeln is NOT INITIAL.
+
loop at gt_likp into gs_likp where vbeln is NOT INITIAL.
    ls_itemdata-DELIVERY = gs_likp-vbeln.
+
  ls_itemdata-DELIVERY = gs_likp-vbeln.
  
    append ls_itemdata to lt_itemdata.
+
  append ls_itemdata to lt_itemdata.
  endloop.
+
endloop.
  
  data ld_time(14) type c.
+
data ld_time(14) type c.
  
  CONCATENATE sy-datum sy-timlo into ld_time.
+
CONCATENATE sy-datum sy-timlo into ld_time.
  
  ls_HEADERDEADLINE-TIME_TYPE = 'HDRSTPLDT'. "WSHDRTDDAT
+
ls_HEADERDEADLINE-TIME_TYPE = 'HDRSTPLDT'. "WSHDRTDDAT
  move ld_time to ls_HEADERDEADLINE-TIME_STAMP_UTC.
+
move ld_time to ls_HEADERDEADLINE-TIME_STAMP_UTC.
  ls_HEADERDEADLINE-time_zone = 'CHILE'.
+
ls_HEADERDEADLINE-time_zone = 'CHILE'.
  
  append ls_HEADERDEADLINE to lt_HEADERDEADLINE.
+
append ls_HEADERDEADLINE to lt_HEADERDEADLINE.
*
+
*
  CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
+
CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
    EXPORTING
+
  EXPORTING
      HEADERDATA          = ls_headerdata
+
    HEADERDATA          = ls_headerdata
  IMPORTING
+
  IMPORTING
    TRANSPORT            = o_TKNUM
+
    TRANSPORT            = o_TKNUM
*    SHIPMENTGUID        =
+
*    SHIPMENTGUID        =
    TABLES
+
  TABLES
    HEADERDEADLINE      = lt_HEADERDEADLINE
+
    HEADERDEADLINE      = lt_HEADERDEADLINE
    ITEMDATA            = lt_itemdata
+
    ITEMDATA            = lt_itemdata
      RETURN              = lt_return
+
    RETURN              = lt_return
            .
+
          .
  if o_TKNUM is INITIAL.
+
if o_TKNUM is INITIAL.
* transporte no creado
+
* transporte no creado
    o_subrc = 1.
+
  o_subrc = 1.
    loop at lt_return into ls_return WHERE type = 'E'.
+
  loop at lt_return into ls_return WHERE type = 'E'.
      exit.
+
    exit.
    endloop.
+
  endloop.
    if sy-subrc = 0.
+
  if sy-subrc = 0.
      MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
+
    MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
                    WITH ls_return-MESSAGE_V1
+
                    WITH ls_return-MESSAGE_V1
                          ls_return-MESSAGE_V2
+
                        ls_return-MESSAGE_V2
                          ls_return-MESSAGE_V3
+
                        ls_return-MESSAGE_V3
                          ls_return-MESSAGE_V4.
+
                        ls_return-MESSAGE_V4.
    endif.
+
  endif.
  else.
+
else.
    o_subrc = 0.
+
  o_subrc = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
+
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
+
    EXPORTING
        WAIT  = 'X'
+
      WAIT  = 'X'
      IMPORTING
+
    IMPORTING
        RETURN = ls_return.
+
      RETURN = ls_return.
  
* GRABA TEXTOS
+
* GRABA TEXTOS
    if ls_return is INITIAL.
+
  if ls_return is INITIAL.
      PERform get_texts_from_screen_and_save using o_TKNUM .
+
    PERform get_texts_from_screen_and_save using o_TKNUM .
    else.
+
  else.
      MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
+
    MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
                    WITH ls_return-MESSAGE_V1
+
                    WITH ls_return-MESSAGE_V1
                          ls_return-MESSAGE_V2
+
                        ls_return-MESSAGE_V2
                          ls_return-MESSAGE_V3
+
                        ls_return-MESSAGE_V3
                          ls_return-MESSAGE_V4.
+
                        ls_return-MESSAGE_V4.
    endif.
+
  endif.
  
    message s006(VW) with o_TKNUM.
+
  message s006(VW) with o_TKNUM.
  ENDIF.
+
ENDIF.
  
ENDFORM.                    " CREAR_TRANSPORTE</nowiki>
+
ENDFORM.                    " CREAR_TRANSPORTE</nowiki>
  
== EJEMPLO 3 con embalaje ==
+
== Ejemplo 3 con embalaje ==
  <nowiki> FORM CREAR_TRANSPORTE using i_unidad
+
  <nowiki>FORM CREAR_TRANSPORTE using i_unidad
                      CHANGING o_TKNUM type TKNUM
+
                      CHANGING o_TKNUM type TKNUM
                                o_SUBRC.
+
                              o_SUBRC.
  
  data: lt_return type TABLE OF bapiret2,
+
data: lt_return type TABLE OF bapiret2,
      ls_return like LINE OF lt_return.
+
    ls_return like LINE OF lt_return.
  
  data: ls_headerdata LIKE  BAPISHIPMENTHEADER,
+
data: ls_headerdata LIKE  BAPISHIPMENTHEADER,
        ls_itemdata type BAPISHIPMENTITEM,
+
      ls_itemdata type BAPISHIPMENTITEM,
        lt_itemdata type TABLE OF BAPISHIPMENTITEM,
+
      lt_itemdata type TABLE OF BAPISHIPMENTITEM,
        ls_HEADERDEADLINE  type BAPISHIPMENTHEADERDEADLINE,
+
      ls_HEADERDEADLINE  type BAPISHIPMENTHEADERDEADLINE,
        lt_HEADERDEADLINE  type table of BAPISHIPMENTHEADERDEADLINE.
+
      lt_HEADERDEADLINE  type table of BAPISHIPMENTHEADERDEADLINE.
  
  data: ls_HDUNHEADER LIKE BAPISHIPMENTHDUNHEADER,
+
data: ls_HDUNHEADER LIKE BAPISHIPMENTHDUNHEADER,
        lt_HDUNHEADER like TABLE OF ls_HDUNHEADER,
+
      lt_HDUNHEADER like TABLE OF ls_HDUNHEADER,
        ls_HDUNITEM LIKE BAPISHIPMENTHDUNITEM,
+
      ls_HDUNITEM LIKE BAPISHIPMENTHDUNITEM,
        lt_HDUNITEM like TABLE OF ls_HDUNITEM.
+
      lt_HDUNITEM like TABLE OF ls_HDUNITEM.
  
  ls_headerdata-SHIPMENT_TYPE = gd_SHTYP.
+
ls_headerdata-SHIPMENT_TYPE = gd_SHTYP.
  ls_headerdata-TRANS_PLAN_PT = vttk-tplst.
+
ls_headerdata-TRANS_PLAN_PT = vttk-tplst.
  ls_headerdata-SHIPPING_COND = vttk-vsbed.
+
ls_headerdata-SHIPPING_COND = vttk-vsbed.
  ls_headerdata-SHIPMENT_ROUTE = vttk-route.
+
ls_headerdata-SHIPMENT_ROUTE = vttk-route.
  ls_headerdata-SERVICE_AGENT_ID = vttk-tdlnr.
+
ls_headerdata-SERVICE_AGENT_ID = vttk-tdlnr.
  ls_headerdata-CONTAINER_ID = vttk-signi.
+
ls_headerdata-CONTAINER_ID = vttk-signi.
  ls_headerdata-EXTERNAL_ID_1 = vttk-exti1.
+
ls_headerdata-EXTERNAL_ID_1 = vttk-exti1.
  move LIKP-ANZPK to ls_headerdata-TEXT_1.
+
move LIKP-ANZPK to ls_headerdata-TEXT_1.
  ls_headerdata-status_plan = 'X'.
+
ls_headerdata-status_plan = 'X'.
  
    loop at gt_likp into gs_likp where vbeln is NOT INITIAL
+
  loop at gt_likp into gs_likp where vbeln is NOT INITIAL
                              .
+
                            .
      ls_itemdata-DELIVERY = gs_likp-vbeln.
+
    ls_itemdata-DELIVERY = gs_likp-vbeln.
  
      append ls_itemdata to lt_itemdata.
+
    append ls_itemdata to lt_itemdata.
    endloop.
+
  endloop.
  
  data ld_time(14) type c.
+
data ld_time(14) type c.
  
  CONCATENATE vttk-dtdis vttk-uzdis into ld_time.
+
CONCATENATE vttk-dtdis vttk-uzdis into ld_time.
  
  ls_HEADERDEADLINE-TIME_TYPE = 'HDRSTPLDT'. "WSHDRTDDAT
+
ls_HEADERDEADLINE-TIME_TYPE = 'HDRSTPLDT'. "WSHDRTDDAT
  move ld_time to ls_HEADERDEADLINE-TIME_STAMP_UTC.
+
move ld_time to ls_HEADERDEADLINE-TIME_STAMP_UTC.
  ls_HEADERDEADLINE-time_zone = 'CHILE'.
+
ls_HEADERDEADLINE-time_zone = 'CHILE'.
  
  append ls_HEADERDEADLINE to lt_HEADERDEADLINE.
+
append ls_HEADERDEADLINE to lt_HEADERDEADLINE.
  
  if i_unidad ne space.
+
  if i_unidad ne space.
    loop at gt_likp into gs_likp where vbeln is NOT INITIAL
+
    loop at gt_likp into gs_likp where vbeln is NOT INITIAL
                                      and sel = 'X'.
+
                                    and sel = 'X'.
      clear ls_HDUNITEM.
+
      clear ls_HDUNITEM.
      select  vbeln posnr matnr lfimg
+
      select  vbeln posnr matnr lfimg
        into
+
      into
  
        (ls_HDUNITEM-DELIV_NUMB,ls_HDUNITEM-DELIV_ITEM,ls_HDUNITEM-material,ls_HDUNITEM-PACK_QTY)
+
        (ls_HDUNITEM-DELIV_NUMB,ls_HDUNITEM-DELIV_ITEM,ls_HDUNITEM-material,ls_HDUNITEM-PACK_QTY)
                    from lips
+
                    from lips
                      where vbeln = gs_likp-vbeln.
+
                    where vbeln = gs_likp-vbeln.
        ls_HDUNITEM-HDL_UNIT_EXID_INTO = '$0001'.
+
        ls_HDUNITEM-HDL_UNIT_EXID_INTO = '$0001'.
        append  ls_HDUNITEM to lt_HDUNITEM.
+
        append  ls_HDUNITEM to lt_HDUNITEM.
      endselect.
+
      endselect.
    endloop.
 
    if sy-subrc = 0.
 
      ls_HDUNHEADER-SHIP_MAT = i_unidad.
 
      ls_HDUNHEADER-HDL_UNIT_EXID = '$0001'.
 
      append ls_HDUNHEADER to lt_HDUNHEADER.
 
    else.
 
      message E490(VW) WITH 'No se ha seleccionado ninguna Entrega'.
 
    endif.
 
 
 
  else.
 
    clear:  lt_HDUNHEADER[],
 
          lt_HDUNITEM[].
 
  endif.
 
*
 
  CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
 
    EXPORTING
 
      HEADERDATA          = ls_headerdata
 
  IMPORTING
 
    TRANSPORT            = o_TKNUM
 
    TABLES
 
    HEADERDEADLINE      = lt_HEADERDEADLINE
 
    ITEMDATA            = lt_itemdata
 
    HDUNHEADER          = lt_HDUNHEADER
 
    HDUNITEM            = lt_HDUNITEM
 
      RETURN              = lt_return
 
            .
 
  if o_TKNUM is INITIAL.
 
* transporte no creado
 
    o_subrc = 1.
 
    loop at lt_return into ls_return WHERE type = 'E'.
 
      exit.
 
 
     endloop.
 
     endloop.
 
     if sy-subrc = 0.
 
     if sy-subrc = 0.
       MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
+
       ls_HDUNHEADER-SHIP_MAT = i_unidad.
                    WITH ls_return-MESSAGE_V1
+
      ls_HDUNHEADER-HDL_UNIT_EXID = '$0001'.
                          ls_return-MESSAGE_V2
+
      append ls_HDUNHEADER to lt_HDUNHEADER.
                          ls_return-MESSAGE_V3
+
    else.
                          ls_return-MESSAGE_V4.
+
      message E490(VW) WITH 'No se ha seleccionado ninguna Entrega'.
 +
    endif.
  
 +
else.
 +
  clear:  lt_HDUNHEADER[],
 +
          lt_HDUNITEM[].
 +
endif.
 +
*
 +
CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
 +
  EXPORTING
 +
    HEADERDATA          = ls_headerdata
 +
  IMPORTING
 +
    TRANSPORT            = o_TKNUM
 +
  TABLES
 +
    HEADERDEADLINE      = lt_HEADERDEADLINE
 +
    ITEMDATA            = lt_itemdata
 +
    HDUNHEADER          = lt_HDUNHEADER
 +
    HDUNITEM            = lt_HDUNITEM
 +
    RETURN              = lt_return
 +
          .
 +
if o_TKNUM is INITIAL.
 +
* transporte no creado
 +
  o_subrc = 1.
 +
  loop at lt_return into ls_return WHERE type = 'E'.
 +
    exit.
 +
  endloop.
 +
  if sy-subrc = 0.
 +
    MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
 +
                    WITH ls_return-MESSAGE_V1
 +
                        ls_return-MESSAGE_V2
 +
                        ls_return-MESSAGE_V3
 +
                        ls_return-MESSAGE_V4.
  
    endif.
 
  else.
 
    o_subrc = 0.
 
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 
      EXPORTING
 
        WAIT  = 'X'
 
      IMPORTING
 
        RETURN = ls_return.
 
  
  * GRABA TEXTOS
+
  endif.
    if ls_return is INITIAL.
+
  else.
      PERform get_texts_from_screen_and_save using o_TKNUM .
+
  o_subrc = 0.
    else.
+
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
+
    EXPORTING
                    WITH ls_return-MESSAGE_V1
+
      WAIT  = 'X'
                          ls_return-MESSAGE_V2
+
    IMPORTING
                          ls_return-MESSAGE_V3
+
      RETURN = ls_return.
                          ls_return-MESSAGE_V4.
+
 
    endif.
+
* GRABA TEXTOS
 +
  if ls_return is INITIAL.
 +
    PERform get_texts_from_screen_and_save using o_TKNUM .
 +
  else.
 +
    MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
 +
                    WITH ls_return-MESSAGE_V1
 +
                        ls_return-MESSAGE_V2
 +
                        ls_return-MESSAGE_V3
 +
                        ls_return-MESSAGE_V4.
 +
  endif.
  
    message s006(VW) with o_TKNUM.
+
  message s006(VW) with o_TKNUM.
  ENDIF.
+
ENDIF.
  
ENDFORM.                    " CREAR_TRANSPORTE</nowiki>
+
ENDFORM.                    " CREAR_TRANSPORTE</nowiki>
  
 
== Modificar Transporte ==
 
== Modificar Transporte ==
 
*Modificar estado transporte
 
*Modificar estado transporte
 +
<nowiki>DATA: l_it_header        TYPE bapishipmentheader,
 +
      l_it_headeraction  TYPE  bapishipmentheaderaction,
 +
      l_it_return        TYPE TABLE OF bapiret2.
 +
DATA: l_wa_return TYPE bapiret2.
  
  <nowiki>DATA: l_it_header       TYPE bapishipmentheader,
+
l_it_header-shipment_num  = shipment.
        l_it_headeraction  TYPE  bapishipmentheaderaction,
+
l_it_headeraction-shipment_num = 'X'.
        l_it_return        TYPE TABLE OF bapiret2.
 
  DATA: l_wa_return TYPE bapiret2.
 
  
  l_it_header-shipment_num  = shipment.
+
l_it_header-status_shpmnt_start      = 'X'.
  l_it_headeraction-shipment_num  = 'X'.
+
l_it_headeraction-status_shpmnt_start = 'C'.
  
  l_it_header-status_shpmnt_start      = 'X'.
+
CALL FUNCTION 'BAPI_SHIPMENT_CHANGE'
  l_it_headeraction-status_shpmnt_start = 'C'.
+
  EXPORTING
 
+
    headerdata      = l_it_header
  CALL FUNCTION 'BAPI_SHIPMENT_CHANGE'
+
    headerdataaction = l_it_headeraction
    EXPORTING
+
  TABLES
      headerdata      = l_it_header
+
    return          = l_it_return.</nowiki>
      headerdataaction = l_it_headeraction
 
    TABLES
 
      return          = l_it_return.</nowiki>
 
  
 
== bloquear patente ( VTTK-SIGNI ) ==
 
== bloquear patente ( VTTK-SIGNI ) ==
  <nowiki> FORM BLOQUEAR_PATENTE .
+
  <nowiki>FORM BLOQUEAR_PATENTE .
  
  data : lt_SYSTEM_STATUS type TABLE OF BAPI_ITOB_STATUS WITH HEADER LINE,
+
data : lt_SYSTEM_STATUS type TABLE OF BAPI_ITOB_STATUS WITH HEADER LINE,
        lt_USER_STATUS type TABLE OF BAPI_ITOB_STATUS WITH HEADER LINE.
+
        lt_USER_STATUS type TABLE OF BAPI_ITOB_STATUS WITH HEADER LINE.
  data wa_return type bapiret2.
+
data wa_return type bapiret2.
  data: l_equi type EQUNR,
+
data: l_equi type EQUNR,
        l_objnr type JSTO-OBJNR,
+
      l_objnr type JSTO-OBJNR,
        l_stat_e LIKE jest-stat.
+
      l_stat_e LIKE jest-stat.
  
  move wa_vttk-signi to l_equi.
+
move wa_vttk-signi to l_equi.
  
  CALL FUNCTION 'BAPI_EQUI_GETSTATUS'
+
CALL FUNCTION 'BAPI_EQUI_GETSTATUS'
    EXPORTING
+
  EXPORTING
      EQUIPMENT          = l_equi
+
    EQUIPMENT          = l_equi
  IMPORTING
+
  IMPORTING
    RETURN              = wa_return
+
    RETURN              = wa_return
    TABLES
+
  TABLES
      SYSTEM_STATUS      = lt_system_status
+
    SYSTEM_STATUS      = lt_system_status
      USER_STATUS        = lt_user_status
+
    USER_STATUS        = lt_user_status
            .
+
          .
  if wa_return is NOT INITIAL.
+
if wa_return is NOT INITIAL.
    write:/ 'Transporte:',
+
  write:/ 'Transporte:',
            wa_vttk-tknum,
+
            wa_vttk-tknum,
            'Error leer estado Patente:',
+
          'Error leer estado Patente:',
            wa_vttk-signi,
+
            wa_vttk-signi,
            wa_return-MESSAGE(80).
+
            wa_return-MESSAGE(80).
    gd_bloqueado = co_no_aplica.
+
  gd_bloqueado = co_no_aplica.
    return.
+
  return.
  endif.
+
endif.
  
  loop at lt_USER_STATUS TRANSPORTING NO FIELDS WHERE status = 'E0001'.
+
loop at lt_USER_STATUS TRANSPORTING NO FIELDS WHERE status = 'E0001'.
  ENDLOOP.
+
ENDLOOP.
  if sy-subrc = 0.
+
if sy-subrc = 0.
  
    CONCATENATE 'IE' wa_vttk-signi into l_objnr.
+
  CONCATENATE 'IE' wa_vttk-signi into l_objnr.
  
    move 'E0002' to l_stat_e.
+
  move 'E0002' to l_stat_e.
     CALL FUNCTION 'STATUS_CHANGE_EXTERN'
+
  CALL FUNCTION 'STATUS_CHANGE_EXTERN'
 +
    EXPORTING
 +
      OBJNR                    = l_objnr
 +
      USER_STATUS              = l_stat_e
 +
     EXCEPTIONS
 +
      OBJECT_NOT_FOUND          = 1
 +
      STATUS_INCONSISTENT      = 2
 +
      STATUS_NOT_ALLOWED        = 3
 +
      OTHERS                    = 4
 +
            .
 +
  IF SY-SUBRC <> 0.
 +
    write:/ 'Transporte:',
 +
            wa_vttk-tknum,
 +
            'Error bloqueo patente:',
 +
            wa_vttk-signi.
 +
  else.
 +
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 
       EXPORTING
 
       EXPORTING
         OBJNR                    = l_objnr
+
         WAIT         = 'X'
        USER_STATUS              = l_stat_e
+
              .
    EXCEPTIONS
+
    write:/ 'Transporte:',
      OBJECT_NOT_FOUND         = 1
+
            wa_vttk-tknum,
      STATUS_INCONSISTENT      = 2
+
            'Patente bloqueada con exito:',
      STATUS_NOT_ALLOWED        = 3
 
      OTHERS                    = 4
 
              .
 
    IF SY-SUBRC <> 0.
 
      write:/ 'Transporte:',
 
            wa_vttk-tknum,
 
            'Error bloqueo patente:',
 
 
             wa_vttk-signi.
 
             wa_vttk-signi.
    else.
+
    gd_bloqueado = co_yes.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
+
    add 1 to gd_num_bloqueados.
      EXPORTING
+
  ENDIF.
        WAIT          = 'X'
+
else.
                .
+
  gd_bloqueado = co_no_aplica.
      write:/ 'Transporte:',
+
endif.
            wa_vttk-tknum,
 
            'Patente bloqueada con exito:',
 
              wa_vttk-signi.
 
      gd_bloqueado = co_yes.
 
      add 1 to gd_num_bloqueados.
 
    ENDIF.
 
  else.
 
    gd_bloqueado = co_no_aplica.
 
  endif.
 
  
ENDFORM.                    " BLOQUEAR_PATENTE</nowiki>
+
ENDFORM.                    " BLOQUEAR_PATENTE</nowiki>

Latest revision as of 21:58, 4 April 2020

Ejemplo 1

REPORT ztest_bapi_shipment_create2 .
***************************************************************
* This report is provided to help understanding the interface *
* of function module 'BAPI_SHIPMENT_CREATE' with regard to    *
* its ability to fill the different shipment-deadlines        *
* With running this report, new shipments are created         *
* see note 531207
***************************************************************

* fill the interface for bapi
DATA: headerdata LIKE bapishipmentheader,
        headerdeadline LIKE bapishipmentheaderdeadline
                   OCCURS 0 WITH HEADER LINE,
        itemdata LIKE bapishipmentitem  OCCURS 0 WITH HEADER LINE,
        stagedata LIKE bapishipmentstage OCCURS 0 WITH HEADER LINE,
        stagedeadline LIKE bapishipmentstagedeadline
                          OCCURS 0 WITH HEADER LINE,
        itemonstage LIKE bapishipmentitemonstage
                         OCCURS 0 WITH HEADER LINE,
        address LIKE bapishipmentaddress
                         OCCURS 0 WITH HEADER LINE,
        hdunheader LIKE bapishipmenthdunheader
                         OCCURS 0 WITH HEADER LINE,
        hdunitem LIKE bapishipmenthdunitem
                         OCCURS 0 WITH HEADER LINE,
        return LIKE bapiret2  OCCURS 0 WITH HEADER LINE.


SELECTION-SCREEN COMMENT /1(83) com1.
SELECTION-SCREEN COMMENT /1(83) com2.
SELECTION-SCREEN COMMENT /1(83) com3.
SELECTION-SCREEN COMMENT /1(83) com4.
SELECTION-SCREEN COMMENT /1(83) com5.
SELECTION-SCREEN COMMENT /1(83) com6.
SELECTION-SCREEN COMMENT /1(83) com7.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN ULINE.


SELECTION-SCREEN BEGIN OF BLOCK header WITH FRAME TITLE text-hrd.
* Headerdate - obligatory
SELECTION-SCREEN COMMENT /1(79) com8 FOR FIELD tplst.
PARAMETER: tplst LIKE vttk-tplst.
SELECTION-SCREEN COMMENT /1(79) com9 FOR FIELD tplst.
PARAMETER: shtyp LIKE vttk-shtyp.
SELECTION-SCREEN END OF BLOCK header.

SELECTION-SCREEN ULINE.

SELECTION-SCREEN BEGIN OF BLOCK status WITH FRAME TITLE com10.
* Plan
PARAMETER:  plan LIKE  bapishipmentheader-status_plan.
*checkin
PARAMETER:  check LIKE  bapishipmentheader-status_checkin.
*load start
PARAMETER:  load_s LIKE  bapishipmentheader-status_load_start.
*load end
PARAMETER:  load_e LIKE  bapishipmentheader-status_load_end.
*Completion
PARAMETER:  compl LIKE  bapishipmentheader-status_compl.
* tra begin
PARAMETER:  ship_s LIKE  bapishipmentheader-status_shpmnt_start.
* tra end
PARAMETER:  ship_e LIKE  bapishipmentheader-status_shpmnt_end.
SELECTION-SCREEN END OF BLOCK status.

* Headerdeadline
SELECTION-SCREEN BEGIN OF BLOCK h_deadline WITH FRAME TITLE com11.
PARAMETERS: ttype(10)
           DEFAULT 'HDRSTPLDT', "= End of planning
           utc LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype2(10)
           DEFAULT 'HDRSTCIPDT',"= planned date of check-in
           utc2 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone2 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype3(10)
           DEFAULT 'HDRSTCIADT',"= actual date of check-in
           utc3 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone3 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype4(10)
           DEFAULT 'HDRSTLSPDT',"= planned date f. start loading
           utc4 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone4 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype5(10)
           DEFAULT 'HDRSTLSADT',"= current date f. start loading
           utc5 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone5 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype6(10)
           DEFAULT 'HDRSTLEPDT',"= planned date f. end loading
           utc6 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone6 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype7(10)
           DEFAULT 'HDRSTLEADT',"= actual date f. end loading
           utc7 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone7 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype8(10)
           DEFAULT 'HDRSTCPDT',"= planned date f. shpmnt completion
           utc8 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone8 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype9(10)
           DEFAULT 'HDRSTCADT',"= actual date f. shpmnt completion
           utc9 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone9 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype10(10)
           DEFAULT 'HDRSTSSPDT',"= planned date f. start shpmnt
           utc10 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone10 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype11(10)
           DEFAULT 'HDRSTSSADT',"= actual date f. start shpmnt
           utc11 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone11 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype12(10)
           DEFAULT 'HDRSTSEPDT',"= planned date f. end shpmnt
           utc12 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone12 LIKE bapishipmentheaderdeadline-time_zone.

PARAMETERS: ttype13(10)
           DEFAULT 'HDRSTSEADT',"= actual date f. end shpmnt
           utc13 LIKE bapishipmentheaderdeadline-time_stamp_utc,
           zone13 LIKE bapishipmentheaderdeadline-time_zone.

SELECTION-SCREEN END OF BLOCK h_deadline.

***********************************************************************
* Format the select-options                                           *
***********************************************************************
INITIALIZATION.
 com1 = 'This report was provided to help understanding the behaviour'.
 com2 = 'of function module BAPI_SHIPMENT_CREATE with regard to its '.
 com3 = 'ability to fill the new shipments deadlines: '.
 com4 = 'Planning, Check-In, Loading Start, Loading end, '.
 com5 = 'Shpmnt completion, Shipment start and shipment end.'.
 com6 = 'This report creates new shipments which can be '.
 com7 = 'viewed e.g. with transaction VT03n'.
 com8 = 'Transportation Planning Point (obligatory)'.
 com9 = 'Shipment type (obligatory)'.
 com10 = 'BAPISHIPMENTHEADER-Flags --> see note 531207 '.
 com11 = 'HEADERDEADLINE-Structure --> see note 531207 '.
***********************************************************************


START-OF-SELECTION.
******************head begin***********************************
 headerdata-trans_plan_pt = tplst.
 headerdata-shipment_type = shtyp.

* change Plan status
*  HEADERDATA-SHIPMENT_NUM = tknum.
 IF plan <> space.
   headerdata-status_plan = plan.
 ENDIF.
* Change Check_in status
 IF check <> space.
   headerdata-status_checkin = check.
 ENDIF.
*load beginn
 IF load_s <> space .
   headerdata-status_load_start = load_s.
 ENDIF.
* load end
 IF load_e <> space .
   headerdata-status_load_end = load_e.
 ENDIF.
* completion
 IF compl <> space.
   headerdata-status_compl = compl.
 ENDIF.
*tra beginn
 IF ship_s <> space.
   headerdata-status_shpmnt_start = ship_s.
 ENDIF.
*tra beginn
 IF ship_e <> space.
   headerdata-status_shpmnt_end = ship_e.
 ENDIF.

***** HEADERDEADLINE END OF PLANNING
 IF ttype <> space.
   headerdeadline-time_type = ttype.
   headerdeadline-time_stamp_utc = utc.
   headerdeadline-time_zone = zone.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE PLANNED DATE OF CHECK-IN
 IF ttype2 <> space.
   headerdeadline-time_type = ttype2.
   headerdeadline-time_stamp_utc = utc2.
   headerdeadline-time_zone = zone2.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE ACTUAL DATE OF CHECK-IN
 IF ttype3 <> space.
   headerdeadline-time_type = ttype3.
   headerdeadline-time_stamp_utc = utc3.
   headerdeadline-time_zone = zone3.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE PLANNED D START OF LOADING
 IF ttype4 <> space.
   headerdeadline-time_type = ttype4.
   headerdeadline-time_stamp_utc = utc4.
   headerdeadline-time_zone = zone4.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE CURRENT D START OF LOADING
 IF ttype5 <> space.
   headerdeadline-time_type = ttype5.
   headerdeadline-time_stamp_utc = utc5.
   headerdeadline-time_zone = zone5.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE PLANNED D END OF LOADING
 IF ttype6 <> space.
   headerdeadline-time_type = ttype6.
   headerdeadline-time_stamp_utc = utc6.
   headerdeadline-time_zone = zone6.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE ACTUAL D END OF LOADING
 IF ttype7 <> space.
   headerdeadline-time_type = ttype7.
   headerdeadline-time_stamp_utc = utc7.
   headerdeadline-time_zone = zone7.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE PLANNED D SHIPMENT COMPLETION
 IF ttype8 <> space.
   headerdeadline-time_type = ttype8.
   headerdeadline-time_stamp_utc = utc8.
   headerdeadline-time_zone = zone8.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE ACTUAL D SHIPMENT COMPLETION
 IF ttype9 <> space.
   headerdeadline-time_type = ttype9.
   headerdeadline-time_stamp_utc = utc9.
   headerdeadline-time_zone = zone9.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE PLANNED D START OF SHIPMENT
 IF ttype10 <> space.
   headerdeadline-time_type = ttype10.
   headerdeadline-time_stamp_utc = utc10.
   headerdeadline-time_zone = zone10.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE ACTUAL D START OF SHIPMENT
 IF ttype11 <> space.
   headerdeadline-time_type = ttype11.
   headerdeadline-time_stamp_utc = utc11.
   headerdeadline-time_zone = zone11.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE PLANNED D END OF SHIPMENT
 IF ttype12 <> space.
   headerdeadline-time_type = ttype12.
   headerdeadline-time_stamp_utc = utc12.
   headerdeadline-time_zone = zone12.
   APPEND headerdeadline.
 ENDIF.
***** HEADERDEADLINE CURRENT D END OF SHIPMENT
 IF ttype13 <> space.
   headerdeadline-time_type = ttype13.
   headerdeadline-time_stamp_utc = utc13.
   headerdeadline-time_zone = zone13.
   APPEND headerdeadline.
 ENDIF.

************************************************************
************************************************************
 CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
      EXPORTING
           headerdata     = headerdata
      TABLES
           headerdeadline = headerdeadline
           itemdata       = itemdata
           stagedata      = stagedata
           stagedeadline  = stagedeadline
           itemonstage    = itemonstage
           address        = address
           hdunheader     = hdunheader
           hdunitem       = hdunitem
           return         = return.

 LOOP AT return.

   WRITE: return.

 ENDLOOP.

*Colocar commit work para grabar

Ejemplo 2

FORM CREAR_TRANSPORTE  CHANGING o_TKNUM type TKNUM
                               o_SUBRC.
 data: lt_return type TABLE OF bapiret2,
     ls_return like LINE OF lt_return.

 data: ls_headerdata LIKE  BAPISHIPMENTHEADER,
       ls_itemdata type BAPISHIPMENTITEM,
       lt_itemdata type TABLE OF BAPISHIPMENTITEM,
       ls_HEADERDEADLINE  type BAPISHIPMENTHEADERDEADLINE,
       lt_HEADERDEADLINE  type table of BAPISHIPMENTHEADERDEADLINE.

 ls_headerdata-SHIPMENT_TYPE = 'ZDT'.
 ls_headerdata-TRANS_PLAN_PT = vttk-tplst.
 ls_headerdata-SHIPPING_COND = vttk-vsbed.
 ls_headerdata-SHIPMENT_ROUTE = vttk-route.
 ls_headerdata-SERVICE_AGENT_ID = vttk-tdlnr.
 ls_headerdata-CONTAINER_ID = vttk-signi.
 ls_headerdata-EXTERNAL_ID_1 = vttk-exti1.
 ls_headerdata-status_plan = 'X'.

 loop at gt_likp into gs_likp where vbeln is NOT INITIAL.
   ls_itemdata-DELIVERY = gs_likp-vbeln.

   append ls_itemdata to lt_itemdata.
 endloop.

 data ld_time(14) type c.

 CONCATENATE sy-datum sy-timlo into ld_time.

 ls_HEADERDEADLINE-TIME_TYPE = 'HDRSTPLDT'. "WSHDRTDDAT
 move ld_time to ls_HEADERDEADLINE-TIME_STAMP_UTC.
 ls_HEADERDEADLINE-time_zone = 'CHILE'.

 append ls_HEADERDEADLINE to lt_HEADERDEADLINE.
*
 CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
   EXPORTING
     HEADERDATA           = ls_headerdata
  IMPORTING
    TRANSPORT            = o_TKNUM
*     SHIPMENTGUID         =
   TABLES
    HEADERDEADLINE       = lt_HEADERDEADLINE
    ITEMDATA             = lt_itemdata
     RETURN               = lt_return
           .
 if o_TKNUM is INITIAL.
* transporte no creado
   o_subrc = 1.
   loop at lt_return into ls_return WHERE type = 'E'.
     exit.
   endloop.
   if sy-subrc = 0.
     MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
                    WITH ls_return-MESSAGE_V1
                         ls_return-MESSAGE_V2
                         ls_return-MESSAGE_V3
                         ls_return-MESSAGE_V4.
   endif.
 else.
   o_subrc = 0.
   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
     EXPORTING
       WAIT   = 'X'
     IMPORTING
       RETURN = ls_return.

* GRABA TEXTOS
   if ls_return is INITIAL.
     PERform get_texts_from_screen_and_save using o_TKNUM .
   else.
     MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
                    WITH ls_return-MESSAGE_V1
                         ls_return-MESSAGE_V2
                         ls_return-MESSAGE_V3
                         ls_return-MESSAGE_V4.
   endif.

   message s006(VW) with o_TKNUM.
 ENDIF.

ENDFORM.                    " CREAR_TRANSPORTE

Ejemplo 3 con embalaje

FORM CREAR_TRANSPORTE using i_unidad
                      CHANGING o_TKNUM type TKNUM
                               o_SUBRC.

 data: lt_return type TABLE OF bapiret2,
     ls_return like LINE OF lt_return.

 data: ls_headerdata LIKE  BAPISHIPMENTHEADER,
       ls_itemdata type BAPISHIPMENTITEM,
       lt_itemdata type TABLE OF BAPISHIPMENTITEM,
       ls_HEADERDEADLINE  type BAPISHIPMENTHEADERDEADLINE,
       lt_HEADERDEADLINE  type table of BAPISHIPMENTHEADERDEADLINE.

 data: ls_HDUNHEADER	LIKE BAPISHIPMENTHDUNHEADER,
       lt_HDUNHEADER	like TABLE OF ls_HDUNHEADER,
       ls_HDUNITEM LIKE BAPISHIPMENTHDUNITEM,
       lt_HDUNITEM like TABLE OF ls_HDUNITEM.

 ls_headerdata-SHIPMENT_TYPE = gd_SHTYP.
 ls_headerdata-TRANS_PLAN_PT = vttk-tplst.
 ls_headerdata-SHIPPING_COND = vttk-vsbed.
 ls_headerdata-SHIPMENT_ROUTE = vttk-route.
 ls_headerdata-SERVICE_AGENT_ID = vttk-tdlnr.
 ls_headerdata-CONTAINER_ID = vttk-signi.
 ls_headerdata-EXTERNAL_ID_1 = vttk-exti1.
 move LIKP-ANZPK to ls_headerdata-TEXT_1.
 ls_headerdata-status_plan = 'X'.

   loop at gt_likp into gs_likp where vbeln is NOT INITIAL
                             .
     ls_itemdata-DELIVERY = gs_likp-vbeln.

     append ls_itemdata to lt_itemdata.
   endloop.

 data ld_time(14) type c.

 CONCATENATE vttk-dtdis vttk-uzdis into ld_time.

 ls_HEADERDEADLINE-TIME_TYPE = 'HDRSTPLDT'. "WSHDRTDDAT
 move ld_time to ls_HEADERDEADLINE-TIME_STAMP_UTC.
 ls_HEADERDEADLINE-time_zone = 'CHILE'.

 append ls_HEADERDEADLINE to lt_HEADERDEADLINE.

  if i_unidad ne space.
    loop at gt_likp into gs_likp where vbeln is NOT INITIAL
                                     and sel = 'X'.
      clear ls_HDUNITEM.
      select  vbeln posnr matnr lfimg
       into

        (ls_HDUNITEM-DELIV_NUMB,ls_HDUNITEM-DELIV_ITEM,ls_HDUNITEM-material,ls_HDUNITEM-PACK_QTY)
                    from lips
                     where vbeln = gs_likp-vbeln.
        ls_HDUNITEM-HDL_UNIT_EXID_INTO = '$0001'.
        append  ls_HDUNITEM to lt_HDUNITEM.
      endselect.
    endloop.
    if sy-subrc = 0.
      ls_HDUNHEADER-SHIP_MAT = i_unidad.
      ls_HDUNHEADER-HDL_UNIT_EXID = '$0001'.
      append ls_HDUNHEADER to lt_HDUNHEADER.
    else.
      message E490(VW) WITH 'No se ha seleccionado ninguna Entrega'.
    endif.

 else.
   clear:  lt_HDUNHEADER[],
          lt_HDUNITEM[].
 endif.
*
 CALL FUNCTION 'BAPI_SHIPMENT_CREATE'
   EXPORTING
     HEADERDATA           = ls_headerdata
  IMPORTING
    TRANSPORT            = o_TKNUM
   TABLES
    HEADERDEADLINE       = lt_HEADERDEADLINE
    ITEMDATA             = lt_itemdata
    HDUNHEADER           = lt_HDUNHEADER
    HDUNITEM             = lt_HDUNITEM
     RETURN               = lt_return
           .
 if o_TKNUM is INITIAL.
* transporte no creado
   o_subrc = 1.
   loop at lt_return into ls_return WHERE type = 'E'.
     exit.
   endloop.
   if sy-subrc = 0.
     MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
                    WITH ls_return-MESSAGE_V1
                         ls_return-MESSAGE_V2
                         ls_return-MESSAGE_V3
                         ls_return-MESSAGE_V4.


   endif.
 else.
   o_subrc = 0.
   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
     EXPORTING
       WAIT   = 'X'
     IMPORTING
       RETURN = ls_return.

* GRABA TEXTOS
   if ls_return is INITIAL.
     PERform get_texts_from_screen_and_save using o_TKNUM .
   else.
     MESSAGE ID ls_return-id TYPE 'E' NUMBER ls_return-number
                    WITH ls_return-MESSAGE_V1
                         ls_return-MESSAGE_V2
                         ls_return-MESSAGE_V3
                         ls_return-MESSAGE_V4.
   endif.

   message s006(VW) with o_TKNUM.
 ENDIF.

ENDFORM.                    " CREAR_TRANSPORTE

Modificar Transporte

  • Modificar estado transporte
DATA: l_it_header        TYPE bapishipmentheader,
       l_it_headeraction  TYPE  bapishipmentheaderaction,
       l_it_return        TYPE TABLE OF bapiret2.
 DATA: l_wa_return TYPE bapiret2.

 l_it_header-shipment_num  = shipment.
 l_it_headeraction-shipment_num  = 'X'.

 l_it_header-status_shpmnt_start       = 'X'.
 l_it_headeraction-status_shpmnt_start = 'C'.

 CALL FUNCTION 'BAPI_SHIPMENT_CHANGE'
   EXPORTING
     headerdata       = l_it_header
     headerdataaction = l_it_headeraction
   TABLES
     return           = l_it_return.

bloquear patente ( VTTK-SIGNI )

FORM BLOQUEAR_PATENTE .

 data : lt_SYSTEM_STATUS type TABLE OF BAPI_ITOB_STATUS WITH HEADER LINE,
        lt_USER_STATUS type TABLE OF BAPI_ITOB_STATUS WITH HEADER LINE.
 data wa_return type bapiret2.
 data: l_equi type EQUNR,
       l_objnr type JSTO-OBJNR,
       l_stat_e LIKE jest-stat.

 move wa_vttk-signi to l_equi.

 CALL FUNCTION 'BAPI_EQUI_GETSTATUS'
   EXPORTING
     EQUIPMENT           = l_equi
  IMPORTING
    RETURN              = wa_return
   TABLES
     SYSTEM_STATUS       = lt_system_status
     USER_STATUS         = lt_user_status
           .
 if wa_return is NOT INITIAL.
   write:/ 'Transporte:',
            wa_vttk-tknum,
           'Error leer estado Patente:',
            wa_vttk-signi,
            wa_return-MESSAGE(80).
   gd_bloqueado = co_no_aplica.
   return.
 endif.

 loop at lt_USER_STATUS TRANSPORTING NO FIELDS WHERE status = 'E0001'.
 ENDLOOP.
 if sy-subrc = 0.

   CONCATENATE 'IE' wa_vttk-signi into l_objnr.

   move 'E0002' to l_stat_e.
   CALL FUNCTION 'STATUS_CHANGE_EXTERN'
     EXPORTING
       OBJNR                     = l_objnr
       USER_STATUS               = l_stat_e
    EXCEPTIONS
      OBJECT_NOT_FOUND          = 1
      STATUS_INCONSISTENT       = 2
      STATUS_NOT_ALLOWED        = 3
      OTHERS                    = 4
             .
   IF SY-SUBRC <> 0.
     write:/ 'Transporte:',
            wa_vttk-tknum,
            'Error bloqueo patente:',
            wa_vttk-signi.
   else.
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT          = 'X'
               .
     write:/ 'Transporte:',
            wa_vttk-tknum,
            'Patente bloqueada con exito:',
             wa_vttk-signi.
     gd_bloqueado = co_yes.
     add 1 to gd_num_bloqueados.
   ENDIF.
 else.
   gd_bloqueado = co_no_aplica.
 endif.

ENDFORM.                    " BLOQUEAR_PATENTE