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: 

How to decode file content and convert to byte array using base64 decoder

Former Member
0 Kudos

Hi All,

we have a requirement to to decode file content and convert to byte array using base64 decoder and convert it again as a file.

please explain me step by step how to proceed with this requirement.

Thanks,

Suresh.

2 REPLIES 2

JerryWang
Advisor
Advisor
0 Kudos

Hello friend,

you can use function module SSFC_BASE64_DECODE / SSFC_BASE64_ENCODE to do decode & encode.

Best Regards,

Jerry

Former Member
0 Kudos

Hi,

use this code for solve your issue:

         TRY.

           CALL METHOD zcl_fie_oioubl_import=>decode_base64
             EXPORTING
               iv_base64_string = lv_file_woh
               iv_output_string = 'X'
             IMPORTING
               ov_string        = lv_file_decode.
         ENDTRY.
       ELSE.
         lv_file_decode = lv_file_woh.
       ENDIF.

method: decode_base64(

CHECK iv_base64_string IS NOT INITIAL.

   CONSTANTS:
     lc_op_dec TYPE x VALUE 37.
   DATA:
     lr_conv TYPE REF TO cl_abap_conv_in_ce.

   CALL FUNCTION 'SSFC_BASE64_DECODE'
     EXPORTING
       b64data = iv_base64_string
     IMPORTING
       bindata = ov_xstring
     EXCEPTIONS
       SSF_KRN_ERROR                  = 1
       SSF_KRN_NOOP                   = 2
       SSF_KRN_NOMEMORY               = 3
       SSF_KRN_OPINV                  = 4
       SSF_KRN_INPUT_DATA_ERROR       = 5
       SSF_KRN_INVALID_PAR            = 6
       SSF_KRN_INVALID_PARLEN         = 7
       OTHERS                         = 8.

IF sy-subrc <> 0.
     RAISE EXCEPTION TYPE zcx_fie_oioubl_import
      EXPORTING sy_object = sy.
ENDIF.

IF iv_output_string = 'X'.
   TRY.
       lr_conv = cl_abap_conv_in_ce=>create( input = ov_xstring ).
       lr_conv->read( IMPORTING data = ov_string ).
   ENDTRY.
ENDIF.

)

       "create new file with correct filename
       OPEN DATASET lv_file_path FOR OUTPUT IN BINARY MODE.
       TRANSFER lv_file_decode TO lv_file_path . "FIXME: only if the filetype is binary
       CLOSE DATASET lv_file_path.

Thanks & regards,

Prathap.