cancel
Showing results for 
Search instead for 
Did you mean: 

Need to display an image in Webdynpro Java

Former Member
0 Kudos

Hi All,

I need to display an image in webdynpro java application. Actually the image is nothing but an output of a RFC call.

So this is the BAPI am consuming from webdynpro application, SO_DYNP_DOCUMENT_DISPLAY.

When I execute the RFC from SAP it simply displaying the image as output, but I don't know how to capture the same output in my webdynpro application context or code. Please suggest me the right way to do the same.

Also I got another customized BAPI which returns the same image in three format

1 Binary

2 Hexa

3 exString

Here I can read both binary and hexa in my application but not able to render the image from the retrieved binary and hexa contents. I heard that exString is the right format to receive and process image in webdynpro application, but here am not even able to read the exString from the model.

Also I have done all the basic requirements in the webdynpro. Like created image componet, created dynamic url using IWDResource and mapped the same to the image datasource with no issues. The only issue is with the BAPI or data format I guess. So please suggest me the correct way to do the same.

Thanks & Regards

Rajesh A

Accepted Solutions (1)

Accepted Solutions (1)

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

IWDResource resource = WDResourceFactory.createCachedResource(new ByteArrayInputStream(wdContext.currentFile_OutputElement().getChaE_String()),"JPG",WDWebResourceType.JPG_IMAGE,true);

IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.toString(),"Image Window");

window.show();

Please try the above code. wdContext.currentFile_OutputElement().getX_String() is the XString attribute from the BAPI and the image is of type JPEG. if you want to open only JPEG then use this or use the resourcetype as Unknown.

If you have any issues, let us know.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi Nizamudeen ,

Thanks for the reply, I have already implemented the code you have mentioned above, but not able to see the image in window.

Also I am getting only XString from BAPI as byte[] in my application, but still i cannot render image from the retrieved content.

Please suggest me.

Thanks & Regards

Rajesh A

Former Member
0 Kudos

Hi Nizamudeen,

Also in the webdynpro side am only receiving 255 bytes out of 4.52 KB, the actual image size. The BAPI returns the image output in a single line not in multiple lines. I am not sure where the problem resides whether in ABAP side or webdynpro side.

Also suggest me how to validate the output from BAPI. Please suggest me.

Thanks & Regards

Rajesh A

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

I think, the XString which you are getting from BAPI is wrong, try someother RFC's. The procedure is something like we need to get the binary of the image and then try to convert the binary to XSTring using SCMS_BINARY_TO_XSTRING.

Reply for any queries.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi Nizamudeen,

Thanks for the reply. My colleague has been posted his ABAP code in the forum already in the following link,

Please validate the same code and let us know if the same need to be changed..

Thanks & Regards

Rajesh A

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

I went through your code, i am not sure why String to XString conversion is happening, i saw the FM's. What you can ask him to do is,

1. Call this FM SO_DOCUMENT_READ_API1.

2. You will get the OBJECT_CONTENT, now you pass the same without changing it to SCMS_BINARY_TO_XSTRING.

3. It will provide you the output in XString, pass that as an output to you in export parameter.

Please check the same and let me know.

Regards

Nizamudene SM

Former Member
0 Kudos

Hi Nizamudeen ,

SCMS_BINARY_TO_XSTRING you have suggested the function to convert binaries to xString, here we are supposed to pass the length of the object_content received. We dont know how to find the object_content length and export image as xString.

Kindly help us to resolve this issue.

Thanks & Regards

Rajesh A

Former Member
0 Kudos

Hi Nizamudeen ,

From the ABAP front we can see the xString data with no issues in the output parameter with the name "xstring_data". But when I execute the same BAPI from webdynpro application am getting nothing in the xstring_data, just returned -1 when i read the byte array from xstring_data context element. This is looking very strange.

Also the same BAPI will return correct value to xstring_data in backend and not returning the data to the same parameter when executed from the webdynpro application. Also I can get values in webdynpro for the rest of the parameters as well.

Now the only problem is getting xstring values from backend to front end. Please let me know the mechanism to do the same, I will also post my webdynpro implementation for your understanding, please correct me if am wrong..

