*----------------------------------------------------------------------*
***INCLUDE MZ_TP3F01 .
*----------------------------------------------------------------------*
*
FORM suchen .
* 3. Variante: BAPI-Aufruf
  CLEAR: wa, itab.
  DATA:
    from TYPE bapisfldst,
    to   TYPE bapisfldst,
    date TYPE TABLE OF bapisfldra WITH HEADER LINE,
    bapi_tab TYPE TABLE OF zbapisfldat WITH HEADER LINE,
    ret_tab  TYPE TABLE OF bapiret2 WITH HEADER LINE.
*
  from-city = zflug_input-cityfrom.
  to-city   = zflug_input-cityto.
* Abfrage, ob 0, 1 oder 2 Datums-Felder gefüllt wurden
  IF zflug_input-vondatum IS INITIAL AND
     zflug_input-bisdatum IS INITIAL. "kein Feld gefüllt
*   do nothing!
  ELSEIF zflug_input-vondatum IS INITIAL OR
    zflug_input-bisdatum IS INITIAL. "praktisch: 2. Feld gefüllt
    date-option = 'EQ'. date-sign = 'I'.
    date-low  = zflug_input-bisdatum.
    APPEND date.
  ELSE. "beide Felder gefüllt
    date-option = 'BT'. date-sign = 'I'.
    date-low  = zflug_input-vondatum.
    date-high = zflug_input-bisdatum.
    APPEND date.
  ENDIF.
*
  CALL FUNCTION 'Z_BAPI_FLIGHT_GETLIST'
    EXPORTING
      destination_from = from
      destination_to   = to
    TABLES
      date_range       = date
      return           = ret_tab
      flug_list        = bapi_tab.
  LOOP AT bapi_tab.
    wa-fldate    = bapi_tab-flightdate.
    wa-carrid    = bapi_tab-airlineid.
    wa-connid    = bapi_tab-connectid.
    wa-fltime    = bapi_tab-flighttime.
    wa-price     = bapi_tab-price.
    wa-currency  = bapi_tab-curr.
    wa-seatsfree = bapi_tab-seatsfree.
    APPEND wa TO itab.
  ENDLOOP.
  DESCRIBE TABLE itab LINES count.
ENDFORM.                    " suchen
*
FORM buchen .
  DATA:
    book_wa LIKE bapisbonew,
    airlineid TYPE bapisbokey-airlineid,
    bookingnumber TYPE bapisbokey-bookingid,
    ret_tab  TYPE TABLE OF bapiret2 WITH HEADER LINE.
* globale Daten in wa für BAPI transportieren
  book_wa-airlineid  = zzflug-carrid.
  book_wa-connectid  = zzflug-connid.
  book_wa-flightdate = zzflug-fldate.
  book_wa-customerid = scustom-id.

*  book_wa-class      = scustom-class.
  book_wa-counter    = 1."scustom-counter.
*  book_wa-agencynum  = 1." scustom-agencynum.
*  book_wa-passname   = scustom-passname.
*  book_wa-passbirth  = scustom-passbirth.
*  book_wa-passform   = scustom-passform.

  CALL FUNCTION 'BAPI_FLBOOKING_CREATEFROMDATA'
    EXPORTING
      booking_data        = book_wa
    IMPORTING
      airlineid           = airlineid
      bookingnumber       = bookingnumber
*   TICKET_PRICE        =
    TABLES
      return              = ret_tab.
*
  COMMIT WORK.
* zurück transportieren
  sbook-carrid = airlineid.
  sbook-connid = zzflug-connid.
  sbook-fldate = zzflug-fldate.
  sbook-bookid = bookingnumber.
ENDFORM.                    " buchen
*
FORM kunde_anlegen .
  DATA:
    custom TYPE bapiscunew,
    custid TYPE bapiscudat-customerid,
    ret_tab  TYPE TABLE OF bapiret2 WITH HEADER LINE.
* Transport Dynpro-Felder --> BAPI-Felder
  custom-custname = scustom-name.
  custom-form     = scustom-form.
  custom-street   = scustom-street.
  custom-postcode = scustom-postcode.
  custom-city     = scustom-city.
  custom-phone    = scustom-telephone.
  custom-email    = scustom-email.
  custom-custtype = scustom-custtype.

  CALL FUNCTION 'BAPI_FLCUST_CREATEFROMDATA'
    EXPORTING
      customer_data  = custom
    IMPORTING
      customernumber = custid
    TABLES
      return         = ret_tab.
*
  COMMIT WORK.
* Transport BAPI-Feld --> Dynpro-Feld
  scustom-id = custid.
ENDFORM.                    " kunde_anlegen