Universal ODATA Prototype Tester

Ooooh DATA, der Fiori Datenmotor
Alles zum Thema ODATA Gateway Services, CDS Views

Universal ODATA Prototype Tester

Postby Tron » Mon Sep 20, 2021 3:28 pm

Bugfix 28.09.2021 : Initial value for Date = '00000000'.

Moin.
Nach vielen Services, die schon erstellt habe, war eines meiner Ziele einen Web - unabhängigen Odata Prototyp Tester zu verwirklichen, da
1.) POST / PATCH / UPDATE Operationen im Gateway client nur mühsam bis gar nicht zu bedienen sind (Thema CSRF-Token).
2.) Eine Möglichkeit vorhanden ist, auch komplett ohne Frontend zu arbeiten und damit Web-seitige Fehlerquellen auszuschließen.
3.) Aufwendigeres RFC Debugging zu umgehen.

Möglich wird das durch die konfektionierten Funktionsbausteine und ihre einheitliche Schnittstelle.
siehe viewtopic.php?f=40&t=20631
e.g.
001.png
001.png (61.25 KiB) Viewed 115 times

Die Importparameter :
I_KEYS
I_SELECT_OPT
I_ORDER
I_SELECT_FIELDS
I_PAGING
Die Exportparameter :
O_DATA
O_MSG
so kann der Prototyp tester den Baustein dynamisch aufrufen.

000.png
000.png (33.91 KiB) Viewed 114 times

002.png
002.png (27.12 KiB) Viewed 114 times

Testwerte können gespeichert und wieder geladen werden (ähnlich Funktionsbaustein DB)
003.png
003.png (103.69 KiB) Viewed 114 times

die gelesenen Daten oder Messages werden auch gespeichert, wenn man will.

