Adding Picture in Report – No Screen use.. both on selection screen and on the report pages

REPORT zdyb11.

* START OF DO NOT CHANGE***********************************
DATA: docking TYPE REF TO cl_gui_docking_container,
picture_control_1 TYPE REF TO cl_gui_picture,
url(256) TYPE c .
DATA: query_table LIKE w3query OCCURS 1 WITH HEADER LINE,
html_table LIKE w3html OCCURS 1,
return_code LIKE w3param-ret_code,
content_type LIKE w3param-cont_type,
content_length LIKE w3param-cont_len,
pic_data LIKE w3mime OCCURS 0,
pic_size TYPE i.
* END OF DO NOT CHANGE*************************************
DATA : sum(4) , num1(4) , num2(4).
PARAMETERS: p_dummy(4) DEFAULT ‘4’ .
PARAMETERS: p_dummy1(4) DEFAULT ‘5’ .
AT SELECTION-SCREEN OUTPUT.
PERFORM show_pic. “” Sets on Selction Screen …
START-OF-SELECTION.
write:/’111′.

PERFORM show_pic.
*&——————————————————————-
*& Form show_pic
*&——————————————————————-
FORM show_pic.
DATA: repid LIKE sy-repid.
” Set URI here…

url =’http://sdsd.gif’.
repid = sy-repid.
CREATE OBJECT picture_control_1 EXPORTING parent = docking.
CHECK sy-subrc = 0.
* CALL METHOD picture_control_1->set_3d_border
* EXPORTING
* border = 5.
CALL METHOD picture_control_1->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_stretch.
CALL METHOD picture_control_1->set_position
EXPORTING
height = 70
left = 600
top = 0
width = 700.
*CHANGE POSITION AND SIZE ABOVE***************************
IF url IS INITIAL.
REFRESH query_table.
query_table-name = ‘_OBJECT_ID’.
*CHANGE IMAGE NAME BELOW UPLOADED IN SWO0******************
query_table-value = ‘BIKER’.
APPEND query_table.
CALL FUNCTION ‘WWW_GET_MIME_OBJECT’
TABLES
query_string = query_table
html = html_table
mime = pic_data
CHANGING
return_code = return_code
content_type = content_type
content_length = content_length
EXCEPTIONS
object_not_found = 1
parameter_not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION ‘DP_CREATE_URL’
EXPORTING
type = ‘image’
subtype = cndp_sap_tab_unknown
size = pic_size
lifetime = cndp_lifetime_transaction
TABLES
data = pic_data
CHANGING
url = url
EXCEPTIONS
OTHERS = 1.
ENDIF.
CALL METHOD picture_control_1->load_picture_from_url
EXPORTING
url = url.
*Syntax for URL

*url = ‘file://D:\corp-gbanerji\pickut\cartoon_184.gif’.
*url = ‘http://l.yimg.com/a/i/ww/beta/y3.gif&#8217;.
ENDFORM. “show_pic

 

 

 

******************

CALL METHOD picture_control_1->set_position
EXPORTING
height = 60
left = 100
top = 20
width = 200.
*CHANGE POSITION AND SIZE ABOVE***************************
IF url IS INITIAL.
REFRESH query_table.
query_table-name = ‘_OBJECT_ID’.
*CHANGE IMAGE NAME BELOW UPLOADED IN SWO0******************
query_table-value = ‘ZLOGO’.
APPEND query_table.

Unicode Translate structure to String and back

CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
im_value = i_tmp
IMPORTING
ex_container = temp_temp
EXCEPTIONS
illegal_parameter_type = 1
others = 2 .
IF sy-subrc eq 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

translate temp_temp using ‘| ‘. “remove |

CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>READ_CONTAINER_C
EXPORTING
IM_CONTAINER = temp_temp
IMPORTING
EX_VALUE = i_tmp
EXCEPTIONS
ILLEGAL_PARAMETER_TYPE = 1
others = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

File aid

REPORT ZFARPAID.
DATA: LINE1(300),HEAD(300),TAIL(300),REC01(300),REC02(300).
INCLUDE ZFARP_WALLACE_TOP.
INCLUDE <LINE>.
parameters: FNAME LIKE FILENAME-FILEEXTERN.

PARAMETERS: start TYPE i DEFAULT 1.
PARAMETERS: end TYPE i DEFAULT 200.

DATA: n TYPE i.

