Dynamic Code Processor

Dynamic Code Processor

We are going to see Dynamic Code Processor. Make every moment count, and you won’t ever work one more day in your life. I firmly put stock in this proverb and consistently endeavor to find fascinating stuff at my work place. Indeed, I work in the blue screen of SAP entire day and I can gladly say it isn’t wearing in any way out. However many grumble, yet I love what I do. Did you realize we can furtively talk utilizing SAP ABAP? No, no.. you don’t have to fabricate another visiting instrument. There is a standard capability module ‘ TH_POPUP ‘ which you can utilize straight out of the container. Actually take a look at my other article ABAP – Ability to Kill to get familiar with the SAP ABAP visit.

The point I’m attempting to make is, there are tons and lots of fascinating exercises we can act in SAP. Try not to say, you are excessively occupied with your undertaking work and you can’t investigate. I would recommend, cut down a little ways from your Facebook perusing, 1 hour from going through the phony news and pointless messages in Whatsapp and a short ways from Instagram. You presently have 2 hours of time to investigate a novel, new thing in SAP.

Check how Stephan made a Straightforward Mini-computer in SAP ABAP.

With a similar way of thinking to take a stab at something new and investigate more in SAP, we will discover some new information and different in ABAP programming today.

Scenario: Dynamic Code Processor

Today morning, one of the practical specialists came to me and said that our business group is ending up being insane step by step. (well… we ABAPer expresses exactly the same things for utilitarian advisors as well).. shhhhh ?

After his articulation, he uncovered the necessity of business group..

Problem statement: Dynamic Code Processor

There ought to be a text enclose the determination screen, in which client can put any number juggling tasks, contingent proclamations, string activities and so forth and after its execution the outcome ought to get printed. So, they needed to think of some ABAP Orders (open SQL) in the text box and it ought to give the ideal result.

Resolution Discussion:

Subsequent to hearing this, we both giggled on the business necessity and their absurdity. We thought it was a joke. However, the business colleagues were serious. They maintained that us should foster something and give the arrangement.

He trusted the evidence speak for itself that day and left me contemplating. I like insane thoughts. However, not so insane.

Presently the next move was up to me. How to give an answer which will be dynamic and versatile? They need to compose any questions in the text box and anticipate a result.

After all Research and development, I reduced the beneath arrangement which treats the choice text box as a smaller than usual ABAP supervisor. I felt like a genious creator after this arrangement. Indeed, I want to pat my back for this creative arrangement.

Here client can put any ABAP inquiry with any math tasks, IF conditions, Select questions, Circles, Read articulations and so forth. What’s more, the magnificence is, it gets executed and gives the outcome in yield. Be that as it may, the sentence structure must be right when you put the question in the message box.

Energized right??… . We should look at it.

Resolution: Dynamic Code Processor

There are numerous routes in ABAP to do Dynamic Code Processor; like this field-images or dynamic inside table creation and so forth.

From this rundown, we will utilize the Subroutine Pool rationale.

We should see, what’s the subroutine pool is about..

Subroutine Pool: Dynamic Code Processor

It contains assortments of subroutines that can be called remotely from different projects.

Syntax of subroutine pool:

GENERATE SUBROUTINE POOL <itab> NAME <prog> [<options>].

Details:

The above assertion creates a transitory subroutine pool in the principal memory region of the running system.

<itab>: The code of the subroutine pool is written in internal table which is passed under <itab>.

<prog>: The generated subroutine pool is stored internally under program name <prog>.

<options>: Below options are there to pass our subroutine:

Options                                                     Description
MESSAGE <mess>  In the case of a syntax error, field <mess> contains the error message. 
INCLUDE <incl>  In the case of a syntax error, field <incl> contains the name of the include program in which the error possibly occurred. 
LINE <line>  In the case of a syntax error, field <line> contains the number of the wrong line. 
WORD <word>  In the case of a syntax error, field <word> contains the wrong word. 
OFFSET <offs>  In the case of a syntax error, field <offs> contains the offset of the wrong word in the line. 
TRACE-FILE <trac>  If you use this option, you switch on the trace mode and field <trac> contains the trace output.

So, the syntax which will be there in our program is:

GENERATE SUBROUTINE POOL src
 NAME prog_name MESSAGE msg LINE line WORD word OFFSET off.

Let’s dive deep..

Program explanation:

We need to create a mother program which will take input query from the User and displays its output.

As we will make a transitory program through Produce SUBROUTINE choice, we want to compose the name and statements for that brief program:

