Skip to Content
0

Upload Image through Odata to standard transaction

Nov 03, 2016 at 12:27 PM

343

avatar image

Hi Experts,

I have to upload 64baseString image data(coming from odata service) to standard transaction. i am able to upload data but for displaying it gives an error that file is corrupted.

Please suggest.

Thanks & Regards

Sushil Kumar Shrivastava

Below is my code..

INCLUDE : <CNTN01>.
PARAMETERS: P_BOTYPE LIKE BORIDENT-OBJTYPE DEFAULT 'BUS2032', " e.g. 'BUS2012'
P_BO_ID LIKE BORIDENT-OBJKEY DEFAULT '0000000037',
P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'bin',
P_DOCTY LIKE BORIDENT-OBJTYPE DEFAULT 'MESSAGE',
P_RELTYP LIKE BRELTYP-RELTYPE DEFAULT 'ATTA',
P_PATH TYPE IBIPPARMS-PATH MEMORY ID AD_LOCAL_PATH .

TYPES: BEGIN OF TY_MESSAGE_KEY,
FOLTP TYPE SO_FOL_TP,
FOLYR TYPE SO_FOL_YR,
FOLNO TYPE SO_FOL_NO,
DOCTP TYPE SO_DOC_TP,
DOCYR TYPE SO_DOC_YR,
DOCNO TYPE SO_DOC_NO,
FORTP TYPE SO_FOR_TP,
FORYR TYPE SO_FOR_YR,
FORNO TYPE SO_FOR_NO,
END OF TY_MESSAGE_KEY.

DATA : LV_MESSAGE_KEY TYPE TY_MESSAGE_KEY.
DATA : LO_MESSAGE TYPE SWC_OBJECT.
DATA : LT_DOC_CONTENT TYPE STANDARD TABLE OF SOLI-LINE.
DATA : LT_CONTENT TYPE SOLI-LINE.
DATA: W_PROG TYPE SY-REPID, "Current Program Name
W_DYNNR TYPE SY-DYNNR. "Current Dynpro Number


START-OF-SELECTION .
P_DOCTY = 'MESSAGE'.

CASE P_RELTYP.
WHEN 'ATTA'.
P_MSGTYP = 'BIN'.
WHEN OTHERS.
EXIT.
ENDCASE.

DATA: HEXA TYPE STRING.
DATA : DEC TYPE I.
HEXA = 'FFD8FFE000104A46494600010100000100010000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720'.
DATA: GT_BIN_DATA TYPE STANDARD TABLE OF CHAR1024.
DATA: E_XSTRING TYPE XSTRING..
DATA : LV_SIZE TYPE I.
CALL FUNCTION 'SSFC_BASE64_DECODE'
EXPORTING
B64DATA = HEXA
IMPORTING
BINDATA = E_XSTRING
EXCEPTIONS
OTHERS = 8.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = E_XSTRING
* APPEND_TO_TABLE = ' '
IMPORTING
OUTPUT_LENGTH = LV_SIZE
TABLES
BINARY_TAB = GT_BIN_DATA .
REFRESH LT_DOC_CONTENT.
LT_DOC_CONTENT[] = GT_BIN_DATA[].
********************************************************** Testing ***********************************************************************************
DATA : STR TYPE XSTRING.
SWC_CREATE_OBJECT LO_MESSAGE 'MESSAGE' LV_MESSAGE_KEY.
SWC_CONTAINER LT_MESSAGE_CONTAINER.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' '20150531201352.jpg'.
*SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' 'Demo.txt'.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTLANGU' 'E'.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'NO_DIALOG' 'X'.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTNAME' P_DOCTY.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTYPE' P_MSGTYP.
*SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_SIZE .
SWC_CALL_METHOD LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER.
SWC_GET_OBJECT_KEY LO_MESSAGE LV_MESSAGE_KEY.
***************************************************************************
*swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_Size .
swc_refresh_object LO_MESSAGE.

