Pavan – SAP for Beginners https://www.sapforbeginners.com/blog Everything on SAP Mon, 20 Aug 2018 21:07:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 Send Internal Tables in an e-Mail as Excel attachments using Function Module https://www.sapforbeginners.com/blog/send-internal-tables-in-an-e-mail-as-excel-attachments-using-function-module/ https://www.sapforbeginners.com/blog/send-internal-tables-in-an-e-mail-as-excel-attachments-using-function-module/#respond Mon, 20 Aug 2018 21:07:23 +0000 http://www.sapforbeginners.com/blog/?p=40 Introduction: We are going to create a program that uses “SO_NEW_DOCUMENT_ATT_SEND_API1” function module to send two internal tables in an e-mail as separate excel attachments. Explanation: I am abstaining from writing any explanations on below snippet as it is a simple program and easy to understand. We build couple of internal tables and attach the two internal tables “IT_ITAB1” & “IT_ITAB2” as two separate excel attachments in the e-mail. The only part that you might be wondering is the use of the program “RSCONN01” and the program queues the email. Please feel free to comment below if you have any queries or issues in following the post.
*&---------------------------------------------------------------------*
*& Report  Z_ITAB_MAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_itab_mail.

*Global Top
CLASS: cl_abap_char_utilities DEFINITION LOAD.
DATA: docdata            TYPE sodocchgi1,
      gs_objpack         TYPE sopcklsti1,
      it_objpack         TYPE STANDARD TABLE OF sopcklsti1,
      it_objtxt          TYPE STANDARD TABLE OF solisti1,
      it_objbin1         TYPE STANDARD TABLE OF solisti1,
      it_objbin2         TYPE STANDARD TABLE OF solisti1,
      it_objbin_final    TYPE STANDARD TABLE OF solisti1,
      it_reclist         TYPE STANDARD TABLE OF somlreci1,
      gs_objtxt          TYPE solisti1,
      gs_objbin1         TYPE solisti1,
      gs_objbin2         TYPE solisti1,
      gs_objbin_final    TYPE solisti1,
      gs_reclist         TYPE somlreci1,
      tab_lines          TYPE sy-tabix.

DATA: gd_sender_type  TYPE so_adr_typ.
DATA: c_tab           TYPE c            VALUE cl_abap_char_utilities=>horizontal_tab,
      c_ret           TYPE c            VALUE cl_abap_char_utilities=>cr_lf.
DATA: c_dev TYPE sy-sysid.
TYPES: BEGIN OF i_data,
      a(20),
      b(20),
      END OF i_data.
TYPES: BEGIN OF st,
      f1(2) TYPE c,
      f2(2) TYPE n,
      END OF st.
DATA: it_itab1 TYPE STANDARD TABLE OF st,
      gs_itab1 TYPE                   st,
      it_itab2 TYPE STANDARD TABLE OF st,
      gs_itab2 TYPE                   st.
DATA: n TYPE i.


*Selection Screen
PARAMETER: p_email1 TYPE so_recname
                    DEFAULT 'admin@sapforbeginners.com',
           p_sender LIKE somlreci1-receiver.

*Start of Selection
START-OF-SELECTION.

*Begin of preparing two internal tables with random data
  gs_itab1-f1 = 'Row1 Column1'.
  gs_itab1-f2 = 'Row1 Column2'.
  APPEND gs_itab1 TO it_itab1.
  CLEAR gs_itab1.

  gs_itab1-f1 = 'Row2 Column1'.
  gs_itab1-f2 = 'Row2 Column2'.
  APPEND gs_itab1 TO it_itab1.
  CLEAR gs_itab1.

  gs_itab1-f1 = 'Row3 Column1'.
  gs_itab1-f2 = 'Row3 Column2'.
  APPEND gs_itab1 TO it_itab1.
  CLEAR gs_itab1.

  gs_itab2-f1 = 'Row1 Column1'.
  gs_itab2-f2 = 'Row1 Column2'.
  APPEND gs_itab2 TO it_itab2.
  CLEAR gs_itab2.

  gs_itab2-f1 = 'Row2 Column1'.
  gs_itab2-f2 = 'Row2 Column2'.
  APPEND gs_itab2 TO it_itab2.
  CLEAR gs_itab2.

  gs_itab2-f1 = 'Row3 Column1'.
  gs_itab2-f2 = 'Row3 Column2'.
  APPEND gs_itab2 TO it_itab2.
  CLEAR gs_itab2.
