Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Hi all,
According to my current project requirement we needed to retrieve the specific Data of an attachment(mainly for .txt type of file) of PO:Purchase Order(which can only be retrieved in an

internal table in binary format) using function module 'BBP_PD_PO_GETDETAIL' and send it in base64 format using 'SCMS_BASE64_ENCODE_STR' Conversion method.
All were working fine but the data we were getting in the attachment was not as per standards.
we were getting a lots of "null"s at the end of our Data.(PFA-Attachment1 )
Large number of "null" characters were getting added at the end of the attachment contents when we opened the newly generated attachment as a text file from

target side/destination side.
The internal table in which we were getting this attachment data in binary format has the row contents (The only field 'LINE')as type of RAW and of length

1022.
Thus this length of 1022 was the issue because after assigning the attachment data it considers the remaining characters as "null" if the assigned data is not

large enough.
It can be undestood in more detail using following example.

e.g. :

The attachment that is the textfile of a Purchase Order contains the string data as :
"Test Proxy completed"//(The only Data needs to be sent as a contents of a text file )

Instead the textfile which was generated at destination contained data :

Test Proxy completed.nullnullnullnullnullnullnullnullnullnullnullnullnull
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
....(continued)."

(PFA-Attachment1 )

---------------------------------------------------------------------------------------------------------
Actual Issue was:

      The actual issue was those nulls were getting added while retrieving this data in binary format itself(got it with the help of Debugging)
when we were calling that "BBP_PD_PO_GETDETAIL" method and retrieving the attachment data in Binary format in an internal table.
The size of normal string is much greater than the actual data provided hence it considers remaining spaces as "null"
("0" in binary/hexadecimal format).

----------------------------------------------------------------------------------------------------------

So after few RND I came up with the solution for this issue which can be stated as follow:

Consider that we have retrieved binary Data into an internal table :
lt_contents.(Last field of lt_attachment table which is the outcome of 'BBP_PD_PO_GETDETAI' function module)
**********************************************************************************************************

DATA: lv_file TYPE string,
      lv_file_con1 TYPE xstring,
      lv_file_con2 TYPE xstring,
      lv_file_space type xstring,
      lv_file_con TYPE xstring.

LOOP AT lt_contents INTO lw_content.      // Get the RAW/Binary Data into a local work area for further usage.

lv_file_con1 = lw_content-line.
CONCATENATE  lv_file_con2 lv_file_con1 INTO lv_file_con2 IN BYTE MODE. //collecting the attachment contents in a variable from an internal table.

ENDLOOP.

lv_file_con = lv_file.
CLEAR lv_file.
lv_file_space = '0'.       // Hexadecimal symbol for space that is 0 which is to be eliminated.

shift lv_file_con2 right deleting trailing lv_file_space in byte mode.  // removing RHS spaces/'0's/null's.

**After RIGHT SHIFT  the spaces are get added at LHS of Data which can be eliminated using left shift.

shift lv_file_con2 left deleting leading lv_file_space in byte mode.  // all spacess/0's/"null"s are get eliminated in this step

CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'      // converting Data into base64 format
  EXPORTING
  input    = lv_file_con2
**      unescape = 'X'
  IMPORTING
  output   = lv_file.        // This lv_file will content the required data (without any "null" characters)hexadecimal form.

**-------------------------------------------------------------------------------------------------------------

Thats it from my side.
If you expert guyz can suggest any changes I need to be made or can come up with a better solution
then you are most welcome.

Thanks and Regards,

Vikas Kailas Khanase
(+91) 9324758106

13 Comments
Labels in this area