FUNCTION Z_FLIGHT_MODEL_DATA. *"---------------------------------------------------------------------- *"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(QUERY_TABLE) TYPE TABNAME *" VALUE(ACTION) TYPE CHAR01 *" VALUE(LOGGING) TYPE CHAR01 OPTIONAL *" EXPORTING *" VALUE(SYSTEM) TYPE SY-SUBRC *" TABLES *" FIELDS STRUCTURE RFC_DB_FLD *" OPTIONS STRUCTURE ZZRFC_DB_OPT *" SCARR STRUCTURE SCARR *" ZSCARR STRUCTURE ZSCARR *" SPFLI STRUCTURE SPFLI *" SFLIGHT STRUCTURE SFLIGHT *" ZZSBOOK STRUCTURE ZZSBOOK *" SBOOK STRUCTURE SBOOK *" SCUSTOM STRUCTURE SCUSTOM *" ZZCURX STRUCTURE ZCURX *" SCOUNTER STRUCTURE SCOUNTER *" STRAVELAG STRUCTURE STRAVELAG *" SAPLANE STRUCTURE SAPLANE *" SGEOCITY STRUCTURE SGEOCITY *" SAIRPORT STRUCTURE SAIRPORT *" SBUSPART STRUCTURE SBUSPART *" SCURR STRUCTURE SCURR *" BFUSER_TYP STRUCTURE BFUSER_TYP *" ZZFLIGHTS STRUCTURE ZZFLIGHTS *" T002T STRUCTURE T002T *" TCURT STRUCTURE TCURT *" T005T STRUCTURE T005T *" EXCEPTIONS *" NOT_AUTHORIZED *" TABLE_NOT_AVAILABLE *" ACTION_UNKNOWN *" ACTION_NOT_SUPPORTED *" NO_DATA_FOR_DB_CHANGE *" DB_FAILED *" NO_DELETE *" TABLE_NOT_ACTIVE *"---------------------------------------------------------------------- tables: dd03l, zzprot. data: tlines type i. data: dbcount type i. data: check_action. Data: line like RFC_DB_OPT. TRANSLATE query_table TO UPPER CASE. TRANSLATE action TO UPPER CASE. Logging = 'X'. check_action = action. if action = 'I' or action = 'D'. check_action = 'U'. endif. CALL FUNCTION 'VIEW_AUTHORITY_CHECK' EXPORTING VIEW_ACTION = check_action VIEW_NAME = QUERY_TABLE EXCEPTIONS NO_AUTHORITY = 2 NO_CLIENTINDEPENDENT_AUTHORITY = 3 TABLE_NOT_FOUND = 4. IF SY-SUBRC = 2 OR SY-SUBRC = 3. RAISE NOT_AUTHORIZED. ELSEIF SY-SUBRC = 1. RAISE TABLE_NOT_AVAILABLE. ENDIF. * Export fieldnames, field-length and field-types CLEAR fields. SELECT * FROM dd03l WHERE tabname = query_table ORDER BY position. if dd03l-fieldname(1) ne '.'. MOVE dd03l-fieldname TO fields-fieldname. MOVE dd03l-leng TO fields-length. case dd03l-datatype. when 'INT4' or 'INT1' or 'INT2'. MOVE 'I' TO fields-type. when 'RAW' or 'LRAW' or 'RAWSTRING'. MOVE 'X' TO fields-type. when 'FLTP'. MOVE 'F' TO fields-type. when 'DATS'. MOVE 'D' TO fields-type. when 'TIMS'. MOVE 'T' TO fields-type. when OTHERS. MOVE 'C' TO fields-type. endcase. APPEND fields. endif. ENDSELECT. * CALL FUNCTION 'RFC_GET_STRUCTURE_DEFINITION' * EXPORTING * TABNAME = query_table ** IMPORTING ** TABLENGTH = * TABLES * FIELDS = fields * EXCEPTIONS * TABLE_NOT_ACTIVE = 1 * OTHERS = 2. * * IF SY-SUBRC <> 0. * raise TABLE_NOT_ACTIVE. * ENDIF. * sort fields by position. * mapping cySytem-languagekey to SAP-languagekey loop at options. if options-text cs 'SPRAS'. SY-FDPOS = SY-FDPOS + 9. case options+SY-FDPOS(1). when '0'. options+SY-FDPOS(1) = 'D'. when '1'. options+SY-FDPOS(1) = 'E'. endcase. endif. MODIFY options. endloop. *Start Logging if LOGGING ne space. perform logging using action query_table. loop at options. perform logging using 'Options:' options-text. endloop. if action ne 'S'. CASE query_table. when 'SCARR'. loop at scarr. perform logging using 'SCARR:' scarr. endloop. when 'SCUSTOM'. loop at scustom. perform logging using 'SCUSTOM:' scustom. endloop. when 'SBOOK'. loop at sbook. perform logging using 'SBOOK:' sbook. endloop. when 'SBUSPART'. loop at sbuspart. perform logging using 'SBUSPART:' sbook. endloop. when 'SPFLI'. loop at spfli. perform logging using 'SPFLI:' sbook. endloop. endcase. endif. endif. case Action. *Select Query_Table when 'S'. system = 0. CASE query_table. WHEN 'SCARR'. SELECT * FROM scarr INTO CORRESPONDING FIELDS OF TABLE scarr where (options). system = sy-subrc. WHEN 'ZSCARR'. SELECT * FROM zscarr INTO CORRESPONDING FIELDS OF TABLE zscarr where (options). system = sy-subrc. WHEN 'SPFLI'. SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE spfli where (options). system = sy-subrc. WHEN 'SFLIGHT'. SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE sflight where (options). system = sy-subrc. WHEN 'SBOOK'. SELECT * FROM sbook INTO CORRESPONDING FIELDS OF TABLE sbook where (options). system = sy-subrc. WHEN 'ZZSBOOK'. SELECT * FROM zzsbook INTO CORRESPONDING FIELDS OF TABLE zzsbook where (options). system = sy-subrc. WHEN 'SCUSTOM'. SELECT * FROM scustom INTO CORRESPONDING FIELDS OF TABLE scustom where (options). system = sy-subrc. WHEN 'ZZCURX'. SELECT * FROM zcurx INTO CORRESPONDING FIELDS OF TABLE zzcurx where (options). system = sy-subrc. WHEN 'SCURR'. SELECT * FROM scurr INTO CORRESPONDING FIELDS OF TABLE scurr where (options). system = sy-subrc. WHEN 'SCOUNTER'. SELECT * FROM scounter INTO CORRESPONDING FIELDS OF TABLE scounter where (options). system = sy-subrc. WHEN 'STRAVELAG'. SELECT * FROM stravelag INTO CORRESPONDING FIELDS OF TABLE stravelag where (options). system = sy-subrc. WHEN 'SAPLANE'. SELECT * FROM saplane INTO CORRESPONDING FIELDS OF TABLE saplane where (options). system = sy-subrc. WHEN 'SGEOCITY'. SELECT * FROM sgeocity INTO CORRESPONDING FIELDS OF TABLE sgeocity where (options). system = sy-subrc. WHEN 'SAIRPORT'. SELECT * FROM sairport INTO CORRESPONDING FIELDS OF TABLE sairport where (options). system = sy-subrc. WHEN 'SBUSPART'. SELECT * FROM sbuspart INTO CORRESPONDING FIELDS OF TABLE sbuspart where (options). system = sy-subrc. WHEN 'BFUSER_TYP'. SELECT * FROM bfuser_typ INTO CORRESPONDING FIELDS OF TABLE bfuser_typ where (options). system = sy-subrc. WHEN 'ZZFLIGHTS'. SELECT * FROM zzflights INTO CORRESPONDING FIELDS OF TABLE zzflights where (options) order by cityfrom cityto fldate. system = sy-subrc. WHEN 'T002T'. SELECT * FROM T002T INTO CORRESPONDING FIELDS OF TABLE T002T where (options). system = sy-subrc. WHEN 'T005T'. SELECT * FROM T005T INTO CORRESPONDING FIELDS OF TABLE T005T where (options). system = sy-subrc. WHEN 'TCURT'. SELECT * FROM TCURT INTO CORRESPONDING FIELDS OF TABLE TCURT where (options). system = sy-subrc. WHEN OTHERS. system = 8. ENDCASE. *Update Query_Table when 'U'. CASE query_table. WHEN 'SBOOK'. describe table sbook lines tlines. if tlines = 1. PERFORM update_sbook USING sbook CHANGING system. else. raise NO_DATA_FOR_DB_CHANGE. endif. WHEN 'SCARR'. describe table scarr lines tlines. if tlines gt 0. loop at scarr. UPDATE scarr from scarr. if sy-subrc ne 0. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. WHEN 'SCUSTOM'. describe table scustom lines tlines. if tlines gt 0. loop at scustom. UPDATE scustom from scustom. if sy-subrc ne 0. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. WHEN 'SBUSPART'. describe table sbuspart lines tlines. if tlines gt 0. loop at sbuspart. UPDATE sbuspart from sbuspart. if sy-subrc ne 0. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. WHEN 'SPFLI'. describe table spfli lines tlines. if tlines gt 0. loop at spfli. UPDATE spfli from spfli. if sy-subrc ne 0. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. when others. raise ACTION_NOT_SUPPORTED. endcase. *Insert Query_Table when 'I'. CASE query_table. WHEN 'SBOOK'. describe table sbook lines tlines. if tlines gt 0. loop at sbook. PERFORM insert_sbook USING sbook CHANGING system. if system ne 0. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. WHEN 'SCARR'. describe table scarr lines tlines. if tlines gt 0. loop at scarr. select single * from scarr where carrid = scarr-carrid. if sy-subrc ne 0. insert scarr from scarr. if sy-subrc ne 0. raise DB_FAILED. endif. else. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. WHEN 'SBUSPART'. describe table sbuspart lines tlines. if tlines gt 0. loop at sbuspart. select single * from sbuspart where buspartnum = sbuspart-buspartnum. if sy-subrc ne 0. insert sbuspart from sbuspart. if sy-subrc ne 0. system = sy-subrc. raise DB_FAILED. endif. else. system = sy-subrc. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. WHEN 'SCUSTOM'. describe table scustom lines tlines. if tlines gt 0. loop at scustom. select single * from sbuspart where buspartnum = scustom-id. if sy-subrc eq 0. scustom-name = sbuspart-contact. insert scustom from scustom. if sy-subrc ne 0. raise DB_FAILED. endif. else. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. when others. raise ACTION_NOT_SUPPORTED. endcase. *Delete Query_Table when 'D'. CASE query_table. WHEN 'SCARR'. describe table scarr lines tlines. if tlines gt 0. loop at scarr. dbcount = 0. select count(*) from sbook into dbcount where carrid = scarr-carrid. if dbcount > 0. raise NO_DELETE. endif. select count(*) from sflight into dbcount where carrid = scarr-carrid. if dbcount > 0. raise NO_DELETE. endif. select count(*) from spfli into dbcount where carrid = scarr-carrid. if dbcount > 0. raise NO_DELETE. endif. select count(*) from scounter into dbcount where carrid = scarr-carrid. if dbcount > 0. raise NO_DELETE. endif. DELETE from scarr where carrid = scarr-carrid. if sy-subrc ne 0. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. system = sy-subrc. WHEN 'SCUSTOM'. describe table scustom lines tlines. if tlines gt 0. loop at scustom. select count(*) from sbook into dbcount where customid = scustom-id. if dbcount > 0. raise NO_DELETE. exit. endif. DELETE from scustom where id = scustom-id. if sy-subrc ne 0. raise DB_FAILED. endif. endloop. else. raise NO_DATA_FOR_DB_CHANGE. endif. when others. raise ACTION_NOT_SUPPORTED. endcase. when others. RAISE ACTION_UNKNOWN. endcase. if logging ne space. perform logging using 'RFC-RC:' system. commit work. endif. ENDFUNCTION. *---------------------------------------------------------------------* * FORM insert_sbook * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* FORM insert_sbook CHANGING booking STRUCTURE sbook value(ret) LIKE sy-subrc. DATA wa TYPE sflight. CLEAR ret. CALL FUNCTION 'NUMBER_GET_NEXT' EXPORTING nr_range_nr = '01' object = 'SBOOKID' quantity = '1' subobject = booking-carrid * TOYEAR = '0000' * IGNORE_BUFFER = '' IMPORTING number = booking-bookid. * QUANTITY = * systemCODE = * EXCEPTIONS * INTERVAL_NOT_FOUND = 1 * NUMBER_RANGE_NOT_INTERN = 2 * OBJECT_NOT_FOUND = 3 * QUANTITY_IS_0 = 4 * QUANTITY_IS_NOT_1 = 5 * INTERVAL_OVERFLOW = 6 * OTHERS = 7 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ret = sy-subrc. EXIT. ENDIF. INSERT sbook FROM booking. IF sy-subrc <> 0. ret = sy-subrc. EXIT. ENDIF. SELECT SINGLE * INTO wa FROM sflight CLIENT SPECIFIED WHERE mandt = sy-mandt AND carrid = booking-carrid AND connid = booking-connid AND fldate = booking-fldate AND currency = booking-loccurkey. IF sy-subrc = 0. wa-paymentsum = wa-paymentsum + booking-loccuram. wa-seatsocc = wa-seatsocc + 1. UPDATE sflight FROM wa. ret = sy-subrc. ENDIF. ENDFORM. *---------------------------------------------------------------------* * FORM update_sbook * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* FORM update_sbook USING booking STRUCTURE sbook value(ret) LIKE sy-subrc. DATA wa TYPE sbook. DATA wa1 TYPE sflight. if not booking-cancelled is initial. SELECT SINGLE * INTO wa FROM sbook CLIENT SPECIFIED WHERE mandt = sy-mandt AND carrid = booking-carrid AND connid = booking-connid AND bookid = booking-bookid AND fldate = booking-fldate. IF sy-subrc = 0 AND wa-cancelled IS INITIAL. wa-cancelled = booking-cancelled. wa-wunit = 'KG'. UPDATE sbook FROM wa. IF sy-subrc = 0. SELECT SINGLE * INTO wa1 FROM sflight CLIENT SPECIFIED WHERE mandt = sy-mandt AND carrid = booking-carrid AND connid = booking-connid AND fldate = booking-fldate AND currency = booking-loccurkey. IF sy-subrc = 0. wa1-paymentsum = wa1-paymentsum - booking-loccuram. wa1-seatsocc = wa1-seatsocc - 1. UPDATE sflight FROM wa1. ret = sy-subrc. ENDIF. ELSE. ret = sy-subrc. EXIT. ENDIF. ELSE. ret = sy-subrc. EXIT. ENDIF. else. SELECT SINGLE * INTO wa FROM sbook CLIENT SPECIFIED WHERE mandt = sy-mandt AND carrid = booking-carrid AND connid = booking-connid AND bookid = booking-bookid AND fldate = booking-fldate. IF sy-subrc = 0. move-corresponding booking to wa. wa-wunit = 'KG'. UPDATE sbook FROM wa. else. ret = sy-subrc. EXIT. endif. endif. ENDFORM. *---------------------------------------------------------------------* * FORM logging * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* * --> VALUE(TEXT1) * * --> VALUE(TEXT2) * *---------------------------------------------------------------------* FORM logging USING value(text1) value(text2). data: dbcount type i. if zzprot-idx = 0. dbcount = 0. select count(*) from zzprot into dbcount. zzprot-idx = dbcount + 1. else. zzprot-idx = zzprot-idx + 1. endif. zzprot-datum = sy-datum. zzprot-uhrzeit = sy-uzeit. zzprot-zeile = text1. zzprot-zeile+10(189) = text2. insert zzprot. * commit work. endform.