0% found this document useful (0 votes)
169 views

Sap Abap Error Code

This document contains ABAP code for forms that retrieve tax invoice data from database tables, process the data, and print or email a tax invoice smart form. The forms select data from various tables, calculate totals, and call a smart form to output the invoice. Conditional logic is used for printing, emailing, or previewing the output.

Uploaded by

vmuthukumaar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views

Sap Abap Error Code

This document contains ABAP code for forms that retrieve tax invoice data from database tables, process the data, and print or email a tax invoice smart form. The forms select data from various tables, calculate totals, and call a smart form to output the invoice. Conditional logic is used for printing, emailing, or previewing the output.

Uploaded by

vmuthukumaar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 12

*&---------------------------------------------------------------------*

*& Include
ZFI_TAX_INVOICE_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form refresh_table_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM refresh_table_data.
REFRESH: g_bsid_itab, g_bsid_hd, g_bsid_it, g_bset_itab, g_bkpf_itab, g_bsid_c
opy.
ENDFORM.
" refresh_table_data
*&---------------------------------------------------------------------*
*&
Form get_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_data.
SELECT
FROM
INTO
WHERE

bukrs kunnr belnr gjahr budat zuonr sgtxt blart shkzg wrbtr waers
bsid
CORRESPONDING FIELDS OF TABLE g_bsid_itab
bukrs = p_bukrs AND
kunnr IN s_kunnr AND
budat IN s_budat AND
blart EQ p_blart.

SELECT bukrs kunnr belnr gjahr budat zuonr sgtxt blart shkzg wrbtr waers
FROM bsad
APPENDING CORRESPONDING FIELDS OF TABLE g_bsid_itab
WHERE bukrs = p_bukrs AND
kunnr IN s_kunnr AND
budat IN s_budat AND
blart EQ p_blart.
IF NOT g_bsid_itab IS INITIAL.
SORT g_bsid_itab BY kunnr bukrs belnr gjahr.
g_bsid_copy = g_bsid_itab.
DELETE ADJACENT DUPLICATES FROM g_bsid_copy COMPARING bukrs belnr gjahr.
** Get reversal FI document
SELECT bukrs belnr gjahr xreversal
FROM bkpf
INTO TABLE g_bkpf_itab
FOR
ALL ENTRIES IN g_bsid_copy
WHERE bukrs = g_bsid_copy-bukrs AND
belnr = g_bsid_copy-belnr AND
gjahr = g_bsid_copy-gjahr.

IF sy-subrc = 0.
DELETE g_bkpf_itab WHERE xreversal = space.
ENDIF.
IF NOT g_bkpf_itab IS INITIAL.
** delete reversal documents
LOOP AT g_bsid_itab ASSIGNING <fs_bsid>.
READ TABLE g_bkpf_itab ASSIGNING <fs_bkpf> WITH KEY bukrs = <fs_bsid>-bu
krs
belnr = <fs_bsid>-be
lnr
gjahr = <fs_bsid>-gj
ahr.
IF sy-subrc = 0.
DELETE g_bsid_itab.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
SELECT
FROM
INTO
FOR
WHERE

bukrs belnr gjahr shkzg fwste


bset
TABLE g_bset_itab
ALL ENTRIES IN g_bsid_itab
bukrs = g_bsid_itab-bukrs AND
belnr = g_bsid_itab-belnr AND
gjahr = g_bsid_itab-gjahr.

ENDFORM.
" get_data
*&---------------------------------------------------------------------*
*&
Form process_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM process_data.
LOOP AT g_bsid_itab ASSIGNING <fs_header>.
CLEAR: v_wmwst.
LOOP AT g_bset_itab ASSIGNING <fs_bset> WHERE

bukrs = <fs_header>-bukrs AN

D
belnr = <fs_header>-belnr AND
gjahr = <fs_header>-gjahr.
v_wmwst = v_wmwst + <fs_bset>-fwste.
ENDLOOP.

