码迷,mamicode.com
首页 > 其他好文 > 详细

Decoding BASE64 in ABAP

时间:2016-05-26 19:01:40      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:

Code Gallery
Decoding BASE64 in ABAP
Skip to end of metadata
Created by Frank Klausner, last modified by Manish Kumar on Aug 21, 2013 Go to start of metadata
Author: Frank Klausner
Submitted: June 26, 2007
There are routines proposed below, first one is to convert base64 to a string, and second one to a xstring.
Third one was mentioned by Sandra in comments section.
A small form routine to decode base64 (TYPE STRING) into plaintext (TYPE STRING) :
FORM decode_base64
    USING
      base64     TYPE string,
    CHANGING
      plaintext  TYPE string.
 
  CHECK base64 IS NOT INITIAL.
 
  CONSTANTS:
    lc_op_dec TYPE x VALUE 37.
  DATA:
    l_xstr TYPE xstring,
    lr_conv TYPE REF TO cl_abap_conv_in_ce.
 
  CALL SSF_ABAP_SERVICE
    ID OPCODE FIELD   lc_op_dec
    ID BINDATA FIELD   l_xstr
    ID B64DATA FIELD   base64. "#EC CI_CCALL
 
  TRY.
 
      lr_conv = cl_abap_conv_in_ce=>create( input = l_xstr ).
      lr_conv->read( IMPORTING data = plaintext ).
 
    CATCH cx_sy_conversion_codepage.
      CLEAR plaintext.
      MESSAGE i999(samx) WITH text-004 text-005.
  ENDTRY.
 
ENDFORM.

A small form routine to decode base64 (TYPE STRING) into xstring (TYPE XSTRING) :
FORM decode_base64_to_xstring
      USING
        i_base64   TYPE string
      CHANGING
        e_xstring  TYPE xstring.
 
  CALL FUNCTION SSFC_BASE64_DECODE
    EXPORTING
      b64data = i_base64
    IMPORTING
      bindata = e_xstring
    EXCEPTIONS
      OTHERS  = 8.
 
ENDFORM.
Conversion from base64 to string may also be achieved by this small code :
CALL METHOD cl_http_utility=>if_http_utility~decode_base64
    EXPORTING
      encoded = l_string_base64
    RECEIVING
      decoded = l_string.
snippet abap web conversion
1 Comment
User icon: c0cbtrx
Sandra Rossi
Conversion from base64 to string may also be achieved by this small code :
CALL METHOD cl_http_utility=>if_http_utility~decode_base64
    EXPORTING
      encoded = l_string_base64
    RECEIVING
      decoded = l_string.

 

Decoding BASE64 in ABAP

标签:

原文地址:http://www.cnblogs.com/caizjian/p/5532185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!