Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all 935 articles
Browse latest View live

How to Use VB# (Visual Basic dotNET) Inside ABAP

$
0
0

Hello community,

 

I presented here the possibiltiy how to use Windows PowerShell inside ABAP.

 

Here now the possibility how to use VB#, Visual Basic for dotNET, inside ABAP, on the same way:


"-Begin-----------------------------------------------------------------
  Program zUseVBSharp.

 

    "-TypePools---------------------------------------------------------
      Type-Pools OLE2 .

 

    "-Constants--------------------------------------------------------
      Constants OUTPUT_CONSOLE Type i Value 0.
      Constants OUTPUT_WINDOW Type i Value 1.
      Constants OUTPUT_BUFFER Type i Value 2.

 

    "-Variables---------------------------------------------------------
      Data PS Type OLE2_OBJECT.
      Data Result Type i Value 0.
      Data strResult Type String Value ''.
      Data tabResult Type Table Of String.
      Data PSCode Type String Value ''.

 

    "-Macros------------------------------------------------------------
      Define _.
        Concatenate PSCode &1 cl_abap_char_utilities=>cr_lf Into PSCode.
      End-Of-Definition.

 

    "-Main--------------------------------------------------------------
      Create Object PS 'SAPIEN.ActiveXPoSH'.

      If sy-subrc = 0 And PS-Handle <> 0 And PS-Type = 'OLE2'.

 

        Call Method Of PS 'Init' = Result Exporting #1 = 0.

        If Result = 0.

 

          Call Method Of PS 'IsPowerShellInstalled' = Result.

          If Result <> 0.

 

            Set Property Of PS 'OutputMode' = OUTPUT_BUFFER.

 

"-PowerShell Begin------------------------------------------------------

 

_ '$VBCode = @"'.

 

"-VB# Begin-------------------------------------------------------------

 

_ 'Option Strict On'.

 

_ 'Imports System'.
_ 'Imports Microsoft.VisualBasic'.

 

_ 'Namespace VBCode'.

 

_ '  Public Class VB'.

 

_ '    Public Shared Function Hello1() As String'.
_ '      Return "Hello World!"'.
_ '    End Function'.

 

_ '    Public Function Hello2(ByVal Name As String) As String'.
_ '      Return "Hello " & Name & "!"'.
_ '    End Function'.

 

_ '    Public Sub Hello3(ByVal Name As String)'.
_ '      MsgBox(Name, MsgBoxStyle.OkOnly, "Hello")'.
_ '    End Sub'.

 

_ '  End Class'.

 

_ 'End Namespace'.

 

"-VB# End---------------------------------------------------------------

 

_ '"@;'.

 

_ 'Add-Type -TypeDefinition $VBCode -Language VisualBasic'.
_ '$VB = new-Object VBCode.VB'.

 

_ '[VBCode.VB]::Hello1()'.
_ '$VB.Hello2("Stefan")'.
_ '$VB.Hello3("Stefan")'.

 

"-PowerShell End--------------------------------------------------------

 

            Call Method Of PS 'Execute' Exporting
              #1 = PSCode.

 

            Call Method Of PS 'OutputString' = strResult.

 

            Split strResult At cl_abap_char_utilities=>cr_lf
              Into Table tabResult.

 

            Loop At tabResult Into strResult.
              Write: / strResult.
            EndLoop.

 

          EndIf.

 

        EndIf.

 

        Free Object PS.

      EndIf.

 

"-End-------------------------------------------------------------------

 

The PowerShell code encloses the VB# code. The VB# code is a namespace, a class and three methods. In the PowerShell code, below VB# code, these methods are called. Hello1 and Hello2 returns the result inside the output buffer of ActiveX-PowerShell and Hello3 opens a message box.

 

On the same way you can embed C# code inside ABAP.

 

I think this possibility opens the gate very wide to embed the power of dotNET framework and its languages.

 

Cheers

Stefan


How to use Windows Management Instrumentation (WMI) Inside ABAP

$
0
0

Hello community,

 

Windows Management Instrumentation (WMI) is a powerful interface to the operating system, you can find more information here..

 

Here a report how to use the WMI inside ABAP:


