SHARE
TWEET

Untitled

a guest Nov 21st, 2019 135 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *&---------------------------------------------------------------------*
  2. *&  Include           ZSD_ALF_INCL
  3. *&---------------------------------------------------------------------*
  4. include zsd_alf_exc_incl.
  5. CLASS lcl_server_api DEFINITION DEFERRED.
  6.  
  7. " wspólna struktura plików
  8. CLASS lcl_file_extension DEFINITION CREATE PROTECTED ABSTRACT.
  9.   PUBLIC SECTION.
  10.     METHODS:
  11.       get_path ABSTRACT
  12.         IMPORTING iv_data        TYPE any
  13.         RETURNING VALUE(rv_path) TYPE char50,
  14.  
  15.       send_to_server ABSTRACT
  16.         IMPORTING iv_pdf_data TYPE any
  17.                   iv_key_data TYPE any
  18.       RAISING lcx_no_att_exception lcx_send_failed_exception.
  19.  
  20.     CLASS-METHODS:
  21.       get_instance
  22.         IMPORTING iv_name            TYPE data
  23.                   iv_web_handler     TYPE i
  24.         RETURNING VALUE(ro_instance) TYPE REF TO lcl_file_extension.
  25.  
  26.   PROTECTED SECTION.
  27.     TYPES:
  28.       BEGIN OF _lty_class_instances,
  29.         name     TYPE char40,
  30.         instance TYPE REF TO lcl_file_extension,
  31.       END OF _lty_class_instances,
  32.  
  33.       _ltyt_class_instances TYPE TABLE OF _lty_class_instances WITH KEY name.
  34.  
  35.     CLASS-DATA:
  36.       cdt_instances TYPE _ltyt_class_instances.
  37.  
  38.     METHODS:
  39.       constructor
  40.         IMPORTING iv_web_handler TYPE i,
  41.  
  42.       get_server_api
  43.         RETURNING VALUE(ro_server_api) TYPE REF TO lcl_server_api,
  44.  
  45.       get_web_handler
  46.         RETURNING VALUE(rv_web_handler) TYPE i,
  47.  
  48.       set_web_handler
  49.         IMPORTING iv_web_handler TYPE i.
  50.  
  51.   PRIVATE SECTION.
  52.     DATA:
  53.       cdo_server_api  TYPE REF TO lcl_server_api,
  54.       cdv_web_handler TYPE i.
  55. ENDCLASS.
  56.  
  57. " wykonywanie operacji na danych plikach
  58. CLASS lcl_file_handler DEFINITION.
  59.   PUBLIC SECTION.
  60.     TYPES:
  61.       _ltyt_alf_xml TYPE TABLE OF zsd_alf_xml WITH DEFAULT KEY.
  62.  
  63.     CONSTANTS:
  64.       cdc_pdf TYPE char3 VALUE 'PDF',
  65.       cdc_xml TYPE char3 VALUE 'XML'.
  66.  
  67.     METHODS:
  68.       constructor
  69.         IMPORTING iv_web_handler TYPE i.
  70.  
  71.     CLASS-METHODS:
  72.       get_instance
  73.         IMPORTING iv_file_type       TYPE char3
  74.                   iv_web_handler     TYPE i
  75.         RETURNING VALUE(ro_instance) TYPE REF TO lcl_file_extension.
  76.  
  77.   PRIVATE SECTION.
  78. *    DATA:
  79. *          cdv_web_handler TYPE i.
  80. ENDCLASS.
  81.  
  82. " metody do obsłgi metod na serwerze
  83. CLASS lcl_server_api DEFINITION.
  84.   PUBLIC SECTION.
  85.     METHODS:
  86.       xstring_to_binary
  87.         IMPORTING iv_pdf                    TYPE xstring
  88.         RETURNING VALUE(ro_server_instance) TYPE REF TO lcl_server_api
  89.         RAISING lcx_no_att_exception,
  90.  
  91.       string_to_xstring
  92.         IMPORTING iv_pdf           TYPE string
  93.         RETURNING VALUE(rv_string) TYPE xstring,
  94.  
  95.       xml_transformation
  96.         IMPORTING it_aflfresco_data TYPE any
  97.         RETURNING VALUE(rv_data)    TYPE string,
  98.  
  99.       send_to_server
  100.         IMPORTING iv_webservice_handler TYPE i
  101.                   iv_server_path        TYPE char50
  102.         RAISING lcx_send_failed_exception.
  103.  
  104.   PRIVATE SECTION.
  105.     CONSTANTS:
  106.       cdc_encoding_utf_16 TYPE char18 VALUE 'encoding="utf-16"?',
  107.       cdc_encoding_utf_8  TYPE char18 VALUE 'encoding="utf-8"?'.
  108.  
  109.     DATA:
  110.       cdv_binary_length TYPE i,
  111.       cdt_binary_att    TYPE solix_tab.
  112.  
  113. ENDCLASS.
  114.  
  115. CLASS lcl_xml_extension DEFINITION INHERITING FROM lcl_file_extension CREATE PUBLIC.
  116.   PUBLIC SECTION.
  117.     METHODS:
  118.       get_path REDEFINITION,
  119.       send_to_server REDEFINITION.
  120.  
  121.   PRIVATE SECTION.
  122.     CONSTANTS:
  123.       cdc_server_path_for_vf        TYPE char20 VALUE '/One/FakturySAP/VF',
  124.       cdc_server_underline_separator TYPE char1 VALUE '_',
  125.       cdc_server_file_extension_xml TYPE char4 VALUE '.xml'.
  126. ENDCLASS.
  127.  
  128. CLASS lcl_pdf_extension DEFINITION INHERITING FROM lcl_file_extension CREATE PUBLIC.
  129.   PUBLIC SECTION.
  130.     METHODS:
  131.       get_path REDEFINITION,
  132.       send_to_server REDEFINITION.
  133.  
  134.   PRIVATE SECTION.
  135.     CONSTANTS:
  136.       cdc_server_path               TYPE char20 VALUE '/One/FakturySAP/',
  137.       cdc_server_file_extension_pdf TYPE char4 VALUE '.pdf'.
  138. ENDCLASS.
  139.  
  140. CLASS lcl_server_api IMPLEMENTATION.
  141.   METHOD xstring_to_binary.
  142.     CLEAR:
  143.       cdv_binary_length.
  144.  
  145.     REFRESH:
  146.       cdt_binary_att.
  147.  
  148.     CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  149.       EXPORTING
  150.         buffer          = iv_pdf
  151.         append_to_table = 'X' "Do not clear/refresh table
  152.       IMPORTING
  153.         output_length   = cdv_binary_length
  154.       TABLES
  155.         binary_tab      = cdt_binary_att.
  156.  
  157.     ro_server_instance = me.
  158.  
  159.     IF cdt_binary_att is INITIAL.
  160.       raise EXCEPTION TYPE lcx_no_att_exception .
  161.     ENDIF.
  162.   ENDMETHOD.
  163.  
  164.   METHOD send_to_server.
  165.     CHECK lines( cdt_binary_att ) > 0.
  166.     CALL FUNCTION 'FTP_R3_TO_SERVER'
  167.       EXPORTING
  168.         handle         = iv_webservice_handler
  169.         fname          = iv_server_path      "file path of destination system
  170.         character_mode = ''
  171.         blob_length    = cdv_binary_length
  172.       TABLES
  173.         blob           = cdt_binary_att
  174.       EXCEPTIONS
  175.         tcpip_error    = 1
  176.         command_error  = 2
  177.         data_error     = 3
  178.         OTHERS         = 4.
  179.     IF sy-subrc <> 0.
  180.       raise EXCEPTION type lcx_send_failed_exception.
  181.     ENDIF.
  182.   ENDMETHOD.
  183.  
  184.   METHOD xml_transformation.
  185.     CALL TRANSFORMATION ('ID')
  186.       SOURCE tab = gt_tab
  187.       RESULT XML rv_data.
  188.  
  189.     REPLACE cdc_encoding_utf_16 IN rv_data WITH cdc_encoding_utf_8.
  190.  
  191.   ENDMETHOD.
  192.  
  193.   METHOD string_to_xstring.
  194.     CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  195.       EXPORTING
  196.         text   = iv_pdf
  197.       IMPORTING
  198.         buffer = rv_string.
  199.   ENDMETHOD.
  200. ENDCLASS.
  201.  
  202. CLASS lcl_file_extension IMPLEMENTATION.
  203.   METHOD constructor.
  204.     cdo_server_api = NEW lcl_server_api( ).
  205.   ENDMETHOD.
  206.  
  207.   METHOD get_server_api.
  208.     ro_server_api = cdo_server_api.
  209.   ENDMETHOD.
  210.  
  211.   METHOD get_web_handler.
  212.     rv_web_handler = cdv_web_handler.
  213.   ENDMETHOD.
  214.  
  215.   METHOD set_web_handler.
  216.     cdv_web_handler = iv_web_handler.
  217.   ENDMETHOD.
  218.  
  219.   METHOD get_instance.
  220.     READ TABLE lcl_file_extension=>cdt_instances ASSIGNING FIELD-SYMBOL(<fs_instance>) WITH KEY name = iv_name.
  221.     IF sy-subrc = 0.
  222.       ro_instance = <fs_instance>-instance.
  223.     ELSE.
  224.       CREATE OBJECT ro_instance TYPE (iv_name) EXPORTING iv_web_handler = iv_web_handler.
  225.       APPEND INITIAL LINE TO lcl_file_extension=>cdt_instances ASSIGNING <fs_instance>.
  226.       <fs_instance>-name = iv_name.
  227.       <fs_instance>-instance = ro_instance.
  228.       ro_instance->set_web_handler( iv_web_handler ).
  229.     ENDIF.
  230.   ENDMETHOD.
  231. ENDCLASS.
  232.  
  233. CLASS lcl_xml_extension IMPLEMENTATION.
  234.   METHOD get_path.
  235.     CONCATENATE cdc_server_path_for_vf cdc_server_underline_separator iv_data cdc_server_file_extension_xml INTO rv_path.
  236.   ENDMETHOD.
  237.  
  238.   METHOD send_to_server.
  239.     DATA(lo_server) = me->get_server_api( ).
  240. *    DATA(lv_pdf) = lo_server->string_to_xstring( lo_server->xml_transformation( iv_pdf_data ) ).
  241. *    lo_server->xstring_to_binary( lv_pdf )->send_to_server(
  242.     lo_server->xstring_to_binary( lo_server->string_to_xstring( lo_server->xml_transformation( iv_pdf_data ) ) )->send_to_server(
  243.         iv_webservice_handler = me->get_web_handler( )
  244.         iv_server_path        = me->get_path( iv_key_data )
  245.     ).
  246.   ENDMETHOD.
  247. ENDCLASS.
  248.  
  249. CLASS lcl_pdf_extension IMPLEMENTATION.
  250.   METHOD get_path.
  251.     CONCATENATE cdc_server_path iv_data cdc_server_file_extension_pdf INTO rv_path.
  252.   ENDMETHOD.
  253.  
  254.   METHOD send_to_server.
  255.     me->get_server_api( )->xstring_to_binary( iv_pdf_data )->send_to_server(
  256.       EXPORTING
  257.         iv_webservice_handler = me->get_web_handler( )
  258.         iv_server_path        = me->get_path( iv_key_data )
  259.     ).
  260.  
  261.   ENDMETHOD.
  262. ENDCLASS.
  263.  
  264. CLASS lcl_file_handler IMPLEMENTATION.
  265.   METHOD constructor.
  266. *    cdv_web_handler = iv_web_handler.
  267.   ENDMETHOD.
  268.  
  269.   METHOD get_instance.
  270.     CASE iv_file_type.
  271.       WHEN 'PDF'.
  272.         DATA(lv_name) = 'LCL_PDF_EXTENSION'.
  273.       WHEN 'XML'.
  274.         lv_name = 'LCL_XML_EXTENSION'.
  275.       WHEN OTHERS.
  276.     ENDCASE.
  277.  
  278.     ro_instance = lcl_file_extension=>get_instance(
  279.                   iv_name        = lv_name
  280.                   iv_web_handler = iv_web_handler
  281.               ).
  282.  
  283.   ENDMETHOD.
  284. ENDCLASS.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top