DATA FNAME2 LIKE FILENAME-FILEEXTERN.
INITIALIZATION.

START-OF-SELECTION.

DATA: REF(60) VALUE ‘/home/USER/wal/wal_layout.txt’.

OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC <> 0 .
WRITE / ‘File opening Error’.
EXIT.

ENDIF.

PERFORM GET_RECORD_LAYOUT.

DATA: cc TYPE i.

DO.
READ DATASET fname INTO line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
cc = cc + 1.
n = 1.
IF cc GE start .

IF cc LE end.
PERFORM readinput_file.

ELSE.
EXIT.
endif.

ENDIF.
ENDDO.

*&———————————————————————*
*& Form READINPUT_FILE
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM READINPUT_FILE.

CASE LINE(1).

WHEN ‘H’.
NEW-LINE.
ULINE.
WRITE: /10 ‘REC 01′ COLOR COL_NEGATIVE .
CLEAR REC_ONE.
REC_ONE = LINE.
PERFORM WRITE_REC USING REC_ONE REC01 ’10’.
WRITE: /10(70) SY-ULINE .
WHEN ‘L’.
WRITE: /30 ‘REC 02′ COLOR COL_POSITIVE.
CLEAR REC_TWO.
REC_ONE = LINE.
PERFORM WRITE_REC USING REC_TWO REC02 ’30’.

WHEN ‘T’.
WRITE: /10(70) SY-ULINE COLOR COL_POSITIVE .
WRITE /10 ‘Trailor’ COLOR COL_GROUP .
TRAILER = LINE.
PERFORM WRITE_REC USING TRAILER TAIL ’10’.
WRITE: /10(70) SY-ULINE COLOR COL_POSITIVE .
ENDCASE.

ENDFORM. ” READINPUT_FILE

*———————————————————————*
* FORM WRITE_REC *
*———————————————————————*
* …….. *
*———————————————————————*
* –> ZZ *
* –> P_LINE *
*———————————————————————*
FORM WRITE_REC USING ZZ P_LINE Y.
DATA: N TYPE I.
N = 1.
DATA: BEGIN OF ITAB OCCURS 10 ,
WORD(40),
END OF ITAB.
FIELD-SYMBOLS: <F2> .
DATA LEN TYPE I.
DO .
ASSIGN COMPONENT N OF STRUCTURE ZZ TO <F2>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
CLEAR LEN.
DESCRIBE FIELD <F2> LENGTH LEN in CHARACTER MODE.
<F2> = LINE(LEN).
SPLIT P_LINE AT ‘,’ INTO TABLE ITAB.
READ TABLE ITAB INDEX N.

WRITE :/Y ITAB,<F2> COLOR COL_NORMAL INTENSIFIED OFF.
LINE = LINE+LEN.
N = N + 1.
ENDDO.

ENDFORM.
*&———————————————————————*
*& Form GET_RECORD_LAYOUT
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM GET_RECORD_LAYOUT.

OPEN DATASET REF FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC <> 0 .
WRITE / ‘File opening Error’.
ENDIF.
DO.
READ DATASET REF INTO LINE1.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
DATA: TT(50).

CASE LINE1(1).

WHEN ‘H’ .
SPLIT LINE1 AT ‘,’ INTO TT LINE1.
REC01 = LINE1.
WHEN ‘L’ .
SPLIT LINE1 AT ‘,’ INTO TT LINE1.
REC02 = LINE1.
WHEN ‘T’ .
SPLIT LINE1 AT ‘,’ INTO TT LINE1.
TAIL = LINE1.
ENDCASE.

ENDDO.
CLOSE DATASET REF.

ENDFORM. ” GET_RECORD_LAYOUT

Upload and download transport request..

http://it.toolbox.com/wiki/index.php/Upload/download_SAP_transport_request

 

Upload Transport request utility

This easy-to-use utility uploads transport request binaries from user front end PC, adds request to the import queue, and starts single request import. The report checks the following authority objects:

  • S_CTS_ADMI, with values ‘TADD’ (authority to add request to the import queue), ‘IMPS’ (authority to start request import) for field CTS_ADMFCT
  • S_DATASET with field values ACTVT = ‘34’ (Write access for application server files), FILENAME = corresponding request file name

