Saturday 4 December 2021

Hassle-free way to frequently change long string data in database without file upload

Problem Statement:

You do not have a user interface or an application ready to save the data in ABAP dictionary object, and you need to upload the data into a database table.

The above does not seem to be a problem because you can generate Table Maintenance Generator.

Wait wait wait! The problem is yet to come.

The table has a string field and TMG creation gives this error “Data type STRING is not supported in field”.

Seems a problem now, but a smaller one? 

Yes?

Yes, it seems small until we do not know that our requirement is to store a string of length greater than 255 characters.

You might be wondering that it’s so simple to create an ABAP report that calls a standard function module to upload the data.

Yes? 

Then hold your horses, the real problem is here.

Problem Number 1: Most of the Function Modules have the restriction of uploading up to 255 characters only.

Oh No!

After a lot of huff and puff you were able to find an appropriate function module GUI_UPLOAD.

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
GUI_UPLOAD FM

Feeling better?

Sorry but we have another problem to disappoint you.

Problem Number 2: Imagine you have data in a format like JSON which you need to change frequently for testing purpose and upload this data in string format in the database table. So, you will

◉ create a report where you
    ◉ need to read the JSON file
    ◉ convert the data as per your requirement.
    ◉ integrate GUI_UPLOAD function
◉ make required changes to the JSON file
◉ execute the ABAP report
◉ upload the file

Next time, when you need a change, you will repeat the complete process.

Imagine, when this change is required multiple times in a day by multiple users. How much time it would consume?

You can save that time and make a coffee for yourself.

Can you think of a solution where just making the change and a click serves the purpose?

If yes, then post the solutions coming in your mind in comment section.

Solution:


Create an API to save data in the database table and call that API via any REST client like postman.

Woohoo!

This would

◉ solve the limitation of 255 character &
◉ It would not require uploading the file every time a change is required

Step by step guide to set this up in Postman API platform:


Step 1: Create a post request

Create a new request and change its type to POST

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
Create a POST type request

Step 2: Enter the URL of the API to save data

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
Enter the URL

Step 3: Go to “Params” and maintain the required parameters like sap-client

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
Maintain Params

Step 4: Go to “Authorisation” tab and maintain the credentials

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
Maintain Credentials

Step 5: Go to “Headers” tab and maintain information given

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
Headers Info

Step 6: Go to body and maintain the data to be saved in table

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
Body Info

Here, the template needs to have the string that has length more than 255.

Now, let’s see where we can maintain that data.

Step 7: Go to pre-request Script and maintain the data

SAP ABAP Exam Prep, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Guides, SAP ABAP Career, SAP ABAP Certification
Pre-request Script

The “query” variable can hold any length of JSON object and then following statement will

convert the object to string and this variable gets assigned to the table field as per the config done in step 6.

pm.collectionVariables.set('query', JSON.stringify(JSON.stringify(query)));

Source: sap.com

No comments:

Post a Comment