*End of internal table data


  LOOP AT it_itab1 INTO gs_itab1.
    CONCATENATE gs_itab1-f1 gs_itab1-f2 INTO gs_objbin1 SEPARATED BY c_tab.
    CONCATENATE c_ret gs_objbin1 INTO gs_objbin1.
    APPEND gs_objbin1 TO it_objbin1.
  ENDLOOP.
  CLEAR: gs_objbin1, gs_itab1.

  LOOP AT it_itab2 INTO gs_itab2.
    CONCATENATE gs_itab2-f1 gs_itab2-f2 INTO gs_objbin2 SEPARATED BY c_tab.
    CONCATENATE c_ret gs_objbin2 INTO gs_objbin2.
    APPEND gs_objbin2 TO it_objbin2.
  ENDLOOP.
  CLEAR: gs_objbin2, gs_itab2.

  LOOP AT it_objbin1 INTO gs_objbin1.
    MOVE gs_objbin1-line TO gs_objbin_final-line.
    APPEND gs_objbin_final TO it_objbin_final.
  ENDLOOP.
  CLEAR: gs_objbin_final, gs_objbin1.

  LOOP AT it_objbin2 INTO gs_objbin2.
    MOVE gs_objbin2-line TO gs_objbin_final-line.
    APPEND gs_objbin_final TO it_objbin_final.
  ENDLOOP.
  CLEAR: gs_objbin2, gs_objbin_final.

  PERFORM process_email.

  c_dev = sy-sysid.
  IF sy-sysid = c_dev.
    WAIT UP TO 5 SECONDS.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    AND RETURN.
  ENDIF.
  IF sy-subrc = 0.
    WRITE: / 'Email succesfilly delivered'.
  ELSE.
    WRITE: / 'Email could not be delivered'.
  ENDIF.

]]>
https://www.sapforbeginners.com/blog/send-internal-tables-in-an-e-mail-as-excel-attachments-using-function-module/feed/ 0
Special Copy & Paste in ABAP Editor https://www.sapforbeginners.com/blog/special-copy-paste-in-abap-editor/ https://www.sapforbeginners.com/blog/special-copy-paste-in-abap-editor/#respond Sun, 19 Aug 2018 19:15:33 +0000 http://www.sapforbeginners.com/blog/?p=33 Introduction:

The ABAP Editor copy-paste functionality is not just limited to the normal copy (CTRL+C) and paste (CTRL+V) function but has many improved functions of pushing into buffers which are explained below in this post.

Explanation:

The ABAP editor provides the below options for enhanced copy and paste functions.

  • CLIPBOARD RING
  • BUFFERS

CLIPBOARD RING:

Follow the below steps to understand.

Go to SE38 Transaction Code and create a report as shown below.

Now let us copy the lines from LINE 1 to Line 12 by pressing CTRL + C one at a time.

Now press CTRL+SHIFT+V and you will see something like below

You can select any of the last 12 copied item to be pasted.

Only the last 12 copied items will be stored in the clipboard.

BUFFERS:

There are three types of buffers. They are as follows.

  1. X Buffer
  2. Y Buffer
  3. Z Buffer

You can right click on the code or use Utilities Menu items to Copy into these Buffers.

Use insert X buffer to paste contents saved in X buffer and similarly for Y and Z buffers.

You can also edit the contents of the buffer by using edit buffer.