The utility has the following parameters:

  • Co-file name – full file path of the request command file, file name must be of the form ‘Knnnnnnn.SSS’, where ‘nnnnnnn’ is the request number, and ‘SSS’ – source system identifier. Request command file can be selected via F4 value request. Remaining request data files must be located in the same frontend directory.
  • Add request to import queue – if the flag is set then request is added to the import queue and also
  • Target client – client number which should be assigned to the request*
  • File path separator (on WAS) – separating character for building application server file path. The parameter is operating system dependent and is calculated in INITIALIZATION event. As a rule there is no need to change the default value.

Download Transport request utility

The utility downloads transport request binaries from application server to the user client PC. The request must be released. The utility checks authority to access application server files, object S_DATASET with field values:

  • ACTVT = ‘33’ (Read access)
  • FILENAME = corresponding request file name

The utility has the following parameters:

  • Request/Task – Number of the request to download. The request must be released. Search help provides a tree list of released requests.
  • Target folder – Full path name of client PC folder where request binary files are to be downloaded to.
  • File path separator (on WAS) – separating character for building application server file path. The parameter is operating system dependent and is calculated in INITIALIZATION event. As a rule there is no need to change the default value.

Report YRS_UPLOAD_TRANSPORT_REQUEST

*======================================================================*
* Initial idea and first release by Igor Yaskevitch (IBS), 2003        *
* Enhancements by Sergei Korolev, 2005 (added import queue             *
* manipulations, authority checking, minor interface improvements)     *
*----------------------------------------------------------------------*
* Function : This is a utility tool for uploading binary               *
* files of a transport request from a Client PC,                       *
* adding to an import queue and importing into the                     *
* system.                                                              *
*======================================================================*
REPORT yrs_upload_transport_request.

TYPE-POOLS: abap, sabc, stms.

CONSTANTS: gc_tp_fillclient LIKE stpa-command VALUE 'FILLCLIENT'.
DATA:
  lt_request TYPE stms_tr_requests,
  lt_tp_maintain TYPE stms_tp_maintains.

DATA:
  sl TYPE i,
  l_datafile(255) TYPE c,
  datafiles TYPE i,
  ret TYPE i,
  ans TYPE c.

DATA:
  et_request_infos TYPE stms_wbo_requests,
  request_info TYPE stms_wbo_request,
  system TYPE tmscsys-sysnam,
  request LIKE e070-trkorr.

DATA:
  folder TYPE string,
  retval LIKE TABLE OF ddshretval WITH HEADER LINE,
  fldvalue LIKE help_info-fldvalue,
  transdir TYPE text255,
  filename LIKE authb-filename,
  trfile(20) TYPE c.

DATA:
  BEGIN OF datatab OCCURS 0,
    buf(8192) TYPE c,
  END OF datatab.

DATA: len TYPE i,
      flen TYPE i.

SELECTION-SCREEN COMMENT /1(79) comm_sel.

PARAMETERS:
p_cofile(255) TYPE c LOWER CASE OBLIGATORY.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE bl_title.

PARAMETERS:
  p_addque AS CHECKBOX DEFAULT 'X',
  p_tarcli LIKE tmsbuffer-tarcli
           DEFAULT sy-mandt
           MATCHCODE OBJECT h_t000,

   p_sepr OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b01.

INITIALIZATION.
  bl_title = 'Import queue parameters'(b01).
  comm_sel = 'Select co-file. Filename must start with ''K''.'(001).
  IF sy-opsys = 'Windows NT'.
    p_sepr = '\'.
  ELSE.
    p_sepr = '/'.
  ENDIF.
**  CALL FUNCTION 'WSAF_BUILD_SEPARATOR'
**    IMPORTING
**      separator                  = p_sepr
**    EXCEPTIONS
**      separator_not_maintained   = 1
**      wrong_call                 = 2
**      wsaf_config_not_maintained = 3
**      OTHERS                     = 4.
*  IF sy-subrc NE 0.
*    MESSAGE s001(00) WITH 'Unable to find out the separator symbol for the system.'(008).
*  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_cofile.
  DATA:
    file TYPE file_table,
    rc TYPE i,
    title TYPE string,
    file_table TYPE filetable,
    file_filter TYPE string VALUE 'CO-files (K*.*)|K*.*||'.

  title = 'Select CO-file'(006).
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = title
      file_filter             = file_filter
    CHANGING
      file_table              = file_table
      rc                      = rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  READ TABLE file_table INTO file INDEX 1.
  p_cofile = file.

