Upload file in Webdynpro ABAP - file-upload

I'm searching a Webdynpro way to uploaded xstring file into the BDS (Business Document Service), most of the files are in binary or ZIP format. I use the File upload function of Webdynpro.
I've tried to insert the file with the BDS-function CREATE_WITH_AS_TABLE but only rubbish was stored in the BDS.
Can someone help me to solve this little problem?
Thanks

Hi thanks for your answer.
I found the solution of this little problem. I forgot to convert the xsting in binary format to insert the file in the bds system. Unfortunatly many guys have the same problem but nobody posted a snippet.
The important code is:
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = im_xstr
IMPORTING
output_length = lv_size
TABLES
binary_tab = lt_data.
My complete class:
method WD_SAVE_NEW_FILE.
DATA: i_files TYPE sbdst_files,
wa_files LIKE LINE OF i_files,
i_signature TYPE sbdst_signature,
wa_signature LIKE LINE OF i_signature.
* prepare data for FM - COMPONENTS
DATA: i_components TYPE sbdst_components,
wa_components LIKE LINE OF i_components .
wa_components-doc_count = 1.
wa_components-comp_count = 1.
wa_components-comp_id = IM_FILE_NAME.
wa_components-mimetype = IM_FILE_MIME.
APPEND wa_components to i_components.
* set signature to intial = 1
wa_signature-doc_count = 1.
wa_signature-doc_ver_no = 1.
wa_signature-doc_var_id = 1.
wa_signature-doc_var_tg = ''.
wa_signature-comp_count = 1.
wa_signature-prop_name = 'BDS_DOCUMENTCLASS'.
wa_signature-prop_value = ''.
APPEND wa_signature TO i_signature.
CLEAR wa_signature.
wa_signature-doc_count = 1.
wa_signature-doc_ver_no = 1.
wa_signature-doc_var_id = 1.
wa_signature-doc_var_tg = ''.
wa_signature-comp_count = 1.
wa_signature-prop_name = 'DESCRIPTION'.
wa_signature-prop_value = im_file_comment.
APPEND wa_signature TO i_signature.
CLEAR wa_signature.
DATA lt_data TYPE sbdst_content.
DATA lv_size TYPE i.
DATA ls_xstring TYPE XSTRINGVAL.
* Fill ls_xstring
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = im_xstr
IMPORTING
output_length = lv_size
TABLES
binary_tab = lt_data.
CALL METHOD me->o_document_set->create_with_table
EXPORTING
classname = me->i_classname
classtype = me->i_classtype
content = lt_data
components = i_components
CHANGING
object_key = me->i_object_key
signature = i_signature
EXCEPTIONS
nothing_found = 1
parameter_error = 2
not_allowed = 3
error_kpro = 4
internal_error = 5
not_authorized = 6
OTHERS = 7.
CASE sy-subrc.
WHEN 0.
*
WHEN 1.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WHEN 2.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WHEN 3.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WHEN 4.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WHEN 5.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WHEN 6.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
WHEN OTHERS.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDCASE.
*return values
endmethod.
I hope the code will help other Web Dynpro newbie's.
Cheers
Heinrich

Have you tried this function?
-BDS_BUSINESSDOCUMENT_CREATEF
Also to store that file in BDS, you have to use
-CL_BDS_DOCUMENT_SET=>CREATE_WITH_TABLE
Hope its helpful.

Related

How to assign Float type field to a Char type field in odoo 15?

