Skip to Content
Technical Articles
Author's profile photo Sandra Rossi

API to Read and Write function module Test Data (SE37)

I propose here an API which permits to create test data in transaction code SE37 very easily, and also execute and load them. There are 3 demo programs: one to demonstrate the API, one to export test data to an XML file and another one to restore.

The API is in my github repository (https://github.com/sandraros/FM-Test-Data). Feedback welcome! You may create Issues for bugs, requests or propose fixes (Pull Requests) directly at github. Note that it requires 3 little other APIs to be installed (see below Installation steps).

Note that the API doesn’t allow to do things which are not permitted by SE37 like updating existing test data, you can only load and create (copy), and delete.

Table of Contents:

  1. Example scenarios
    1. Snippet to create test data for DATE_GET_WEEK
  2. Installation steps

(Table of contents generated by https://sandraros.github.io/BuildSAPBlogPostTOC.html)

Example scenarios

The class ZCL_FM_TEST_DATA has very simple methods to be used depending on the scenario you want to implement. Here are a few of them.

If you want to create a new Test Data:

  • Only with input data (see Example code below)
    • Create
    • Set_input_parameters
    • Save
  • With both input and output data to do regression tests (standard SE37 feature)
    • Create
    • Set_input_parameters
    • Execute
    • Save

If you want to execute an existing test data:

  • Load
  • Execute

If you want to backup and restore some Test Data, use the demo programs Z_FM_TEST_DATA_DEMO_EXPORT and Z_FM_TEST_DATA_DEMO_IMPORT:

  • For the export:
    • Load
    • Serialize (to an XML string)
    • Write the XML string to wherever you want
  • For the import:
    • Load the XML string from wherever you want
    • Deserialize
    • Save

Snippet to create test data for DATE_GET_WEEK

REPORT zdemo.

START-OF-SELECTION.
  DATA(test_data) = zcl_fm_test_data=>create( fm_name = 'DATE_GET_WEEK' title = 'demo' ).
  test_data->set_input_parameters( VALUE #( ( name = 'DATE' value = REF #( sy-datum ) ) ) ).
  test_data->save( ).
  COMMIT WORK.
  MESSAGE |Test data { condense( test_data->id ) } created| type 'I'.

NB: the method SET_INPUT_PARAMETERS works the same way as calling a function module with parameters passed in a dynamic way. For more information, see the ABAP documentation: CALL FUNCTION, parameter_tables.

Installation steps

First install abapGit. There are all the instructions to install abapGit there.

For installing the API of FM Test Data, you must repeat the following steps for each one of the 4 required Git repositories:

  • Start ZABAPGIT
  • Click the button “New Online”
  • Enter the URL of the Git repository, for instance https://github.com/sandraros/S-RTTI for the first repository
  • Enter any package name, one dedicated to each Git repository, for instance $SRTTI for the first repository
  • Keep the default values of all the other fields
  • Click the button “Create Online Repo”
  • Click the button “Pull” (that will create and activate the packages, classes and programs)

Repeat the steps above for the 4 repositories:

Now you can run and play with the program Z_FM_TEST_DATA_DEMO, and create your own programs.

 

Assigned Tags

      13 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Andrea Borgia
      Andrea Borgia

      Wow, I just got a chance to try out this project: I must say I'm impressed by the quality of your code!

      Feel free to ping me if you need tests, perhaps on older systems.

      Author's profile photo Sandra Rossi
      Sandra Rossi
      Blog Post Author

      Thank you for your kind words! I must say that I didn't use it yet for real scenarios. Maybe in the next few days because in my project we will switch S/4HANA to a brand new installation.

      I don't really know what to do with these 4 libraries, if you want to use them, issues and PRs are welcome! 🙂

       

      Author's profile photo priya ramani
      priya ramani

      Hi @Sandra Rossi

      Its very awesome.

       

      But can you please give some more steps for people like me who are very new to GITHUB and interested to do the above project.

      i was unable to install ABAPGITHUB , i'm stuck at very first step.

       

      Thanks ,

      Priya.

      Author's profile photo Sandra Rossi
      Sandra Rossi
      Blog Post Author

      Hello, I have updated the post, could you tell me whether it's more clear, or if you have issues while installing abapGit?

      Author's profile photo priya ramani
      priya ramani

      Hi Sandra Rossi,

       

      Thanks for the updating the document , it is clear now.

      One doubt should we install standalone version or developer version ?

      my concern is can anyone can find out what we are doing , since it is my work profile SAP system ?

      Can you please confirm.

       

      Thanks,

      Priya.

      Author's profile photo Sandra Rossi
      Sandra Rossi
      Blog Post Author

      If you don't want to install many many abapGit objects, you may use the abapGit standalone version (one huge program, nothing else). There's no need to install the developer version if you don't want to keep abapGit up-to-date.

      Only people who have access to your system can see what you are doing. abapGit doesn't look into your system. When you pull repositories via abapGit, it just installs workbench objects.

      Author's profile photo priya ramani
      priya ramani

      Hi Sandra Rossi ,

      Thanks for the information.

       

      I tried to create , given url as 'https://github.com/sandraros/exportimport_pr' as mentioned in the above step 3 :

      • Enter the URL of the Git repository, for instance https://github.com/sandraros/S-RTTI for the first repository

      But it is asking username and password in a popup with some note as given below:

      Note GitHub requires using personal tokens (since 8/2021)

       

      Can you please help in the above issue.

       

      Thanks,

      Priya.

      Author's profile photo Sandra Rossi
      Sandra Rossi
      Blog Post Author

      I'm surprised that Github asks for a PAT for just pulling a repository via abapGit (you just need one to push ABAP code to Github repository). After "new online", you enter the URL, package and click "Create online repo" and you have the error? Or after "pull"? Could you share a screenshot?

      Author's profile photo Sandra Rossi
      Sandra Rossi
      Blog Post Author

      I think I understand what's going on. Your company has probably a proxy to access internet. I guess the PAT message (personal access token) is just for information in case you want to push/write to Github repositories. Try entering your company user/password.

      Author's profile photo Jayanta Choudhuri
      Jayanta Choudhuri

      Hi Sandra

      Sorry to bother you as wiki below last updated in 2019 but no provision to comment

      I found this interesting

      https://wiki.scn.sap.com/wiki/display/TechTSG/ABAP+program+to+perform+environment+analysis

      But the Include does not compile in my dev edition ABAP1909
      The data type of the component "SRS_ID" of "LS_DD03P" is not compatible with the data type of "SRS_ID" at line 879

      If not supported I will delete this "misplaced" comment.

      ALT+ENTER Properties gives a lot of info
      Does Environment Analysis  more wrt "used and required objects"

      Regards
      Jayanta@Kolkata

      Author's profile photo Sandra Rossi
      Sandra Rossi
      Blog Post Author

      Maybe you can try this more recent Github alternative and see whether it works. You may create a Github issue if you have any question.

      Author's profile photo NIkhil Gupta
      NIkhil Gupta

      Hello Sandra,

       

      We have a requirement where we want to reprocess the data coming from third party , using the same FM, since the data is in complex structure and format we can't save it in table. I cam across your blog and thought if we can save the data as test data for the FM and while reprocessing we use your API to retreive the data and process it.

      My question are.

      1. Is it good to use this aprroach to have a reprocess utility to have test data directory as data storage?
      2. How much test variants can we store in test directory?

       

      Author's profile photo Sandra Rossi
      Sandra Rossi
      Blog Post Author

      As you could see, standard "SE37 Test" is very limited and doesn't work for complex structures so you should better create your own test tool.

      Regards.