AT SELECTION-SCREEN.
  DATA:
  file TYPE string.
  sl = STRLEN( p_cofile ).
  IF sl < 11.
    MESSAGE e001(00)
    WITH 'Invalid co-file name format. File name format must be KNNNNNNN.SSS'(009).
  ENDIF.
  sl = sl - 11.
  IF p_cofile+sl(1) NE 'K'.
    MESSAGE e001(00)
    WITH 'Invalid co-file name format. File name format must be KNNNNNNN.SSS'(009).
  ENDIF.
  sl = sl + 1.
  IF NOT p_cofile+sl(6) CO '0123456789'.
    MESSAGE e001(00)
    WITH 'Invalid co-file name format. File name format must be KNNNNNNN.SSS'(009).
  ENDIF.
  sl = sl + 6.
  IF p_cofile+sl(1) NE '.'.
    MESSAGE e001(00)
    WITH 'Invalid co-file name format. File name format must be KNNNNNNN.SSS'(009).
  ENDIF.
  sl = sl - 7.
  CLEAR datafiles.
  l_datafile = p_cofile.
  l_datafile+sl(1) = 'R'.
  file = l_datafile.
  IF cl_gui_frontend_services=>file_exist( file = file ) = 'X'.
    ADD 1 TO datafiles.
  ENDIF.
  l_datafile+sl(1) = 'D'.
  file = l_datafile.
  IF cl_gui_frontend_services=>file_exist( file = file ) = 'X'.
    ADD 1 TO datafiles.
  ENDIF.
  sl = sl + 8.
  request = p_cofile+sl(3).
  sl = sl - 8.
  CONCATENATE request p_cofile+sl(7) INTO request.
  TRANSLATE request TO UPPER CASE.
  IF datafiles = 0.
    MESSAGE e398(00)
    WITH 'Corresponding data-files of transport request'(010)
    request
    'not found.'(011).
  ELSE.
    MESSAGE s398(00)
    WITH datafiles
    'data-files have been found for transport request'(012)
    request.
  ENDIF.

START-OF-SELECTION.
  DATA:
  parameter TYPE spar,
  parameters TYPE TABLE OF spar.
  CALL FUNCTION 'RSPO_R_SAPGPARAM'
    EXPORTING
      name   = 'DIR_TRANS'
    IMPORTING
      value  = transdir
    EXCEPTIONS
      error  = 1
      OTHERS = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  filename = p_cofile+sl(11).
  TRANSLATE filename TO UPPER CASE.
  CONCATENATE transdir 'cofiles' filename
  INTO filename
  SEPARATED BY p_sepr.
  OPEN DATASET filename FOR INPUT IN BINARY MODE.
  ret = sy-subrc.
  CLOSE DATASET filename.
  IF NOT ret = 0.
    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
        text_question  = 'Copy all files?'(a03)
      IMPORTING
        answer         = ans
      EXCEPTIONS
        text_not_found = 1
        OTHERS         = 2.
  ELSE.
    parameter-param = 'FILE'.
    parameter-value = filename.
    APPEND parameter TO parameters.
    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
        text_question  = 'File ''&FILE&'' already exists. Rewrite?'(a04)
      IMPORTING
        answer         = ans
      TABLES
        parameter      = parameters
      EXCEPTIONS
        text_not_found = 1
        OTHERS         = 2.
  ENDIF.
  CHECK ans = '1'.
  trfile = p_cofile+sl(11).
  TRANSLATE trfile TO UPPER CASE.
  PERFORM copy_file USING 'cofiles' trfile p_cofile.
  trfile(1) = 'R'.
  l_datafile+sl(1) = 'R'.
  PERFORM copy_file USING 'data' trfile l_datafile.
  IF datafiles > 1.
    trfile(1) = 'D'.
    l_datafile+sl(1) = 'D'.
    PERFORM copy_file USING 'data' trfile l_datafile.
  ENDIF.
  IF p_addque = 'X'.
    system = sy-sysid.
    DO 1 TIMES.