Full Code:
from odoo import fields, models, api
class ExtraWeight(models.Model):
_name = 'courier.extra.weights'
_description = 'Charge setting for Extra Weight'
_rec_name = 'combination'
extra_weight = fields.Float(string='Next (KG)', required=True, translate=True)
extra_charge = fields.Float(string='Charge for next Weight (TK)', required=True, translate=True)
max_weight = fields.Float(string='Max Wight (KG)', required=True, translate=True)
combination = fields.Char('Combination', compute='_compute_fields_combination')
#api.depends('extra_weight', 'extra_charge')
def _compute_fields_combination(self):
for record in self:
record.combination = 'Extra Increment:' + str(record.extra_weight) + '(KG) Rate' + str(record.extra_charge) + '(TK) Max:'+str(record.max_weight)+'(KG)'
I want to set 'Extra Increment:' + str(record.extra_weight) + '(KG) Rate' + str(record.extra_charge) + '(TK) Max:'+str(record.max_weight)+'(KG)' to combination. But I am getting the following error:
COALESCE types text and double precision cannot be matched
LINE 1: ...CE("courier_extra_weights__extra_weight"."value", "courier_e..
Your code looks good to me. It seems Char is not suitable as per your output length. Replace field type from Char to Text

HTTPError: HTTP Error 404: Not Found TextBlob and Extra data: line 1 column 352 (char 351) (Phyton)

I am doing a data translation to do a sentiment analysis but I have problems when translating with the TextBlob library, as seen in the code, it gives me an HTTP404 error.
FORM 1
TextBlob('Odio el código spaguetti').translate(from_lang='es', to='en').sentiment #fr, pt, it
I have 2 ways of doing the translation but I would like you to help me understand which is the most optimal because I need to do the code quickly:
in form 2 it gives me an error:JSONDecodeError: Extra data: line 1 column 352 (char 351)
form 2
traductor = google_translator()
texto = df["Comentarios"]
texto_trad = pd.Series([])
for cont in range(len(texto)):
traduccion = traductor.translate(texto[cont], lang_src='es', lang_tgt='en')
text_trad[cont] = traduccion
print(text_trad)
thanks for your help

ValueError: invalid literal for int() with base 10: 'O'

I am relatively new to python, and as such I don't always understand why I get errors. I keep getting this error:
Traceback (most recent call last):
File "python", line 43, in <module>
ValueError: invalid literal for int() with base 10: 'O'
This is the line it's referring to:
np.insert(arr, [i,num], "O")
I'm trying to change a value in a numpy array.
Some code around this line for context:
hOne = [one,two,three]
hTwo = [four,five,six]
hThree = [seven, eight, nine]
arr = np.array([hOne, hTwo, hThree])
test = "O"
while a != Answer :
Answer = input("Please Enter Ready to Start")
if a == Answer:
while win == 0:
for lists in arr:
print(lists)
place = int(input("Choose a number(Use arabic numerals 1,5 etc.)"))
for i in range(0,len(arr)):
for num in range(0, len(arr[i])):
print(arr[i,num], "test")
print(arr)
if place == arr[i,num]:
if arr[i,num]:
np.delete(arr, [i,num])
np.insert(arr, [i,num], "O")
aiTurn = 1
else:
print(space_taken)
The number variables in the lists just hold the int version of themselves, so one = 1, two = 2 three = 3, etc
I've also tried holding "O" as a variable and changing it that way as well.
Can anyone tell me why I'm getting this error?

what should I add to display the value of fields correctly?

what should I add to display user_id and cat correctly
#api.model
def create(self, vals):
record=super(test, self).create(vals)
if vals['total'] > 0:
vals['date'] = fields.Datetime.now()
self.env['journal'].create({
'user_id': record.patient_id,
'cat': record.cat,})
....
.....
on the tree view (journal):
user_id is displayed as test.user(6,)
cat is displayed as cat1
EDITS:
class test(models.Model):
_name = 'test'
cat = fields.Selection(
required=True,
related='test_type_cat.name',
store=True,
)
user_id = fields.Many2one('res.users', string='user', readonly=True,)
.....
#api.model
def create(self, vals):
record=super(test, self).create(vals)
if vals['total'] > 0:
vals['date'] = fields.Datetime.now()
self.env['journal'].create({
'patient_id': record.patient_id.name,
'cat': record.cat,
'user_id': record.user_id.name,
})
record.total = 0
return record
why does it work with .name and not .id ?
for m2o field should I pass the integer value ? if it is the case why does it work here with .name ? and what about m2m and o2m?
this worked for you because you are creating a record in model: journal not in test model.
and if you go to journal model you will find that patient_id is Char field not a many2one field.
so if you pass: record.patient_id you are passing an object and it's converted to char this is why you get test(1,). because pateint_id is a many2one field in test model witch mean is an object.
Hope this clear thing little bit for you.

Difference between 2 timestamps

I have a program in ABAP where they use the type 'timestampl' in a variable, so they can get the time of certain events. They use it because they need the milliseconds.
I now have the mission of getting the difference between 2 of these variables, and I can't seem to find a function module or another solution.
Any help is much appreciated!
Use the method CL_ABAP_TSTMP=>SUBTRACT, by passing two timestamps which must be of the type TIMESTAMPL so that to contain milliseconds, and the difference between the 2 timestamps will be returned in number of seconds, including the milliseconds.
Example:
DATA: lv_tstmp1 TYPE timestampl,
lv_tstmp2 TYPE timestampl,
lv_diff TYPE tzntstmpl.
lv_tstmp1 = '20190704000010.999'. " July 4th, 00:00:10 and 999 ms
lv_tstmp2 = '20190703235950.001'. " July 3rd, 23:59:50 and 001 ms
CALL METHOD cl_abap_tstmp=>subtract
EXPORTING
tstmp1 = lv_tstmp1
tstmp2 = lv_tstmp2
RECEIVING
r_secs = lv_diff.
ASSERT lv_diff = '20.998'. " expectation verified or run time error
A Google search turns up this recommendation: http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/840ad679-0601-0010-cd8e-9989fd650822#q-8: use the class CL_ABAP_TSTMP. You can also see an example of how to use the class in this thread: http://scn.sap.com/thread/85476.
cl_abap_tstmp=>systemtstmp_syst2utc(
exporting
syst_date = <wa_joblist>-strtdate
syst_time = <wa_joblist>-strttime
importing
utc_tstmp = start_stamp ).
cl_abap_tstmp=>systemtstmp_syst2utc(
exporting
syst_date = sy-datum
syst_time = sy-uzeit
importing
utc_tstmp = now_stamp ).
seconds = cl_abap_tstmp=>subtract(
tstmp1 = now_stamp
tstmp2 = start_stamp ).
Use the FM *'CCU_TIMESTAMP_DIFFERENCE'*
After Checking which timestamp is greater call the FM.
IF TIMESTAMP_2 > TIMESTAMP_1.
CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'
EXPORTING
TIMESTAMP1 = TIMESTAMP_2
TIMESTAMP2 = TIMESTAMP_1
IMPORTING
DIFFERENCE = TIMESTAMP_DIFFERENCE.
EndIf.
The existing proposals ignore the milliseconds. Here's a solution for modern ABAP AS that also considers msecs:
r_secs = CONV #( cl_abap_tstmp=>subtract(
tstmp1 = CONV timestamp( i_ts1 )
tstmp2 = CONV timestamp( i_ts1 )
) ).
r_secs = r_secs + ( frac( i_ts1 ) - frac( i_ts2 ) ).
i_ts1 and i_ts2 are two timestamps, r_secs (type f) is the result.
Here's a small tester:
REPORT ztest_timestampl_dif.
CLASS lcl_timestampl DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
test,
dif
IMPORTING
i_ts1 TYPE timestampl
i_ts2 TYPE timestampl
RETURNING VALUE(r_secs) TYPE f.
ENDCLASS.
START-OF-SELECTION.
lcl_timestampl=>test( ).
CLASS lcl_timestampl IMPLEMENTATION.
METHOD test.
DATA:
l_ts1 TYPE timestampl,
l_ts2 TYPE timestampl,
l_msecs TYPE f.
GET TIME STAMP FIELD l_ts1.
WAIT UP TO '0.378' SECONDS.
GET TIME STAMP FIELD l_ts2.
l_msecs = dif( i_ts1 = l_ts1 i_ts2 = l_ts2 ).
cl_demo_output=>display( l_msecs ).
ENDMETHOD.
METHOD dif.
r_secs = CONV #( cl_abap_tstmp=>subtract(
tstmp1 = CONV timestamp( i_ts1 )
tstmp2 = CONV timestamp( i_ts1 )
) ).
r_secs = r_secs + ( frac( i_ts1 ) - frac( i_ts2 ) ).
ENDMETHOD.
ENDCLASS.
Consider to add handling for overflows, if you are using it productive.