"-Begin-----------------------------------------------------------------
  Program zUseWMI.

 

    "-Type pools--------------------------------------------------------
      Type-Pools OLE2.

 

    "-Variables---------------------------------------------------------
      Data VBSCode Type String Value ''.
      Data WMI Type OLE2_OBJECT.
      Data CompName Type String Value ''.
      Data WMICmd Type String Value ''.
      Data oWBEM Type OLE2_OBJECT.
      Data Model Type String Value ''.
      Data Manufacturer Type String Value ''.
      Data TotalPhyMem Type String Value ''.

 

    "-Macros------------------------------------------------------------
      Define _.
        Concatenate VBSCode &1 cl_abap_char_utilities=>cr_lf
          Into VBSCode.
      End-Of-Definition.

 

    "-Main--------------------------------------------------------------
      PerForm GetWMIObj Changing WMI.
      If WMI-Handle <> 0 And WMI-Type = 'OLE2'.

 

        "-Now you can use the Windows Management Instrumentation (WMI)--

 

          PerForm GetComputerName Changing CompName.

          Concatenate 'Win32_ComputerSystem=''' CompName ''''
            Into WMICmd.

          Call Method Of WMI 'Get' = oWBEM Exporting #1 = WMICmd.

 

          Get Property Of oWBEM 'Model' = Model.
          Get Property Of oWBEM 'Manufacturer' = Manufacturer.
          Get Property Of oWBEM 'TotalPhysicalMemory' = TotalPhyMem.

 

          Write: / Model.
          Write: / Manufacturer.
          Write: / TotalPhyMem.

 

        "---------------------------------------------------------------

 

        Free Object WMI.

 

      EndIf.

 

"-End-------------------------------------------------------------------

 

"-SubRoutines begin-----------------------------------------------------

 

  "-RunScript-----------------------------------------------------------
    Form RunScript Using Cmd Type String Changing Result Type Any.

 

      "-Variables-------------------------------------------------------
        Data ScriptCtrl Type OBJ_RECORD.

 

      Create Object ScriptCtrl 'MSScriptControl.ScriptControl'.
      If sy-subrc = 0.
        Set Property Of ScriptCtrl 'AllowUI' = 1.
        Set Property Of ScriptCtrl 'Language' = 'VBScript'.
        Call Method Of ScriptCtrl 'AddCode' Exporting #1 = VBSCode.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
        If sy-subrc = 0.
          Call Method Of ScriptCtrl 'Eval' = Result Exporting #1 = Cmd.
          Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
        EndIf.
      EndIf.
      Free Object ScriptCtrl.

    EndForm.

 

  "-GetWMIObj-----------------------------------------------------------
    Form GetWMIObj Changing Result Type OBJ_RECORD.

 

      Clear VBSCode.

 

_ 'Function GetWMIObj()'.
_ '  Dim oObj'.
_ '  Set oObj = GetObject("winmgmts:", "")'.
_ '  If IsObject(oObj) Then'.
_ '    Set GetWMIObj = oObj'.
_ '  End If'.
_ 'End Function'.

 

      PerForm RunScript Using 'GetWMIObj()' Changing Result.

 

    EndForm.

 

  "-GetComputerName-----------------------------------------------------
    Form GetComputerName Changing Result Type String.

 

      Clear VBSCode.

 

_ 'Function GetComputerName()'.
_ '  Set oWSN = CreateObject("WScript.Network")'.
_ '  If IsObject(oWSN) Then'.
_ '    GetComputerName = oWSN.ComputerName'.
_ '    Set oWSN = Nothing'.
_ '  End If'.
_ 'End Function'.

 

      PerForm RunScript Using 'GetComputerName()' Changing Result.

 

    EndForm.

 

"-Subroutines end-------------------------------------------------------

 

The form routine GetWMIObj delivers the OLE object of the WMI and GetComputerName delivers the name of the computer. Both routines works with VBScript in the routine RunScript. The Main routine uses three methods of the Win32_ComputerSystem class: Model, Manufacturer and TotalPhysicalMemory and writes this Information on the screen.

 

The WMI offers thousands of classes, e.g. about BIOS, Boot configuration, printers, network, installed software etc. etc. etc.

 

Cheers

Stefan


SCN Trial Editions: SAP NetWeaver Application Server ABAP 7.4

$
0
0

Latest News

Oct 25, 2013: No country limitation anymore, if you use the direct links below.

Sep 27, 2013: New step-by-step tutorials for setting up your AWS environment.

 

product_32.png

Get your hands on the latest release of SAP NetWeaver Application Server ABAP, learn more about its new capabilities, the programming language enhancements, and test-drive the SAP development tools for Eclipse!

 

You can choose from different SCN trial editions which are provided as pre-configured virtual appliances by the SAP Cloud Appliance Library (free of charge). SAP offers this software based on a 90-day trial and evaluation license agreement.

 

Get Your Free Trial As Virtual Appliance

 

The SCN trials of SAP NetWeaver Application Server ABAP 7.4 are available with two different database flavors, i.e. on SAP HANA (in-memory database) and on SAP MaxDB (classical RDBMS). Both virtual appliances come with a detailed user guide describing how to set up and run these virtual appliances.

 

Light_Bulb_32.pngYou should be familiar with the prerequisites and tutorials on our How-to and FAQ page before you order and run these virtual appliances. We also recommend to set up a billing alert for your AWS charges.

 

To get access to these virtual appliances and run them on your own cloud service provider account please visit the SAP Store, log on with your SCN user and hit the Demo Now button. For questions and feedback please post a message in the corresponding ABAP trial thread.

 

tag_cloud_chart_grey_32.png

AS ABAP 7.4 on SAP HANA
[Trial Edition]

tag_cloud_chart_32.png

AS ABAP 7.4 on SAP MaxDB
[Trial Edition]

tag_cloud_chart_grey_32.png

BW 7.4 on SAP MaxDB*
[Trial Edition]

 

*The SAP NetWeaver Business Warehouse 7.4 trial consists of AS ABAP 7.4 and AS Java 7.4 with usage type BI Java as described in the attached solution guide.

 

Try Out These Sample Applications and Tutorials

 

All trial editions come with a pre-configured developer user, pre-installed sample applications and tutorials explaining new capabilities and technologies. The following tutorials are already available:

 

ABAP for SAP HANA reference scenario

The ABAP for SAP HANA reference scenario offers guides and tutorials including a pre-installed sample application which guide you through the E2E development process and provide sample coding leveraging the code-pushdown paradigm on SAP’s in-memory database. For more information please visit the reference scenario home page or directly consult the corresponding how-to guide by Jens Weiler.

 

How to implement an OData service with SAP NetWeaver Gateway

This how-to guide by Andre Fischer describes how to quickly create an OData service with SAP NetWeaver Gateway. You will learn how to create a data model based on a DDIC structure and implement the corresponding services using the OData channel programming model. For more information please download the how-to guide from SCN.

 

How to build SAPUI5/HTML5 applications consuming OData services

This blog by Bertram Ganz describes the end-to-end process required to develop a SAPUI5/HTML5 application user interface (with table, popup and ux3 shell) consuming a local OData service by SAP NetWeaver Gateway. The created OData service is based on the SAP NetWeaver Enterprise Sales and Procurement Model as a pre-installed demo/proxy application that provides a list of products as business data. For detailed instructions please download the how-to guide from SCN.

 

BW sample scenarios and demo content (for the BW 7.4 trial)

The SAP NetWeaver Business Warehouse 7.4 trial provides pre-activated sample scenarios for selected OLAP functions and integrated planning and contains predefined objects, such as InfoProviders, Queries and Workbooks. For more information please refer to this page. Moreover, you can execute the Open Items Analytics Dashboard.

Version Management Display Settings

$
0
0

Version Management is important part of any ABAP developer life. Version Management allows us to compare the different versions of a program and helps us to retrieve changes. It also allows us to compare the program in different system through remote comparison. This document helps the developer to understand the different views in version management.

There are three types of views in version management.

  1. 1) Single Column Format.
  2. 2) Parallel Display.
  3. 3) Display in split screen editor.

Menu Path:

  1. Utilities-->Versions-->Version Management.

Select the versions of programs which are to be compared and click on compare (F8) from application toolbar.

Select settings from the application tool bar in the next window.

version.png

Below window will be displayed where you can choose the version compare display settings.

version settings.png

 

 

Single Column Format:

            This is the first version compare tool when the version management tool was launched. This is obsolete view and it is not convenient to check the difference in two programs. In this the differences are displayed line by line comparing two programs.

version2.png



Parallel Display Format:

            This is the updated version and currently being used extensively by many developers. In this the differences can be viewed parallel comparing two programs.


Version 3.png

 

Display in split screen editor:

In this view both the programs which are being compared will be displayed in two parallel editors can be and navigated independently. The differences are marked with ‘Not Equal’ symbol in red color. In this we will have additional options like pretty printer, Where used list etc.


Version Final.png

 

Switching back to Parallel Display Format

To switch back to other displays select utilities from Menu bar and then list display from versions.

  1. Utilities-->Versions-->List Display.

Mass user creation using BAPI

$
0
0

Hello,

 

last time I had to create a lot of users and lock them on few systems. I wrote a program that is using BAPI_USER_CREATE1 and BAPI_USER_LOCK. Program is expecting local .csv file separated by semicolons with Username, FirstName, LastName and ValidationDate. Program is importing csv file onto server and for every row is creating and then locking user. I used also RFC connection to run this program on other systems. How to do it just look below the source code.

 

Mass user creation

REPORT  Z_MASS_USER_CREATION.

 

 

data: paa_file type SAPB-SAPPFAD,

      pafile type SAPB-SAPPFAD,

      paa_file2 TYPE string.

PARAMETERS: p_file(70) TYPE c.

 

 

pafile = p_file.

paa_file2 = 'V2.csv'.

 

 

paa_file = paa_file2.

OPEN DATASET paa_file FOR OUTPUT IN TEXT MODE ENCODING UTF-8.

CLOSE DATASET paa_file.

 

 

CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'

  EXPORTING

    PATH             = pafile

   TARGETPATH       = paa_file

* EXCEPTIONS

*   ERROR_FILE       = 1

*   OTHERS           = 2

          .

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.

 

 

DATA: text type table of string,

      csvstr type string,

      pa_file type string,

      curpos TYPE i,

      endpos TYPE i.

 

 

pa_file = paa_file2.

 

 

TYPES: BEGIN OF user,

        uname type BAPIBNAME-BAPIBNAME,

        logond type BAPILOGOND,

        pwd type BAPIPWD,

        addr type BAPIADDR3,

       End of user.

 

 

DATA: wa_user type user.

 

 

  TRY .

      OPEN DATASET pa_file FOR INPUt in TEXT MODE ENCODING UTF-8.

      SET DATASET pa_file POSITION END OF FILE .

      GET DATASET pa_file POSITION endpos.

      SET DATASET pa_file POSITION 0.

 

 

      WHILE curpos <> endpos.

 

 

        READ DATASET pa_file INTO csvstr.

        APPEND csvstr TO text.

        GET DATASET pa_file POSITION curpos.

 

 

          SPLIT csvstr AT ';' INTO wa_user-uname wa_user-addr-FIRSTNAME wa_user-addr-LASTNAME wa_user-logond-GLTGB."wa_zsl-hub wa_zsl-dest wa_zsl-dist wa_zsl-cost.

        wa_user-pwd = 'Welcome123'.

        wa_user-logond-USTYP = 'A'.

        CONCATENATE wa_user-addr-FIRSTNAME wa_user-addr-LASTNAME INTO wa_user-addr-FULLNAME.

 

 

CALL FUNCTION 'BAPI_USER_CREATE1'

  EXPORTING

    USERNAME                      = wa_user-uname

*   NAME_IN                       =

    LOGONDATA                     = wa_user-logond

    PASSWORD                      = wa_user-pwd

*   DEFAULTS                      =

    ADDRESS                       = wa_user-addr

*   COMPANY                       =

*   SNC                           =

*   REF_USER                      =

*   ALIAS                         =

*   EX_ADDRESS                    =

*   UCLASS                        =

*   FORCE_SYSTEM_ASSIGNMENT       =

*   SELF_REGISTER                 = ' '

*   TECH_USER                     =

* TABLES

*   PARAMETER                     =

*   RETURN                        =

*   ADDTEL                        =

*   ADDFAX                        =

*   ADDTTX                        =

*   ADDTLX                        =

*   ADDSMTP                       =

*   ADDRML                        =

*   ADDX400                       =

*   ADDRFC                        =

*   ADDPRT                        =

*   ADDSSF                        =

*   ADDURI                        =

*   ADDPAG                        =

*   ADDCOMREM                     =

*   GROUPS                        =

*   PARAMETER1                    =

*   EXTIDHEAD                     =

*   EXTIDPART                     =

          .

DATA RETURN_DUMMY LIKE BAPIRET2 OCCURS 0.

 

 

CALL FUNCTION 'BAPI_USER_LOCK'

  EXPORTING

    USERNAME       = wa_user-uname

  TABLES

    RETURN         = RETURN_DUMMY

          .

 

 

 

 

 

 

      ENDWHILE.

 

 

      CLOSE DATASET pa_file.

    CATCH cx_sy_file_open_mode.

      APPEND 'No file has been found.' TO text.

  ENDTRY.

 

 

If you want to run this program via RFC on target system just change two lines of this code before executing:

 

CALL FUNCTION 'BAPI_USER_CREATE1'

to

CALL FUNCTION 'BAPI_USER_CREATE1' DESTINATION 'target_rfc_name'

 

and

 

CALL FUNCTION 'BAPI_USER_LOCK'

to

CALL FUNCTION 'BAPI_USER_LOCK' DESTINATION 'target_rfc_name'

 

where target_rfc_name is a name of RFC to target system.

 

I hope that will help someone and save a lot of time by creating users from file instead of manually creating

 

Regards

Gabriel

Create customers using CMD_EI_API with central and sales data

$
0
0

Hello everybody,

 

Today i would like to share a code snippet to create customers based upon a text file with tab separator, it's very easy and functional using this api, in 161 lines of code you can create a client with basic central data and sales data.

 

The form receives the work area with customer data, this create a customer at time, so i call this routine from a loop of a internal table with file data.

 

form create_customer_api  using p_wa_file type ty_file

                                 value(p_row_id) type sy-tabix.

  data: l_wa_main type cmds_ei_main,

        l_it_customers type cmds_ei_extern_t,

        l_wa_customers type cmds_ei_extern,

        l_wa_phones type cvis_ei_phone_str,

        l_wa_email type cvis_ei_smtp_str,

        l_wa_sales type cmds_ei_sales,

        l_wa_loading type cmds_ei_loading,

        l_wa_functions type cmds_ei_functions,

        l_update_errors type cvis_message,

        l_it_bdcmsgcoll type table of bdcmsgcoll,

        l_wa_bdcmsgcoll type bdcmsgcoll,

        l_wa_messages type bapiret2,

        l_wa_log_alv type ty_log_alv,

        l_kunnr type kna1-kunnr.

 

  l_wa_customers-header-object_task = 'I'.

 

  l_wa_customers-central_data-address-task = 'I'.

 

  case p_wa_file-anred.

   when 'Sra.'.

    l_wa_customers-central_data-address-postal-data-title = '0001'.

   when 'Sr.'.

    l_wa_customers-central_data-address-postal-data-title = '0002'.

   when 'Empresa'.

    l_wa_customers-central_data-address-postal-data-title = '0003'.

   when others.

    l_wa_customers-central_data-address-postal-data-title = p_wa_file-anred.

  endcase.

 

  l_wa_customers-central_data-address-postal-data-name = p_wa_file-name1.

  l_wa_customers-central_data-address-postal-data-name_2 = p_wa_file-name2.

  l_wa_customers-central_data-address-postal-data-name_3 = p_wa_file-name3.

  l_wa_customers-central_data-address-postal-data-name_4 = p_wa_file-name4.

  l_wa_customers-central_data-address-postal-data-sort1 = p_wa_file-sortl.

  l_wa_customers-central_data-address-postal-data-street = p_wa_file-street.

  l_wa_customers-central_data-address-postal-data-str_suppl3 = p_wa_file-str_suppl3.

  l_wa_customers-central_data-address-postal-data-postl_cod1 = p_wa_file-post_code1.

  l_wa_customers-central_data-address-postal-data-city = p_wa_file-city1.

  l_wa_customers-central_data-address-postal-data-region = p_wa_file-region.

  l_wa_customers-central_data-address-postal-data-transpzone = p_wa_file-transpzone.

  l_wa_customers-central_data-address-postal-data-extens_1 = p_wa_file-extension1.

  l_wa_customers-central_data-address-postal-data-langu = 'S'.

  l_wa_customers-central_data-address-postal-data-country = 'CO'.

  l_wa_customers-central_data-central-data-brsch = p_wa_file-brsch.

  l_wa_customers-central_data-central-data-stcd1 = p_wa_file-stcd1.

  l_wa_customers-central_data-central-data-stcdt = p_wa_file-stcdt.

  l_wa_customers-central_data-central-data-fityp = p_wa_file-fityp.

  l_wa_customers-central_data-central-data-niels = p_wa_file-niels.

  l_wa_customers-central_data-central-data-kukla = p_wa_file-kukla.

  l_wa_customers-central_data-central-data-bran1 = p_wa_file-bran1.

  l_wa_customers-central_data-central-data-ktokd = pa_ktokd.

  l_wa_customers-central_data-central-data-katr1 = p_wa_file-katr1.

  l_wa_customers-central_data-central-data-katr2 = p_wa_file-katr2.

  l_wa_customers-central_data-central-data-katr3 = p_wa_file-katr3.

 

  l_wa_loading-task = 'I'.

  l_wa_loading-data_key-ablad = p_wa_file-ablad.

  l_wa_loading-data-knfak = p_wa_file-knfak.

  append l_wa_loading to l_wa_customers-central_data-loading-loading.

 

  l_wa_phones-contact-task = 'I'.

  l_wa_phones-contact-data-telephone = p_wa_file-telf1.

  append l_wa_phones to l_wa_customers-central_data-address-communication-phone-phone.

 

  l_wa_email-contact-task = 'I'.

  l_wa_email-contact-data-e_mail = p_wa_file-smtp_addr.

  append l_wa_email to l_wa_customers-central_data-address-communication-smtp-smtp.

 

  l_wa_sales-task = 'I'.

  l_wa_sales-data_key-vkorg = pa_vkorg.

  l_wa_sales-data_key-vtweg = pa_vtweg.

  l_wa_sales-data_key-spart = pa_spart.

 

  l_wa_sales-data-bzirk = p_wa_file-bzirk.

  l_wa_sales-data-vkbur = p_wa_file-vkbur.

  l_wa_sales-data-vkgrp = p_wa_file-vkgrp.

  l_wa_sales-data-kdgrp = p_wa_file-kdgrp.

  l_wa_sales-data-konda = p_wa_file-konda.

  l_wa_sales-data-kalks = p_wa_file-kalks.

  l_wa_sales-data-pltyp = p_wa_file-pltyp.

  l_wa_sales-data-versg = p_wa_file-versg.

  l_wa_sales-data-lprio = p_wa_file-lprio.

  l_wa_sales-data-vsbed = p_wa_file-vsbed.

  l_wa_sales-data-vwerk = p_wa_file-vwerk.

  l_wa_sales-data-bokre = p_wa_file-bokre.

  l_wa_sales-data-prfre = p_wa_file-prfre.

  l_wa_sales-data-inco1 = p_wa_file-inco1.

  l_wa_sales-data-kkber = p_wa_file-kkber.

  l_wa_sales-data-kabss = p_wa_file-kabss.

 

  l_wa_functions-task = 'I'.

  l_wa_functions-data_key-parvw = 'WE'.

 

  l_wa_functions-data-defpa = 'X'.

  append l_wa_functions to l_wa_sales-functions-functions.

 

  clear l_wa_functions-data-defpa.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'

    exporting

      input = p_wa_file-kunn2

    importing

      output = l_wa_functions-data-partner.

  l_wa_functions-data_key-parvw = 'AG'.

 

  append l_wa_functions to l_wa_sales-functions-functions.

 

  l_wa_functions-data_key-parvw = 'VE'.

  l_wa_functions-data-partner = p_wa_file-pernr.

  append l_wa_functions to l_wa_sales-functions-functions.

 

  append l_wa_sales to l_wa_customers-sales_data-sales.

 

  cmd_ei_api=>get_number( exporting iv_ktokd = pa_ktokd

                          importing ev_kunnr = l_wa_customers-header-object_instance-kunnr

                                    es_error = l_update_errors ).

 

  append l_wa_customers to l_wa_main-customers.

 

  if l_update_errors-is_error = space.

   clear: l_update_errors.

   cmd_ei_api=>maintain(

      exporting

        iv_test_run    = space

        is_master_data = l_wa_main

      importing

        es_error       l_update_errors ).

   if l_update_errors-is_error = space.

    commit work.

   else.

    rollback work.

   endif.

  endif.

 

  if l_update_errors-is_error = 'X'.

    cont_reg_error = cont_reg_error + 1.

    loop at l_update_errors-messages into l_wa_messages.

     l_wa_log_alv-row_id = p_row_id.

     l_wa_log_alv-msgtyp = l_wa_messages-type.

     call function 'MESSAGE_TEXT_BUILD'

       exporting

         msgid               = l_wa_messages-id

         msgnr               = l_wa_messages-number

         msgv1               = l_wa_messages-message_v1

         msgv2               = l_wa_messages-message_v2

         msgv3               = l_wa_messages-message_v3

         msgv4               = l_wa_messages-message_v4

       importing

         message_text_output = l_wa_log_alv-message.

 

     append l_wa_log_alv to it_log_alv.

    endloop.

  else.

   l_wa_log_alv-row_id = p_row_id.

   l_wa_log_alv-msgtyp = 'S'.

   l_wa_log_alv-kunnr = l_wa_customers-header-object_instance-kunnr.

   l_wa_log_alv-message = 'Cliente creado exitosamente'.

   append l_wa_log_alv to it_log_alv.

  endif.

endform.        


Kind regards.


Jhon Jairo.

Get column list (Name and Attribute) from internal table with class CL_ABAP_STRUCTDESCR

$
0
0

  data: begin of lt_tab occurs 0,

        bukrs type bukrs,

        text  type c,

        amt   type p,

        end of lt_tab.

 

  type-pools abap.

  data gt_comp type abap_component_tab with header line.

 

  perform get_column tables lt_tab

                   changing gt_comp[].

 

  loop at gt_comp where type->type_kind = 'P'.

    write:/ gt_comp-name.

  endloop.


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

*&      Form  get_column

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

form get_column tables pt_tab

              changing pt_comp.

  data: lr_data type ref to data,

        lr_desc type ref to cl_abap_structdescr.

 

  create data lr_data like line of pt_tab.

  lr_desc ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).

  pt_comp  = lr_desc->get_components( ).

endform.                    " get_column

Single Euro Payments Area (SEPA) Implementation of Direct Debit-Technical Design

$
0
0

Single Euro Payments Area (SEPA) Implementation of DD(Direct Debit)(Technical)

Sep, 2013

Introduction

SEPA stands for ‘Single Euro Payment Area’. It’s a system that is designed to create financial efficiency for countries using the currency Euro by providing a unified system in which to perform financial transactions. The SEPA seeks to create a better system for credit transfers, an improved debit system and a cheaper way for individuals and firms to make transactions within member countries or regions. Implementation of SEPA makes the customers life easier. Irrespective of the national area customers will be able to use the same card for all euro payments and also they need only one bank account in euro area.

Introduction to SEPA process:

The below mentioned should be done for Implementation of SEPA business in any SAP system:

1.    SEPA_Activation_Mandate_Management

Following are the activities which are to be done as part of this:

i.        SEPA mandate management has to be activated for the usage with SDD CORE and SDD B2B from FI-AR payment processing.  Apart from activating the SEPA Mandate management we need to maintain the SEPA Mandate management modifiable fields.

 

Below is the path for activating the SEPA Mandate Management and maintain the modifiable fields.

IMG -> Financial Accounting -> Accounts Receivable and Account Payable -> Business Transactions -> Incoming Payments -> Management of SEPA Mandates -> General Settings.

screen1.png

IMG -> Financial Accounting -> Accounts Receivable and Account Payable -> Business Transactions -> Incoming Payments -> Management of SEPA Mandates -> Define Modifiable Fields

screen2.png                                                                                                                                                                  

ii.        Creation of new DMEE Payment Format tree for SEPA credit transfer and SEPA direct debit.

·         SEPA_CT and SEPA_DD are the DMEE formats provided by SAP.

·         As we will be dealing with multiple countries it is always better to copy the DMEE formats and create new ones. If there is any custom requirement for any country create a user exit and assign to the field that needs to be changed dynamically.

2.  Pre Notification with payment run  :

With a direct debit pre-notification, Markets can inform a payer in writing in advance of the debiting of his account. To do this, one has to schedule a run for the creation of direct debit pre-notifications before the payment run, meaning before clearing the open items and creation of payment media. These correspond in structure to the payment advice notes, and therefore contain details of the run date, the amount to be collected, mandate ID, Unified Creditor Identifier etc.

Following are the SAP notes to be implemented for SEPA Pre-notification.

SAP Note

Description

1679118

F110:  Custom Selection for Batch Input

1760564

F110S:  Selection Check for Customers and Vendors

1770425

F111/SEPA: Mandate rejected as invalid after change

1771071

FBCJ : Reversal possible despite cleared item

1776076

F110/F111 : BADI for SEPA Mandate usage

1780941

SEPA: Direct debit Pre-Notification

1792691

Valid SEPA mandate is not found in the system during payment proposal processing

 

As part of the Note implementation 1780941, we need to implement manual steps given below for importing the Standard SAP Form.

·    SAP has provided text file by using this file we need to import the object F110_DD_PRENOTIF into SAP by executing program RSTXCRP.  This is standard SAP form which will be used for sending PreNotifications.

·    SAP has provided XML file by using this file we need to import the object F110_DD_PRENOTIF into SAP using SFP transaction code. Once it is uploaded, activate the form.

Once all the relevant OSS Notes are implemented for SEPA Direct debit pre-notification, we will get option of checkbox for Pre-notification in F110 transaction and also pre-notification relevant standard program RFFOAVIS_DD_PRENOTIF and script form (F110_DD_PRENOTIF) available in the system.

screen3.png

The above check box is checked if we need to do SEPA prenotification.

screen4.png

 

RFFOAVIS_DD_PRENOTIF: This is the payment advice print program that is used to print the pre-notifications the pre-notification

F110_DD_PRENOTIF: This is the standard SAP script which is used to send the pre-notifications.

scrren61.png

          Based on the user requirement, the form name can be changed

·      The new "direct debit pre-notification" object is visible in the payment run (F110), in the document display (FB03), in the line item display (FBL5N) and in mandate display (FSEPA_M4). It can be deleted again if the direct debit pre-notification customer objects to it (for example, because the customer pays the bill himself). Otherwise, the posting run and the payment medium creation are performed after the end of the specified wait time based on the direct debit pre-notifications.

3.  Creation of SEPA Mandates for payment transactions :

·       Before doing any transaction for any SEPA customer we need to have a mandate create for the Customer.

·       Before creating a mandate the Customer Should have IBAN number.

·       Transactions used :

Creation

FSEPA_M1

Change

FSEPA_M2

Display

FSEPA_M3,FSEPA_M4

NOTE: Mandates can also be created from the payment tab of the Customer Master XD01, FD01, XD02,FD02.

NOTE: Mandate Number can be either External or Internal Number.

·       To make our work easier technically we can use the below procedure using the below BAPI's:

·       The table that is Master for all the SEPA mandates is SEPA_MANDATE.

·       SEPA_MANDATE: This is the Standard Smart form used to print the mandate details for any customer.

·       Assume a file with the Customer and mandate Information is available

Ø  Check if the customer is created by checking in the KNB1 table.

Ø  If the Customer is present then check if the Customer has IBAN and BIC number.

Ø  Check if the mandate is not created for Customer with the mandate number using the BAPI SEPA_MANDATES_API_GET.

Ø  For the BAPI SEPA_MANDATES_API_GET pass the customer number in the importing parameter to check if there is any mandate information present for the Customer SEPA_GET_CRITERIA_MANDATE-snd_id = Customer Number .

screen6.png

Ø  ET_MANDATES contains the mandate information that is fetched from BAPI based on the Customer Number.

scrren71.png

NOTE :   SEPA_MANDATES_API_GET FM cannot be used for multiple mandate scenario. We can write take MGUID from REGUH table and go to SEPA_MANDATE table and get the IBAN number and mandate number.

 

Three BAPI'S are majorly used to Creation and updating of the mandate details of the Customer.

To fetch the Mandate information for a particular Customer from the table SEPA_MANDATE table

SEPA_MANDATES_API_GET

Create the Mandate for a Customer

BAPI_SEPA_MANDATE_CREATE1

Modification of Mandate details for a customer

BAPI_SEPA_MANDATE_CHANGE1

 

·       Mandate Creation:

Ø Use the BAPI BAPI_SEPA_MANDATE_CREATE1 to create the mandate .

Ø BAPI_S_SEPA_MANDATE_COMMON structure which is importing parameter to the above mentioned BAPI has to be filled with the mandate information .This contains both the Sender (Customer Details ) and  receiver details (Company code data ).

screen-8.png

Ø Then collect all the address information either from the file provided or from the customer master data and fill the Sender information in the structure BAPI_S_SEPA_MANDATE_COMMON.

Ø Then based on the company code fetch the address details of the Company code and fill the Receiver information in the structure BAPI_S_SEPA_MANDATE_COMMON.

Ø ES_MANDATE_CREATED exporting parameter in the above BAPI gives a success message if the mandates are correctly created for the customer.

Ø  Error handling can be done with the return exporting parameter.

screen9.png

 

·       If the mandate already exists then check if there is any change in the mandate information.

Mandate modification:

Ø  Use the BAPI BAPI_SEPA_MANDATE_CHANGE1 to change the already existing mandate.

Ø  BAPI_S_SEPA_MANDATE_CHANGE structure which is importing parameter to the above mentioned BAPI has to be filled with the mandate information .This contains both the Sender (Customer Details) and  receiver details (Company code data ).

screen9.png

Ø  In case ofupdation is failed it can handled by  return parameter of the BAPI

screen-10.png

  Display of Mandates :

Ø  The created mandates can be checked by FSEPA_M3 Give the Mandate number or Customer Number and check for the Mandate information.

screen11.png

On Click on Enter the below Screen appears which displays all the information.

screen12.png

 

Ø We can also check the Mandate information through Customer master display  using transaction fd02,xd02,xd03,fd03.screen13.png

Click on the Tab to check and create the mandate Details from Customer master

Display the List of Mandates:

Ø  Use the transaction FSEPA_M4 to display a list for customers for a particular company code.

screen14.png

Ø  Mention the company code in the below transaction and then execute all the mandates present for the company code will be displayed.

Ø  A list of mandates will be displayed as shown in the below screen shot.

screen15.png

The above lights depicts different status of the mandates below are the differnent status of mandates.

0         

Entered

1

Active

2

To Be Confirmed

3

Locked

4

Canceled

5

Obsolete

6

CompletedCompleted

Ø  If we need to print a particular mandate information then select the Print mandate button on the top right corner of the list .

screen16.png

Ø  For this SAP has provided a smartform SEPA_MANDATE.This can be customized at central level and the thus the mandate can be created and mandate information can be printed.

screen17.png

All the inforamtion related to the mandate is available in the table SEPA_MANDATE.


Featured Content for ABAP Development

$
0
0

ABAP Developement Tools for Eclipse 2.19

The ABAP Development Tools for Eclipse 2.19 are available as of today! Read this interesting blog by Thomas Fiedler to find out what's new and where to get the latest version.December 20, 2013

 

SQL Monitor Unleashed

Have you heard about the SQL Monitor already? It can be used to detect custom code which can be optimized (in the context of the migration to SAP HANA, but also independent of that). If you like to learn more, read Johannes Marbach's blog series. You find the first blog here.November 18, 2013

 

Considerations for Custom ABAP Code During a Migration to SAP HANA

Considering a migration of your custom code to an AS ABAP 7.4 on SAP HANA system? Then you should read this best practice guide by Eric Westenberger containing important considerations and recommendations. Moreover, this document provides an overview of the available tools and services which can ease a transition of custom ABAP code, and gives guidance how to use them.September 27, 2013

 

SCN Trial Editions of SAP NetWeaver Application Server ABAP 7.4

Get your hands on SAP NetWeaver Application Server ABAP 7.4 on SAP HANA or SAP MaxDB and learn more about its new capabilities and the programming language enhancements! Visit this page to learn more about the new ABAP trials provided as virtual appliances by the SAP Cloud Appliance Library.July 24, 2013

 

Dynamic Fonts in Adobe Forms

$
0
0

Introduction:-

 

Adobe Forms are PDF (Portable Document Format) documents containing data from various core systems represented in a
well-known structuring method for data output. Adobe forms can be both static as well as interactive and can be printed, distributed via email and saved locally.

 

The reasons behind using Adobe Forms are it provides security options like digital signatures, disabling print option and the major reason is PDF document is an open standard.

 

TYPES:-


1) Interactive Forms: - Interactive Forms are PDF documents that require forms to be filled by the users which can be either done
online or offline and the data entered can be used for further processing. Thus interactive forms can be classified into two types:-

 

  1. Online:-Here the user displays and fills the form via WebDynpro which can be accessed via a portal or web Application Server.
  2. Offline:-Here the user downloads and saves the form in local hard drive for filling it up later and uploading the completed one

                  back to the server. 

2)PDF-Based Print Forms:-The PDF-based Print forms are similar to SMARTFORMS used to print Invoices, salary, etc. They are static in nature as there is no user interaction.  Now in this document we will learn how to use Dynamic fonts in a single Adobe Forms. 

 

 

Prerequisites of using fonts in Adobe Forms:-

 

  1. The font to be used should be installed in the system where the Adobe Form is developed and also in the system where it is viewed.
  2. ADS (Adobe Document Services) require access to fonts that are installed in thefont manager module. So the new font to be used has to be placed in the font manager module of the ADS.

 

Steps to be followed to use multiple font using java script:-

 

1.Go to the TCODE SFP to open the adobe form.

          1.jpg

             

2. Go to the interface and add the following field of string type. Here wf_font will hold the font type that is to be used in the form.

            2.jpg

3. In the context of the form add the field wf_font from the interface.

            3.jpg

  4. Go to the form layout and add normal text field from the object library to the main page and design view for holding the value of the field wf_font. Ensure that you have the field as invisible (presence in object properties).

              4.jpg

                WF_FONT field in Master Page.

            5.jpg

              WF_Font in the design view.

    5.Now the most important part is writing the JAVA SCRIPT to change the font at each and every element. We will write the JAVA                SCRIPT at the initialize event. The script we are going to write is “this.font.typeface = “NAME OF THE FONT”.

       

      The “this” in the above script refers to the specific field (wf_vblen,wf_mat,etc).Now we are sending the font dynamically from      the print program and we have the same in the field wf_font of the form.

     

      So the required JAVA SCRIPT will be:-

         

      this.font.typeface = xfa.resolveNode("data.#pageSet[0].Page1.WF_FONT").rawValue;

       

      Where xfa.resolveNode () evaluates the specified reference syntax expression and returns the value of the object specified in      the reference syntax expression.

     

      As a result we will get the value (like ‘Times New Roman’, Etc.) we have passed from the print program and the same is assigned to      the font of the element in the form layout.

 

      The same script is to be placed at all the elements in the layout.

      6.jpg

        JAVA SCRIPT at one node in the master page.

        7.jpg

        JAVA SCRIPT at one node in the Design View.

         

 

NOTE: - We are using a different field in design view as the value of the field in the master page can’t be accessed in the design view.

 

 

 

Changes in code:-

 

Apart from the normal logic to fetch and display data in the adobe form we need to pass the font name to the form interface.

  8.jpg

      9.jpg

Here when you right click and check the document properties you can see the fonts. That is CorpoS (corporateS).

     

        10.jpg

          11.jpg

        Same for using the font “Times New Roman”.

 

 

 

Problem Areas of using Dynamic font:-

 

  Using dynamic fonts in Adobe Forms has some restriction. Few are discussed below:-

 

 

  • We can use the JAVA SCRIPTS only for fields that we send value from print program and not hard coded text. So all the hard coded text has to replaced by the text fields.
  • In Adobe Form we have the default Page no. and we don’t have to place any logic for that. But the same is hard coded text( page ). So we have to replace that with a text field and place the below java script to ensure we get the page no. in different fonts.

      12.jpg

 

  • Another issue that we face is when we use fonts with a bigger size. As a result the text field behaves only with the original assigned font and not the dynamically assigned font thus resulting in overflowed or truncated text.

 

The print program code is attached.

 

     

 

                 

Output Catcher for ABAP

$
0
0

Hello community,


Output Catch is a small SAP server application to catch text on the presentation server from ABAP on the application server. You can send text direct to the editor of output catch, to a specific log file on the client, to a Windows debugger or to the Windows event protocol of the client.


It is very easy to use Output Catch:

  1. Register the Destination OUTPUTCATCH with the TAC SM59.
  2. Start the program OutputCatchU.exe.
  3. Fill the connection parameters.

    catch2.jpg
  4. Register the functions and use one of the output or log variants.

  

Now you can e.g. send with the code

 

CallFunction'OUTPUT'Destination'OUTPUTCATCH'
  ExportingTEXT='Hello World'SEP=0UNAME=sy-uname
  Exceptions Others= 1
.

the TEXT Hello World to the editor in the tab Output. It works with background and dialog processes. The communication to an SAP system is via librfc32u.dll, the classic unicode RFC library. If the SAP GUI for Windows is present on your presentation server, you can use Output Catch without any additional libraries.

 

I use Output Catch inter alia to monitor interface parameters of background processes.

 

Output Catch is free and you can find it here.

 

Cheers

Stefan

Changing Subject of Mail sent through "Spool Recipient"

$
0
0

Scenario: We usually use the “Spool Recipient” of the SM37 Background Job  to send the Spool Outputs to designated users
in their Work Place Inbox.

 

Spool Recipient:

1.jpg


Workplace Inbox:

2.jpg

 

If you notice the Subject of the Item, it takes theBackground Jobs Name & Step Number & we obviously Didn’t Like that

 

3.jpg

 

What we did:

 

After some research, we stumbled upon one SAP Note which will allow us this to change.

 

Note number: 1101211 - Using spool request title as e-mail  title.

 

This Note allows you to set the Title of your Email to be  the Title of your Spool Request.

 

So, We thought if we could have our Spool contain the Namewhich we wanted, it would definitely flow to the Title of the Email sent to Workplace Inbox,

We went about this in 2 Steps

 

  1. Do what the SAP Note said

 

Run the Program RSPO0021 with the Below Parameters:

 

4.jpg

 

Once this is done, we proceed with a way to change the Spool Request Name.

 

 

2.   Since ours was a Custom Program calling a Standard Program, we passed the Name we wanted to the Spool Parameters Id along with the Calling
Program.

 

In the Below screenshot we call the Standard Program “RFEBCK00”,so in the Spool  Parameters we passed the needed values.

 

5.jpg


6.jpg

 

So, if your case is a Standard Program just change it in the Spool Title” while setting the Print Parameters.

 

 

 

After these changes we ran the Custom Program and went to check the Output and see if the Name on the work item is changed


We checked first if the Spool got the Name we wanted,

7.jpg

The above screen says we did!

 

Next, we want to check the all Important One

 

8.jpg

 

Thankfully the effort paid off !

SCN Trial Editions: SAP NetWeaver Application Server ABAP 7.4

$
0
0

Latest News

Oct 25, 2013: No country limitation anymore, if you use the direct links below.

Sep 27, 2013: New step-by-step tutorials for setting up your AWS environment.

 

product_32.png

Get your hands on the latest release of SAP NetWeaver Application Server ABAP, learn more about its new capabilities, the programming language enhancements, and test-drive the SAP development tools for Eclipse!

 

You can choose from different SCN trial editions which are provided as pre-configured virtual appliances by the SAP Cloud Appliance Library (free of charge). SAP offers this software based on a 90-day trial and evaluation license agreement.

 

Get Your Free Trial As Virtual Appliance

 

The SCN trials of SAP NetWeaver Application Server ABAP 7.4 are available with two different database flavors, i.e. on SAP HANA (in-memory database) and on SAP MaxDB (classical RDBMS). Both virtual appliances come with a detailed user guide describing how to set up and run these virtual appliances.

 

Light_Bulb_32.pngYou should be familiar with the prerequisites and tutorials on our How-to and FAQ page before you order and run these virtual appliances. We also recommend to set up a billing alert for your AWS charges.

 

To get access to these virtual appliances and run them on your own cloud service provider account please visit the SAP Store, log on with your SCN user and hit the Demo Now button. For questions and feedback please post a message in the corresponding ABAP trial thread.

 

tag_cloud_chart_grey_32.png

AS ABAP 7.4 on SAP HANA
[Trial Edition]

tag_cloud_chart_32.png

AS ABAP 7.4 on SAP MaxDB
[Trial Edition]

tag_cloud_chart_grey_32.png

BW 7.4 on SAP MaxDB*
[Trial Edition]

 

*The SAP NetWeaver Business Warehouse 7.4 trial consists of AS ABAP 7.4 and AS Java 7.4 with usage type BI Java as described in the attached solution guide.

 

Try Out These Sample Applications and Tutorials

 

All trial editions come with a pre-configured developer user, pre-installed sample applications and tutorials explaining new capabilities and technologies. The following tutorials are already available:

 

ABAP for SAP HANA reference scenario

The ABAP for SAP HANA reference scenario offers guides and tutorials including a pre-installed sample application which guide you through the E2E development process and provide sample coding leveraging the code-pushdown paradigm on SAP’s in-memory database. For more information please visit the reference scenario home page or directly consult the corresponding how-to guide by Jens Weiler.

 

How to implement an OData service with SAP NetWeaver Gateway

This how-to guide by Andre Fischer describes how to quickly create an OData service with SAP NetWeaver Gateway. You will learn how to create a data model based on a DDIC structure and implement the corresponding services using the OData channel programming model. For more information please download the how-to guide from SCN.

 

How to build SAPUI5/HTML5 applications consuming OData services

This blog by Bertram Ganz describes the end-to-end process required to develop a SAPUI5/HTML5 application user interface (with table, popup and ux3 shell) consuming a local OData service by SAP NetWeaver Gateway. The created OData service is based on the SAP NetWeaver Enterprise Sales and Procurement Model as a pre-installed demo/proxy application that provides a list of products as business data. For detailed instructions please download the how-to guide from SCN.

 

BW sample scenarios and demo content (for the BW 7.4 trial)

The SAP NetWeaver Business Warehouse 7.4 trial provides pre-activated sample scenarios for selected OLAP functions and integrated planning and contains predefined objects, such as InfoProviders, Queries and Workbooks. For more information please refer to this page. Moreover, you can execute the Open Items Analytics Dashboard.

Single Euro Payments Area (SEPA) Implementation of Direct Debit-Technical Design

$
0
0

Single Euro Payments Area (SEPA) Implementation of DD(Direct Debit)(Technical)

Sep, 2013

Introduction

SEPA stands for ‘Single Euro Payment Area’. It’s a system that is designed to create financial efficiency for countries using the currency Euro by providing a unified system in which to perform financial transactions. The SEPA seeks to create a better system for credit transfers, an improved debit system and a cheaper way for individuals and firms to make transactions within member countries or regions. Implementation of SEPA makes the customers life easier. Irrespective of the national area customers will be able to use the same card for all euro payments and also they need only one bank account in euro area.

Introduction to SEPA process:

The below mentioned should be done for Implementation of SEPA business in any SAP system:

1.    SEPA_Activation_Mandate_Management

Following are the activities which are to be done as part of this:

i.        SEPA mandate management has to be activated for the usage with SDD CORE and SDD B2B from FI-AR payment processing.  Apart from activating the SEPA Mandate management we need to maintain the SEPA Mandate management modifiable fields.

 

Below is the path for activating the SEPA Mandate Management and maintain the modifiable fields.

IMG -> Financial Accounting -> Accounts Receivable and Account Payable -> Business Transactions -> Incoming Payments -> Management of SEPA Mandates -> General Settings.

screen1.png

IMG -> Financial Accounting -> Accounts Receivable and Account Payable -> Business Transactions -> Incoming Payments -> Management of SEPA Mandates -> Define Modifiable Fields

screen2.png                                                                                                                                                                  

ii.        Creation of new DMEE Payment Format tree for SEPA credit transfer and SEPA direct debit.

·         SEPA_CT and SEPA_DD are the DMEE formats provided by SAP.

·         As we will be dealing with multiple countries it is always better to copy the DMEE formats and create new ones. If there is any custom requirement for any country create a user exit and assign to the field that needs to be changed dynamically.

2.  Pre Notification with payment run  :

With a direct debit pre-notification, Markets can inform a payer in writing in advance of the debiting of his account. To do this, one has to schedule a run for the creation of direct debit pre-notifications before the payment run, meaning before clearing the open items and creation of payment media. These correspond in structure to the payment advice notes, and therefore contain details of the run date, the amount to be collected, mandate ID, Unified Creditor Identifier etc.

Following are the SAP notes to be implemented for SEPA Pre-notification.

SAP Note

Description

1679118

F110:  Custom Selection for Batch Input

1760564

F110S:  Selection Check for Customers and Vendors

1770425

F111/SEPA: Mandate rejected as invalid after change

1771071

FBCJ : Reversal possible despite cleared item

1776076

F110/F111 : BADI for SEPA Mandate usage

1780941

SEPA: Direct debit Pre-Notification

1792691

Valid SEPA mandate is not found in the system during payment proposal processing

 

As part of the Note implementation 1780941, we need to implement manual steps given below for importing the Standard SAP Form.

·    SAP has provided text file by using this file we need to import the object F110_DD_PRENOTIF into SAP by executing program RSTXCRP.  This is standard SAP form which will be used for sending PreNotifications.

·    SAP has provided XML file by using this file we need to import the object F110_DD_PRENOTIF into SAP using SFP transaction code. Once it is uploaded, activate the form.

Once all the relevant OSS Notes are implemented for SEPA Direct debit pre-notification, we will get option of checkbox for Pre-notification in F110 transaction and also pre-notification relevant standard program RFFOAVIS_DD_PRENOTIF and script form (F110_DD_PRENOTIF) available in the system.

screen3.png

The above check box is checked if we need to do SEPA prenotification.

screen4.png

 

RFFOAVIS_DD_PRENOTIF: This is the payment advice print program that is used to print the pre-notifications the pre-notification

F110_DD_PRENOTIF: This is the standard SAP script which is used to send the pre-notifications.

scrren61.png

          Based on the user requirement, the form name can be changed

·      The new "direct debit pre-notification" object is visible in the payment run (F110), in the document display (FB03), in the line item display (FBL5N) and in mandate display (FSEPA_M4). It can be deleted again if the direct debit pre-notification customer objects to it (for example, because the customer pays the bill himself). Otherwise, the posting run and the payment medium creation are performed after the end of the specified wait time based on the direct debit pre-notifications.

3.  Creation of SEPA Mandates for payment transactions :

·       Before doing any transaction for any SEPA customer we need to have a mandate create for the Customer.

·       Before creating a mandate the Customer Should have IBAN number.

·       Transactions used :

Creation

FSEPA_M1

Change

FSEPA_M2

Display

FSEPA_M3,FSEPA_M4

NOTE: Mandates can also be created from the payment tab of the Customer Master XD01, FD01, XD02,FD02.

NOTE: Mandate Number can be either External or Internal Number.

·       To make our work easier technically we can use the below procedure using the below BAPI's:

·       The table that is Master for all the SEPA mandates is SEPA_MANDATE.

·       SEPA_MANDATE: This is the Standard Smart form used to print the mandate details for any customer.

·       Assume a file with the Customer and mandate Information is available

Ø  Check if the customer is created by checking in the KNB1 table.

Ø  If the Customer is present then check if the Customer has IBAN and BIC number.

Ø  Check if the mandate is not created for Customer with the mandate number using the BAPI SEPA_MANDATES_API_GET.

Ø  For the BAPI SEPA_MANDATES_API_GET pass the customer number in the importing parameter to check if there is any mandate information present for the Customer SEPA_GET_CRITERIA_MANDATE-snd_id = Customer Number .

screen6.png

Ø  ET_MANDATES contains the mandate information that is fetched from BAPI based on the Customer Number.

scrren71.png

NOTE :   SEPA_MANDATES_API_GET FM cannot be used for multiple mandate scenario. We can write take MGUID from REGUH table and go to SEPA_MANDATE table and get the IBAN number and mandate number.

 

Three BAPI'S are majorly used to Creation and updating of the mandate details of the Customer.

To fetch the Mandate information for a particular Customer from the table SEPA_MANDATE table

SEPA_MANDATES_API_GET

Create the Mandate for a Customer

BAPI_SEPA_MANDATE_CREATE1

Modification of Mandate details for a customer

BAPI_SEPA_MANDATE_CHANGE1

 

·       Mandate Creation:

Ø Use the BAPI BAPI_SEPA_MANDATE_CREATE1 to create the mandate .

Ø BAPI_S_SEPA_MANDATE_COMMON structure which is importing parameter to the above mentioned BAPI has to be filled with the mandate information .This contains both the Sender (Customer Details ) and  receiver details (Company code data ).

screen-8.png

Ø Then collect all the address information either from the file provided or from the customer master data and fill the Sender information in the structure BAPI_S_SEPA_MANDATE_COMMON.

Ø Then based on the company code fetch the address details of the Company code and fill the Receiver information in the structure BAPI_S_SEPA_MANDATE_COMMON.

Ø ES_MANDATE_CREATED exporting parameter in the above BAPI gives a success message if the mandates are correctly created for the customer.

Ø  Error handling can be done with the return exporting parameter.

screen9.png

 

·       If the mandate already exists then check if there is any change in the mandate information.

Mandate modification:

Ø  Use the BAPI BAPI_SEPA_MANDATE_CHANGE1 to change the already existing mandate.

Ø  BAPI_S_SEPA_MANDATE_CHANGE structure which is importing parameter to the above mentioned BAPI has to be filled with the mandate information .This contains both the Sender (Customer Details) and  receiver details (Company code data ).

screen9.png

Ø  In case ofupdation is failed it can handled by  return parameter of the BAPI

screen-10.png

  Display of Mandates :

Ø  The created mandates can be checked by FSEPA_M3 Give the Mandate number or Customer Number and check for the Mandate information.

screen11.png

On Click on Enter the below Screen appears which displays all the information.

screen12.png

 

Ø We can also check the Mandate information through Customer master display  using transaction fd02,xd02,xd03,fd03.screen13.png

Click on the Tab to check and create the mandate Details from Customer master

Display the List of Mandates:

Ø  Use the transaction FSEPA_M4 to display a list for customers for a particular company code.

screen14.png

Ø  Mention the company code in the below transaction and then execute all the mandates present for the company code will be displayed.

Ø  A list of mandates will be displayed as shown in the below screen shot.

screen15.png

The above lights depicts different status of the mandates below are the differnent status of mandates.

0         

Entered

1

Active

2

To Be Confirmed

3

Locked

4

Canceled

5

Obsolete

6

CompletedCompleted

Ø  If we need to print a particular mandate information then select the Print mandate button on the top right corner of the list .

screen16.png

Ø  For this SAP has provided a smartform SEPA_MANDATE.This can be customized at central level and the thus the mandate can be created and mandate information can be printed.

screen17.png

All the inforamtion related to the mandate is available in the table SEPA_MANDATE.

Featured Content for ABAP Development

$
0
0

ABAP Developement Tools for Eclipse 2.19

The ABAP Development Tools for Eclipse 2.19 are available as of today! Read this interesting blog by Thomas Fiedler to find out what's new and where to get the latest version.December 20, 2013

 

SQL Monitor Unleashed

Have you heard about the SQL Monitor already? It can be used to detect custom code which can be optimized (in the context of the migration to SAP HANA, but also independent of that). If you like to learn more, read Johannes Marbach's blog series. You find the first blog here.November 18, 2013

 

Considerations for Custom ABAP Code During a Migration to SAP HANA

Considering a migration of your custom code to an AS ABAP 7.4 on SAP HANA system? Then you should read this best practice guide by Eric Westenberger containing important considerations and recommendations. Moreover, this document provides an overview of the available tools and services which can ease a transition of custom ABAP code, and gives guidance how to use them.September 27, 2013

 

SCN Trial Editions of SAP NetWeaver Application Server ABAP 7.4

Get your hands on SAP NetWeaver Application Server ABAP 7.4 on SAP HANA or SAP MaxDB and learn more about its new capabilities and the programming language enhancements! Visit this page to learn more about the new ABAP trials provided as virtual appliances by the SAP Cloud Appliance Library.July 24, 2013

 


Mass user lock with abap program

$
0
0

Recently I had an issue with locking users. I have generated a report about users who have not been logged for a couple of months. This file contained only usernames, since that is all you need to know when it comes to locking someone. The expiration date in this task is the date of lock.

 

Since locking hundreds of users and setting their expiration date in a couple of systems is insanity, I had to find a different way to do so. Here is a program serving that task:

 

Mass user lock
REPORT  Z_MASS_USER_LOCK.

"variables for uploading and reading file with usernames
DATA: paa_file  TYPE SAPB-SAPPFAD,
       pafile    TYPE SAPB-SAPPFAD.
       "paa_file2 TYPE string.

"parameter for local file path
PARAMETERS: p_file(70) TYPE c.
"set filenames
pafile = p_file.
paa_file = 'Users_For_Lock.csv'.

"path to local file in wich users to be locked is stored
OPEN DATASET  paa_file FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
CLOSE DATASET paa_file.

CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'
   EXPORTING
     PATH             = pafile
     TARGETPATH       = paa_file
* EXCEPTIONS
*   ERROR_FILE       = 1
*   OTHERS           = 2
           .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
   MESSAGE 'No such file' TYPE 'E'.
ENDIF.

DATA: text    TYPE TABLE OF string,
       csvstr  TYPE string,
       pa_file TYPE string,
       curpos  TYPE i,
       endpos  TYPE i.

pa_file = paa_file.

"data of the user we want to lock
TYPES: BEGIN OF user,
         uname  TYPE BAPIBNAME-BAPIBNAME, "username
         logond TYPE BAPILOGOND,         "logon date, here we set valid through date
         logonx TYPE BAPILOGONX,
        END   OF user.

DATA: wa_user type user.

"

TRY .
     OPEN DATASET pa_file FOR INPUt in TEXT MODE ENCODING UTF-8.
     SET DATASET  pa_file POSITION END OF FILE .
     GET DATASET  pa_file POSITION endpos.
     SET DATASET  pa_file POSITION 0.

     WHILE curpos <> endpos.

       READ DATASET pa_file INTO csvstr.
       APPEND csvstr TO text.
       GET DATASET pa_file POSITION curpos.

       wa_user-uname = csvstr.           "set uname of the user to be locked
       wa_user-logond-GLTGB = sy-datum"set current date as the validity expiration date
       wa_user-logonx-GLTGB = 'X'.       "mark that you want to change the validity expiration date

       DATA RETURN_DUMMY LIKE BAPIRET2 OCCURS 0.


       "set users expiration date
       CALL FUNCTION 'BAPI_USER_CHANGE'
         EXPORTING
           USERNAME          = wa_user-uname
           LOGONDATA         = wa_user-logond
           LOGONDATAX        = wa_user-logonx
         TABLES
           RETURN            = RETURN_DUMMY
         .

       "lock the user
       CALL FUNCTION 'BAPI_USER_LOCK'
         EXPORTING
           USERNAME = wa_user-uname
         TABLES
           RETURN   = RETURN_DUMMY.



     ENDWHILE.

     CLOSE DATASET pa_file.
   CATCH cx_sy_file_open_mode.
     MESSAGE 'Upload a proper file' TYPE 'E'.
ENDTRY.

 

After starting the program, this is what you should get:

 

In p_file parameter you add path to local .csv file containing a list of users. An example file should look like this:

Users_to_be_locked.csv

Username1

Username2

Username3

Username4

Username5

...

Username n

 

 

Afterwards you press F8 and the program should run perfectly.

The program uploads your local file into server and works on it. It sets expiration date as current date.

 

To lock users on other system, all you need is an RFC connection to them and to modify lines:

       "set users expiration date
       CALL FUNCTION 'BAPI_USER_CHANGE'
         EXPORTING
           USERNAME          = wa_user-uname
           LOGONDATA         = wa_user-logond
           LOGONDATAX        = wa_user-logonx
         TABLES
           RETURN            = RETURN_DUMMY
         .

       "lock the user
       CALL FUNCTION 'BAPI_USER_LOCK'
         EXPORTING
           USERNAME = wa_user-uname
         TABLES
           RETURN   = RETURN_DUMMY.

 

to

 

       "set users expiration date
       CALL FUNCTION 'BAPI_USER_CHANGE' DESTINATION <rfc_name>
         EXPORTING
           USERNAME          = wa_user-uname
           LOGONDATA         = wa_user-logond
           LOGONDATAX        = wa_user-logonx
         TABLES
           RETURN            = RETURN_DUMMY
         .

       "lock the user
       CALL FUNCTION 'BAPI_USER_LOCK' DESTINATION <rfc_name>
         EXPORTING
           USERNAME = wa_user-uname
         TABLES
           RETURN   = RETURN_DUMMY.

 

 

Hope this proves usefull

How to Simulate an E-Mail Attachment Conversion

$
0
0

Hello community,

 

often developers has the problem that not all applications, which are necessary for their development, are available at the right time. So it is necessary to simulate one or the other application. Here is a solution how to simulate a conversion for images from e-mail attachments, e.g. for an ERMS (E-mail Response Management System). An example: The office worker gets an e-mail from a customer about a case of damage with a photo from his camera. The photo has not a normal format like jpeg or tif. For a fast claims processing it is necessary to convert the photo in pdf and to store it in the archive. For this case the ERMS offers an automatic conversion - but this conversion is not available now. To convert an image you can use nconvert, it is a part from free available XNview. Convert nconvert with BinFile2ABAP in an ABAP function module. With this function module and nconvertX, an ActiveX library for the presentation server which offers the possiblilty to use nconvert inside ABAP, you can simulate an image conversion. Download the picture below.

 

nconvertx.jpg

 

Here an source example, to show how easy an conversion could be:

 

Function ZNCONVERTX.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(TARGETFILETYPE) TYPE  STRING

*"     VALUE(SOURCEFILENAME) TYPE  STRING

*"----------------------------------------------------------------------

 

  "-Constants-----------------------------------------------------------

    Constants SW_HIDE Type i Value 0.

    Constants SW_SHOWNORMAL Type i Value 1.

 

  "-Variables-----------------------------------------------------------

    Data oConv Type OLE2_OBJECT.

    Data WorkDir Type String Value ''.

    Data rc Type i Value 0.

    Data Params Type String Value ''.

 

  "-Macros--------------------------------------------------------------

    Define Flush.

      Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

    End-Of-Definition.

 

  "-Main----------------------------------------------------------------


    "-Unpack nconvert.exe to work directory-----------------------------

      Call Function 'ZNCONVERTEXE'.


    Create Object oConv 'nconvertX'.

    If sy-subrc <> 0 Or  oConv-Handle = 0 Or oConv-Type <> 'OLE2'.


      "-Unpack nconvertX.dll to work directory and registers the library

        Call Function 'ZNCONVERTXDLL'.


      Create Object oConv 'nconvertX'.

    EndIf.

 

    If sy-subrc = 0 And oConv-Handle > 0 And oConv-Type = 'OLE2'.

 

      Call Method cl_gui_frontend_services=>get_sapgui_workdir

        Changing

          SAPWORKDIR = WorkDir

        Exceptions

          Others = 1.

 

      Translate TargetFileType To Lower Case.

      Concatenate `-out ` TargetFileType ` ` SourceFileName Into Params.

 

      "-Converts the image to another format----------------------------

        Call Method Of oConv 'NConvert' = rc Exporting #1 = WorkDir

          #2 = Params #3 = SW_HIDE #4 = 1.

      Flush.

 

      Free Object oConv.

    EndIf.

 

EndFunction.

 

001.JPG

This function module converts with this arguments the image 001.bmp to pdf. All files are in the SAP GUI work directory.

nconvert supports 493 different formats. It is also possible to resize the images or to do a lot of other things.

To convert an image to a specific format type e.g. a few files to tif:

nconvert -out tiff file1.pic file2.jpg file3.tga

 

With nconvert and nconvertX it is very easy to simulate an e-mail image attachment conversion.

 

Enjoy it.

 

Cheers

Stefan

How to - Add Custom XML Parts to Microsoft PowerPoint using ABAP

$
0
0

This document explains how to:

 

Add Custom XML Parts to PowerPoint using ABAP

 

    1. Prepare XML data

METHOD prepare_customxml.
*    Exporting  EV_CUSTOMXML4PPT  TYPE XSTRING
*    Exception  XSLT_ERROR
  CONSTANTS:  lc_encode        TYPE abap_encod VALUE 'UTF-8'.
  DATA:
        lv_customxml4ppt              TYPE string,
        l_convout                          TYPE REF TO cl_abap_conv_out_ce,
        lv_len                                TYPE i.
  l_convout = cl_abap_conv_out_ce=>create( encoding = lc_encode ).
  lv_customxml4ppt = '<xmlPPT value="This is an example of valid xml" />'. "You can add a valid xml here
  l_convout->convert(
      EXPORTING
              data  = lv_customxml4ppt
      IMPORTING
              buffer = ev_customxml4ppt
              len    = lv_len ).

ENDMETHOD.

    2. Get the PowerPoint template

              The template can be uploaded to the MIME repository and can be read from there.
METHOD get_ppt_template.
*    Exporting EV_PPT TYPE XSTRING
  DATA:
  lo_mr_api                  TYPE REF TO if_mr_api.
  lo_mr_api = cl_mime_repository_api=>get_api( ).
  lo_mr_api->get(
        EXPORTING
              i_url    = ppt_template_url          "Give the template url in MIME repository here
        IMPORTING
              e_content = ev_ppt
        EXCEPTIONS
              OTHERS    = 1
  ).

ENDMETHOD.

    3. Add Custom XML to PowerPoint template

METHOD add_customxml2ppt.
*    Importing      IV_PPT                    TYPE XSTRING
*    Importing      IV_CUSTOMXML    TYPE XSTRING
*    Exporting      EV_PPT                    TYPE XSTRING   
*    Exception      XSLT_ERROR
  DATA:
    ppt                              TYPE REF TO cl_pptx_document,
    presentationpart          TYPE REF TO cl_pptx_presentationpart,
    l_packagecontent        TYPE string,
    customxmlpartcoll      TYPE REF TO cl_openxml_partcollection,
    customxmlpart            TYPE REF TO cl_oxml_customxmlpart,
    customxmlpropspart  TYPE REF TOTO cl_oxml_customxmlpropspart,
    propertyxml                TYPE xstring,
    preguid                        TYPE string,
    guid                            TYPE string.
  TRY.
      ppt = cl_pptx_document=>load_document( iv_data = iv_ppt ).
      l_packagecontent = ppt->get_content_type( ).
* get the presentation part
      presentationpart = ppt->get_presentationpart( ).
* get collection of customXML parts
      customxmlpartcoll = presentationpart->get_customxmlparts( ).
* create a customXML part here
      customxmlpart = presentationpart->add_customxmlpart( ).
* insert xml data
      customxmlpart->feed_data( iv_customxml  ).
* add customXML properties part
      customxmlpropspart = customxmlpart->add_customxmlpropspart( ).
* create GUID string
      preguid = cl_openxml_helper=>create_guid_string( ).
* enclose with {...} brackets
      CONCATENATE '{' preguid '}' INTO guid.
* create custom XML property content
      CALL TRANSFORMATION docx_create_custompropscontent
            PARAMETERS guid = guid
            SOURCE XML iv_customxml
            RESULT XML propertyxml.
* insert propertyxml
      customxmlpropspart->feed_data( propertyxml ).
      ev_ppt = ppt->get_package_data( ).
    CATCH cx_openxml_format.
    CATCH cx_openxml_not_allowed.
    CATCH cx_openxml_not_found.
    CATCH cx_transformation_error.
      RAISE xslt_error.
  ENDTRY.

ENDMETHOD.

    4. Integrate the above steps - XML, PowerPoint template, Custom XML

METHOD get_ppt_download.
*      Exporting EV_XML_XSTRING_PPT      TYPE XSTRING
*      Exception ERROR_OCCURRED
  DATA:
              lv_customxml4ppt      TYPE xstring,
              lv_ppt_template          TYPE xstring.
  prepare_customxml(
    IMPORTING
      ev_customxml4ppt = lv_customxml4ppt
    EXCEPTIONS
      xslt_error          = 1
      OTHERS          = 2
                        ).
  IF sy-subrc = 1.
    RAISE error_occurred.
  ELSEIF sy-subrc = 2.
    RAISE error_occurred.
  ENDIF.
  get_ppt_template(
    IMPORTING
      ev_ppt          = lv_ppt_template
                  ).

  add_customxml2ppt(
    EXPORTING
      iv_ppt                = lv_ppt_template
      iv_customxml    = lv_customxml4ppt
    IMPORTING
      ev_ppt                = ev_xml_xstring_ppt
    EXCEPTIONS
      xslt_error        = 1
      OTHERS        = 2
                    ).

  IF sy-subrc <> 0.
    RAISE error_occurred.
  ENDIF.

ENDMETHOD.

 

 

 

Related Articles:

 

How to - Add Custom XML Parts to Microsoft Word using ABAP

$
0
0

Note to Moderator: Request you to kindly DM me if you find any issues with this document.

 

This document explains how to:

 

Add Custom XML Parts to Word using ABAP

 

    1. Prepare XML data

METHOD prepare_customxml.
*    Exporting  EV_CUSTOMXML4DOC  TYPE XSTRING
*    Exception  XSLT_ERROR
  CONSTANTS:  lc_encode        TYPE abap_encod VALUE 'UTF-8'.
  DATA:
        lv_customxml4doc          TYPE string,
        l_convout                          TYPE REF TO cl_abap_conv_out_ce,
        lv_len                                TYPE i.
  l_convout = cl_abap_conv_out_ce=>create( encoding = lc_encode ).
  lv_customxml4doc = '<xmlDOC value="This is an example of valid xml" />'. "You can add a valid xml here
  l_convout->convert(
      EXPORTING
              data  = lv_customxml4doc
      IMPORTING
              buffer = ev_customxml4doc
              len    = lv_len ).

ENDMETHOD.

    2. Get the Word template

              The template can be uploaded to the MIME repository and can be read from there.
METHOD get_doc_template.
*    Exporting EV_DOC TYPE XSTRING
  DATA:
  lo_mr_api                  TYPE REF TO if_mr_api.
  lo_mr_api = cl_mime_repository_api=>get_api( ).
  lo_mr_api->get(
        EXPORTING
              i_url    = doc_template_url          "Give the template url in MIME repository here
        IMPORTING
              e_content = ev_doc
        EXCEPTIONS
              OTHERS    = 1
  ).

ENDMETHOD.

    3. Add Custom XML to Word template

METHOD add_customxml2doc.
*    Importing      IV_DOC                      TYPE XSTRING
*    Importing      IV_CUSTOMXML        TYPE XSTRING
*    Exporting      EV_DOC                    TYPE XSTRING   
*    Exception      XSLT_ERROR
  DATA:
    doc                            TYPE REF TO cl_docx_document,
    documentpart            TYPE REF TO cl_docx_maindocumentpart,
    l_packagecontent        TYPE string,
    customxmlpartcoll      TYPE REF TO cl_openxml_partcollection,
    customxmlpart            TYPE REF TO cl_oxml_customxmlpart,
    customxmlpropspart  TYPE REF TOTO cl_oxml_customxmlpropspart,
    propertyxml                TYPE xstring,
    preguid                        TYPE string,
    guid                            TYPE string.
  TRY.
    doc = cl_docx_document=>load_document( iv_data = iv_doc ).
      l_packagecontent = doc->get_content_type( ).
* get the maindocument part
      documentpart = doc->get_maindocumentpart( ).
* get collection of customXML parts
      customxmlpartcoll = documentpart->get_customxmlparts( ).
* create a customXML part here
      customxmlpart = documentpart->add_customxmlpart( ).
* insert xml data
      customxmlpart->feed_data( iv_customxml  ).
* add customXML properties part
      customxmlpropspart = customxmlpart->add_customxmlpropspart( ).
* create GUID string
      preguid = cl_openxml_helper=>create_guid_string( ).
* enclose with {...} brackets
      CONCATENATE '{' preguid '}' INTO guid.
* create custom XML property content
      CALL TRANSFORMATION docx_create_custompropscontent
            PARAMETERS guid = guid
            SOURCE XML iv_customxml
            RESULT XML propertyxml.
* insert propertyxml
      customxmlpropspart->feed_data( propertyxml ).
      ev_doc = doc->get_package_data( ).
    CATCH cx_openxml_format.
    CATCH cx_openxml_not_allowed.
    CATCH cx_openxml_not_found.
    CATCH cx_transformation_error.
      RAISE xslt_error.
  ENDTRY.

ENDMETHOD.

    4. Integrate the above steps - XML, Word template, Custom XML

METHOD get_doc_download.
*      Exporting EV_XML_XSTRING_DOC      TYPE XSTRING
*      Exception ERROR_OCCURRED
  DATA:
              lv_customxml4doc      TYPE xstring,
              lv_doc_template          TYPE xstring.
  prepare_customxml(
    IMPORTING
      ev_customxml4doc = lv_customxml4doc
    EXCEPTIONS
      xslt_error          = 1
      OTHERS          = 2
                        ).
  IF sy-subrc = 1.
    RAISE error_occurred.
  ELSEIF sy-subrc = 2.
    RAISE error_occurred.
  ENDIF.
  get_doc_template(
    IMPORTING
      ev_doc          = lv_doc_template
                  ).

  add_customxml2doc(
    EXPORTING
      iv_doc                = lv_doc_template
      iv_customxml    = lv_customxml4doc
    IMPORTING
      ev_doc                = ev_xml_xstring_doc
    EXCEPTIONS
      xslt_error        = 1
      OTHERS        = 2
                    ).

  IF sy-subrc <> 0.
    RAISE error_occurred.
  ENDIF.

ENDMETHOD.

 

 

 

Related Articles:

 

How to - Add Custom XML Parts to Microsoft Excel using ABAP

$
0
0

Note to Moderator: Request you to kindly DM me if you find any issues with this document.

 

This document explains how to:

 

Add Custom XML Parts to Excel using ABAP

 

    1. Prepare XML data

METHOD prepare_customxml.
*    Exporting  EV_CUSTOMXML4XLS  TYPE XSTRING
*    Exception  XSLT_ERROR
  CONSTANTS:  lc_encode        TYPE abap_encod VALUE 'UTF-8'.
  DATA:
        lv_customxml4xls              TYPE string,
        l_convout                          TYPE REF TO cl_abap_conv_out_ce,
        lv_len                                TYPE i.
  l_convout = cl_abap_conv_out_ce=>create( encoding = lc_encode ).
  lv_customxml4xls = '<xmlXLS value="This is an example of valid xml" />'. "You can add a valid xml here
  l_convout->convert(
      EXPORTING
              data  = lv_customxml4xls
      IMPORTING
              buffer = ev_customxml4xls
              len    = lv_len ).

ENDMETHOD.

    2. Get the Excel template

              The template can be uploaded to the MIME repository and can be read from there.
METHOD get_xls_template.
*    Exporting EV_XLS TYPE XSTRING
  DATA:
  lo_mr_api                  TYPE REF TO if_mr_api.
  lo_mr_api = cl_mime_repository_api=>get_api( ).
  lo_mr_api->get(
        EXPORTING
              i_url    = xls_template_url          "Give the template url in MIME repository here
        IMPORTING
              e_content = ev_xls
        EXCEPTIONS
              OTHERS    = 1
  ).

ENDMETHOD.

    3. Add Custom XML to Excel template

METHOD add_customxml2xls.
*    Importing      IV_XLS                    TYPE XSTRING
*    Importing      IV_CUSTOMXML    TYPE XSTRING
*    Exporting      EV_XLS                    TYPE XSTRING   
*    Exception      XSLT_ERROR
  DATA:
    xls                              TYPE REF TO cl_xlsx_document,
    workbookpart            TYPE REF TO cl_xlsx_workbookpart,
    l_packagecontent        TYPE string,
    customxmlpartcoll      TYPE REF TO cl_openxml_partcollection,
    customxmlpart            TYPE REF TO cl_oxml_customxmlpart,
    customxmlpropspart  TYPE REF TOTO cl_oxml_customxmlpropspart,
    propertyxml                TYPE xstring,
    preguid                        TYPE string,
    guid                            TYPE string.
  TRY.
    xls = cl_xlsx_document=>load_document( iv_data = iv_xls ).
      l_packagecontent = xls->get_content_type( ).
* get the workbook part
      workbookpart = xls->get_workbookpart( ).
* get collection of customXML parts
      customxmlpartcoll = workbookpart->get_customxmlparts( ).
* create a customXML part here
      customxmlpart = workbookpart->add_customxmlpart( ).
* insert xml data
      customxmlpart->feed_data( iv_customxml  ).
* add customXML properties part
      customxmlpropspart = customxmlpart->add_customxmlpropspart( ).
* create GUID string
      preguid = cl_openxml_helper=>create_guid_string( ).
* enclose with {...} brackets
      CONCATENATE '{' preguid '}' INTO guid.
* create custom XML property content
      CALL TRANSFORMATION docx_create_custompropscontent
            PARAMETERS guid = guid
            SOURCE XML iv_customxml
            RESULT XML propertyxml.
* insert propertyxml
      customxmlpropspart->feed_data( propertyxml ).
      ev_xls = xls->get_package_data( ).
    CATCH cx_openxml_format.
    CATCH cx_openxml_not_allowed.
    CATCH cx_openxml_not_found.
    CATCH cx_transformation_error.
      RAISE xslt_error.
  ENDTRY.

ENDMETHOD.

    4. Integrate the above steps - XML, Excel template, Custom XML

METHOD get_xls_download.
*      Exporting EV_XML_XSTRING_XLS      TYPE XSTRING
*      Exception ERROR_OCCURRED
  DATA:
              lv_customxml4xls      TYPE xstring,
              lv_xls_template          TYPE xstring.
  prepare_customxml(
    IMPORTING
      ev_customxml4xls = lv_customxml4xls
    EXCEPTIONS
      xslt_error          = 1
      OTHERS          = 2
                        ).
  IF sy-subrc = 1.
    RAISE error_occurred.
  ELSEIF sy-subrc = 2.
    RAISE error_occurred.
  ENDIF.
  get_xls_template(
    IMPORTING
      ev_xls          = lv_xls_template
                  ).

  add_customxml2xls(
    EXPORTING
      iv_xls                = lv_xls_template
      iv_customxml    = lv_customxml4xls
    IMPORTING
      ev_xls                = ev_xml_xstring_xls
    EXCEPTIONS
      xslt_error        = 1
      OTHERS        = 2
                    ).

  IF sy-subrc <> 0.
    RAISE error_occurred.
  ENDIF.

ENDMETHOD.

 

 

 

Related Articles:

 

Viewing all 935 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>