create and Save SO10 text in Transport request through program

Text File contents:

2021 Paid Holiday & Break Schedule – January
New Year’s Day 2021 Friday, January 1, 2021
Sankranti Thursday, January 14, 2021
Republic Day Tuesday, January 26, 2021

Source Code:

DATA : _t_datatab      TYPE table_of_strings,
       _t_texts        TYPE STANDARD TABLE OF tline,
       _thead          TYPE thead,
       _text_obj_name  TYPE thead-tdname,
       _text           TYPE as4text,
       _request_header TYPE trwbo_request_header,
       _t_task_headers TYPE trwbo_request_headers,
       _t_e071         TYPE TABLE OF e071,
       _t_e071k        TYPE TABLE OF e071k,
       _s_e071         TYPE e071,
       _t_users        TYPE scts_users.

SELECTION-SCREEN BEGIN OF BLOCK sel1 WITH FRAME TITLE TEXT-t01.
PARAMETERS : p_txtnm  TYPE thead-tdname MODIF ID m2,
             p_fltokn TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK sel1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fltokn.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FLTOKN'
    IMPORTING
      file_name  = p_fltokn.

START-OF-SELECTION.

* Upload the Text File - SO10 Text
  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = CONV #( p_fltokn )
      filetype                = 'ASC'
    CHANGING
      data_tab                = _t_datatab
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      not_supported_by_gui    = 17
      error_no_gui            = 18
      OTHERS                  = 19.
  IF sy-subrc IS INITIAL.
    LOOP AT _t_datatab ASSIGNING FIELD-SYMBOL(<fs_datatab>).
      _t_texts = VALUE #( BASE _t_texts ( tdformat = '*' tdline = <fs_datatab> ) ).
    ENDLOOP.
  ENDIF.

* Create Text
  _text_obj_name = p_txtnm.
  _thead-tdid = 'ST'.
  _thead-tdspras = 'E'.
  CALL FUNCTION 'CREATE_TEXT'
    EXPORTING
      fid       = _thead-tdid
      flanguage = _thead-tdspras
      fname     = _text_obj_name
      fobject   = 'TEXT'
    TABLES
      flines    = _t_texts
    EXCEPTIONS
      no_init   = 1
      no_save   = 2
      OTHERS    = 3.
  IF sy-subrc IS INITIAL.

* TR Author
    _t_users = VALUE #( BASE _t_users ( user = sy-uname ) ).
* TR Description
    _text = |{ 'Text Object:' } { _text_obj_name }|.

* Create TR
    CALL FUNCTION 'TR_INSERT_REQUEST_WITH_TASKS'
      EXPORTING
        iv_type           = 'K'
        iv_text           = _text
        iv_owner          = sy-uname
        it_users          = _t_users
      IMPORTING
        es_request_header = _request_header
        et_task_headers   = _t_task_headers
      EXCEPTIONS
        insert_failed     = 1
        enqueue_failed    = 2
        OTHERS            = 3.
    IF sy-subrc IS INITIAL AND _request_header-trkorr IS NOT INITIAL AND _t_task_headers[] IS NOT INITIAL.

* Commit CREATE_TEXT - If TR created successfully
      COMMIT WORK.

      REFRESH : _t_e071, _t_e071k[].
      CLEAR : _s_e071.
      _s_e071-obj_name = _text_obj_name.
      ASSIGN _t_task_headers[ 1 ] TO FIELD-SYMBOL(<fs_task_headers>).
      IF <fs_task_headers> IS ASSIGNED.
        DO 2 TIMES.
          SELECT SINGLE * FROM e070 INTO @DATA(_s_e070) WHERE trkorr EQ @<fs_task_headers>-trkorr.
          IF sy-subrc IS INITIAL.
            EXIT.
          ELSE.
            WAIT UP TO 1 SECONDS.
          ENDIF.
        ENDDO.

* If Subtask is Unclassified - Then change it to Development/Correction
        IF _s_e070-trfunction EQ 'X'.	"Unclassified Task
          CALL FUNCTION 'TRINT_CHANGE_TRFUNCTION'
            EXPORTING
              iv_new_trfunction      = 'S'
            CHANGING
              cs_request_header      = <fs_task_headers>
            EXCEPTIONS
              action_aborted_by_user = 1
              change_not_allowed     = 2
              db_access_error        = 3
              OTHERS                 = 4.
          IF sy-subrc IS INITIAL.
            COMMIT WORK.
          ENDIF.
        ENDIF.