In above screen capture (red box), I have given the name as ZSB_SUBPOOL to my brief program and put away all announcement in SRC with is of table kind string. You understand a big motivator for SB in the second and third person of the program name?

Kindly note: You can give any name without Z or Y. Have a go at giving the name as SUBPOOL and it will in any case work.

Then, make a subroutine named as ‘DYN1’ whose PERFORM will be called after Produce SUBROUTINE explanation likewise passing the info boundary string P_FORM to SRC there.

Then, at that point, we are adding boundary p_form to src.

Toward the end composing the Outcome on the screen with Compose explanation.

And afterward end the subroutine with ENDFORM.

FORM DYN1 USING p_form TYPE string.
 APPEND p_form TO src.
 WRITE / RESULT.
ENDFORM.

The last step is to call this brief program by means of Produce SUBROUTINE POOL technique.

This is an extremely strong order. It does the grammar check and assuming that all is great, it makes the brief program in memory and executes it.

When the Produce Subroutine Pool step is finished and there is no mistake, it will call the program with rationale written in PERFORM ‘DYN1’.

In the event that you input the above text in the determination screen and troubleshoot the code, you will get to see the entire code of brief program as underneath:

Isn’t it cool?

Code Snippet: 

REPORT zdynamic_query_sb.
 
 TYPES:
   source_line(256) TYPE c.
 
 DATA:
   src           TYPE TABLE OF source_line,
   prog_name(30) TYPE c,
   msg(120)      TYPE c,
   line(10)      TYPE c,
   word(10)      TYPE c,
   off(3)        TYPE c.
 
 APPEND 'PROGRAM SUBPOOL.' TO src.
 APPEND 'DATA RESULT TYPE string.' TO src.
 APPEND 'DATA: a TYPE DECFLOAT34 VALUE ''5.0''.' TO src.
 APPEND 'DATA: b TYPE DECFLOAT34 VALUE ''4.5''.' TO src.
 
 PARAMETERS p_form TYPE string.
 
 APPEND 'FORM DYN1 USING p_form TYPE string.' TO src.
 APPEND p_form TO src.
 APPEND ' WRITE / RESULT.' TO src.
 APPEND 'ENDFORM.' TO src.
 
 GENERATE SUBROUTINE POOL src
     NAME prog_name MESSAGE msg LINE line WORD word OFFSET off. 
 IF sy-subrc <> 0.
   WRITE: / 'Error during generation in line', line,
         / msg, / 'Word:', word, 'at offset', off.
 ELSE.
   PERFORM dyn1 IN PROGRAM (prog_name) USING p_form.
 ENDIF.

Time to Test  

Execute the program and we will get underneath choice screen: 

Embed any example ABAP question to come by its outcome.

Kindly Note: RESULT ought to continuously be the variable name for our case which you need to print.

After execution, we will obtain consequence of above inquiry as beneath:

APPEND 'DATA: a TYPE DECFLOAT34 VALUE ''5.0''.' TO src.
APPEND 'DATA: b TYPE DECFLOAT34 VALUE ''4.5''.' TO src.

Additionally, you can get to the worldwide variable which you characterized in the memory program. Here we characterized An and B factors in the program. We can give them on determination screen text field and can get to them in memory program too. 

The worth of variable An is ‘5.0’ though the worth of B is ‘4.5’ so the Consequence of above question will be ‘0.5’. 

Some random Quiz questions: 

  1. What would be the output of this text input?
    RESULT = ‘HELLO Elearning’. in the text field?
  2. Do you this this input will work?
    data(ls_1) = ‘Swapna’. data(ls_2) = ‘Dream’. Concatenate ls_1 ls_2 into RESULT SEPARATED BY SPACE.
  3. What would be the output for this input text?
    data(ln_1) = 10. data(ln_2) = 5. RESULT = ln_1 * ln_2

Solution

Straight String Operation.
Concatenate works fine. 
errrr!!!! You missed the period at the end. Syntax error. 

In this program you can compose any ABAP question like from number-crunching tasks, contingent activities or even select inquiry as well. It Enchantment. Isn’t that so?

So the thing would you say you are hanging tight for? Duplicate the program and partake in this smaller than normal ABAP question processor which you recently made.?

SAP is enjoyable. We simply have to figure out how to have a good time!!

 

YOU MAY BE INTERESTED IN

ABAP on SAP HANA. Part VI. New Age Open SQL ABAP 740

Bridging the Gap: Integrating ABAP with Other Cloud Services

A to Z of OLE Excel in ABAP 7.4

WhatsApp WhatsApp us