Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos


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=ht...!

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=http...!


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=55...!
*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:


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>

7 Comments