Digital Signature in SAP FIORI

How to save the Digital Signature in SAP.

This code helps to DeCode the BASE64 format which FIORI applications sends, this needs to converted to BINARY format and further to be used as per the requirement.

Some times the Image you get is Black but it might not be the mistake at SAP end while sending the time the background in getting black from UI end.

Its better or advised to save the data in the Z table and then it can be retrieved. You can create the a fieldĀ  OF DATA TYPE RAWSTRING.

Below example sign field is created with datatype RAWSTRING using predefined type.

*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” REFERENCE(IV_INPUT) TYPE STRING OPTIONAL
*” REFERENCE(IV_NAME) TYPE STXBITMAPS-TDNAME OPTIONAL
*” REFERENCE(IV_DEL) TYPE CHAR01 OPTIONAL
*” EXPORTING
*” REFERENCE(EV_RETURN) TYPE CHAR01
*”———————————————————————-

TYPES: BEGIN OF lty_bitmap,
l(64) TYPE x,
END OF lty_bitmap.

DATA:
lo_conv_x2c TYPE REF TO cl_abap_conv_in_ce,
base64_string TYPE string,
base64_xstring TYPE xstring,
lv_size TYPE i,
lt_content TYPE TABLE OF lty_bitmap, ” sdokcntbin.
ls_dsign TYPE zfcs_sign_update.

CONSTANTS : lc_filename TYPE rlgrap-filename VALUE ”,
lc_object TYPE stxbitmaps-tdobject VALUE ‘GRAPHICS’,
lc_id TYPE stxbitmaps-tdid VALUE ‘BMAP’,
lc_btype TYPE stxbitmaps-tdbtype VALUE ‘BMON’,
lc_extension TYPE char03 VALUE ‘BMP’,
lc_title LIKE bapisignat-prop_value VALUE ”,
lc_resident TYPE stxbitmaps-resident VALUE ”,
lc_autoheight TYPE stxbitmaps-autoheight VALUE ‘X’,
lc_bmcomp TYPE stxbitmaps-bmcomp VALUE ‘X’.

DATA: lv_docid TYPE stxbitmaps-docid,
lv_resolution TYPE stxbitmaps-resolution.

lo_conv_x2c = cl_abap_conv_in_ce=>create( ).

* lo_conv_x2c->convert( EXPORTING input = Iv_input
* IMPORTING data = base64_string ).
*
base64_string = iv_input.
*— decoding base_64
CALL FUNCTION ‘SSFC_BASE64_DECODE’
EXPORTING
b64data = base64_string
* B64LENG =
* B_CHECK =
IMPORTING
bindata = base64_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.

“Getting the data
CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’
EXPORTING
buffer = base64_xstring
append_to_table = ‘X’
IMPORTING
output_length = lv_size
TABLES
binary_tab = lt_content.

DESCRIBE TABLE lt_content LINES DATA(lv_count).
READ TABLE lt_content INTO DATA(ls_content)
INDEX lv_count.
IF ls_content-l = text-e01.
ev_return = ‘E’.
ELSE.
ev_return = ‘S’.
IF iv_del IS INITIAL.
“Saving Dsign
ls_dsign-tdname = iv_name.
ls_dsign-sign = base64_xstring.
MODIFY zfcs_sign_update FROM ls_dsign.

“Uploading the Grahic(s)
PERFORM import_bitmap
USING lc_filename
iv_name
lc_object “GRAPHICS
lc_id “BMAP
lc_btype “BMON
lc_extension “BMP
lc_title
lc_resident
lc_autoheight “X
lc_bmcomp “X
lt_content
CHANGING lv_docid
lv_resolution.
ELSE.
“Deleted Upload
CALL FUNCTION ‘SAPSCRIPT_DELETE_GRAPHIC_BDS’
EXPORTING
i_object = ‘GRAPHICS’
i_name = iv_name
i_id = ‘BMAP’
i_btype = ‘BMON’
dialog = ”
EXCEPTIONS
enqueue_failed = 1
delete_failed = 2
not_found = 3
canceled = 4
OTHERS = 5.

ENDIF.
ENDIF. “Check no error
ENDFUNCTION.