<fs_header>-wmwst = v_wmwst.
IF <fs_header>-shkzg = 'H'.
<fs_header>-wrbtr = <fs_header>-wrbtr * '-1'.
ENDIF.
<fs_header>-wrbt1 = <fs_header>-wrbtr - <fs_header>-wmwst.
ENDLOOP.
g_bsid_hd = g_bsid_itab.
DELETE ADJACENT DUPLICATES FROM g_bsid_hd COMPARING kunnr.
ENDFORM.
" process_data
*&---------------------------------------------------------------------*
*&
Form print_form
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM print_form.
CLEAR: fm_name.
REFRESH: dtab.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFI_TAX_INVOICE'
IMPORTING
fm_name = fm_name.
LOOP AT g_bsid_hd ASSIGNING <fs_header>.
CLEAR: tot_royality, tot_tax, tot_amount.
REFRESH: g_bsid_it.
count = count + 1.
LOOP AT g_bsid_itab ASSIGNING <fs_item> WHERE kunnr = <fs_header>-kunnr.
CLEAR: g_bsid_wa.
g_bsid_wa = <fs_item>.
APPEND g_bsid_wa TO g_bsid_it.
tot_amount = tot_amount + <fs_item>-wrbtr.
tot_tax
= tot_tax
+ <fs_item>-wmwst.
tot_royality = tot_royality + <fs_item>-wrbt1.
ENDLOOP.
** set printer attributes
CLEAR: ls_control, ls_composer.
ls_control-device
= 'PRINTER'.
ls_control-no_dialog
= 'X'.

IF r3 = 'X'.
ls_control-getotf
ENDIF.

= 'X'.

ls_composer-tddest

= 'LP01'.

IF r1 = 'X' OR r2 = 'X'.
IF r1 = 'X'.
ls_composer-tdimmed
ELSEIF r2 = 'X'.
ls_composer-tdimmed
ENDIF.

= ''.
= 'X'.

ENDIF.
ls_composer-tdnoprev

= 'X'.

IF count EQ '1'.
ls_composer-tdnewid
ELSE.
ls_composer-tdnewid
ENDIF.
** call customer service tax
CALL FUNCTION fm_name
EXPORTING
control_parameters
output_options
user_settings
bsid
tot_royality
tot_tax
tot_amount
IMPORTING
document_output_info
job_output_info
job_output_options
TABLES
it_bsid

= 'X'.
= ''.

invoice smartform
=
=
=
=
=
=
=

ls_control
ls_composer
''
<fs_header>
tot_royality
tot_tax
tot_amount

= ssfcrespd
= ssfcrescl
= ssfcresop
= g_bsid_it.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
** Print Preview and Printout.
IF r1 = 'X' OR r2 = 'X'.
LOOP AT ssfcrescl-spoolids INTO w_rspoid.
counter = counter + 1.
ENDLOOP.
ELSE.
** Mail.
REFRESH: g_otf_itab, g_tline_itab, i_record.
g_otf_itab = ssfcrescl-otfdata[].

PERFORM convert_otf_to_pdf.
PERFORM CONVERT_OTF_TO_PDF.

perform process_email.
endif .
endif.
ENDLOOP.
ENDFORM.
" print_form
*&---------------------------------------------------------------------*
*&
Form convert_otf_to_pdf
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
*FORM convert_otf_to_pdf .
*
* CALL FUNCTION 'CONVERT_OTF'
*
EXPORTING
*
format
= 'PDF'
*
max_linewidth
= 132
*
IMPORTING
*
bin_filesize
= bin_filesize
*
TABLES
*
otf
= g_otf_itab
*
lines
= g_tline_itab
*
EXCEPTIONS
*
err_max_linewidth
= 1
*
err_format
= 2
*
err_conv_not_possible = 3
*
err_bad_otf
= 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.
*
* LOOP AT g_tline_itab INTO g_tline_wa.
*
*** Replacing space by ~
*
TRANSLATE g_tline_wa USING ' ~'.
*
CONCATENATE w_buffer g_tline_wa INTO w_buffer.
*
* ENDLOOP.
*
*** Replacing ~ by space
* TRANSLATE w_buffer USING '~ '.
*
* DO.
*
*
i_record = w_buffer.
*** Appending 255 characters as a record
*
APPEND i_record.
*
SHIFT w_buffer LEFT BY 255 PLACES.
*
*
IF w_buffer IS INITIAL.

