Wednesday, April 3, 2024

Base64 Text data upload and download in PNG format.

 


DATALV_BASE64_STRING(10000TYPE C,
      LT_BYTE_TABLE           TYPE TABLE OF SOLIX,
      BINARY_TAB              TYPE TABLE OF SOLIX,
      LW_BINARY_TAB           TYPE SOLIX,
      LV_PNG                  TYPE XSTRING.
DATA GV_STRING  TYPE STRING .
DATALV_FILENAME      TYPE STRING,
      LV_FILENAME_1    TYPE STRING,
      LV_FILE_CONTENTS TYPE STRING,
      LT_FILE_CONTENTS TYPE TABLE OF STRING.
DATA:XSTR_CONTENT TYPE XSTRING.
DATA GT_BINARY TYPE TABLE OF BAPICONTEN.
DATA LT_TAB TYPE TABLE OF SWASTRTAB.
DATA GT_STR TYPE TABLE OF STRING.

PERFORM READ_FILE.
FORM READ_FILE.

DATA LV_XSTRING TYPE XSTRING.
DATA LV_IMAGE TYPE XSTRING.
DATALO_HTTP_CLIENT       TYPE REF TO IF_HTTP_CLIENT,
      LV_URL               TYPE STRING,
      LV_JSON_X            TYPE XSTRING,
      LV_RESPONSE          TYPE STRING,
      LV_RESPONSE_2(10000TYPE C.

LV_FILENAME 'C:\Users\user\Desktop\TESTTTT.txt'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
  FILENAME                LV_FILENAME
IMPORTING
  FILELENGTH              LEN
  HEADER                  XSTR_CONTENT
TABLES
  DATA_TAB                LT_FILE_CONTENTS
EXCEPTIONS
  FILE_OPEN_ERROR         1
  FILE_READ_ERROR         2
  NO_BATCH                3
  GUI_REFUSE_FILETRANSFER 4
  INVALID_TYPE            5
  NO_AUTHORITY            6
  UNKNOWN_ERROR           7
  BAD_DATA_FORMAT         8
  HEADER_NOT_ALLOWED      9
  SEPARATOR_NOT_ALLOWED   10
  HEADER_TOO_LONG         11
  UNKNOWN_DP_ERROR        12
  ACCESS_DENIED           13
  DP_OUT_OF_MEMORY        14
  DISK_FULL               15
  DP_TIMEOUT              16
  OTHERS                  17.

IF SY-SUBRC 0.
  LOOP AT LT_FILE_CONTENTS INTO LV_FILE_CONTENTS.
    CONCATENATE GV_STRING  LV_FILE_CONTENTS INTO GV_STRING.
  ENDLOOP.

  CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
    EXPORTING
      INPUT  GV_STRING
*     UNESCAPE       = 'X'
    IMPORTING
      OUTPUT LV_XSTRING
    EXCEPTIONS
      FAILED 1
      OTHERS 2.

  IF SY-SUBRC 0.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        BUFFER     LV_XSTRING
      TABLES
        BINARY_TAB LT_BYTE_TABLE
      EXCEPTIONS
        FAILED     1
        OTHERS     2.

    IF SY-SUBRC 0.
      LV_FILENAME_1 'C:\Users\user\Desktop\Test.png'
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME                LV_FILENAME_1
          FILETYPE                'BIN'
        TABLES
          DATA_TAB                LT_BYTE_TABLE
        EXCEPTIONS
          FILE_WRITE_ERROR        1
          NO_BATCH                2
          GUI_REFUSE_FILETRANSFER 3
          INVALID_TYPE            4
          NO_AUTHORITY            5
          UNKNOWN_ERROR           6
          HEADER_NOT_ALLOWED      7
          SEPARATOR_NOT_ALLOWED   8
          FILESIZE_NOT_ALLOWED    9
          HEADER_TOO_LONG         10
          DP_ERROR_CREATE         11
          DP_ERROR_SEND           12
          DP_ERROR_WRITE          13
          UNKNOWN_DP_ERROR        14
          ACCESS_DENIED           15
          DP_OUT_OF_MEMORY        16
          DISK_FULL               17
          DP_TIMEOUT              18
          FILE_NOT_FOUND          19
          DATAPROVIDER_EXCEPTION  20
          CONTROL_FLUSH_ERROR     21
          OTHERS                  22.
    ENDIF.
  ENDIF.
ENDIF.

ENDFORN.




No comments:

Post a Comment

Translation of language in Smart Forms.

  Step by Step process to Translate English language to Spanish language in smart form. 1. Go to T-Code SE63 in command bar and then enter. ...