Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Hash Data before downloading file

sawanee_aimsaard
Explorer
0 Kudos

Hi Experts,

I want to hast file with algorithm 'SHA1' before I download the file to my PC

(Hash value will be inserted into header line in text file before downloading it).

CALL FUNCTION 'CALCULATE_HASH_FOR_CHAR'
  EXPORTING
    alg                  = 'SHA1'
    data                 = lv_str
*   LENGTH               = 0
  IMPORTING
    hash                 = lv_hash
*   HASHLEN              =
*   HASHX                =
*   HASHXLEN             =
*   HASHSTRING           =
*   HASHXSTRING          =
*   HASHB64STRING        =
 EXCEPTIONS
   unknown_alg          = 1
   param_error          = 2
   internal_error       = 3
   OTHERS               = 4
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL METHOD cl_gui_frontend_services=>gui_download
  EXPORTING
    filename                  = 'C:\Desktop\TEXT5.txt'
    trunc_trailing_blanks_eol = abap_false
    filetype                  = 'ASC'
  CHANGING
    data_tab                  = lt_data2
  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
    not_supported_by_gui      = 22
    error_no_gui              = 23
    OTHERS                    = 24
        .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

I tried to use function as above('CALCULATE_HASH_FOR_CHAR'). but my file was stored into Standard Table (lt_data2).

Could you please suggest me for using another function to hash text file?

4 REPLIES 4

Sandra_Rossi
Active Contributor
0 Kudos

Why don't you just add programatically lv_hash at the start of the first line of lt_data2, just before gui_download ?

sawanee_aimsaard
Explorer
0 Kudos

I cannot get hash for for It_data2 because I cannot pass internal table into function CALCULATE_HASH_FOR_CHAR.

Sandra_Rossi
Active Contributor

So, you are looking for ABAP code to concatenate a table of characters into a string.

If lt_data2 is a "table of string", you may do that:

lv_str = concat_lines_of( lt_data2 ).<br>

If lt_data2 is a table of structured character-like lines, you may do that:

lv_str = REDUCE #( INIT a = `` FOR <b> IN lt_data2 NEXT a = a && <b> ).

sawanee_aimsaard
Explorer

I can solve the problem. Thank you so much