*
EXIT.
*
ENDIF.
*
* ENDDO.
*
*ENDFORM.
" convert_otf_to_pdf
*&---------------------------------------------------------------------*
*&
Form process_email
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM process_email.
CLEAR: w_doc_chng.
REFRESH: i_objpack[], i_objbin[], i_objtxt[], i_reclist[].
**** Object with PDF
** i_objbin[] = i_record[].
** DESCRIBE TABLE i_objbin LINES v_lines_bin.
**
**** Object with main text of the mail
** i_objtxt = 'Find attached the output of the smart form.'.
** APPEND i_objtxt.
** i_objtxt = 'Regards,'.
** APPEND i_objtxt.
** i_objtxt = sy-uname.
** APPEND i_objtxt.
** DESCRIBE TABLE i_objtxt LINES v_lines_txt.
**
**** Document information.
** w_doc_chng-obj_name = 'SMARTFORM'.
** w_doc_chng-obj_descr = 'CST Invoice'.
** w_doc_chng-expiry_dat = sy-datum + 10.
** w_doc_chng-sensitivty = 'F'.
"Functional object
** w_doc_chng-doc_size = v_lines_txt * 255.
**
**** Pack to main body as RAW.
**** Obj. to be transported not in binary form
** CLEAR i_objpack-transf_bin.
**
**** start line of object header in transport packet
** i_objpack-head_start = 1.
**
**** number of lines of an object header in object packet
** i_objpack-head_num = 0.
**
**** start line of object contents in an object packet
** i_objpack-body_start = 1.
**
**** number of lines of the object contents in an object packet
** i_objpack-body_num = v_lines_txt.
**
**** code for document class
** i_objpack-doc_type = 'RAW'.
** APPEND i_objpack.
**

**** Packing as PDF.


** i_objpack-transf_bin = 'X'.
** i_objpack-head_start = 1.
** i_objpack-head_num = 1.
** i_objpack-body_start = 1.
** i_objpack-body_num = v_lines_bin.
** i_objpack-doc_type = 'PDF'.
** i_objpack-obj_name = 'SMARTFORM'.
** i_objpack-obj_descr = 'CST Invoice'.
**
*** CONCATENATE 'Smartform_output' '.pdf' INTO i_objpack-obj_descr.
** i_objpack-doc_size = v_lines_bin * 255.
** APPEND i_objpack.
**
**** document information.
** CLEAR i_reclist.
** e-mail receivers.
CLEAR: v_smtp_addr, flag, lv_addrnumber.
SELECT SINGLE adrnr FROM kna1 INTO lv_addrnumber WHERE kunnr = <fs_header>-kun
nr.
IF sy-subrc = 0.
SELECT SINGLE smtp_addr
FROM adr6
INTO v_smtp_addr
WHERE addrnumber EQ lv_addrnumber.
ENDIF.
** IF NOT v_smtp_addr IS INITIAL.
**
CLEAR: i_reclist.
**
i_reclist-receiver = v_smtp_addr.
**
i_reclist-rec_type = 'U'. "Internet address
**
i_reclist-com_type = 'INT'. "Send via Internet
**
APPEND i_reclist.
**
**
flag = 'X'.
** ENDIF.
**
** i_reclist-receiver = sy-uname.
** i_reclist-rec_type = 'B'.
** APPEND i_reclist.
**
**** Sending mail.
** CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
**
EXPORTING
**
document_data
= w_doc_chng
**
put_in_outbox
= 'X'
**
commit_work
= 'X'
**
TABLES
**
packing_list
= i_objpack[]
**
contents_bin
= i_objbin[]
**
contents_txt
= i_objtxt[]
**
receivers
= i_reclist[]
**
EXCEPTIONS
**
too_many_receivers
= 1
**
document_not_sent
= 2
**
document_type_not_exist
= 3
**
operation_no_authorization = 4
**
parameter_error
= 5