Das Programm:
004.png
004.png (26.34 KiB) Viewed 114 times


Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  ZODATA_TESTER
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8. REPORT zodata_tester.
  9. DATA: lt_fields TYPE STANDARD TABLE OF sval,
  10.       " ls_fields TYPE sval,
  11.       lv_rc     TYPE c.
  12. DATA g_struc TYPE  dd02l-tabname.
  13. DATA gv_ok_code(4).
  14.  
  15.   l_repid    TYPE syrepid,
  16.   lv_icon_ok TYPE icon-name,
  17.  
  18.   lv_button1 TYPE svalbutton-buttontext,
  19.   lv_icon1   TYPE icon-name,
  20.  
  21.   lv_button2 TYPE svalbutton-buttontext,
  22.   lv_icon2   TYPE icon-name.
  23.  
  24.  
  25.   <dyn_field> TYPE any,
  26.   <dyn_rec>   TYPE any,
  27.   <dyn_tab>   TYPE ANY TABLE.
  28.  
  29.   p_fm   TYPE tfdir-funcname OBLIGATORY,
  30.   p_keys TYPE dd02l-tabname,
  31.   p_path TYPE ibipparms-path OBLIGATORY VISIBLE LENGTH 40 DEFAULT 'C:\Temp\Odata_raw',
  32.   p_text AS CHECKBOX DEFAULT 'X',
  33.   p_pop  AS CHECKBOX DEFAULT 'X',
  34.   p_msg  AS CHECKBOX DEFAULT 'X',
  35.   p_dat  AS CHECKBOX DEFAULT 'X'.
  36.  
  37. IF p_keys IS INITIAL.
  38.   SELECT SINGLE structure FROM fupararef INTO p_keys WHERE
  39.     funcname  = p_fm AND
  40.     parameter = 'I_KEYS'.
  41.  
  42.  
  43. PERFORM f_fill_popup CHANGING p_keys p_text.
  44.  
  45. CALL FUNCTION 'POPUP_GET_VALUES_SET_MAX_FIELD'
  46.   EXPORTING
  47.     number_of_fields = 30
  48.   EXCEPTIONS
  49.     out_of_range     = 1.
  50.  
  51. lv_icon_ok  = icon_test.
  52.  
  53. lv_button1 = 'Save Test Data' ##NO_TEXT.
  54. lv_icon1   = icon_system_save.
  55.  
  56. lv_button2 = 'Read Test Data' ##NO_TEXT.
  57. lv_icon2   = icon_import.
  58.  
  59. l_repid = sy-repid.
  60.  
  61.  
  62.   CLEAR gv_ok_code.
  63.   CALL FUNCTION 'POPUP_GET_VALUES_USER_BUTTONS'
  64.     EXPORTING
  65. *     F1_FORMNAME       = ' '
  66. *     F1_PROGRAMNAME    = ' '
  67. *     F4_FORMNAME       = ' '
  68. *     F4_PROGRAMNAME    = ' '
  69.       formname          = 'ACTION'
  70.       programname       = l_repid
  71.       popup_title       = 'Please Enter'
  72.       ok_pushbuttontext = 'Execute'
  73.       icon_ok_push      = lv_icon_ok
  74.       first_pushbutton  = lv_button1
  75.       icon_button_1     = lv_icon1
  76.       second_pushbutton = lv_button2
  77.       icon_button_2     = lv_icon2
  78. *     QUICKINFO_OK_PUSH = ' '
  79. *     QUICKINFO_BUTTON_1              = ' '
  80. *     QUICKINFO_BUTTON_2              = ' '
  81.       start_column      = '2'
  82.       start_row         = '2'
  83. *     NO_CHECK_FOR_FIXED_VALUES       = ' '
  84.     IMPORTING
  85.       returncode        = lv_rc  "space/'A'=Abbruch
  86.     TABLES
  87.       fields            = lt_fields
  88.     EXCEPTIONS
  89.       error_in_fields   = 1
  90.       OTHERS            = 2.
  91.  
  92.   IF lv_rc  NE space OR sy-subrc NE 0.
  93.     EXIT.
  94.   ENDIF.
  95.  
  96.  
  97.  
  98.  
  99.  
  100. FORM f_fill_popup CHANGING i_struc TYPE dd02l-tabname i_names TYPE c.
  101.   DATA t_field_def TYPE TABLE OF rpy_fiel.
  102.   DATA s_def TYPE rpy_fiel.
  103.   DATA ls_fields TYPE sval.
  104.  
  105.  
  106.   CALL FUNCTION 'RPY_TABLE_READ'
  107.     EXPORTING
  108. *     ACTIVATION_TYPE_I     = 'M'
  109. *     LANGUAGE         = SY-LANGU
  110.       table_name       = i_struc
  111. *     WITH_DOCU        = ' '
  112. *     DOCUTYPE         = 'U'
  113. * IMPORTING
  114. *     TABL_INF         =
  115. *     TABL_TECHNICS    =
  116. *     ACTIVATION_TYPE_O     =
  117.     TABLES
  118.       tabl_fields      = t_field_def
  119. *     DOCU_TABLE_USER  =
  120. *     DOCU_TABLE_TECH  =
  121.     EXCEPTIONS
  122.       cancelled        = 1
  123.       not_found        = 2
  124.       permission_error = 3
  125.       illegal_type     = 4
  126.       OTHERS           = 5.
  127.  
  128.   IF sy-subrc <> 0.
  129.     EXIT.
  130.   ENDIF.
  131.  
  132.   LOOP AT  t_field_def INTO s_def ." WHERE dtelname NE 'MANDT'.
  133.     CLEAR ls_fields.
  134.     ls_fields-tabname   = i_struc.
  135.  
  136.     ls_fields-fieldname = s_def-fieldname.
  137.     IF s_def-datatype = 'DATS'.
  138.       ls_fields-value = '00000000'.
  139.     ELSE.
  140.       CLEAR ls_fields-value.
  141.     ENDIF.
  142.  
  143. *FIELD_ATTR
  144. *FIELD_OBL
  145. *COMP_CODE
  146.     "ls_fields-FIELDTEXT = s_def-SCRTEXT_M.
  147.     IF p_text IS INITIAL.
  148.       ls_fields-fieldtext = s_def-scrtext_m.
  149.     ELSE.
  150.       "    CONCATENATE s_def-dtelname  s_def-scrtext_m INTO ls_fields-fieldtext SEPARATED BY space.
  151.       ls_fields-fieldtext = s_def-fieldname.
  152.     ENDIF.
  153.  
  154.     "COMP_TAB = CHECKTABLE
  155.     "COMP_FIELD
  156.     ls_fields-novaluehlp = ' '.
  157.  
  158.     APPEND ls_fields TO lt_fields.
  159.  
  160.  
  161. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
  162.  
  163.   PERFORM f4_path.
  164.  
  165.   TYPES: BEGIN OF ty_info,
  166.            typ(1),
  167.            null(1),
  168.            line(120),
  169.          END OF ty_info.
  170.  
  171. * für autom. Variante DEFAULT laden
  172.   DATA:
  173.     l_report   TYPE raldb_repo ##NEEDED,
  174.     l_variante TYPE raldb_vari ##NEEDED,
  175.     t_info     TYPE TABLE OF ty_info ##NEEDED.
  176.  
  177. ** Load variant sy-uname
  178.   l_report   = sy-repid.
  179.   l_variante = sy-uname.
  180.  
  181.  
  182.   CALL FUNCTION 'RS_COVERPAGE_SELECTIONS'
  183.     EXPORTING
  184.       report  = l_report
  185.       variant = l_variante
  186.     TABLES
  187.       infotab = t_info
  188.     EXCEPTIONS
  189.       OTHERS  = 3 ##FM_SUBRC_OK.
  190.  
  191. *&---------------------------------------------------------------------*
  192. *&      Form  f4_path
  193. *&---------------------------------------------------------------------*
  194. FORM f4_path.
  195.  
  196. *== local data
  197.   DATA lv_out    TYPE string.
  198.   DATA lv_in     TYPE string.
  199.   DATA lt_fields TYPE TABLE OF dynpread.
  200.   DATA ls_field  TYPE dynpread.
  201.  
  202. *== get current value for path
  203.   ls_field = 'P_PATH'.
  204.   APPEND ls_field TO lt_fields.
  205.  
  206.   CALL FUNCTION 'DYNP_VALUES_READ'
  207.     EXPORTING
  208.       dyname     = sy-cprog
  209.       dynumb     = sy-dynnr
  210.     TABLES
  211.       dynpfields = lt_fields
  212.     EXCEPTIONS
  213.       OTHERS     = 1.
  214.  
  215.   IF sy-subrc = 0.
  216.     READ TABLE lt_fields INTO ls_field INDEX 1.
  217.     lv_in = ls_field-fieldvalue.
  218.   ENDIF.
  219.  
  220. *== call popup for directory selection
  221.   CALL METHOD cl_gui_frontend_services=>directory_browse
  222.     EXPORTING
  223.       initial_folder  = lv_in
  224.     CHANGING
  225.       selected_folder = lv_out
  226.     EXCEPTIONS
  227.       OTHERS          = 4.
  228.  
  229.   IF sy-subrc = 0 AND lv_out IS NOT INITIAL.
  230. *== set selected path
  231.     p_path = lv_out.
  232.   ELSE.
  233. *== set origin path
  234.     p_path = lv_in.
  235.   ENDIF.
  236.  
  237.  
  238.  
  239. FORM action TABLES  pt_fields STRUCTURE sval
  240.                               USING    p_code
  241.                               CHANGING p_error   STRUCTURE svale
  242.                                        p_show_popup.
  243.  
  244.   DATA lt_fields TYPE TABLE OF sval.
  245.   DATA ls_fields  TYPE sval.
  246.   FIELD-SYMBOLS <p> TYPE sval.
  247.  
  248.   gv_ok_code =  p_code.
  249.  
  250.   CASE p_code.
  251.  
  252. *   WRITE TEST data
  253.     WHEN 'COD1'.
  254.       PERFORM write_data TABLES pt_fields.
  255.  
  256.  
  257. *   Read TEST data
  258.     WHEN 'COD2'.
  259.       lt_fields[] = pt_fields[].
  260.       PERFORM read_data TABLES lt_fields.
  261.       LOOP AT pt_fields ASSIGNING <p>.
  262.         READ TABLE lt_fields INTO ls_fields WITH KEY tabname = <p>-tabname fieldname = <p>-fieldname.
  263.         IF sy-subrc = 0.
  264.           <p>-value = ls_fields-value.
  265.         ENDIF.
  266.       ENDLOOP.
  267.  
  268. *   Run FM
  269.     WHEN 'FURT'.
  270.       PERFORM call_fm TABLES pt_fields.
  271.  
  272.  
  273.  
  274.  
  275. FORM write_data TABLES pt_fields STRUCTURE sval.
  276.   DATA fn TYPE string.
  277.  
  278.   DATA l_tstamp(15) .
  279.   l_tstamp = sy-datum.
  280.   l_tstamp+8(1) = '_'.
  281.   l_tstamp+9 = sy-uzeit.
  282.  
  283.   CONCATENATE p_path '\' 'IKEY_' p_fm '~' g_struc '~' l_tstamp '.txt' INTO fn.
  284.  
  285.   CALL METHOD cl_gui_frontend_services=>gui_download
  286.     EXPORTING
  287. *     bin_filesize            =
  288.       filename                = fn
  289. *     filetype                = 'ASC'
  290. *     append                  = SPACE
  291. *     write_field_separator   = 'X'
  292. *     header                  = '00'
  293. *     trunc_trailing_blanks   = 'X'
  294. *     write_lf                = 'X'
  295. *     col_select              = SPACE
  296. *     col_select_mask         = SPACE
  297. *     dat_mode                = SPACE
  298. *     confirm_overwrite       = SPACE
  299. *     no_auth_check           = SPACE
  300. *     codepage                = SPACE
  301. *     ignore_cerr             = ABAP_TRUE
  302. *     replacement             = '#'
  303. *     write_bom               = SPACE
  304. *     trunc_trailing_blanks_eol = 'X'
  305. *     wk1_n_format            = SPACE
  306. *     wk1_n_size              = SPACE
  307. *     wk1_t_format            = SPACE
  308. *     wk1_t_size              = SPACE
  309. *     show_transfer_status    = 'X'
  310. *     fieldnames              =
  311. *     write_lf_after_last_line  = 'X'
  312. *     virus_scan_profile      = '/SCET/GUI_DOWNLOAD'
  313. *  IMPORTING
  314. *     filelength              =
  315.     CHANGING
  316.       data_tab                = pt_fields[]
  317.     EXCEPTIONS
  318.       file_write_error        = 1
  319.       no_batch                = 2
  320.       gui_refuse_filetransfer = 3
  321.       invalid_type            = 4
  322.       no_authority            = 5
  323.       unknown_error           = 6
  324.       header_not_allowed      = 7
  325.       separator_not_allowed   = 8
  326.       filesize_not_allowed    = 9
  327.       header_too_long         = 10
  328.       dp_error_create         = 11
  329.       dp_error_send           = 12
  330.       dp_error_write          = 13
  331.       unknown_dp_error        = 14
  332.       access_denied           = 15
  333.       dp_out_of_memory        = 16
  334.       disk_full               = 17
  335.       dp_timeout              = 18
  336.       file_not_found          = 19
  337.       dataprovider_exception  = 20
  338.       control_flush_error     = 21
  339.       not_supported_by_gui    = 22
  340.       error_no_gui            = 23
  341.       OTHERS                  = 24.
  342.   .
  343.   IF sy-subrc <> 0.
  344. * Implement suitable error handling here
  345.   ENDIF.
  346.  
  347.  
  348.  
  349. FORM read_data TABLES pt_fields STRUCTURE sval.
  350.   DATA:
  351.     filetable         TYPE filetable,
  352.     file_line         TYPE file_table,
  353.     window_title      TYPE string VALUE 'Select',
  354.     file_filter       TYPE string,
  355.     initial_directory TYPE string,
  356.     rc                TYPE i,
  357.     fn                TYPE string.
  358.  
  359.  
  360.   file_filter             = 'Odata Input (IKEY*.txt)|IKEY*.txt'.
  361.   initial_directory = p_path.
  362.  
  363.   CALL METHOD cl_gui_frontend_services=>file_open_dialog
  364.     EXPORTING
  365.       window_title            = window_title
  366. *     default_extension       =
  367. *     default_filename        =
  368.       file_filter             = file_filter
  369. *     with_encoding           =
  370.       initial_directory       = initial_directory
  371.       multiselection          = abap_false
  372.     CHANGING
  373.       file_table              = filetable
  374.       rc                      = rc
  375. *     user_action             =
  376. *     file_encoding           =
  377.     EXCEPTIONS
  378.       file_open_dialog_failed = 1
  379.       cntl_error              = 2
  380.       error_no_gui            = 3
  381.       not_supported_by_gui    = 4
  382.       OTHERS                  = 5.
  383.   IF sy-subrc <> 0 OR rc = 0.
  384.     EXIT.
  385.   ENDIF.
  386.  
  387.   LOOP AT filetable INTO file_line.
  388.     EXIT.
  389.  
  390.   fn = file_line.
  391.   CALL METHOD cl_gui_frontend_services=>gui_upload
  392.     EXPORTING
  393.       filename                = fn
  394. *     filetype                = 'ASC'
  395. *     has_field_separator     = SPACE
  396. *     header_length           = 0
  397. *     read_by_line            = 'X'
  398. *     dat_mode                = SPACE
  399. *     codepage                = SPACE
  400. *     ignore_cerr             = ABAP_TRUE
  401. *     replacement             = '#'
  402. *     virus_scan_profile      =
  403. *  IMPORTING
  404. *     filelength              =
  405. *     header                  =
  406.     CHANGING
  407.       data_tab                = pt_fields[]
  408. *     isscanperformed         = SPACE
  409.     EXCEPTIONS
  410.       file_open_error         = 1
  411.       file_read_error         = 2
  412.       no_batch                = 3
  413.       gui_refuse_filetransfer = 4
  414.       invalid_type            = 5
  415.       no_authority            = 6
  416.       unknown_error           = 7
  417.       bad_data_format         = 8
  418.       header_not_allowed      = 9
  419.       separator_not_allowed   = 10
  420.       header_too_long         = 11
  421.       unknown_dp_error        = 12
  422.       access_denied           = 13
  423.       dp_out_of_memory        = 14
  424.       disk_full               = 15
  425.       dp_timeout              = 16
  426.       not_supported_by_gui    = 17
  427.       error_no_gui            = 18
  428.       OTHERS                  = 19.
  429.   IF sy-subrc <> 0.
  430.   ENDIF.
  431.  
  432. *&---------------------------------------------------------------------*
  433. *&      Form  create Structure dynamically
  434. *&---------------------------------------------------------------------*
  435. *       text
  436. *----------------------------------------------------------------------*
  437. FORM create_itab USING i_tdef TYPE dd02l-tabname .
  438.  
  439.   DATA:
  440.     l_ref_type_descr_ddic   TYPE REF TO cl_abap_typedescr,
  441.     l_ref_type_descr_line   TYPE REF TO cl_abap_typedescr,
  442.     l_ref_struct_descr_line TYPE REF TO cl_abap_structdescr,
  443.     l_tab_component         TYPE        cl_abap_structdescr=>component_table.
  444.  
  445.   DATA:
  446.     lop_tabledescr    TYPE REF TO cl_abap_tabledescr,
  447.     ldp_dynaic_record TYPE REF TO data,
  448.     ldp_dyn_table     TYPE REF TO data,
  449.     lop_strucdescr    TYPE REF TO cl_abap_structdescr.
  450.  
  451.  
  452.   l_ref_type_descr_ddic = cl_abap_typedescr=>describe_by_name( i_tdef ).
  453.   l_ref_struct_descr_line ?= l_ref_type_descr_ddic.
  454.   l_tab_component = l_ref_struct_descr_line->get_components( ).
  455.  
  456.   lop_strucdescr = cl_abap_structdescr=>create( l_tab_component ).
  457.   CREATE DATA ldp_dynaic_record TYPE HANDLE lop_strucdescr.
  458.  
  459.   lop_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = lop_strucdescr ).
  460.   CREATE DATA ldp_dyn_table TYPE HANDLE lop_tabledescr.
  461.  
  462.   ASSIGN ldp_dynaic_record->* TO <dyn_rec>.
  463.   ASSIGN ldp_dyn_table->* TO <dyn_tab>.
  464.  
  465.  
  466.  
  467. FORM create_itab2 USING i_tdef TYPE dd02l-tabname .
  468.   DATA t_field_def TYPE TABLE OF rpy_fiel.
  469.   DATA s_field_def TYPE rpy_fiel.
  470.  
  471.  
  472.   UNASSIGN:
  473.     <dyn_field>,
  474.     <dyn_rec>,
  475.     <dyn_tab>.
  476.  
  477.   CALL FUNCTION 'RPY_TABLE_READ'
  478.     EXPORTING
  479.       table_name       = i_tdef
  480.     TABLES
  481.       tabl_fields      = t_field_def
  482.     EXCEPTIONS
  483.       cancelled        = 1
  484.       not_found        = 2
  485.       permission_error = 3
  486.       illegal_type     = 4
  487.       OTHERS           = 5.
  488.  
  489.   IF sy-subrc <> 0.
  490.     EXIT.
  491.   ENDIF.
  492.  
  493.   DATA:
  494.     ldp_dyn_table     TYPE REF TO data,
  495.     lop_tabledescr    TYPE REF TO cl_abap_tabledescr,
  496.     ldp_dynaic_record TYPE REF TO data,
  497.     lop_strucdescr    TYPE REF TO cl_abap_structdescr,
  498.     ls_component      TYPE abap_componentdescr,
  499.     lt_component      TYPE abap_component_tab.
  500.  
  501.   DATA l_field_length   TYPE i.
  502.   DATA l_decimals   TYPE i.
  503.   DATA fields TYPE  rfc_db_fld.
  504.   DATA lv_int1 TYPE int1.
  505.   DATA lv_int2 TYPE int2.
  506.   DATA lv_int4 TYPE int4.
  507.  
  508. *FIELDNAME                      OFFSET LENGTH T FIELDTEXT
  509. *MANDT                          000000 000003 C
  510. *MATNR                          000003 000018 C
  511. *SPRAS                          000021 000002 C
  512. *MAKTX                          000023 000040 C
  513. *MAKTG                          000063 000040 C
  514.  
  515. *  LOOP AT tfields INTO fields.
  516. *    READ TABLE t_field_def INTO s_field_def WITH KEY fieldname = fields-fieldname.
  517.   LOOP AT t_field_def INTO s_field_def.
  518.     IF sy-subrc = 0.
  519.  
  520. * Create Description
  521. *      "IF NOT c_head IS INITIAL.
  522. *        MOVE-CORRESPONDING s_field_def TO ls_hdr.
  523. *        APPEND ls_hdr TO lt_hdr.
  524. *      "ENDIF.
  525.  
  526.       CASE s_field_def-datatype.
  527.         WHEN 'CHAR' OR 'UNIT' OR 'CUKY' OR 'CLNT'
  528. .         l_field_length = s_field_def-length.
  529.           ls_component-name = s_field_def-fieldname.
  530.           ls_component-type = cl_abap_elemdescr=>get_c( p_length = l_field_length ).
  531.           APPEND ls_component TO lt_component.
  532.  
  533.         WHEN 'LANG'.
  534.           l_field_length = s_field_def-length.
  535.           ls_component-name = s_field_def-fieldname.
  536.           ls_component-type = cl_abap_elemdescr=>get_c( p_length = l_field_length ).
  537.           APPEND ls_component TO lt_component.
  538.  
  539.         WHEN 'DEC' OR 'QUAN' OR 'CURR'.
  540.           l_field_length = s_field_def-intlength
  541. .           l_decimals = s_field_def-decimals.
  542.           ls_component-name = s_field_def-fieldname.
  543.           ls_component-type = cl_abap_elemdescr=>get_p( p_length = l_field_length  p_decimals = l_decimals ).
  544.           APPEND ls_component TO lt_component.
  545.  
  546.         WHEN 'NUMC'.
  547.           l_field_length = s_field_def-length.
  548.           ls_component-name = s_field_def-fieldname.
  549.           ls_component-type = cl_abap_elemdescr=>get_n( p_length = l_field_length ).
  550.           APPEND ls_component TO lt_component.
  551.  
  552.         WHEN 'INT1' OR 'INT2' OR 'INT4'.
  553.  
  554.           ls_component-name = s_field_def-fieldname.
  555.  
  556.           IF s_field_def-datatype = 'INT1'.
  557.             ls_component-type ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int1 ).
  558.           ELSEIF  s_field_def-datatype = 'INT2'.
  559.             ls_component-type ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int2 ).
  560.           ELSEIF  s_field_def-datatype = 'INT4'.
  561.             ls_component-type ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int4 ).
  562.           ENDIF.
  563.  
  564.           APPEND ls_component TO lt_component.
  565.  
  566.         WHEN 'DATS'.
  567.           l_field_length = s_field_def-length.
  568.           ls_component-name = s_field_def-fieldname.
  569.           ls_component-type = cl_abap_elemdescr=>get_d( ).
  570.           APPEND ls_component TO lt_component.
  571.  
  572.         WHEN 'TIMS'.
  573.           l_field_length = s_field_def-length.
  574.           ls_component-name = s_field_def-fieldname.
  575.           ls_component-type = cl_abap_elemdescr=>get_t( ).
  576.           APPEND ls_component TO lt_component.
  577.  
  578.         WHEN OTHERS.
  579.           break jgu025.
  580.           l_field_length = s_field_def-length.
  581.           ls_component-name = s_field_def-fieldname.
  582.           ls_component-type = cl_abap_elemdescr=>get_c( p_length = l_field_length ).
  583.           APPEND ls_component TO lt_component.
  584.  
  585.       ENDCASE.
  586.     ENDIF.
  587.  
  588.  
  589.  
  590.   lop_strucdescr = cl_abap_structdescr=>create( lt_component ).
  591.   CREATE DATA ldp_dynaic_record TYPE HANDLE lop_strucdescr.
  592.   lop_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = lop_strucdescr ).
  593.  
  594.   CREATE DATA ldp_dyn_table TYPE HANDLE lop_tabledescr.
  595.  
  596.   ASSIGN ldp_dynaic_record->* TO <dyn_rec>.
  597.   ASSIGN ldp_dyn_table->* TO <dyn_tab>.
  598.  
  599.  
  600.  
  601.  
  602. FORM write_msg USING i_msg TYPE bapirettab.
  603.   DATA fn TYPE string.
  604.  
  605.   DATA l_tstamp(15) .
  606.   l_tstamp = sy-datum.
  607.   l_tstamp+8(1) = '_'.
  608.   l_tstamp+9 = sy-uzeit.
  609.  
  610.   CONCATENATE p_path '\' 'MSG_' p_fm '~'  l_tstamp '.txt' INTO fn.
  611.  
  612.   CALL METHOD cl_gui_frontend_services=>gui_download
  613.     EXPORTING
  614.       filename                = fn
  615.     CHANGING
  616.       data_tab                = i_msg[]
  617.     EXCEPTIONS
  618.       file_write_error        = 1
  619.       no_batch                = 2
  620.       gui_refuse_filetransfer = 3
  621.       invalid_type            = 4
  622.       no_authority            = 5
  623.       unknown_error           = 6
  624.       header_not_allowed      = 7
  625.       separator_not_allowed   = 8
  626.       filesize_not_allowed    = 9
  627.       header_too_long         = 10
  628.       dp_error_create         = 11
  629.       dp_error_send           = 12
  630.       dp_error_write          = 13
  631.       unknown_dp_error        = 14
  632.       access_denied           = 15
  633.       dp_out_of_memory        = 16
  634.       disk_full               = 17
  635.       dp_timeout              = 18
  636.       file_not_found          = 19
  637.       dataprovider_exception  = 20
  638.       control_flush_error     = 21
  639.       not_supported_by_gui    = 22
  640.       error_no_gui            = 23
  641.       OTHERS                  = 24.
  642.   .
  643.   IF sy-subrc <> 0.
  644. * Implement suitable error handling here
  645.   ENDIF.
  646.  
  647.  
  648.  
  649. FORM write_odata .
  650.   DATA fn TYPE string.
  651.  
  652.   DATA l_tstamp(15) .
  653.   l_tstamp = sy-datum.
  654.   l_tstamp+8(1) = '_'.
  655.   l_tstamp+9 = sy-uzeit.
  656.  
  657.   CONCATENATE p_path '\' 'ODATA_' p_fm '~' l_tstamp '.txt' INTO fn.
  658.  
  659.   CALL METHOD cl_gui_frontend_services=>gui_download
  660.     EXPORTING
  661.       filename                = fn
  662. *     filetype                = 'ASC'
  663. *     append                  = SPACE
  664.       write_field_separator   = 'X'
  665. *     header                  = '00'
  666.       trunc_trailing_blanks   = 'X'
  667. *     write_lf                = 'X'
  668. *     col_select              = SPACE
  669. *     col_select_mask         = SPACE
  670. *     dat_mode                = SPACE
  671. *     confirm_overwrite       = SPACE
  672. *     no_auth_check           = SPACE
  673. *     codepage                = SPACE
  674. *     ignore_cerr             = ABAP_TRUE
  675. *     replacement             = '#'
  676. *     write_bom               = SPACE
  677. *     trunc_trailing_blanks_eol = 'X'
  678. *     wk1_n_format            = SPACE
  679. *     wk1_n_size              = SPACE
  680. *     wk1_t_format            = SPACE
  681. *     wk1_t_size              = SPACE
  682. *     show_transfer_status    = 'X'
  683. *     fieldnames              =
  684. *     write_lf_after_last_line  = 'X'
  685. *     virus_scan_profile      = '/SCET/GUI_DOWNLOAD'
  686.     CHANGING
  687.       data_tab                = <dyn_tab>[]
  688.     EXCEPTIONS
  689.       file_write_error        = 1
  690.       no_batch                = 2
  691.       gui_refuse_filetransfer = 3
  692.       invalid_type            = 4
  693.       no_authority            = 5
  694.       unknown_error           = 6
  695.       header_not_allowed      = 7
  696.       separator_not_allowed   = 8
  697.       filesize_not_allowed    = 9
  698.       header_too_long         = 10
  699.       dp_error_create         = 11
  700.       dp_error_send           = 12
  701.       dp_error_write          = 13
  702.       unknown_dp_error        = 14
  703.       access_denied           = 15
  704.       dp_out_of_memory        = 16
  705.       disk_full               = 17
  706.       dp_timeout              = 18
  707.       file_not_found          = 19
  708.       dataprovider_exception  = 20
  709.       control_flush_error     = 21
  710.       not_supported_by_gui    = 22
  711.       error_no_gui            = 23
  712.       OTHERS                  = 24.
  713.   .
  714.   IF sy-subrc <> 0.
  715. * Implement suitable error handling here
  716.   ENDIF.
  717.  
  718.  
  719.  
  720.  
  721.  
  722. FORM call_fm TABLES pt_fields STRUCTURE sval.
  723.   "p_fm
  724.   DATA l_fm TYPE rs38l-name.
  725.   DATA s_sval TYPE sval.
  726.   DATA o_msg_tt TYPE  bapirettab.
  727.   DATA o_msg_s TYPE  bapiret2.
  728.   DATA lmsg_type TYPE fupararef-structure.
  729.  
  730.  
  731.   l_fm = p_fm.
  732.  
  733.   CALL FUNCTION 'FUNCTION_EXISTS'
  734.     EXPORTING
  735.       funcname           = l_fm
  736.     EXCEPTIONS
  737.       function_not_exist = 1
  738.       OTHERS             = 2.
  739.   .
  740.   IF sy-subrc <> 0.
  741.     MESSAGE s500(0u) WITH 'Function module does NOT Exist' '' '' '' DISPLAY LIKE 'E'.
  742.     EXIT.
  743.   ENDIF.
  744.  
  745.   PERFORM create_itab USING p_keys.
  746.  
  747.   DATA i TYPE i.
  748.  
  749.   LOOP AT pt_fields INTO s_sval.
  750.     i = sy-tabix.
  751.     ASSIGN COMPONENT i OF STRUCTURE  <dyn_rec> TO <dyn_field>.
  752.     <dyn_field> = s_sval-value.
  753.  
  754.   DATA s_para TYPE fupararef.
  755.  
  756.   i = 0.
  757.   CLEAR s_para.
  758.   SELECT SINGLE * FROM fupararef INTO s_para WHERE
  759.     funcname = l_fm AND
  760.     parameter = 'I_KEYS' AND
  761.     paramtype = 'I'.
  762.   IF NOT s_para IS INITIAL.
  763.     i = 1.
  764.   ENDIF.
  765.  
  766.   CLEAR s_para.
  767.   SELECT SINGLE * FROM fupararef INTO s_para WHERE
  768.     funcname = l_fm AND
  769.     parameter = 'O_DATA' AND paramtype = 'E'.
  770.   IF NOT s_para IS INITIAL.
  771.     i = i + 2.
  772.   ENDIF.
  773.  
  774.   CLEAR: s_para,lmsg_type.
  775.   SELECT SINGLE * FROM fupararef INTO s_para WHERE
  776.     funcname = l_fm AND
  777.     parameter = 'O_MSG' AND paramtype = 'E'.
  778.   IF NOT s_para IS INITIAL.
  779.     SELECT SINGLE COUNT(*) FROM dd40l WHERE typename = s_para-structure.
  780.     IF sy-subrc = 0.
  781.       lmsg_type = 'TTYP'.
  782.     ENDIF.
  783.     SELECT SINGLE COUNT(*) FROM dd02l WHERE tabname = s_para-structure.
  784.     IF sy-subrc = 0.
  785.       lmsg_type = 'STRU'.
  786.     ENDIF.
  787.  
  788.     i = i + 4.
  789.   ENDIF.
  790.  
  791.  
  792.   CASE i.
  793.     WHEN 1.
  794.       CALL FUNCTION l_fm
  795.         EXPORTING
  796.           i_keys = <dyn_rec>.
  797.  
  798.     WHEN 3.
  799.       CALL FUNCTION l_fm
  800.         EXPORTING
  801.           i_keys = <dyn_rec>
  802.         IMPORTING
  803.           o_data = <dyn_tab>.
  804.       IF NOT p_dat IS INITIAL.
  805.         PERFORM write_odata.
  806.       ENDIF.
  807.  
  808.  
  809.     WHEN 5.
  810.       IF lmsg_type = 'TTYP'.
  811.         CALL FUNCTION l_fm
  812.           EXPORTING
  813.             i_keys = <dyn_rec>
  814.           IMPORTING
  815.             o_msg  = o_msg_tt.
  816.         IF NOT p_msg IS INITIAL.
  817.           PERFORM write_msg USING o_msg_tt.
  818.         ENDIF.
  819.       ENDIF.
  820.  
  821.       IF lmsg_type = 'STRU'.
  822.         CALL FUNCTION l_fm
  823.           EXPORTING
  824.             i_keys = <dyn_rec>
  825.           IMPORTING
  826.             o_msg  = o_msg_s.
  827.         IF NOT p_msg IS INITIAL.
  828.           APPEND o_msg_s TO o_msg_tt.
  829.           PERFORM write_msg USING o_msg_tt.
  830.         ENDIF.
  831.       ENDIF.
  832.  
  833.     WHEN 7.
  834.       IF lmsg_type = 'TTYP'.
  835.         CALL FUNCTION l_fm
  836.           EXPORTING
  837.             i_keys = <dyn_rec>
  838.           IMPORTING
  839.             o_data = <dyn_tab>
  840.             o_msg  = o_msg_tt.
  841.         IF NOT p_msg IS INITIAL.
  842.           PERFORM write_msg USING o_msg_tt.
  843.         ENDIF.
  844.       ENDIF.
  845.  
  846.       IF lmsg_type = 'STRU'.
  847.         CALL FUNCTION l_fm
  848.           EXPORTING
  849.             i_keys = <dyn_rec>
  850.           IMPORTING
  851.             o_data = <dyn_tab>
  852.             o_msg  = o_msg_s.
  853.         IF NOT p_msg IS INITIAL.
  854.           APPEND o_msg_s TO o_msg_tt.
  855.           PERFORM write_msg USING o_msg_tt.
  856.         ENDIF.
  857.       ENDIF.
  858.  
  859.     WHEN OTHERS.
  860.  
  861. *  p_msg  AS CHECKBOX DEFAULT 'X',
  862. *  p_dat  AS CHECKBOX DEFAULT 'X'.
  863.  
  864.   IF NOT p_pop IS INITIAL AND NOT <dyn_tab> IS INITIAL.
  865.     cl_demo_output=>display( <dyn_tab> ).
  866.   ENDIF.
  867.  
  868. AT SELECTION-SCREEN ON p_fm.
  869.  
  870.   IF p_keys IS INITIAL.
  871.     SELECT SINGLE structure FROM fupararef INTO p_keys WHERE
  872.       funcname  = p_fm AND
  873.       parameter = 'I_KEYS'.
  874.  
  875.  
  876.   ENDIF.
GeSHi ©

ZODATA_TESTER.7z
(4.89 KiB) Downloaded 7 times
Tron
.....
.....
 
Posts: 1104
Joined: Sat Aug 04, 2007 10:21 pm

Return to ODATA Gateway Services

Who is online

Users browsing this forum: No registered users and 1 guest

cron
  • Latest Topics