Google Search - Blog...........

Showing posts with label abap try catch block example. Show all posts
Showing posts with label abap try catch block example. Show all posts

ABAP - Decoding BASE64 In ABAP

A small form routine to decode base64 (TYPE STRING) into plaintext (TYPE STRING).
FORM decode_base64 USING base64 plaintext.

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

ABAP - Example On Try-Catch Block.

REPORT YSUBCLASS_EXCEPTION_3.

START-OF-SELECTION.

DATA : num type i value 5 .

TRY.
TRY.
num = 'subhendu'.
cleanup.
write:/5 'In cleanup'.
ENDTRY.
CATCH cx_sy_conversion_no_number.
WRITE:/5 'Cannot be converted to number'.
ENDTRY.


Output
In cleanup
Cannot be converted to number