Prior to delving deeply into the SAP program’s inbound IDocs sending process. Typically, an external framework (let’s say XI) creates the incoming IDoc and sends it to Drain. The cycle code/relating capability module is then used to handle the incoming IDoc. In certain situations, however, due to client requirements, the connection point program should be designed so that the incoming IDoc begins within a comparable SAP framework; for instance, the sending and receiving are identical to the receive framework.
Presently for the most part in such necessities, we by and large create the IDoc subsequent to perusing information from a level record. The document is passed to the application server by a middleware (say XI). The SAP interface program peruses the record from the application server and afterward begins handling the information. To make the inbound IDoc, we want to utilize the Capability Module ‘IDOC_INBOUND_WRITE_TO_DB’. This makes and saves the IDoc to the information base. Sending Inbound IDocs from SAP Program.
PC_control_record receives the control record data for the incoming IDoc (similar to EDIDC-IDoc control record). All important information, such as status (53), shipper port, collector accomplice number, recipient port, source accomplice number, and so on, is filled in the control records. The inbound table t_data_records receives all of the IDoc data (such as EDIDD, or IDoc control record). The incoming record’s IDoc information is read, processed, and then entered into the inbound table itab_data_records_db along with the section name and other details.
Presently if the inbound IDoc has been effectively made and we need to deal with something very similar, the capability module ‘IDOC_START_INBOUND’ can be utilized. Here we pass the inbound interaction information containing the IDoc cycle code and occasion code to wa_inbound_process_data_in. The status and delivery are added to the control records inside table i_control_records.
Don’t be confused if your heritage group, outsider group, EDI group, or non-SAP group requests a *.IDO file for an IDocs type. The SAP Idoc necessary sort’s control information and section nuances are related to the IDO document. All of the essential information needed for the non-SAP framework to plan with the SAP Idoc will be included in the IDO record.
Follow the basic advances composed beneath and send the *.IDO file for IDocs record to the requester in no time.
Steps to get *.IDO file for IDocs
Idoc fundamental sort PEXR2002 (Installment/installment counsel note/credit reminder/charge guidance) is taken for exhibit.
1. Go to exchange WE60 and key in the fundamental kind. Check the Control Record and Information Record really look at box.
2. Go to Documentation->Parser
3. Documentation for the fundamental kind is shown. This is the information which should be shipped off *.ido record
4. Presently we want to save this documentation in .ido design. Go to Framework >List->Save->Local File.5. Select unconverted radio button.
6. You will be asked for file path and file name.
7. Give the ideal way and record name, yet make a point to change the expansion from .txt to .ido. Press the Create button. This is the ido document which we are searching for. (amazed.. indeed *.ido document which the EDI/Heritage group asked is this basic record with expansion .ido)
To get such pragmatic issues and goals directly to your inbox, if it’s not too much trouble, Buy in. We regard your security and treat safeguarding it in a serious way.
Assuming you enjoyed this post, if it’s not too much trouble, hit the offer button at the left half of your screen.
In this document, I have made an effort to provide the consistently expected details needed to implement custom change pointers for the custom fields in the custom tables for the custom change object and custom message type.
Configurations and Steps to implement custom change pointer:
Step 1. Make the data type of custom fields ready to record changes. (A to Z of Custom Change Pointer)
For demo, I have utilized the beneath custom table with custom fields.
The information components of the multitude of three custom fields have the Change report checked.
Step 2. Create custom message type (T-code WE81). A to Z of Custom Change Pointer For instance I have made message type Z1P_MATMAS.
Step 3. Activate this message type to catch change pointers (T-code BD50).
Step 4. Create custom Change Document Object to link changes (T-code SCDO).
Put the custom table name (ZTEST_RS for this demo). You can add more than one tables
Step 5. Generate the custom Function Module to update changed documents (T-code SCDO). Click Produce update pgm button.
Save it. A new data dictionary structure called YZTEST_RS is also generated, along with an FM Z_MATMAS_WRITE_DOCUMENT to update change pointer. To trace the change pointers, the custom code would call FM Z_MATMAS_WRITE_DOCUMENT.
Step 6. Check the generated FM Z_MATMAS_WRITE_DOCUMENT.
Check the Tables area. Two tables are characterized. One is for information before change and the other is for information after change.
Kindly note: naturally the Tables in the FM are required. Assuming that you added more than one table in the exchange SCDO while creating the FM, you can make these tables as discretionary physically in SE37, so you can involve similar FM for change pointers for various tables.
Step 7. Link the change document Object, Table and Fields for the given Message Type (BD52).
Please take note that although though the field name “KEY” isn’t a field of any table, it should be provided for every table. Except for the KEY field, the message type is directly referenced to the material expert’s fields and tables. Although it is not necessary for the specific table, this field anticipates a crucial, additional control task. A change pointer is created while creating the corresponding object in Exchange BD52 if the KEY field is identified.
Step 8. Evaluating Change Pointers (T-code BD60). The change pointers are then assessed. It simply relies upon the article concerned what capability module is utilized here. The capability module, MASTERIDOC_CREATE_SMD_MATMAS, which utilizations change pointers to produce IDocs is called.
Step 9. Write the custom code in the TMG event to capture changed/created data. (This is not the only way. You can write your code in other suitable areas)
Details to add event is also there in other post: http://help-sap.blogspot.com/search?q=event
In the Generate Table Maintenance screen go to Menu Environment->Modification->Events.
You will see the following screen.
Click the New Entries button and select the event you want to use and the Routine name.
Click the Manager and make your daily practice in the Incorporate program and compose the code in the daily practice to meet your prerequisite.
Sample Code to catch change pointers
FORM z_before_save.
CONSTANTS: c_insert TYPE cdchngind VALUE ‘I’, c_update TYPE cdchngind VALUE ‘U’, c_check TYPE boolean VALUE ‘X’.
DATA: li_ztest_rs_old TYPE STANDARD TABLE OF ztest_rs INITIAL SIZE 0, li_xztest_rs TYPE STANDARD TABLE OF yztest_rs INITIAL SIZE 0, li_yztest_rs TYPE STANDARD TABLE OF yztest_rs INITIAL SIZE 0, li_cdtext TYPE STANDARD TABLE OF cdtxt INITIAL SIZE 0, lk_ztest_rs_x TYPE ztest_rs, lk_ztest_rs_old TYPE ztest_rs, lk_xztest_rs TYPE yztest_rs, lk_yztest_rs TYPE yztest_rs, lv_object TYPE cdobjectv.
* Sort SORT i_ztest_rs_x[] BY zmatnr zplant. * This will have the most recent data DELETE ADJACENT DUPLICATES FROM i_ztest_rs_x[] COMPARING zmatnr zplant.
* Initial check IF i_ztest_rs_x[] IS NOT INITIAL.
* Get old data SELECT * FROM ztest_rs INTO TABLE li_ztest_rs_old ” Old Data FOR ALL ENTRIES IN i_ztest_rs_x WHERE zmatnr = i_ztest_rs_x-zmatnr AND zplant = i_ztest_rs_x-zplant. * Looping through the current data set LOOP AT i_ztest_rs_x INTO lk_ztest_rs_x.
* Read the old data if available READ TABLE li_ztest_rs_old INTO lk_ztest_rs_old WITH KEY zmatnr = lk_ztest_rs_x-zmatnr zplant = lk_ztest_rs_x-zplant.
IF sy-subrc EQ 0. * If found then check whether anything is changed or not IF lk_ztest_rs_x-zmatnr NE lk_ztest_rs_old-zmatnr OR lk_ztest_rs_x-zplant NE lk_ztest_rs_old-zplant OR lk_ztest_rs_x-zmaktx NE lk_ztest_rs_old-zmaktx .
MOVE-CORRESPONDING lk_ztest_rs_x TO lk_xztest_rs. * This is important lk_xztest_rs-kz = c_update. * Keep the new data APPEND lk_xztest_rs TO li_xztest_rs[].
MOVE-CORRESPONDING lk_ztest_rs_old TO lk_yztest_rs. * This is important lk_yztest_rs-kz = c_update. * Keep the old data APPEND lk_yztest_rs TO li_yztest_rs[].
lv_object = lk_ztest_rs_x-zmatnr.
* Write the change pointer for changed record CALL FUNCTION ‘Z_MATMAS_WRITE_DOCUMENT’ EXPORTING objectid = lv_object tcode = sy-tcode utime = sy-uzeit udate = sy-datum username = sy-uname upd_ztest_rs = c_update TABLES icdtxt_z_matmas = li_cdtext[] xztest_rs = li_xztest_rs[] yztest_rs = li_yztest_rs[].
REFRESH: li_cdtext[], li_xztest_rs[], li_yztest_rs[]. CLEAR: lv_object. ENDIF. * If not found, that means it is a new entry ELSE. MOVE-CORRESPONDING lk_ztest_rs_x TO lk_xztest_rs. * This is important lk_xztest_rs-kz = c_insert. * Keep the new data APPEND lk_xztest_rs TO li_xztest_rs[].
lv_object = lk_ztest_rs_x-zmatnr.
* Write the change pointer for new record/insert record CALL FUNCTION ‘Z_MATMAS_WRITE_DOCUMENT’ EXPORTING objectid = lv_object tcode = sy-tcode utime = sy-uzeit udate = sy-datum username = sy-uname upd_ztest_rs = c_insert TABLES icdtxt_z_matmas = li_cdtext[] xztest_rs = li_xztest_rs[] yztest_rs = li_yztest_rs[].
In order to feed data in the event above, we nee to populate data (I_ZTEST_RS_X[ ]) in the custom database table screen. Write code to keep the run-time table data needed for the above logic.
The changes are logged in the standard table BDCP2. Let us check for any entry in the table for my userid and today’s date MODULE get_new_or_changed_values INPUT. * Keep the screen number CONSTANTS: c_screen_0001 TYPE sydynnr VALUE ‘0001’.
* Get the data and keep in internal table to be used later IF sy-dynnr = c_screen_0001. APPEND ztest_rs TO i_ztest_rs_x. ENDIF.
ENDMODULE.
You might have to pronounce a few worldwide information. This finishes the design and custom code to get the change recognition.
Sample Output to register change pointers for Create and Change:
The progressions are signed in the standard table BDCP2. Allow us to check for any section in the table for my userid and the present date
No section is found. Presently I will Make/Add a section in the custom table by t-code SM30 and save it.
Go to table BDCP2 and search for records. Check one passage is effectively logged.
Change a section and really look at the table for the change pointer.
Check another passage has been added.
Transactions to remember 1. SE11 to check the data type is active to record changes and to create events. 2. SE81 to create message type. 3. BD50 to activate the message type to catch change pointers. 4. SCDO to create Change Objects and generate program/function module to write change pointers. 5. BD52 to link Message Type, Change Objects, Tables and Fields. 6. BD60 to link Message Type to Standard Function Module.
Highlight recollect
In exchange BD52, field name ‘KEY’ ought to be given for each table despite the fact that it’s anything but a field of any table.
IDoc reprocessing in SAP IDoc: Reprocessing IDocs and Change Pointers—Valuable Exchanges
Reviewing the Fruitful IDocs again We are unable to reprocess successful IDocs using BD87, but occasionally, particular problems may require us to resend a usually handled, successful IDoc.
BD21 – Making IDoc Types from Change Pointers (Change Pointers and Reprocessing IDocs ) At times a great deal of Progress Pointer gets made, yet neglects to get handled because of framework issues. This t-code is very useful to create IDocs from natural change pointers. The situation with change pointer can undoubtedly be checked from BDCPV table/view.
BD22 – Erase Change Pointers (Change Pointers and Reprocessing IDocs ) In the creation climate, this one is also quite helpful. We occasionally encounter circumstances where a significant number of progress indicators are generated due to incorrect configuration or settings. This t-code is really helpful to remove them from the framework and clean up the associated data.
Additionally, you can retransmit documents from the relevant application, such as Shipment, Conveyance, and Buy Request, by going back over the Result Type if the number of documents that need to be retransmitted is limited.
Be that as it may, when we really want to send different IDocs, utilizing the standard program RC1_IDOC_SET_STATUS is very useful.
You can go to WE02 or WE09, duplicate all the handled IDoc numbers and glue them in the wake of executing this program in SE38. You would likewise have to indicate the new IDoc status.
On the off chance that you really want to handle this IDoc again utilizing BD87, you can’t straightforwardly set something very similar to 30 (IDoc prepared for dispatch), as BD87 recalls the last status (which was ’53’- Application archive posted) and consequently wouldn’t again deal with this IDoc.
Consequently we can change the status to say some transitional one like 32 – (IDoc was altered) and afterward again run this program and change the status t0 30 from 32.
How to find BADIs?
From that point forward, we can again deal with this IDocs utilizing BD87 and yet again send them to the outer framework like EDI.
Another organization (let’s say XYZ, which is also in SAP) was acquired by your association (let’s say Shy, which is in SAP). The design calls for a field-tested approach that cycles from XYZ to Hesitant and stacks all the information. They must thus establish the links between XYZ business objects and related business objects in the Bashful framework. Tool for GOS attachment from one SAP system to another SAP system.
This basic instrument would transfer any connections (pdf, txt, xls, xml and so on) from source sap framework to target sap framework for all business object types.
Tool for GOS attachment from one SAP system to another SAP system
Stage 1 Plan document with Target Items (PO/PR/Merchant/Materials/Agreements and so on) and comparing Source Articles. Make a point to have comparing driving zeroes for every one of the items. Model PR would have absolute 10 characters; materials would have all out 18 characters, the seller would have complete 10 characters with driving zeroes and so on.
The following is a model record (xls) of Procurement Req from Shy and XYZ framework.
Step 2 Execute program Z_GOS_PREPARE_FILE in target system.
Step 3 Execute program Z_GOS_ATTACHMENT in target system.
Common Business Objects
Pur Req = BUS2105 Material = BUS1001 or BUS1001006 Pur Ord = BUS2012 Vendor = LFA1 Contract = BUS2014 etc
Step 4 Validation for our example:
Go to ME53N for Buy Order in source Framework
Go to ME53N for Buy Demand in target Framework
ABAPer would be more inspired by the code to accomplish the above functionalities. Kindly find the functioning code joined in four documents. If it’s not too much trouble, click the connection on the right.
Programs: 1) Program to prepare the input file. z_gos_prepare_file 2) Main program for attachments. z_gos_attachment
Function Modules:
1) RFC FM in source (XYZ) system. z_get_xyz_gos_attachment_rfc 2) RFC FM in target (COY) system. z_gos_attach_to_coy_rfc
Kindly note: in the Fundamental program (in PERFORM get_rfc_name), you really want to put the RFC name of your framework Being developed, Quality and Creation framework separately.
ABAP GOS attachment from application server Let’s get started on Sample program to attach any file from the application server to any Business Object.
* Sample program to attach documents to any business object REPORT z_gos_attachment NO STANDARD PAGE HEADING LINE-COUNT 132. *———————————————————————* * SELECTION SCREEN * *———————————————————————* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETERS: p_file TYPE localfile, ” Application File Path p_objid TYPE swo_typeid, ” Any object like material no./vendor “/customer/po/pr etc p_bo TYPE swo_objtyp. ” Business object like LFA1 for vendor SELECTION-SCREEN END OF BLOCK b1. DATA: li_content TYPE STANDARD TABLE OF soli, li_objhead TYPE STANDARD TABLE OF soli, lwa_folmem_k TYPE sofmk, lwa_note TYPE borident, lwa_object TYPE borident, lwa_obj_id TYPE soodk, lwa_content TYPE soli, lwa_fol_id TYPE soodk, lwa_obj_data TYPE sood1, lv_ep_note TYPE borident-objkey, lv_lifnr TYPE lifnr, lv_file TYPE string, lv_filename TYPE c LENGTH 100, ” file name and ext lv_extension TYPE c LENGTH 4. ” extension only * Refresh data REFRESH: li_content[], li_objhead[].
* Open corresponding DMS files OPEN DATASET p_file FOR INPUT IN BINARY MODE. IF sy-subrc EQ 0. WHILE sy-subrc = 0. READ DATASET p_file INTO lwa_content. * Do not put Sy-subrc eq 0 here. Please add the last line of the file, * though sy-subrc may fail APPEND lwa_content TO li_content. ENDWHILE. * Close file CLOSE DATASET p_file. * In this example we are attaching in Vendor. * Converting according to your requirement.. For example for Material, * it should be 18 chars * Convert Vendor CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’ EXPORTING input = p_objid IMPORTING output = lv_lifnr.
* Convert to BIN CALL FUNCTION ‘SO_CONVERT_CONTENTS_BIN’ EXPORTING it_contents_bin = li_content[] IMPORTING et_contents_bin = li_content[].
* Get folder id CALL FUNCTION ‘SO_FOLDER_ROOT_ID_GET’ EXPORTING region = ‘B’ IMPORTING folder_id = lwa_fol_id EXCEPTIONS communication_failure = 1 owner_not_exist = 2 system_failure = 3 x_error = 4 OTHERS = 5. * Sy-subrc check not required * Keeping file in string data type lv_file = p_file. * You may not need this step. But no harm in adding this * Get file name and extension CALL FUNCTION ‘CH_SPLIT_FILENAME’ EXPORTING complete_filename = lv_file IMPORTING extension = lv_extension name_with_ext = lv_filename EXCEPTIONS invalid_drive = 1 invalid_path = 2 OTHERS = 3. IF sy-subrc EQ 0. * Object header CLEAR lwa_content. CONCATENATE ‘&SO_FILENAME=’ lv_filename INTO lwa_content. APPEND lwa_content TO li_objhead. CLEAR lwa_content. ENDIF.
lwa_object-objkey = lv_lifnr. * For example, business object name for PO is BUS2012, * business object for PR is BUS2105, * business object for Vendor is LFA1 etc lwa_object-objtype = p_bo. * lwa_object-logsys = lv_logical_system.
TRANSLATE lwa_obj_data-file_ext TO UPPER CASE. * This is very important step. If your object size does not match with the input * file size, then your object might get attached, but it will show error while you * try to open it. * If you have a way, where you can read the input file size directly, then assign * it directly else, use the below formula lwa_obj_data-objlen = lines( li_content ) * 255.
How can I determine if a business object has a GOS attachment? We would really like to know how many GOS connections are there in Buy Requests, Buy Demands, Merchants, and so on. Using the GOS relationship table “SRGBTBREL” is the simplest way to locate this.
Proceed to SE16(N) and provide the name of the business object in the TYPEID_A (Kind of Articles) box. For example, if the business object name is BUS2012 for the PO, BUS2105, LFA1 for the Seller, 1001006 for the Material, and so on, you can click Execute to view the rundown or click Number of Passages to view the number of connections in that business object. How can I determine if a business object has a GOS attachment?
You can get the rundown of business object in exchange SWO1.
On the off chance that for reasons unknown, you can’t sort out the business object in exchange SWO1, then the most straightforward method for finding the business object is by going to the exchange (say MM02, ME22N or XK02 and so on) for the article you are intrigued and connect one archive and save it. Presently take that article number and go to table SRGBTBREL and enter the material/po/merchant and so on in field INSTID_A with all driving zeroes. You will get the business object name in field TYPEID_A.
Prior to proceeding with SAP Cloud Platform Integration (CPI) Part 23: Detailed Instructions for Configuring Mail Adapters with Attachments. Let’s quickly go over the Mail Adapter. An extensive set of tools and capabilities for coordinating various frameworks and applications inside an organization is provided by SAP CPI (SAP Cloud Stage Mix). The Mail Connector, which enables regular integration with email features and facilitates the sharing of data and relationships, is one of SAP CPI’s key features.
The SAP CPI Mail Connector serves as a bridge between the joining stage and email frameworks like as Gmail, Microsoft Trade, or another SMTP/POP3-compatible mail server. As part of scenarios involving reconciliation, it provides the ability to send and receive messages along with their connections.
Here are a few critical viewpoints and capacities of the SAP CPI Mail Connector: SAP Cloud Platform Integration (CPI) Part 23 – Step-by-Step Guide to Mail Adapter Configuration with Attachments
Configuration:
The Mail Connector can be effortlessly arranged inside SAP CPI utilizing the online incorporation stream proofreader. Directors can characterize settings, for example, mail server subtleties, confirmation certifications, email designs (e.g., plain text or HTML), and connection taking care of choices.
EmailSending:
With the Mail Connector, SAP CPI can send messages from combination streams to outer beneficiaries or interior post boxes. It upholds different email credits like source, recipient(s), subject, body, and need. Connections can likewise be incorporated by indicating the record area or giving the document content straightforwardly inside the combination stream.
EmailReceiving:
The Mail Connector permits SAP CPI to get approaching messages and cycle their items. It upholds the recovery of email credits like source, recipient(s), subject, body, and connections. Joining streams can be set off in view of the appearance of new messages, empowering robotization and reconciliation with different frameworks.
AttachmentHandling:
The Mail Connector works with the treatment of email connections inside SAP CPI. Connections can be removed from approaching messages and handled by the incorporation stream’s prerequisites. They can be saved to nearby registries, changed, or sent to different frameworks on a case by case basis.
ErrorHandlingand Monitoring:
SAP CPI gives vigorous mistake taking care of and checking abilities for the Mail Connector. It permits executives to follow the situation with email handling, screen approaching and active messages, and handle special cases or disappointments during incorporation streams including the Mail Connector.
2. IFlow Setup
The SAP CPI Mail Connector doesn’t uphold demand answer usefulness essentially in light of the nonconcurrent idea of email correspondence.
While utilizing the Mail Connector, the correspondence between the joining stream in SAP CPI and the email server follows a nonconcurrent design. The combination stream can set off the sending of an email or tune in for approaching messages, however it doesn’t keep an immediate, simultaneous association with the email server.
Subsequently, use SEND range capability for email situations.
As to mail connector properties:
Address – SMTP mail address
Intermediary type – In the event that its through cloud connector, notice on-premise or, in all likelihood Web.
Subject – Mail subject. Here we can specify dynamic properties/header which can stream at runtime as displayed beneath.
Mail Body – We can pass the approaching payload as mail body like underneath or design a mail body according to prerequisite.
Body-Emulate type – The substance sort of the body segment. In the event that its Text/HTML, assuming there are any html components, it would be changed over. To send all things considered, pick Message/Plain. There are numerous different choices moreover. Go ahead and investigate.
Body Encoding – UTF-8
For Mail connections,
SAP has given 2 choices. We can make a connection by passing the header content or the body content.
We can find in the underneath picture, where we are passing the stacktrace header (which we set in past satisfied modifier step, ${exception.stacktrace}). Notice the name of the connection too.
Add Message connections – Assuming there are any connections sent by the shipper and the equivalent must be communicated to the recipient, then, at that point, this choice ought to be empowered.
Content exchange Encoding – Programmed
Overall Setup:
Mail:
By along these lines, we can design the mail connector and use it in IFlow. Gratitude for perusing this blog. Blissful learning!
Let’s look at some concrete methods on how to send a custom purchase order form straight to the vendor. This is the cycle stream to achieve the equivalent.
1. Make a Result Type for the Buy Request with ‘Outer Send’ medium in ME22N
2. Select the Result Type and go to Additional Information. Select either ‘Send with application own exchange’ to have the choice to audit the report prior to sending or select ‘Send Quickly’ to send email straightforwardly on Save.
3. To save the result type and start the email, click Save. Assuming you choose “Send with application own exchange,” to initiate the email, navigate to ME9F – > Open the record – > Select the PO and snap Result Message.
Assuming you picked ‘Send Right away’, email would set off upon save. Go to SOST to see email set off.
Detailed Steps :
1. Go to NACE transaction to create a custom output type and assign your PO form and its program in ‘Processing Routine’
2. Add outer send as ‘Medium’, your zprogram’s name in ‘Program’, a subroutine in your zprogram in ‘Program’s Structure Schedule’, your PO structure’s name in ‘PDF/Smartform Structure’ and pdf in ‘Type’
or then again you can utilize Standard PO structure in light of your necessity or need.
3. Make a custom program to set off PO structure and join it to an email to the seller. The rationale is to set off PO structure’s FM and get the PO structure information from the FM’s Bringing in boundaries, convert it to a paired table and add it as connection to the email. See the code underneath
REPORT zprogram.
INCLUDE rvadtabl. "standardinclude, needed for getting objky from me22n
DATA: gv_fm_name TYPE rs38l_fnam, " FM Name
gs_fp_docparams TYPE sfpdocparams,
gs_fp_outputparams TYPE sfpoutputparams.
Data: gv_purdoc_no type ekko-ebeln,
gv_ldest type char4.
CONSTANTS : gv_form_name TYPE fpname VALUE 'YOUR CUSTOM FORM NAME',
gc_printprev type string VALUE 'PREVOUTPUT'.
FORM zsubroutine USING uv_retco LIKE sy-subrc "return code
uv_screen TYPE c.
PERFORM display CHANGING uv_retco. "if output successfull, need to change return code from 999.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form display
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- ENT_RETCO
*&---------------------------------------------------------------------*
FORM display CHANGING cv_retco TYPE sy-subrc.
IF sy-ucomm = gc_printprev."'PREVOUTPUT'
gs_fp_outputparams-nodialog = ''.
gs_fp_outputparams-preview = abap_true.
ELSE.
gs_fp_outputparams-nodialog = abap_true.
gs_fp_outputparams-preview = ''.
gs_fp_outputparams-reqnew = abap_true.
gs_fp_outputparams-getpdf = abap_true.
IF nast-dimme = abap_true.
gs_fp_outputparams-reqimm = abap_true.
ENDIF.
ENDIF.
DATA: lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
DATA: lt_message_body TYPE bcsy_text VALUE IS INITIAL,
lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL.
DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL,
lw_return TYPE bapiret2.
DATA: lw_formoutput TYPE fpformoutput,
lt_binarytab TYPE solix_tab,
lv_sub TYPE so_obj_des,
lv_in_update TYPE i.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = gs_fp_outputparams
EXCEPTIONS
cancel =
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
msg_arbgb = sy-msgid
msg_nr = sy-msgno
msg_ty = sy-msgty
msg_v1 = sy-msgv1
msg_v2 = sy-msgv2
msg_v3 = sy-msgv3
msg_v4 = sy-msgv4
EXCEPTIONS
OTHERS = 0.
ENDIF.
**
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = gv_form_name
IMPORTING
e_funcname = gv_fm_name.
"Exception handling
CATCH cx_fp_api_internal.
CATCH cx_fp_api_repository.
CATCH cx_fp_api_usage.
ENDTRY.
cv_retco = 0.
gv_purdoc_no = nast-objky. "objky contains purchase doc number
CALL FUNCTION gv_fm_name
EXPORTING
iv_purdoc_no = gv_purdoc_no
IMPORTING
/1bcdwb/formoutput = lw_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc = 0.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
msg_arbgb = 'ZSCM'
msg_nr = '022'
msg_ty = 'S'
* MSG_V1 = TEXT-001
EXCEPTIONS
OTHERS = 0.
ELSE.
CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
EXPORTING
msg_arbgb = sy-msgid
msg_nr = sy-msgno
msg_ty = sy-msgty
msg_v1 = sy-msgv1
msg_v2 = sy-msgv2
msg_v3 = sy-msgv3
msg_v4 = sy-msgv4
EXCEPTIONS
OTHERS = 0.
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
"Convert Form Output to Binary table to be added as email attachment
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lw_formoutput-pdf
* APPEND_TO_TABLE = ' '
* IMPORTING
* OUTPUT_LENGTH =
TABLES
binary_tab = lt_binarytab.
SELECT SINGLE ekko~ebeln, ekpo~ebelp, ekko~lifnr, ekpo~werks, ekko~bedat FROM ekko
INNER JOIN ekpo
ON ekko~ebeln = ekpo~ebeln
INTO @DATA(lw_povendor)
WHERE ekko~ebeln = @gv_purdoc_no
AND ekpo~loekz = ''.
IF sy-subrc = 0.
"Here you can create a Custom Table to maintain email data for each Vendor. I am fetching Email To, Email Cc, Email From and Subject Line that is maintained for that PO's vendor
SELECT SINGLE * FROM zvendoremaildatatable INTO @DATA(lw_vendordetails)
WHERE lifnr = @lw_povendor-lifnr.
IF sy-subrc = 0.
lv_sub = lw_vendordetails-zsubject.
"You can edit the subject line with PO data dynamically data(lv_bedat_formatted) = |{ lw_povendor-bedat+4(2) }| && |/| && |{ lw_povendor-bedat+6(2) }|.
REPLACE FIRST OCCURRENCE OF 'mmdd' IN lv_sub WITH lv_bedat_formatted. "lw_povendor-bedat
REPLACE FIRST OCCURRENCE OF '&&' IN lv_sub WITH gv_purdoc_no.
lo_send_request = cl_bcs=>create_persistent( ).
"Add email body APPEND 'Thanks,' TO lt_message_body.
APPEND 'Bhavya Kariwala' TO lt_message_body.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_message_body
i_subject = lv_sub ).
DATA(lv_attachment_name) = |PO#| && |{ gv_purdoc_no }| && | Form|.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'pdf'
i_attachment_subject = CONV sood-objdes( lv_attachment_name )
* I_ATTACHMENT_SIZE =
* I_ATTACHMENT_LANGUAGE = SPACE
* I_ATT_CONTENT_TEXT =
* I_ATTACHMENT_HEADER =
i_att_content_hex = lt_binarytab ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
lo_send_request->set_document( lo_document ).
"Set sender
lo_sender = cl_sapuser_bcs=>create( sy-uname ).
lo_sender = cl_cam_address_bcs=>create_internet_address( CONV adr6-smtp_addr( lw_vendordetails-zemail_from ) ).
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
"Set recipient
"I have maintained multiple email addresses for a vendor separated by ';', so it's now been put into an internal table to be looped through. SPLIT lw_vendordetails-zemail_to AT ';' INTO TABLE DATA(lt_emailto). SPLIT lw_vendordetails-zemail_cc AT ';' INTO TABLE DATA(lt_emailcc).
"Check to see if email was triggered in UPDATE TASK CALL FUNCTION 'TH_IN_UPDATE_TASK' IMPORTING IN_UPDATE_TASK = lv_in_update . IF lv_in_update <> 1. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true IMPORTING return = lw_return. endif.
ENDIF. ENDIF. ENDFORM.
4. Furthermore, as consumed in the code above, you can make a table to keep up with Email Information for every Merchant. You can make a Table Upkeep Generator to keep up with sections against every Seller so this interaction can turn out to be more robotized.
Hope you got the How to Send Custom Purchase Order Form Directly to the Vendor?
Send an email in Apex that includes a PDF attachment (Object Oriented Method of Sending an Email with a PDF Attachment)
The blog post I wrote on the topic of “Item Arranged approach to sending an email from ABAP side” is expanded upon in this one. An object-oriented method for attaching a PDF to an email.
You will also learn how to send an email using an object-oriented method with a PDF attached in this blog post, Object Oriented Way of Sending an Email with PDF as an Attachment. In this case, a SMARTFORM will generate the PDF.
Prerequisite (Object Oriented Way of Sending an email with PDF as an Attachment)
A Smartform – It tends to be an essential smartform with a short message, we simply need it for show reason.
Essential information on involving class CL_BCS for email sending.
A trigger program.
Steps
Create a Smartform with any Z/Y name.
I made with the name “ZTEST_SMARTFORM_ATTACHMENT”. It simply have a short text as beneath:
Create an executable program in SE38.
I made it with the name “ZTEST_EMAIL_WITH_ATTACHMENT”.
DATA DECLARATIONS
(Please excuse for the naming convention used)
CONSTANTS:
lc_sfname TYPE tdsfname VALUE 'ZTEST_SMARTFORM_ATTACHMENT'. "Name of Smartform
"Local Object References
DATA: lo_bcs TYPE REF TO cl_bcs,
lo_doc_bcs TYPE REF TO cl_document_bcs,
lo_recep TYPE REF TO if_recipient_bcs,
lo_sapuser_bcs TYPE REF TO cl_sapuser_bcs,
lo_cx_bcx TYPE REF TO cx_bcs.
"Local Internal Tables.
DATA: lt_otfdata TYPE ssfcrescl,
lt_binary_content TYPE solix_tab,
lt_text TYPE bcsy_text,
lt_pdf_tab TYPE STANDARD TABLE OF tline,
lt_otf TYPE STANDARD TABLE OF itcoo.
"Local Structures
DATA: ls_ctrlop TYPE ssfctrlop,
ls_outopt TYPE ssfcompop.
"Local Variables
DATA: lv_bin_filesize TYPE so_obj_len,
lv_sent_to_all TYPE os_boolean,
lv_bin_xstr TYPE xstring,
lv_fname TYPE rs38l_fnam,
lv_string_text TYPE string.
Get the name of the function module of the SMARTFORM .
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lc_sfname
IMPORTING
fm_name = lv_fname
EXCEPTIONS
no_form = 1
no_function_module = 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.
Fill the Control Parameters, output options and call the FM of your SMARTFORM.
We will get the OTF data generated by the smartform in internal table “lt_otf”.
"Control Parameters
ls_ctrlop-getotf = 'X'.
ls_ctrlop-no_dialog = 'X'.
ls_ctrlop-preview = space.
"Output Options
ls_outopt-tdnoprev = 'X'.
ls_outopt-tddest = 'LOCL'.
ls_outopt-tdnoprint = 'X'. "No printing from print preview
CALL FUNCTION lv_fname
EXPORTING
control_parameters = ls_ctrlop
output_options = ls_outopt
IMPORTING
job_output_info = lt_otfdata
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
lt_otf[] = lt_otfdata-otfdata[].
Convert OTF Data to XSTRING “lv_bin_xstr”.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF' "PDF to get pdf output
IMPORTING
bin_filesize = lv_bin_filesize
bin_file = lv_bin_xstr
TABLES
otf = lt_otf[]
lines = lt_pdf_tab[]
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 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.
Convert the XSTRING to Binary table “lt_binary_content”.
***Xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_bin_xstr
TABLES
binary_tab = lt_binary_content.
Note: this is fundamental provided that you need to set the source unique in relation to genuine client (SY-UNAME). In any case source is set consequently with genuine client. FYI. I have remarked the code in my program.