* E071 Details
        _s_e071-trkorr   = <fs_task_headers>-trkorr.
        _s_e071-as4pos   = 0.
        _s_e071-pgmid    = 'R3TR'.
        _s_e071-object   = 'TEXT'.
        _s_e071-obj_name = |{ 'TEXT' }{ ',' }{ _text_obj_name }{ ',' }{ _thead-tdid }{ ',' }{ _thead-tdspras }|.
        APPEND _s_e071 TO _t_e071.
        CLEAR : _s_e071.

* Assign Text Object to TR
        CALL FUNCTION 'TR_APPEND_TO_COMM_OBJS_KEYS'
          EXPORTING
            wi_trkorr                      = <fs_task_headers>-trkorr
          TABLES
            wt_e071                        = _t_e071
            wt_e071k                       = _t_e071k
          EXCEPTIONS
            key_char_in_non_char_field     = 1
            key_check_keysyntax_error      = 2
            key_inttab_table               = 3
            key_longer_field_but_no_generc = 4
            key_missing_key_master_fields  = 5
            key_missing_key_tablekey       = 6
            key_non_char_but_no_generic    = 7
            key_no_key_fields              = 8
            key_string_longer_char_key     = 9
            key_table_has_no_fields        = 10
            key_table_not_activ            = 11
            key_unallowed_key_function     = 12
            key_unallowed_key_object       = 13
            key_unallowed_key_objname      = 14
            key_unallowed_key_pgmid        = 15
            key_without_header             = 16
            ob_check_obj_error             = 17
            ob_devclass_no_exist           = 18
            ob_empty_key                   = 19
            ob_generic_objectname          = 20
            ob_ill_delivery_transport      = 21
            ob_ill_lock                    = 22
            ob_ill_parts_transport         = 23
            ob_ill_source_system           = 24
            ob_ill_system_object           = 25
            ob_ill_target                  = 26
            ob_inttab_table                = 27
            ob_local_object                = 28
            ob_locked_by_other             = 29
            ob_modif_only_in_modif_order   = 30
            ob_name_too_long               = 31
            ob_no_append_of_corr_entry     = 32
            ob_no_append_of_c_member       = 33
            ob_no_consolidation_transport  = 34
            ob_no_original                 = 35
            ob_no_shared_repairs           = 36
            ob_no_systemname               = 37
            ob_no_systemtype               = 38
            ob_no_tadir                    = 39
            ob_no_tadir_not_lockable       = 40
            ob_privat_object               = 41
            ob_repair_only_in_repair_order = 42
            ob_reserved_name               = 43
            ob_syntax_error                = 44
            ob_table_has_no_fields         = 45
            ob_table_not_activ             = 46
            tr_enqueue_failed              = 47
            tr_errors_in_error_table       = 48
            tr_ill_korrnum                 = 49
            tr_lockmod_failed              = 50
            tr_lock_enqueue_failed         = 51
            tr_not_owner                   = 52
            tr_no_systemname               = 53
            tr_no_systemtype               = 54
            tr_order_not_exist             = 55
            tr_order_released              = 56
            tr_order_update_error          = 57
            tr_wrong_order_type            = 58
            ob_invalid_target_system       = 59
            tr_no_authorization            = 60
            ob_wrong_tabletyp              = 61
            ob_wrong_category              = 62
            ob_system_error                = 63
            ob_unlocal_objekt_in_local_ord = 64
            tr_wrong_client                = 65
            ob_wrong_client                = 66
            key_wrong_client               = 67
            OTHERS                         = 68.
        IF sy-subrc IS INITIAL.
          MESSAGE i398(00) WITH 'Text object: ' _text_obj_name 'created with TR:' _request_header-trkorr.
        ELSE.
          MESSAGE s208(00) WITH 'Text object not attached to Transport Request' DISPLAY LIKE 'E'.
          LEAVE LIST-PROCESSING.
        ENDIF.
      ENDIF.
    ELSE.
      MESSAGE s208(00) WITH 'Error: Transport Request not created' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
    ENDIF.
  ELSE.
    MESSAGE s208(00) WITH 'Error: Text Object not created' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.

Output:

Transport Request:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s