* Check authority to add request to the import queue
      CALL FUNCTION 'TR_AUTHORITY_CHECK_ADMIN'
        EXPORTING
          iv_adminfunction = 'TADD'
        EXCEPTIONS
          e_no_authority   = 1
          e_invalid_user   = 2
          OTHERS           = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        EXIT.
      ENDIF.
      CALL FUNCTION 'TMS_UI_APPEND_TR_REQUEST'
        EXPORTING
          iv_system             = system
          iv_request            = request
          iv_expert_mode        = 'X'
          iv_ctc_active         = 'X'
        EXCEPTIONS
          cancelled_by_user     = 1
          append_request_failed = 2
          OTHERS                = 3.
      CHECK sy-subrc = 0.
      CALL FUNCTION 'TMS_MGR_READ_TRANSPORT_REQUEST'
        EXPORTING
          iv_request                 = request
          iv_target_system           = system
        IMPORTING
          et_request_infos           = et_request_infos
        EXCEPTIONS
          read_config_failed         = 1
          table_of_requests_is_empty = 2
          system_not_available       = 3
          OTHERS                     = 4.
      CLEAR request_info.
      READ TABLE et_request_infos INTO request_info INDEX 1.
      IF request_info-e070-korrdev = 'CUST'
      AND NOT p_tarcli IS INITIAL.
        CALL FUNCTION 'TMS_MGR_MAINTAIN_TR_QUEUE'
          EXPORTING
            iv_command                 = gc_tp_fillclient
            iv_system                  = system
            iv_request                 = request
            iv_tarcli                  = p_tarcli
            iv_monitor                 = 'X'
            iv_verbose                 = 'X'
          IMPORTING
            et_tp_maintains            = lt_tp_maintain
          EXCEPTIONS
            read_config_failed         = 1
            table_of_requests_is_empty = 2
            OTHERS                     = 3.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          EXIT.
        ENDIF.
      ENDIF.
* Check authority to start request import
      CALL FUNCTION 'TR_AUTHORITY_CHECK_ADMIN'
        EXPORTING
          iv_adminfunction = 'IMPS'
        EXCEPTIONS
          e_no_authority   = 1
          e_invalid_user   = 2
          OTHERS           = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        EXIT.
      ENDIF.
      CALL FUNCTION 'TMS_UI_IMPORT_TR_REQUEST'
        EXPORTING
          iv_system             = system
          iv_request            = request
          iv_tarcli             = p_tarcli
          iv_some_active        = space
        EXCEPTIONS
          cancelled_by_user     = 1
          import_request_denied = 2
          import_request_failed = 3
          OTHERS                = 4.
    ENDDO.
  ENDIF.
*&--------------------------------------------------------------------*
*& Form copy_file
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->SUBDIR text
* -->FNAME text
* -->SOURCE_FILEtext
*---------------------------------------------------------------------*
FORM copy_file USING subdir fname source_file.
  DATA: l_filename TYPE string.
  l_filename = source_file.
  CONCATENATE transdir subdir fname
  INTO filename
  SEPARATED BY p_sepr.
  REFRESH datatab.
  CLEAR flen.
  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = l_filename
      filetype                = 'BIN'
    IMPORTING
      filelength              = flen
    CHANGING
      data_tab                = 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 NE 0.
    WRITE: / 'Error uploading file'(003), l_filename.
    EXIT.
  ENDIF.
  CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
    EXPORTING
      activity         = sabc_act_write
      filename         = filename
    EXCEPTIONS
      no_authority     = 1
      activity_unknown = 2
      OTHERS           = 3.
  IF sy-subrc <> 0.
    FORMAT COLOR COL_NEGATIVE.
    WRITE: / 'Write access denied. File'(013), filename.
    FORMAT COLOR OFF.
    EXIT.
  ENDIF.
  OPEN DATASET filename FOR OUTPUT IN BINARY MODE.
  IF sy-subrc NE 0.
    WRITE: / 'File open error'(004), trfile.
    EXIT.
  ENDIF.
  LOOP AT datatab.
    IF flen < 8192.
      len = flen.
    ELSE.
      len = 8192.
    ENDIF.
    TRANSFER datatab-buf TO filename LENGTH len.
    flen = flen - len.
  ENDLOOP.
  CLOSE DATASET filename.
  WRITE: / 'File'(005), trfile, 'uploaded'(007).
ENDFORM. "copy_file

Report YRS_DOWNLOAD_TRANSPORT_REQUEST

