Skip to Content

Thanks to SAP for releasing XI 3.0 Support Pack 12 which has provided us with the variable substitution option in the File Adapter. The main feature that has been added in the case of receiver file adapter is that a file which is getting written can be named with a payload value that is being sent out. This scenario explains how to generate dynamic files using the variable substitution option which came up with the new Support Pack. For this the following scenario is considered.

Consider a scenario where IDOCs are send as files to a legacy system. Here the tricky situation is that for each and every interface files depending on their extension, there will be a different number range associated with the file name and it should be reset after reaching the end number for the number range.

The following step-by-step illustration will show how this can be implemented using the message mapping feature in SAP XI 3.0 SP12.
h3. Prerequisites

Assuming that the following have been done and configured.

1.A value table has been created in the ABAP stack of the WAS in which XI is running and the entries as the file types, which will be written into the files are maintained.

2.Create a number range object in SNRO transaction in the same ABAP stack which will be having the sub objects as the file types maintained in the value table with their number ranges maintained.

h3. Step1

Creation of the RFC function module in the ABAP stack through transaction SE37 with the Remote-Enabled Module option checked and Start Immediately option chosen in the attributes of this FM.
!https://weblogs.sdn.sap.com/weblogs/images/29453/RFC1-mod.jpeg|height=217|alt=image|width=401|src=https://weblogs.sdn.sap.com/weblogs/images/29453/RFC1-mod.jpeg|border=0!

This function module will have an import parameter FILETYPE which is of type CHAR10 and it will have a export parameter FILENAME which is of type CHAR10 and will have the file name with the dynamic name concatenated.

*Source Code for the RFC Function Module: *

*”—-


“Local Interface:

*”  IMPORTING

*”     VALUE(FILETYPE) TYPE  CHAR10

*”  EXPORTING

*”     VALUE(FILENAME) TYPE  CHAR10

*”—-


DATA: length TYPE i,

      temp_lastno_ch(10),

      temp_subobj(3),

      temp_fname(10).

CONSTANTS: c_nr_range_nr(1) VALUE ‘1’,

           c_nr_object(6)   VALUE ‘ZTEST1’.

IF NOT filetype IS INITIAL.

   temp_subobj = filetype+0(3).

   CALL FUNCTION ‘NUMBER_GET_NEXT’

   EXPORTING

        nr_range_nr                   = ‘1’

        object                        = ‘ZTEST1’

  •       QUANTITY                      = ‘1’

        subobject                     = temp_subobj

  •       TOYEAR                        = ‘0000’

  •       IGNORE_BUFFER                 = ‘ ‘

   IMPORTING

        number                        = temp_lastno_ch

  •       QUANTITY                      =

  •       RETURNCODE                    =

   EXCEPTIONS

        interval_not_found            = 1

        number_range_not_intern       = 2

        object_not_found              = 3

        quantity_is_0                 = 4

        quantity_is_not_1             = 5

        interval_overflow             = 6

        buffer_overflow               = 7

        OTHERS                        = 8.

   IF sy-subrc EQ 0.

      SHIFT temp_lastno_ch LEFT DELETING LEADING ‘0’.

      length = STRLEN( temp_lastno_ch ).

      CLEAR: temp_fname(10).

      CASE length.

        WHEN ‘1’.

         CONCATENATE ‘PN00000’ temp_lastno_ch

         INTO temp_fname.

         MOVE temp_fname TO filename.

WHEN ‘2’.
CONCATENATE ‘PN0000’ temp_lastno_ch
INTO temp_fname.
MOVE temp_fname TO filename.
WHEN ‘3’.
CONCATENATE ‘PN000’ temp_lastno_ch
INTO temp_fname.
MOVE temp_fname TO filename.

        WHEN ‘4’.

         CONCATENATE ‘PN00’ temp_lastno_ch

         INTO temp_fname.

         MOVE temp_fname TO filename.

        WHEN ‘5’.

         CONCATENATE ‘PN0’ temp_lastno_ch

         INTO temp_fname.

         MOVE temp_fname TO filename.

        WHEN ‘6’.

         CONCATENATE ‘PN’ temp_lastno_ch

         INTO temp_fname.

         MOVE temp_fname TO filename.

      ENDCASE.

    ENDIF.

  ELSE.

  •   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  •           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

ENDFUNCTION.

h3. Step2

Integration Repository

a)Create a data type, message type and message interfaces for inbound and outbound process under the interface objects.

b)Create the message mapping

!https://weblogs.sdn.sap.com/weblogs/images/29453/MM_mod.jpeg|height=355|alt=image|width=548|src=https://weblogs.sdn.sap.com/weblogs/images/29453/MM_mod.jpeg|border=0!

c)Create a user-defined function LOOKUP as follows with the import parameters.

!https://weblogs.sdn.sap.com/weblogs/images/29453/UserFunction_mod.jpeg|height=321|alt=image|width=550|src=https://weblogs.sdn.sap.com/weblogs/images/29453/UserFunction_mod.jpeg|border=0!
*Source code for the user-defined function: *

Go to the test tab of the message mapping and on testing of this message mapping the result will be as follows: image

d)Create an interface mapping using this message mapping and activate all the integration directory objects.

h3. Step3

Integration Directory

As part of the outbound adapter configuration, 1) As the file name schema provide the value as %Var1%.xml 2) click on the option for Variable Substitution and insert a line. Here put in the variable as “Var1” and in the reference column user the value payload:mtsp,1,Name,1. This will make the outbound file adapter to understand payload value from the Name tag has to be substituted as the file name.

Result The file adapter will now take the value in the tag as will substitute as the the output file name which will be generated. As per the screen shot will be PN000003.xml </p>

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

    1. Jayakrishnan Nair Post author
      Hi Sujan,
          Thank you…We were also struck up with the scenario mentioned in this weblog and SP12 helped to resolve the issue with variable susbtitution…

          Cheers & have a nice time ahead with XI…

      Cheers
      Jayakrishnan

      (0) 
  1. Angel Cueto
    Hi,
    I have a problem, the check box “enable variable” and the “variable table” do not appear for me in the step 3.
    We have SAP XI SP12, is a new instalation.
    If someone know why this configuration do not appear for me, I will apreciate the help.
    Thanks
    (0) 
    1. Jayakrishnan Nair Post author
      Hi Angel,
         Pls do check whether the SP12 implementation was done in a successful manner.

      You need as well XI CONTENT SAP_BASIS 6.40.
      Upload this directly to your Integration Builder in case you haven’t done so.

      Apply the note 850694 in case you are not able to use the variable substitution path for message types with ‘_’ characters.

      Cheers
      Jayakrishnan

      (0) 
  2. Jesse Wolff
    Great job.

    I just wanted to add that as of SP13 Mapping Lookups can be used to make the RFC call instead of a straight JCO call.

    http://help.sap.com/saphelp_nw04/helpdata/en/cf/406642ea59c753e10000000a1550b0/frameset.htm

    The issue with the JCO call is that you need to specify the login parameters and that will differ between different environments (DEV, TST, PRD). It’s possible to do this in a dynamic way but it’s much more complex than using Mapping Lookups.

    Thanks
    Jesse

    (0) 
  3. Smitha Madhavan
    Thank you for this post.

    When i tried this, i came to know that the file name should be given in lowercase. Variable name should be given as “var1” and file name schema value would be “%var1%.xml”. It is shown correctly in the screenshot, but not in the write up.

    Thanks and Regards,
    Smitha

    (0) 

Leave a Reply