on 01-23-2008 3:05 PM
Hi experts,
I have implemented this BAdi, and I use it in actions in order to print / mail / fax PDF forms.
Here is a code snipplet:
-
" calling PDF form
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = ls_fp_name
IMPORTING
e_funcname = ls_fp_funcname
" E_INTERFACE_TYPE =
.
ls_fp_outputparams-nodialog = 'X'.
ls_fp_outputparams-getpdf = 'X'.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = ls_fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ls_fp_docparams-langu = 'E'.
ls_fp_docparams-country = 'EN'.
CALL FUNCTION ls_fp_funcname
EXPORTING
/1bcdwb/docparams = ls_fp_docparams
output_options = ls_output_options
order_num = order_id
" description =
partner_1 = ls_partner_1_details
partner_2 = ls_partner_2_details
emp_resp_name = emp_resp_name
item = ls_item
veh_details = ls_veh_details
taxnumber = taxnumber
bank_account = bank_account
days_text = days_text
" IMPORTING
" /1BCDWB/FORMOUTPUT = ls_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3.
IF sy-subrc <> 0.
CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'
IMPORTING
e_adserrstr = last_ads_error_string.
rp_status = 2.
ELSE.
rp_status = 1.
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE'
" IMPORTING
" E_RESULT =
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 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.
Here if I debug the BAdI I always get "Usage error" exception at FM - CALL FUNCTION ls_fp_funcname.
If I remove FP_JOB_OPEN, everything is working fine, but I have to use FP_JOB_OPEN, because I would like to send the pdf form as email.
What could be the problem, do you have any idea?
Thanks!
Gabor
Hi Gabor,
Can you check the program bcs_example_06.
This is example program to send pdf as mail.
pavan meda
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gabor,
Can you clarify " If I remove FP_JOB_OPEN, everything is working fine" in your intial message.
Is FP_JOB_OPEN first time called or 2nd time.
Can uncomment the below code lines in function call.
" IMPORTING
" /1BCDWB/FORMOUTPUT = ls_formoutput
after coming out the function call at runtime, Structure ls_formoutput contains one hexa string which u can use for mail , see the last 15 lines code in bcs_example_06.
pavan meda
Dear Pavan,
I uncommented ls_formoutput, but its structure is completely empty.
I debugged the program and I realised, that inside the generated function module a message is dropped: FPRUNX 101 - Job already started. I have found a SAP Note Number: 858325, Message "Job already started" when you display PDF forms but it doesn't give me solution.
I wrote another program based on BCS_EXAMPLE_6, it gives me the same message:
REPORT test.
DATA: fm_name TYPE rs38l_fnam,
fp_docparams TYPE sfpdocparams,
fp_outputparams TYPE sfpoutputparams,
error_string TYPE string.
DATA ls_formoutput TYPE fpformoutput.
DATA lx_fp_api TYPE REF TO cx_fp_api.
DATA lp_form TYPE tdsfname VALUE 'YH_MAK_BERAUTO'.
DATA lp_langu TYPE langu VALUE 'H'.
DATA lp_countr TYPE land1 VALUE 'HU'.
" BCS data
DATA send_request TYPE REF TO cl_bcs.
DATA text TYPE bcsy_text.
DATA document TYPE REF TO cl_document_bcs.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA sent_to_all TYPE os_boolean.
DATA pdf_content TYPE solix_tab.
DATA lp_pdf_size TYPE so_obj_len.
" Print data:
" First get name of the generated function module
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = lp_form
IMPORTING
e_funcname = fm_name.
CATCH cx_fp_api INTO lx_fp_api.
" exception handling
MESSAGE ID lx_fp_api->msgid TYPE lx_fp_api->msgty
NUMBER lx_fp_api->msgno
WITH lx_fp_api->msgv1 lx_fp_api->msgv2
lx_fp_api->msgv3 lx_fp_api->msgv4.
EXIT.
ENDTRY.
" Set output parameters and open spool job
fp_outputparams-nodialog = 'X'. " no print preview
fp_outputparams-getpdf = 'X'. " request PDF
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
" Set form language and country (->form locale)
fp_docparams-langu = lp_langu.
fp_docparams-country = lp_countr.
" Now call the generated function module
CALL FUNCTION fm_name
EXPORTING
/1bcdwb/docparams = fp_docparams
IMPORTING
/1bcdwb/formoutput = ls_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'
IMPORTING
e_adserrstr = error_string.
IF NOT error_string IS INITIAL.
" we received a detailed error description
WRITE:/ error_string.
EXIT.
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
" Close spool job
CALL FUNCTION 'FP_JOB_CLOSE'
" IMPORTING
" E_RESULT =
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 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.
" -
Call BCS interface -
TRY.
" -
create persistent send request -
send_request = cl_bcs=>create_persistent( ).
" -
add document -
" get PDF xstring and convert it to BCS format
lp_pdf_size = XSTRLEN( ls_formoutput-pdf ).
pdf_content = cl_document_bcs=>xstring_to_solix(
ip_xstring = ls_formoutput-pdf ).
document = cl_document_bcs=>create_document(
i_type = 'PDF'
i_hex = pdf_content
i_length = lp_pdf_size
i_subject = 'test created by BCS_EXAMPLE_6' ). "#EC NOTEXT
" add document to send request
send_request->set_document( document ).
" -
add recipient (e-mail address) -
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = 'gantal@hostlogic.hu' ).
" add recipient to send request
send_request->add_recipient( i_recipient = recipient ).
" -
send document -
sent_to_all = send_request->send(
i_with_error_screen = 'X' ).
IF sent_to_all = 'X'.
MESSAGE i022(so).
ENDIF.
" -
explicit 'commit work' is mandatory! -
COMMIT WORK.
" -
" " exception handling
" -
" " replace this very rudimentary exception handling
" " with your own one !!!
" -
CATCH cx_bcs INTO bcs_exception.
WRITE: text-001.
WRITE: text-002, bcs_exception->error_type.
EXIT.
ENDTRY.
Hi Gabor,
For your form which type of interface is used.If the interface is smartform based interface, there will be job open and job close function modules in the auto generated function module (fm_name) after activation.
I believe this could be the problem for the error "Job already started".
If what I said is correct dont call job open and job close in the program , direcftly use function fm_name.check the structure ls_formoutput .If you face the same problem try to use normal interface.
pavan meda
Dear Pavan, I tried to remove FP_JOB_OPEN, and simply calling the generated FM it is working fine. But the reason that I want to use FP_JOB_OPEN, that I would like to send the form by email, and I have to supress the print dialog window. I tried another way to supress the dialog, by calling the generated FM this way:
ls_control_parameters-device = 'MAIL'.
ls_control_parameters-no_dialog = 'X'.
CALL FUNCTION fm_name
EXPORTING
/1bcdwb/docparams = fp_docparams
/1bcdwb/output_options = ls_output_options
/1bcdwb/control_parameters = ls_control_parameters
IMPORTING
/1bcdwb/formoutput = ls_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
But here the ls_formoutput is empty again, but I am able to print the form, and adobe reader is coming up and displaying the form.
So in conclusion I HAVE TO use FP_JOB_OPEN, but I don't know what is the reason "Job already started" message.
I tried to change the interface type of the form from S to ABAP dictionary based interface but I got a runtime error (maybe because I didn't re-activated the form).
Gabor
Dear Pavan!
First of all, thank you very much of your kind help and support!
I succeeded to get the PDF data, and I have found out what was the problem.
1. I had to change the type of my form interface to ABAP dictionary based interface
2. I had to re-activate the PDF form in SFP, so the system re-created the generated function module
3. In my program, I called FP_JOB_OPEN with the same parameters like in BCS_EXAMPLE_6
4. I called the generated function module, with the import parameter ls_formoutput
5. then I called FP_JOB_CLOSE, there was no error
6. after that I have called BCS interface and everything is worked fine!
Now I am happy
Thank you, Pavan, have a nice day!
Gabor
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.