**
x_error
= 6
**
enqueue_error
= 7
**
OTHERS
= 8.
**
** IF sy-subrc = 0.
**
**
IF flag = 'X'.
**
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
**
ENDIF.
**
**
CLEAR: w_dtab.
**
WRITE icon_green_light AS ICON TO w_dtab-status.
w_dtab-input
= <fs_header>-kunnr.
w_dtab-output = v_smtp_addr.
w_dtab-mesage = 'Mail Delivered and Check SAP User Inbox in Business Workp
lace'.
APPEND w_dtab TO dtab.
*******************upto this changed***********
* ENDIF.

***************************************Starting from this*******************


DATA: lt_return TYPE bapiret2_t,
lt_mail_text TYPE bcsy_text,
lt_binary_content TYPE solix_tab.
* lt_binary_content TYPE SOLI_TAB.
*-- Declaring local variable
DATA: lv_subject TYPE so_obj_des VALUE 'CST Invoice',
lv_text_length TYPE so_obj_len,
lv_attcdoctype TYPE so_obj_tp value 'PDF',
lv_atttitle TYPE so_obj_des value 'attach',
lv_email TYPE ad_smtpadr.
*-- Declaring objects
DATA: lcl_document_bcs TYPE REF TO cl_document_bcs,
lcl_cx_doc_bcs TYPE REF TO cx_document_bcs,
lcl_sender TYPE REF TO IF_SENDER_BCS ,"cl_sapuser_bcs,
lcl_cx_send_req_bcs TYPE REF TO cx_send_req_bcs,
lcl_send_request TYPE REF TO cl_bcs,
lif_recipent TYPE REF TO if_recipient_bcs,
lcl_bcs_exception TYPE REF TO cx_bcs.
DATA sent_to_all TYPE os_boolean.
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'RAW'
i_subject = lv_subject
i_length = lv_text_length
i_text = lt_mail_text
* I_HEX = xstring_pdf
RECEIVING
result = lcl_document_bcs.
CALL METHOD cl_document_bcs=>xstring_to_solix

EXPORTING
ip_xstring = PDF_XSTRING
RECEIVING
rt_solix = lt_binary_content.
lv_attcdoctype = 'pdf'.
lv_atttitle = lv_subject.
data: l_binary_content type soli_tab.

lcl_document_bcs->add_attachment( EXPORTING
i_attachment_type = lv_attcdoctype
i_attachment_subject = lv_atttitle
i_attachment_language = sy-langu
* i_att_content_text = l_binary_content
i_att_content_hex = lt_binary_content ).
*I_ATT_CONTENT_TEXT = lt_binary_content ).
* ---------- create persistent send request ---------------------lcl_send_request = cl_bcs=>create_persistent( ).
* add document to send request
lcl_send_request->set_document( lcl_document_bcs ).
DATA:LVUNAME TYPE SY-UNAME.
LVUNAME = sy-uname.
lcl_sender = cl_sapuser_bcs=>create( LVUNAME ).
CALL METHOD lcl_send_request->set_sender
EXPORTING
i_sender = lcl_sender.
* ---------- add recipient (e-mail address) ---------------------*TRY.
*CALL METHOD CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS
* EXPORTING
*
I_ADDRESS_STRING =
v_smtp_addr
*
*
I_ADDRESS_NAME =
*
I_INCL_SAPUSER =
* RECEIVING
*
RESULT
= lif_recipent
*
.
* CATCH CX_ADDRESS_BCS .
*ENDTRY.
lif_recipent = cl_cam_address_bcs=>create_internet_address( v_smtp_addr ).
*