wdThis.wdGetMatAttCompController().executeZso_Document_Read_Api1();
byte[] buffer = wdContext.currentOutputElement().getXstring_Data(); // here am receiving -1, Array Index out of bound exp
IWDResource resource = WDResourceFactory.createCachedResource(new ByteArrayInputStream(buffer),"JPG",WDWebResourceType.JPG_IMAGE,true);
String str = resource.getUrl(0);
wdContext.currentContextElement().setUrl(str);

Now in the controller, under executeZso_Document_Read_Api1 method

wdContext.currentZso_Document_Read_Api1_InputElement().modelObject().execute();      wdContext.nodeOutput().invalidate();// why they are invalidating the node after calling the model 

Please suggest me.

Thanks & Regards

Rajesh A

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

If the XString data is coming when you run the BAPI in R/3 then try keep a external breakpoint and ask your abaper to debug the RFC. Then you can come to know the issue.

Also in front end you check the mapping of the model nodes.

Invalidating the node is just to refresh the output node. so no worries about that.

Debug and find out and let me know.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi Nizamudeen,

Thanks for the info provided. We are staring to debug the application as well as ABAP RFC. Also I am having one question here, whether CE 7.1 is capable to read xString data from RFC output.

Also if possible can you share your number, so that I can call and let you know the entire scenario. This is an immediate requirement for us to close. Please help us.

Thanks & Regards

Rajesh A

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

There is no issue with CE7.1 as far as I know.

So, definitely the BAPI which you are using is not returning values when we call from WDJ. So debug and let me know the results.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi Nizamudeen,

As you said we have been debug the code and found the issue while calling Bapi from webdynpro. Now we can get the image content as byte array with no issues. But we are not able to render the actual image from the received byte array

The size of the byte array received is exactly the same as the image size. But still we could not render the image. Sometimes blurred images are displaying for some specific types of image formats. eg: JPG. Nothing will happen for the rest of the formats.

Please suggest.

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

You download the image from R/3 and store in a desktop. Now create an application for uploading the same image using webdynpro, you want to store anywhere, just upload and store the byte array in the context attribute, then on click of the link you open the image and check how it is getting displayed?

I am not sure why it is getting blurred, because it'll always shows you the image as it is how we are getting from R/3.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi Nizamudden,

I have tried all the possible ways but vain. I have downloaded the same image from R3 and while trying to open the file I got exception like, windows photo viewer is not supporting the format dont know why.. I have seen 10% for some images.. dont know wat is happening over there, also dont know where I need to fix this..

This is the code am using in my webdynpro java application

IWDResource resource = WDResourceFactory.createCachedResource(buffer, 
			  "MyImage", WDWebResourceType.UNKNOWN);
  String url = resource.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal());
  wdContext.currentContextElement().setImageUrl(url);

Also I have tried with various MIME types, but vain. Please suggest..

Thanks & Regards

Rajesh A

Former Member
0 Kudos

Hi Nizamudeen,

*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(DOCUMENT_ID) LIKE  SOFOLENTI1-DOC_ID
*"     VALUE(FILTER) LIKE  SOFILTERI1 STRUCTURE  SOFILTERI1 DEFAULT
*"       'X '
*"     VALUE(OBJTP) TYPE  SO_OBJ_TP
*"     VALUE(OBJYR) TYPE  SO_OBJ_YR
*"     VALUE(OBJNO) TYPE  SO_OBJ_NO
*"  EXPORTING
*"     VALUE(DOCUMENT_DATA) LIKE  SOFOLENTI1 STRUCTURE  SOFOLENTI1
*"     VALUE(XSTRING_DATA) TYPE  XSTRING
*"     VALUE(V_LEN_NUM) TYPE  I
*"     VALUE(STRING_DATA) TYPE  STRING
*"  EXCEPTIONS
*"      DOCUMENT_ID_NOT_EXIST
*"      OPERATION_NO_AUTHORIZATION
*"      X_ERROR
*"----------------------------------------------------------------------
DATA: V_LEN TYPE SO_OBJ_LEN.
Data: OBJECT_HEADER type TABLE OF SOLISTI1,
      OBJECT_CONTENT TYPE TABLE OF SOLISTI1.