If you have any issues in following the post, please comment below.

]]>
https://www.sapforbeginners.com/blog/special-copy-paste-in-abap-editor/feed/ 0
How to Create a Dynamic Variant in SAP using TVARV Table https://www.sapforbeginners.com/blog/how-to-create-a-dynamic-variant-in-sap-using-tvarv-table/ https://www.sapforbeginners.com/blog/how-to-create-a-dynamic-variant-in-sap-using-tvarv-table/#respond Sun, 19 Aug 2018 18:48:12 +0000 http://www.sapforbeginners.com/blog/?p=24 In this blog post let us take a look at how we can create a dynamic variant in SAP ABAP program using TVARV table. To demonstrate this I have created a sample custom program “ZTEST” with one select option “S_TEST” on which we are going to create a dynamic variant. The value for the select option “S_TEST” will be dynamically picked from corresponding entries in TVARV table.

The Output of Selection Screen looks like below screenshot, Now we are going to create a dynamic variant for the below selection screen.

Step 1: Maintain the dynamic entries in table TVARV. This can be done using transaction “STVARV”. ( Please be aware that transaction is not “STVARVC” ) Later we have to assign this newly created variable with dynamic variant field. I have created a new entry under Selection Options tab of the transaction “STVARV” with name “ZMATNR” as shown in the screenshot. The titles “Lower limit” and “Upper Limit” indicate the minimum and maximum range of the given selection option.

Now let us create a dynamic variant for the selection-screen. This is done through normal way of creating variant by just clicking “Save” button on the selection screen (Ctrl + S). As soon as you press “Save” following screen will be displayed, Where I have entered “Variant Name” and “Description”.

To  use the table field as value in the select option we have to chose table “Selection Variable Type” as “T” which indicates “Table Variable from TVARVC”.

Then Assign the Variable that you have created using the “STVARV” transaction in the field “Name of Variable” as shown in the below screenshot.

Now we can save the variant with the  details we just have entered and the following screenshot highlights the important fields in the variant.

Select the variant from Variant catalog. It will populate “S_TEST” select-option with the values maintained in TVARV Table against variable “ZMATNR”.

If you found any issues in following the post or for any other queries please comment below.

]]>
https://www.sapforbeginners.com/blog/how-to-create-a-dynamic-variant-in-sap-using-tvarv-table/feed/ 0
How to schedule a Background Job by triggering an Event https://www.sapforbeginners.com/blog/how-to-schedule-a-background-job-by-triggering-an-event/ https://www.sapforbeginners.com/blog/how-to-schedule-a-background-job-by-triggering-an-event/#respond Sun, 19 Aug 2018 18:25:50 +0000 http://www.sapforbeginners.com/blog/?p=11 In this blog post let us take a look on how we can schedule a Background Job using Event as trigger.

First let us maintain an Event in SAP using transaction “SM62” which will be used as trigger to schedule the Job.

Open transaction “SM62” and create an Event with some name by pressing “Create” button under “BckPrcEvnts” tab and save the Event.

Now we have created an Event with name “Z_TRIGGER_BGJOB” which can be triggered using the standard Function Module “BP_EVENT_RAISE”. You can create an ABAP program to trigger the Event. To demonstrate this example, I have created a sample custom program “ZTRIGGER” which uses the Function Module “BP_EVENT_RAISE” to trigger the Event “Z_TRIGGER_BGJOB”.

Now we have an Event and a program which can trigger the Now let us create a Background Job and schedule its execution using Job Control Parameters.

We can create a Background Job using the transaction “SM36”, give a Job name and class and click on “Enter” where a popup window appears asking for the program and variant for which the job should be scheduled.

Now save it and come back, you must be seeing a message saying “1 Step(s) successfully defined”, Now we need to mention the “Start Condition” for the job that we have just defined where we will be using the Event we have created as a trigger to schedule this job.

Once you click on “Start Condition” following popup window appears, Just hit on the “After Event” button which will input enable the Event and Parameter Input options. Give Event details in Event Input Parameter and press “Save”.

That is all, Now let us test whether the Background Job is scheduled after triggering the Event and again finally press the “Save” button again to save. Execute the program “ZTRIGGER” and check whether the Job has been scheduled or not in “SM37” transaction.

]]>
https://www.sapforbeginners.com/blog/how-to-schedule-a-background-job-by-triggering-an-event/feed/ 0