*======================================================================*
* Initial idea and first release by Igor Yaskevitch (IBS), 2003        *
* Enhancements by Sergey Korolev, 2005 (Added F4 value                 *
* requests, authority checks, TMS function usage)                      *
*----------------------------------------------------------------------*
* Function : This is a utility tool for downloading binary             *
* files of transport request to a Client PC                            *
*======================================================================*
REPORT yrs_download_transport_request.
PARAMETERS:
  p_reqest TYPE trkorr OBLIGATORY,
  p_folder(255) TYPE c LOWER CASE, p_sepr OBLIGATORY.

DATA:
  folder TYPE string,
  retval LIKE TABLE OF ddshretval WITH HEADER LINE,
  fldvalue LIKE help_info-fldvalue,
  transdir TYPE text255,
  filename(255),
  trfile(20) TYPE c,
  datatab TYPE TABLE OF text8192 WITH HEADER LINE,
  len TYPE i,
  flen TYPE i.

TYPE-POOLS: sabc, stms, trwbo.

INITIALIZATION.
  CONCATENATE sy-sysid 'K*' INTO p_reqest.

  IF sy-opsys = 'Windows NT'.
    p_sepr = '\'.
  ELSE.
    p_sepr = '/'.
  ENDIF.

*  CALL FUNCTION 'WSAF_BUILD_SEPARATOR'
*       IMPORTING
*            separator                  = p_sepr
*       EXCEPTIONS
*            separator_not_maintained   = 1
*            wrong_call                 = 2
*            wsaf_config_not_maintained = 3
*            OTHERS                     = 4.
*
*  IF sy-subrc NE 0.
*    MESSAGE s001(00)
*      WITH
*      'Unable to find out the separator symbol for the system.'(011).
*  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_reqest.
  DATA:
    tt_system TYPE TABLE OF tmscsys WITH HEADER LINE,
    es_selected_request TYPE trwbo_request_header,
    es_selected_task TYPE trwbo_request_header,
    iv_organizer_type TYPE trwbo_calling_organizer,
    is_selection TYPE trwbo_selection.

  iv_organizer_type = 'W'. is_selection-reqstatus = 'R'.
  CALL FUNCTION 'TR_PRESENT_REQUESTS_SEL_POPUP'
    EXPORTING
      iv_organizer_type   = iv_organizer_type
      is_selection        = is_selection
    IMPORTING
      es_selected_request = es_selected_request
      es_selected_task    = es_selected_task.
  p_reqest = es_selected_request-trkorr.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder.
  DATA: title TYPE string.

  title = 'Select target folder'(005).
  CALL METHOD cl_gui_frontend_services=>directory_browse
    EXPORTING
      window_title    = title
    CHANGING
      selected_folder = folder
    EXCEPTIONS
      cntl_error      = 1
      error_no_gui    = 2
      OTHERS          = 3.

  CALL FUNCTION 'CONTROL_FLUSH'
    EXCEPTIONS
      cntl_system_error = 1
      cntl_error        = 2
      OTHERS            = 3.

  p_folder = folder.

AT SELECTION-SCREEN ON p_reqest.
  DATA: request_info TYPE stms_wbo_request,
        request_infos TYPE stms_wbo_requests.

  REFRESH request_infos.
  CALL FUNCTION 'TMS_MGR_READ_TRANSPORT_REQUEST'
    EXPORTING
      iv_request                 = p_reqest
      iv_header_only             = 'X'
    IMPORTING
      et_request_infos           = request_infos
    EXCEPTIONS
      read_config_failed         = 1
      table_of_requests_is_empty = 2
      system_not_available       = 3
      OTHERS                     = 4.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  CLEAR request_info.
  READ TABLE request_infos INTO request_info INDEX 1.
  IF sy-subrc NE 0
  OR request_info-e070-trkorr IS INITIAL.
    MESSAGE e398(00) WITH 'Request'(006) p_reqest 'not found'(007).
  ELSEIF request_info-e070-trstatus NE 'R'.
    MESSAGE e398(00)
    WITH 'You must release request'(008)
         request_info-e070-trkorr
         'before downloading'(009).
  ENDIF.

START-OF-SELECTION.
  folder = p_folder.
  CONCATENATE p_reqest+3(7) '.' p_reqest(3) INTO trfile.

  CALL FUNCTION 'RSPO_R_SAPGPARAM'
    EXPORTING
      name   = 'DIR_TRANS'
    IMPORTING
      value  = transdir
    EXCEPTIONS
      error  = 0
      OTHERS = 0.

  PERFORM copy_file USING 'cofiles' trfile.
  trfile(1) = 'R'.
  PERFORM copy_file USING 'data' trfile.
  trfile(1) = 'D'.
  PERFORM copy_file USING 'data' trfile.