*BREAK-POINT.
*clearing the variables.
CLEAR: XSTRING_DATA, V_LEN,V_LEN_NUM.
*Reading object in binary
    CALL FUNCTION 'SO_DOCUMENT_READ_API1'
         EXPORTING
              DOCUMENT_ID                = DOCUMENT_ID
              FILTER                     = FILTER
         IMPORTING
              DOCUMENT_DATA              = DOCUMENT_DATA
         TABLES
              OBJECT_HEADER              = OBJECT_HEADER
              OBJECT_CONTENT             = OBJECT_CONTENT
         EXCEPTIONS
              DOCUMENT_ID_NOT_EXIST      = 999
              OPERATION_NO_AUTHORIZATION = 21
              COMMUNICATION_FAILURE      = 71
              SYSTEM_FAILURE             = 72
              OTHERS                     = 4.

*Determining length of the object.
SELECT SINGLE OBJLEN
       FROM SOOD INTO V_LEN
       WHERE OBJTP = OBJTP AND
             OBJYR = OBJYR AND
             OBJNO = OBJNO.
V_LEN_NUM = V_LEN.
*conversion to xstring from binary.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    INPUT_LENGTH       = V_LEN_NUM
 IMPORTING
   BUFFER             = XSTRING_DATA
  TABLES
    BINARY_TAB         = OBJECT_CONTENT.

ENDFUNCTION.

This is the code as you suggested. and in debug mode when we try to save the xstring_data in jpg format we are not getting the actual image . we tried saving in all three format ASCII (text), binary, binary with code page but couldn't able to retrieve the actual image.

We hope this is the root cause for the entire problem, please suggest.

Regards

Rajesh

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

There is a select query used to fetch the size of the object, can you use the doc_size attribute which is available in Document_Data for the same and check.

Also can u send me the whole code available in WDJ.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi ,

Thanks for the reply. I will check and let you know in ABAP and here is the complete WDJ code to get and display image. Please have a look into the same,

public void onActionGetImage(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionGetImage(ServerEvent)
    //$$begin Action Button(-1253566902)
    wdThis.wdGetImageCompController().executeZso_Document_Read_Api1();
    byte[] buffer = wdContext.currentOutputElement().getXstring_Data();
//  byte[] sbuffer = wdContext.currentOutputElement().getString_Data().getBytes();
    IWDMessageManager manager = wdComponentAPI.getMessageManager();
    manager.reportSuccess("Size: "+buffer.length);
    IWDResource resource = WDResourceFactory.createResource(buffer, "MyImage", WDWebResourceType.UNKNOWN);
//  IWDResource resource1 = WDWebResource.getWebResource(new ByteArrayInputStream(buffer), WDWebResourceType.JPG_IMAGE);
    String url = resource.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal());  
    wdContext.currentContextElement().setImageUrl(url);
    manager.reportSuccess("Successfully executed BAPI..");
    //$$end

    //@@end
  }

Thanks & Regards

Rajesh A

Former Member
0 Kudos

Hi Nizamudeen,

**Determining length of the object.
*SELECT SINGLE OBJLEN
*       FROM SOOD INTO V_LEN
*       WHERE OBJTP = OBJTP AND
*             OBJYR = OBJYR AND
*             OBJNO = OBJNO.
  v_len_num = document_data-doc_size.
*conversion to xstring from binary.
  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      input_length = v_len_num
    IMPORTING
      buffer       = xstring_data
    TABLES
      binary_tab   = object_content.

We made the changes in the ABAP front as you suggest, still we are getting the same result. Please suggest.

Thanks & Regards

Rajesh A

former_member185879
Active Contributor
0 Kudos

Hello Rajesh,

wdThis.wdGetImageCompController().executeZso_Document_Read_Api1();

IWDResource resource = WDResourceFactory.createCachedResource(new ByteArrayInputStream(wdContext.currentOutputElement().getXstring_Data()),"JPG",WDWebResourceType.JPG_IMAGE,true);

IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.toString(),"JpegWindow");

window.show();

Can you try the above code by commenting all your other codes.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi Nizamudeen,

Tried the suggested WDJ code got the same result. Don't know how to analyze the issue, kindly suggest.

Thanks & Regards

Rajesh A

former_member183990
Active Contributor
0 Kudos

Please refer this and close this thread rajesh

Regards

S.Janagar

Answers (0)