Decoding BASE64 in ABAP

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) :

Error rendering macro 'code': Invalid value specified for parameter 'lang'

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) :

Error rendering macro 'code': Invalid value specified for parameter 'lang'

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 :

Error rendering macro 'code': Invalid value specified for parameter 'lang'

CALL METHOD cl_http_utility=>if_http_utility~decode_base64
    EXPORTING
      encoded = l_string_base64
    RECEIVING
      decoded = l_string.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ChampaignWolf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值