*---------------------------------------------------------------------*
* FORM copy_file *
*---------------------------------------------------------------------*
* --> SUBDIR * * --> FNAME *
*---------------------------------------------------------------------*
FORM copy_file USING subdir fname.
  DATA:
    auth_filename TYPE authb-filename,
    gui_filename TYPE string.

  CONCATENATE transdir subdir fname
    INTO filename
    SEPARATED BY p_sepr.

  REFRESH datatab.
  CLEAR flen.

  auth_filename = filename.
  CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
    EXPORTING
      activity         = sabc_act_read
      filename         = auth_filename
    EXCEPTIONS
      no_authority     = 1
      activity_unknown = 2
      OTHERS           = 3.

  IF sy-subrc <> 0.
    FORMAT COLOR COL_NEGATIVE.
    WRITE: / 'Read access denied. File'(001),
              filename.
    FORMAT COLOR OFF. EXIT.
  ENDIF.

  OPEN DATASET filename FOR INPUT IN BINARY MODE.

  IF sy-subrc NE 0.
    FORMAT COLOR COL_TOTAL.
    WRITE: / 'File open error'(010), filename.
    FORMAT COLOR OFF. EXIT.
  ENDIF.

  DO.
    CLEAR len.
    READ DATASET filename INTO datatab LENGTH len.
    flen = flen + len.
    IF len > 0. APPEND datatab. ENDIF.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
  ENDDO.
  CLOSE DATASET filename.
  CONCATENATE p_folder '\' fname INTO gui_filename.

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      bin_filesize            = flen
      filename                = gui_filename
      filetype                = 'BIN'
    CHANGING
      data_tab                = datatab[]
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      OTHERS                  = 24.

  IF sy-subrc = 0.
    WRITE: / 'File'(002), filename, 'downloaded. Length'(003), flen.
  ELSE.
    FORMAT COLOR COL_NEGATIVE.
    WRITE: / 'File download error. Filename:'(004), filename.
    FORMAT COLOR OFF.
  ENDIF.
ENDFORM. "copy_file

Read From Remote SAP (PRD from DEV) sample

REPORT YNS1234
.
TABLES : TAB512, RFC_DB_FLD.

*Example to get data from PRod by RFC

TABLES : BSEG.

PARAMETERS: X(50) DEFAULT ‘/home/xxx01/csss.txt’
LOWER CASE OBLIGATORY.

parameters: pbelnr like bseg-belnr.

DATA : ITAB LIKE TAB512 OCCURS 0 WITH HEADER LINE.
DATA: FLIST LIKE RFC_DB_FLD OCCURS 0 WITH HEADER LINE..

refresh flist.

FLIST-FIELDNAME = ‘BELNR’. APPEND FLIST.

FLIST-FIELDNAME = ‘BSCHL’. APPEND FLIST.

FLIST-FIELDNAME = ‘SHKZG’. APPEND FLIST.
FLIST-FIELDNAME = ‘DMBTR’. APPEND FLIST.
FLIST-FIELDNAME = ‘HKONT’. APPEND FLIST.

 

data: options like RFC_DB_OPT occurs 0 with header line..

clear options.

Concatenate text-001 pbelnr text-002

into options-text .

append options.

options-text = text-003.

append options.

refresh itab.

CALL FUNCTION ‘RFC_READ_TABLE’ DESTINATION ‘LOGPR20410’
EXPORTING
QUERY_TABLE = ‘BSEG’
* DELIMITER = ‘ ‘
* NO_DATA = ‘ ‘
* ROWSKIPS = 0
* ROWCOUNT = 5
TABLES
options = options
FIELDS = FLIST
DATA = ITAB
EXCEPTIONS
TABLE_NOT_AVAILABLE = 1
TABLE_WITHOUT_DATA = 2
OPTION_NOT_VALID = 3
FIELD_NOT_VALID = 4
NOT_AUTHORIZED = 5
DATA_BUFFER_EXCEEDED = 6
OTHERS = 7.

IF SY-SUBRC EQ 0.

OPEN DATASET X FOR APPENDING in text mode.

loop at itab.

transfer itab to x.

endloop.

endif.