SAP for Beginners https://www.sapforbeginners.com/blog Everything on SAP Tue, 21 Aug 2018 00:31:02 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 How to read Master data in SAP BPC https://www.sapforbeginners.com/blog/how-to-read-master-data-in-sap-bpc/ https://www.sapforbeginners.com/blog/how-to-read-master-data-in-sap-bpc/#respond Tue, 21 Aug 2018 00:27:02 +0000 http://www.sapforbeginners.com/blog/?p=46
  • Introduction
  • In business scenarios like designing reconciliation reports in BPC, there is a need to read data from the BPC models into local tables and build reports on the data fetched from the models. This post explains the way to read Master data from the BPC dimensions. In BPC we have various methods to read master data for text/attribute and hierarchy data for base member and Node values from the dimensions.

    Although the Master data is stored in tables at the backend we cannot directly use the table names to read as the technical names of the dimensions are subject to change and it is suggested not to use the technical names in BPC.BPC has provided standard classes and interfaces to read data from the models. UJA is the ABAP Package that contains all the modeling and metadata related interfaces. The modeling functionality is driven by a class called CL_UJA_BPC_ADMIN_FACTORY. This class is the main entry point for all modeling related operations and is the dynamic entry point to handle modeling operations.

    1. Reading Master Data

    Master data read includes fetching Attributes, Text and Hierarchies from a dimension for a given appset id. CL_UJA_DIM is the standard dimension class provided by SAP to read dimension master data for an appset id.

    • Attributes and Hierarchies

    IF_UJA_DIM_DATA is the interface used to perform all the operations specific to a dimension and it is implemented in the class CL_UJA_DIM. READ_MBR_DATA and the method READ_MBR_DATA of this interface is used to read the dimension master data (Attributes/Text/Hierarchies).

    The importing parameters of the method READ_MBR_DATA used while reading attributes and hierarchies:

    1. IT_SEL holds the filters on the attribute values to be fetched. Only the intersection of values given in IT_SEL will be read from the dimension.
    2. IT_SEL_MBR holds the attribute that need to be fetched.

     

    *- Code logic to read attributes and hierarchies

    *-   Data declarations
    
    DATA:  lo_dim_reader TYPE REF TO cl_uja_dim,
           dyn_table     TYPE REF TO data.
           lt_dim_data   TYPE REF TO data,
           ls_mbr        TYPE uj_attr_name,
           lt_attr_list  TYPE uja_t_attr_name.
    
     FIELD-SYMBOLS: <fs_t_txt_data> TYPE STANDARD TABLE.
    
    *- Create Instance object for dim class
    TRY.
        CREATE OBJECT lo_dim_reader
            EXPORTING
              i_appset_id = lc_appset
              i_dimension = 'COMPANY_CODE'
        CATCH cx_uja_admin_error .
    ENDTRY.
    
    *- Parameter to get text
    ls_mbr  = 'EVDESCRIPTION'.
    APPEND ls_mbr TO lt_attr_list.
    
    *- Call the method READ_MBR_DATA and get the text data into reference table LT_DIM_DATA.
    
    TRY.
        CALL METHOD lo_dim_reader->if_uja_dim_data~read_mbr_data
            EXPORTING
              it_attr_list = lt_attr_list
            IMPORTING
              er_data      = lt_dim_data.
        CATCH cx_uja_admin_error.
    ENDTRY.
    ASSIGN lt_dim_data->* TO <fs_t_txt_data>.
    *<fs_t_txt_data> has Company code and corresponding short, medium, long descriptions.

     

    •  Text

    The method that reads attributes and hierarchies is as well used to read the text of a dimension. When reading attributes and hierarchies, descriptions are not fetched. To get texts a parameter called ‘EVDESCRIPTION’ is passed to the importing parameter IT_ATTR_LIST of the method READ_MBR_DATA.

    *- Code logic to read text of a dimension

    *-   Data declarations
    
    DATA:  lo_dim_reader TYPE REF TO cl_uja_dim,
           dyn_table     TYPE REF TO data.
           lt_dim_data   TYPE REF TO data,
           ls_mbr        TYPE uj_attr_name,
           lt_attr_list  TYPE uja_t_attr_name.
    
     FIELD-SYMBOLS: <fs_t_txt_data> TYPE STANDARD TABLE.
    
    *- Create Instance object for dim class
    TRY.
        CREATE OBJECT lo_dim_reader
            EXPORTING
              i_appset_id = lc_appset
              i_dimension = 'COMPANY_CODE'
        CATCH cx_uja_admin_error .
    ENDTRY.
    
    *- Parameter to get text
    ls_mbr  = 'EVDESCRIPTION'.
    APPEND ls_mbr TO lt_attr_list.
    
    *- Call the method READ_MBR_DATA and get the text data into reference table LT_DIM_DATA.
    
    TRY.
        CALL METHOD lo_dim_reader->if_uja_dim_data~read_mbr_data
            EXPORTING
              it_attr_list = lt_attr_list
            IMPORTING
              er_data      = lt_dim_data.
        CATCH cx_uja_admin_error.
    ENDTRY.
    ASSIGN lt_dim_data->* TO <fs_t_txt_data>.
    *<fs_t_txt_data> has Company code and corresponding short, medium, long descriptions.

     

    Hope you enjoyed reading the article.

    ]]>
    https://www.sapforbeginners.com/blog/how-to-read-master-data-in-sap-bpc/feed/ 0
    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