lcl_send_request->add_recipient( EXPORTING i_recipient = lif_recipent ).


* ---------- explicit 'commit work' is mandatory! ----------------

DATA:
recipient_sap TYPE REF TO if_recipient_bcs.
recipient_sap = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD lcl_send_request->add_recipient
EXPORTING
i_recipient = recipient_sap
i_express
= 'X'.
*Add these codes before the ststement .
*lcl_send_request->set_send_immediately( 'X' ).

lcl_send_request->set_send_immediately( 'X' ).
lcl_send_request->send( ).
CLEAR: lif_recipent,lcl_send_request.
COMMIT WORK.

ENDFORM.

" process_email

*&---------------------------------------------------------------------*
*&
Form set_print_attributes
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM set_print_attributes .
CLEAR: ls_control_param, ls_composer_param.
ls_control_param-device
ls_control_param-no_dialog
ls_control_param-getotf

= 'PRINTER'.
= 'X'.
= 'X'.

ls_composer_param-tddest
= 'LP01'.
* ls_composer_param-tdimmed
= ''.
* ls_composer_param-tdnoprev = 'X'.
* ls_composer_param-tdnewid
= 'X'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFI_CUST_ACCT_STATEMENT'
IMPORTING
fm_name = wv_fm_name.
ENDFORM.
" set_print_attributes
*&---------------------------------------------------------------------*
*&
Form convert_otf_to_pdf
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM convert_otf_to_pdf .
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format
=
max_linewidth
=
IMPORTING
bin_filesize
=
BIN_FILE
=
TABLES
otf

'PDF'
132
bin_filesize
pdf_xstring

= g_otf_itab

lines
EXCEPTIONS
err_max_linewidth
err_format
err_conv_not_possible
err_bad_otf
OTHERS

= g_tline_itab
=
=
=
=
=

1
2
3
4
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.
ENDFORM.

" convert_otf_to_pdf

*&---------------------------------------------------------------------*
*&
Form display_output
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM display_output .
IF r1 = 'X'.
IF NOT counter IS INITIAL.
CLEAR: wa_list. REFRESH: id_list.
wa_list-id = w_rspoid.
APPEND wa_list TO id_list.
CALL FUNCTION 'RSPO_RID_SPOOLREQ_DISP'
EXPORTING
id_list = id_list.
ENDIF.
ELSEIF r2 = 'X'.
IF NOT counter IS INITIAL.
WRITE:/ 'Successfully Printed'.
ENDIF.
ELSEIF r3 = 'X'.
IF NOT dtab IS INITIAL .
PERFORM display_message.
ENDIF.
ENDIF.
ENDFORM.

" display_output

*&---------------------------------------------------------------------*
*&
Form display_message
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM display_message .
g_repid = sy-repid.
REFRESH: i_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-fieldname = 'STATUS'.
w_fieldcat-seltext_m = 'Status'.
w_fieldcat-col_pos
= 1.
w_fieldcat-outputlen = 5.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-fieldname = 'INPUT'.
w_fieldcat-seltext_m = 'Customer Code'.
w_fieldcat-col_pos
= 2.
w_fieldcat-outputlen = 10.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-fieldname = 'OUTPUT'.
w_fieldcat-seltext_m = 'Mail ID'.
w_fieldcat-col_pos
= 3.
w_fieldcat-outputlen = 10.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.
w_fieldcat-fieldname = 'MESAGE'.
w_fieldcat-seltext_m = 'Message'.
w_fieldcat-col_pos
= 4.
w_fieldcat-outputlen = 150.
APPEND w_fieldcat TO i_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
i_grid_title
= 'LOG DISPLAY'
it_fieldcat
= i_fieldcat
i_save
= 'X'
TABLES
t_outtab
= dtab
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
ENDFORM.

You might also like