swc_call_method LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER.
swc_get_object_key LO_MESSAGE LV_MESSAGE_KEY.
Data: LO_IS_OBJECT_A type SIBFLPORB.
LO_IS_OBJECT_A-CATID = 'BO'.
Data: LO_IS_OBJECT_B type SIBFLPORB.
LO_IS_OBJECT_B-TYPEID = LV_MESSAGE_KEY.
LO_IS_OBJECT_B-OBJTYPE = P_DOCTY.
DATA :RELTYPE TYPE OBLRELTYPE.
RELTYPE = P_RELTYP.
TRY.
CALL METHOD CL_BINARY_RELATION=>CREATE_LINK
EXPORTING
IS_OBJECT_A = LO_IS_OBJECT_A
* IP_LOGSYS_A =
IS_OBJECT_B = LO_IS_OBJECT_B
* IP_LOGSYS_B =
IP_RELTYPE = RELTYPE
* IP_PROPNAM =
* I_PROPERTY =
* IMPORTING
* EP_LINK_ID =
* EO_PROPERTY =
.
CATCH CX_OBL_PARAMETER_ERROR .
CATCH CX_OBL_MODEL_ERROR .
CATCH CX_OBL_INTERNAL_ERROR .
ENDTRY.


*Data: LO_IS_OBJECT_B type BORIDENT.
* LO_IS_OBJECT_B-OBJKEY = LV_MESSAGE_KEY.
* LO_IS_OBJECT_B-OBJTYPE = P_DOCTY.
data: IS_OBJECT_B type BORIDENT.
IS_OBJECT_B-OBJKEY = LV_MESSAGE_KEY.
IS_OBJECT_B-OBJTYPE = P_DOCTY.
data: IS_OBJECT_A type BORIDENT.
IS_OBJECT_A-OBJKEY = P_BO_ID.
IS_OBJECT_A-OBJTYPE = P_BOTYPE.




***************************************************************************


CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
OBJ_ROLEA = IS_OBJECT_A
OBJ_ROLEB = IS_OBJECT_B
RELATIONTYPE = P_RELTYP
* FIRE_EVENTS = 'X'
* IMPORTING
* BINREL =
* TABLES
* BINREL_ATTRIB =
* EXCEPTIONS
* NO_MODEL = 1
* INTERNAL_ERROR = 2
* UNKNOWN = 3
* OTHERS = 4
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
commit work.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Jānis B Nov 03, 2016 at 06:51 PM
0

It's very difficult to understand something in "atrocious" looking code like that, but I'll try to speculate - what is the reason document size is not passed..?

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Janis.

Thanks for reply, on passing document size i am getting an error

as"The transferred object reference when calling class CL_BINARY_RELATION method CREATE_LINK is invalid".

please advice..

Sushil Kumar Shrivastava

0

Hi Janis,

Can you please tell , how to pass size in above program,

i think by after passing it issue will resolve .

Sushil Kumar Shrivastava

0
Sushil Kumar Shrivastava

It should be this:

SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_SIZE .

I believe.

What is that string?

0
Tomas Buryanek Nov 04, 2016 at 02:54 PM
0

The "HEXA" value in your example code is in hexa format. Not in BASE64, so why are you trying to "BASE64 decode" it?

Also it is not complete file. I tried to convert it and it seems like beginning of JPEG file.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

thanks for reply, yes the file is in jpg format , please explain how to convert hexa format to bin.

file is complete.its coming from odata service.

Sushil Kumar Shrivastava

0
Sushil Kumar Shrivastava

It's very difficult to understand what you are trying to do here. If that value is hexadecimal (xstring) why does it need to be converted..? Why not simply define it as xstring?

0

Can you please guide me how can i move imageData(Xstring or 64BitCode) to standard transaction only.

I am stuck here in more than a week.

Thanks in advance

Sushil Kumar Shrivastava

0
Sandra Rossi Nov 05, 2016 at 07:48 PM
0

Am I wrong, or did you just forget to transmit the "DocumentContent"? (cf method Create of Message in SAP Library: http://help.sap.com/saphelp_nw70/helpdata/en/22/93f82df94b11d2a2b200a0c943858e/content.htm?frameset=/en/22/93f82df94b11d2a2b200a0c943858e/frameset.htm )

By the way, I think it's better that you use a table of type X instead of a table of Char (GT_BIN_DATA, LT_DOC_CONTENT), because the document contains bytes, not characters (even though I think it would work here with your current code).

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Sandra,

Thanks for suggestion , now i am able to upload and display image data. but the problem is on displaying ,the i am

getting disturbed image.

please suggest..

Thanks

Sushil Kumar Shrivastava

0
Sushil Kumar Shrivastava

Could you show it? Plus the image you expect?

0