‎2012 Feb 22 4:40 AM
Hi,
I am trying to create an attachment using the FM BDS_BUSINESSDOCUMENT_CREATEF. But it is giving me sy-subrc 4(ERROR_KPRO). Can anyone explain how to correct this and if u have any better code to attach files to BO's pls post it here.
This is my code:
DATA : files LIkE BAPIFILES OCCURS 1 WITH header line.
files-doc_count = '1'.
files-directory = 'C:\Documents and Settings\e529015\Desktop\'.
files-filename = 'layout.jpeg'.
APPEND files.
data: lv_logsys type TBDLS-LOGSYS.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
OWN_LOGICAL_SYSTEM = lv_logsys
EXCEPTIONS
OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'BDS_BUSINESSDOCUMENT_CREATEF'
EXPORTING
LOGICAL_SYSTEM = lv_logsys
classname = 'BUS2038'
classtype = 'BO'
CLIENT = SY-MANDT
OBJECT_KEY = '300023662'
tables
files = files
SIGNATURE =
EXCEPTIONS
NOTHING_FOUND = 1
PARAMETER_ERROR = 2
NOT_ALLOWED = 3
ERROR_KPRO = 4
INTERNAL_ERROR = 5
NOT_AUTHORIZED = 6
OTHERS = 7
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Best Regards,
Pavan Jhawar.
‎2012 Feb 22 4:45 AM
Hi,
Check this code...
DATA: NUMBER_ATTACH TYPE i.
Data Declaration for attachment ********
data: go_myobject type ref to cl_gos_manager.
data: lo_container type ref to cl_gui_custom_container,
ls_object type borident.
MODULE ATTACH_FILE input.
if ok_code = 'CATC'.
IF ZQTHD-JNAME is not initial.
*******Number Ranges For ATTACHMENT ********
if zqthd-objectkey is initial.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = '1'
OBJECT = 'ZATTACH_NR'
QUANTITY = '1'
SUBOBJECT = ' '
TOYEAR = '0000'
IGNORE_BUFFER = ' '
IMPORTING
NUMBER = NUMBER_ATTACH
QUANTITY =
RETURNCODE =
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif.
zqthd-objectkey = NUMBER_ATTACH.
ls_object-objtype = 'ZQUOTATION'.
ls_object-objkey = zqthd-objectkey.
call method go_myobject->start_service_direct
exporting
ip_service = 'PCATTA_CREA'
is_object = ls_object
io_container = lo_container.
ENDIF.
endif.
‎2012 Feb 22 6:19 AM
Hi Ravi,
Thanks for the reply but when i am using this i am getting short dump saying
Runtime Errors OBJECTS_OBJREF_NOT_ASSIGNED
Except. CX_SY_REF_IS_INITIAL
Access via 'NULL' object reference not possible.
any idea how to correct this?
Best Regards,
Pavan Jhawar.
‎2012 Feb 22 6:43 AM
Hi,
The dump issue is solved, but from my program i am selecting the file in pop up and at the end it shows attachment saved successfully but when i check in the document it is not there.
Any idea.
Below is my code.
data: go_myobject type ref to cl_gos_manager.
data: lo_container type ref to cl_gui_custom_container,
ls_object type borident.
ls_object-objtype = 'BUS2080'.
ls_object-objkey = '300023662'.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
OWN_LOGICAL_SYSTEM = ls_object-logsys
EXCEPTIONS
OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1
OTHERS = 2
.
IF sy-subrc <> 0.
Implement suitable error handling here
ENDIF.
data: lp_no_commit TYPE sgs_cmode.
CREATE OBJECT go_myobject
EXPORTING
is_object = ls_object
ip_no_commit = lp_no_commit
EXCEPTIONS
object_invalid = 1
callback_invalid = 2
others = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_myobject->start_service_direct
EXPORTING
ip_service = 'PCATTA_CREA'
is_object = ls_object
io_container = lo_container
EXCEPTIONS
no_object = 1
object_invalid = 2
execution_failed = 3
others = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Best Regards,
Pavan Jhawar.
‎2012 Feb 22 8:29 AM
HI,
It is working fine now. But i have one more requirement. The present code asks the file to pick from presentation server. Is there anyway to get the file from application server and attach it to the business object.
Best Regards,
Pavan Jhawar.