SAP & Oracle partner and support companies

Loading

01
Quality Service
Sed perspe unde omnis natus sit voluptatem acc doloremue.
02
Expert Team
Sed perspe unde omnis natus sit voluptatem acc doloremue.
03
Excellent Support
Sed perspe unde omnis natus sit voluptatem acc doloremue.
04
Management
Sed perspe unde omnis natus sit voluptatem acc doloremue.
Advance ProtectAdvance ProtectAdvance Protect

Protecting your privacy Is
Our Priority

Amet consectur adipiscing elit sed eiusmod ex tempor incididunt labore dolore magna aliquaenim ad minim veniam.

What We’re OfferingWhat We’re OfferingWhat We’re Offering

Dealing in all Professional IT
Services

There are many variations of passages of available but majority have suffered alteration in some form, by humou or randomised words which don't look even slightly believable.

What’s HappeningWhat’s HappeningWhat’s Happening

Latest News & Articles from the
Posts

Amet consectur adipiscing elit sed eiusmod ex tempor incididunt labore dolore magna aliquaenim ad minim veniam.

SAP

How to SPLIT Data in FOR LOOP Using Modern ABAP Syntax?

Before showing How to SPLIT Data in FOR LOOP Using Modern ABAP Syntax? SAP ABAP Designers are know all about Circle — ENDLOOP sentence structure. FOR Circle is moderately new to ABAPers; however, other programming language use it generally. Each engineer has seen this linguistic structure in some or other programming language: for (i=1; i<=3; i++). How could ABAP remain behind?

Whatever the case, previous habits are still present. It is difficult for the slow engineers who were accustomed to standard ABAP programming to use the new punctuation. Today’s article will look at one need that we can definitely meet with the old ABAP, but the new punctuation calls for some help.

The question we asked in our SAP Specialized Wire Gathering and How to SPLIT Data in FOR LOOP Using Modern ABAP Syntax is the result of this post once more. Wesley Massini, one of our real, vibrant, and helpful people, had a program in which he was reading data from a document of a set length. It went perfectly and without any problems. In any case, the document information is no longer fixed once the company decided to separate the content using the highlight “_” later on. At the delimiter highlight, they must separate the data into portions. This delimiter can be anything, such as a pipe (|), tilds (~), or comma (,).

You can also read for:- Transport ABAP Report Variants into a Work Bench Request

Sounds a simple necessity right? Be that as it may, could you at any point do utilizing the new ABAP Sentence structure?

Existing Code for Fixed Length Data

The data in the file would look like this:

It is a document with heterogeneous information. The information in the primary column and second line are unique. For instance, the initial two fields (yellow and blue) in both the columns are Plant and Material. Yet, the third field in red is Seller is first column and keeping in mind that it is a marker in second line. Comparatively fourth field in green is a custom sort in first column and some classification in second line. The thought is, every one of the information columns in the document for type initially ought to go to one inner table and all lines like that of second sort ought to go into another interior table.

We involved SWITCH articulation in new language structure and isolated the columns in view of the length of the information in the document (which is fixed). Column type one has 26 characters while line type two has 18 characters. Likewise, we don’t have to show the augmentation .txt.

As creator and ABAPer Paul Solid says, Compact discs is ABAP in Steriods. We say, not just Compact discs, the new ABAP itself seems to be really dynamic ABAP.

Check the above screen capture. We have In-line information statement, utilization of Significant worth, FOR Circle in inside table, SWITCH and #. Do a F4 on every one of these catchphrases and attempt to figure out the idea.

For our case, we have know the Sort, consequently they come after the Worth administrator. Additionally after SWITCH there is #. The table sorts are announced like underneath.

In order to display the output, we can write the below syntax.

Output

How to Handle Blank Rows?

We are don’t know, how to keep away from the clear lines in both the tables utilizing the cutting edge punctuation. We utilized an Erase proclamation expressly after the information was populated in the inward tables.

Assuming you know how to eliminate the clear lines in the FOR Circle with SWITCH, kindly give the arrangement in the remarks segment. We will refresh this article with your answer.

* Delete Blank Lines
DELETE it_vm_data_tab WHERE werks IS INITIAL.
DELETE it_pm_data_tab WHERE werks IS INITIAL.

New Requirement

Prior our document was fixed length. With the business change, we began getting document with a delimiter highlight ““. In this way, we didn’t have to stress over the length of each fields. Once more, be that as it may, we battled to sort out the most ideal way to Part at “” utilizing new ABAP.

Solution 1

After some examination and with our new information, we accomplished the usefulness utilizing STRLEN, SUBSTRING_BEFORE, SUBSTRING_AFTER , sub, occ string capabilities alongside the Worth and FOR Circle and COND watchwords.

Note: The catchphrase occ is for Event. You could see a negative number for occ = – 1. In the event that occ is positive worth, the events are counted from the left while in the event that occ is a negative number, it is counted from the right side.

Correspondingly check the watchword sub. It is for Substring. Sub searches for the characters in the string.

DATA  result TYPE string.
result = substring( val = 'ABCDEFGH' off = 2 len = 2 ). 
result = substring_from( val = 'ABCDEFGH' sub = 'CD' ).
result = substring_after( val = 'ABCDEFGH' sub = 'CD' ).
result = substring_before( val = 'ABCDEFGH' sub = 'CD' ).
result = substring_to( val = 'ABCDEFGH' sub = 'CD' ).

The above bit is from SAP Help to show the utilization of SUB and different SUBSTRING capabilities. The result for each outcome is “Disc”, “CDEFGH”, “EFGH”, “Stomach muscle”, and “ABCD” in a similar request.

The above code likewise gave a clear line and we had to unequivocally utilize the Erase explanation. Likewise, we had COND in the grammar which could be stayed away from. We accomplished the business necessity, yet we were all the while contemplating whether there is a superior method for accomplishing it. Without the Erase articulation and COND. Also, prepare to be blown away. Stephan gave a faultless arrangement once more!!

Solution 2 from Stephan

Stephan prescribed to place an identifier in the start of the information line for the document. For our case, it is VM and PM. Additionally, with his new arrangement rationale there is compelling reason need to utilize COND.

Actually take a look at the arrangement above. He has utilized WHERE condition in the FOR Circle. There is no requirement for WHEN and afterward. Additionally, the STRLEN check of each column is forestalled alongside COND #.

Code Snippet

* Types Declaration
TYPES:
  BEGIN OF ty_vm_file,
    werks TYPE werks_d,
    matnr TYPE matnr,
    lifnr TYPE lifnr,
    ztype TYPE char1,
  END OF ty_vm_file,

  BEGIN OF ty_pm_file,
    werks TYPE werks_d,
    matnr TYPE matnr,
    htype TYPE char1,
    zcagn TYPE char2,
  END OF ty_pm_file,

  BEGIN OF ty_filename,
    filename TYPE text1024,
  END OF ty_filename,

* Table Type declaration
  tt_vm_tab       TYPE TABLE OF ty_vm_file WITH EMPTY KEY,
  tt_pm_tab       TYPE TABLE OF ty_pm_file WITH EMPTY KEY,
  tt_filename_tab TYPE TABLE OF ty_filename WITH EMPTY KEY.

* My recommendation is to put an identifier at the beginning of the filename like in this sample.
* With this logic there is no need for usage of COND like in the first sample.
DATA(it_fillename_data_tab) = VALUE tt_filename_tab( ( filename = 'VM_CA02_0074203_0000102207_H.txt' )
                                 ( filename = 'PM_CA02_0074203_C_HA.txt' ) ).

DATA(it_vm_data_tab) = VALUE tt_vm_tab( FOR ls_filename IN it_fillename_data_tab
                            WHERE ( filename(3) EQ 'VM_' )
                            ( werks = substring_after( val = substring_before( val = ls_filename-filename sub = '_' occ = 2 ) sub = '_' occ = 1 )
                              matnr = substring_after( val = substring_before( val = ls_filename-filename sub = '_' occ = 3 ) sub = '_' occ = 2 )
                              lifnr = substring_after( val = substring_before( val = ls_filename-filename sub = '_' occ = 4 ) sub = '_' occ = 3 )
                              ztype = substring_after( val = substring_before( val = ls_filename-filename sub = '.' occ = -1 ) sub = '_' occ = -1 )
                                               ) ).

DATA(it_pm_data_tab) = VALUE tt_pm_tab( FOR ls_filename IN it_fillename_data_tab
                       WHERE ( filename(3) EQ 'PM_' )
                               ( werks = substring_after( val = substring_before( val = ls_filename-filename sub = '_' occ = 2 ) sub = '_' occ = 1 )
                                 matnr = substring_after( val = substring_before( val = ls_filename-filename sub = '_' occ = 3 ) sub = '_' occ = 2 )
                                 htype = substring_after( val = substring_before( val = ls_filename-filename sub = '_' occ = 4 ) sub = '_' occ = 3 )
                                 zcagn = substring_after( val = substring_before( val = ls_filename-filename sub = '.' occ = -1 ) sub = '_' occ = -1 )
                                                                          ) ).
* Add both table data for display
cl_demo_output=>write_data( it_vm_data_tab ).
cl_demo_output=>write_data( it_pm_data_tab ).
** Show the output
cl_demo_output=>display( ).

YOU MAY BE INTERESTED IN

Tutorials on SAP ABAP

The World of ABAP Consultants: Unlocking the Power of SAP

Cracking the Code: Your Earning Potential as a SAP ABAP Developer with 5 Years of Experience

SAP

Calculator in SAP using New ABAP Syntax

SAP Google Maps integration We are going to Calculator in SAP using New ABAP Syntax. SAP HANA is Hot. Fiori/UI5 is Cool. OData is Captivating. Yet, in every one of these tomfoolery, fundamental ABAP is as yet flourishing. This article is an illustration of the fundamental ABCs of ABAP which we really want till ABAP doesn’t get wiped out (which won’t ever occur) later on SAP World. Darwin’s law of Advancement holds great to ABAPers also. ABAPers need to advance and get new deceives of the game in their kitty, to remain ahead in the opposition. In this article, I have attempted to show case a portion of the New Language structures of ABAP, which makes programming more straightforward and diminishes the code impressions. Calculator in SAP using New ABAP Syntax.

Calculator in SAP using New ABAP Syntax.

The setting behind this article: Calculator in SAP using New ABAP Syntax!

You can also read for:- Do all ABAPers know Fixed Point Arithmetic?

Question: The outcome ought to be imprinted in Outcome box rather than the Info text. For instance, for Information ‘2+3’ I want the Outcome ‘5’ to be imprinted in outcome box. What I have done is, doled out the Info field ‘IN’ to Result field ‘RES’.

Reply from @Anask (in few seconds or less. That the excellence of this gathering):
It regards the variable as string and simply duplicates content of one field to another. You want to part at SIGN and get information into 2 separate fields and afterward do the administrator activity. Simply utilize Split and afterward figure it out activity. Use CASE articulation and split in light of the sign it contains.

Sample Code:

IF input CS "+".
lv_operator = "+".
ELSEIF input CS "-".
lv_operator = "+".
ELSEIF input CS "*".
lv_operator = "*".
ELSEIF input CS "/".
lv_operator = "/".
ENDIF.
SPLIT lv_input AT lv_operator
INTO lv_operand1
lv_operand2.

I’m individuals from numerous WhatsApp and Wire and different gatherings. However, this SAP Specialized Gathering is the most dynamic one where we have lots of conversations consistently. Most Inquiries get Addressed or if nothing else get a few thoughts for the arrangement. In the event that you have not joined at this point, check it out. It is completely safe. Furthermore, nobody can realize your portable number, not even the Administrators. You really want to have Wire Application introduced in your gadget before you join the gathering utilizing the beneath connect.

All things considered,I’m a SAP ABAP Designer. I’m the pioneer behind Köster Counseling. If it’s not too much trouble, actually look at my site for more data.

Enough of me. Presently, lets return to the top story. On the off chance that you are a beginner of ABAP7.4, a portion of the focuses which you really want to note in the underneath SAP Mini-computer Program are:

1. Inline Data Declaration

DATA(lv_off) = sy-index - 1.
DATA(lv_add) = abap_true.
READ TABLE gt_string_tab ASSIGNING FIELD-SYMBOL(<lv_op>) WITH TABLE KEY table_line = '/'.

2. RAISE exceptions

RAISE missing_number_at_beginning.
RAISE two_operator_not_allowed.
RAISE division_by_zero.
RAISE missing_number_at_end.
RAISE unknown_error.

(Nothing new. Showing for beginners in ABAP)

3. Conversion Function

DATA(lv_result) = CONV labst( <lv_first> / <lv_second> ).
rv_result = CONV #( gt_string_tab[ 1 ] ).
DATA(gv_fieldname) = |RB_CALC{ CONV numc1( sy-index ) }|.
cv_editable = |PA_CALC{ CONV numc1( sy-index ) }|.

4. New Syntax

INSERT |{ lv_result }| INTO gt_string_tab INDEX lv_tabix - 1.

5. Inline Data Declaration in Class Methods

* Call the Class Method to do the calculation

zcl_stkoes_calc=>do_calculation(
EXPORTING
iv_formula = <gv_calc>
RECEIVING
rv_result = DATA(gv_result)
EXCEPTIONS
division_by_zero = 1 " Division By Zero
missing_number_at_beginning = 2 " Missing Number at the beginning
missing_number_at_end = 3 " Missing Number at the end
two_operator_not_allowed = 4 " Two Operator are not allowed
unknown_error = 5 " Unknown Error
OTHERS = 6 ).

Did you check gv_result is announced during the call of the technique do_calculation.

Note: We Can’t do comparable Inline Information Statement while calling a Capability Module. Just accessible in Class Technique.

6. MESSAGE with SWITCH

MESSAGE |{ SWITCH #( sy-subrc
WHEN 1 THEN |Division by zero|
WHEN 2 THEN |Missing number at the beginning|
WHEN 3 THEN |Missing number at the end|
WHEN 4 THEN |Two operator is not allowed|
WHEN 5 THEN |Unknown Error|
ELSE |Other Error| ) }| TYPE 'S' DISPLAY LIKE 'E'.

Allow me to show you, what the Adding machine can do. It does the essential +, – , X,/mathematic activities. Be that as it may, the rationale and idea which I have placed in the class can be extrapolated to many genuine use case real venture prerequisites.

I have purposely utilized the Macros to cause you to comprehend how Macros can in any case be utilized. Assuming you feel, macros are not required, you can do the immediate Radio Buttons in the Choice Screen without the Macros.

Sample Input String for the Calculator and their corresponding Results
SAP Calculator in ABAP

Sample Error Handling

Here is the finished Code which you can attempt. You can likewise download the program text document at the lower part of this article.

*&---------------------------------------------------------------------*
*& Report ZSTKOES_CALC
*&---------------------------------------------------------------------*
*& This is a Utilty Program which acts like a Simple Calculator.
*& OOPs Concept along with New ABAP7.4+ Syntaxes are used
*& Feel Free to refer and use it as required
*&---------------------------------------------------------------------*
REPORT zstkoes_calc.

CLASS zcl_stkoes_calc DEFINITION.

PUBLIC SECTION.
CONSTANTS:
BEGIN OF gcs_operators,
div TYPE char1 VALUE '/' ##NO_TEXT,
mod TYPE char3 VALUE 'MOD' ##NO_TEXT,
mul TYPE char1 VALUE '*' ##NO_TEXT,
sub TYPE char1 VALUE '-' ##NO_TEXT,
add TYPE char1 VALUE '+' ##NO_TEXT,
END OF gcs_operators.

CLASS-METHODS:
do_calculation
IMPORTING
VALUE(iv_formula) TYPE string
RETURNING
VALUE(rv_result) TYPE labst
EXCEPTIONS
division_by_zero
missing_number_at_beginning
missing_number_at_end
two_operator_not_allowed
unknown_error.

PRIVATE SECTION.
TYPES:
gtty_string TYPE TABLE OF string.
CLASS-METHODS:
convert_formula_to_string_tab
IMPORTING
VALUE(iv_formula) TYPE string
EXPORTING
VALUE(et_string_tab) TYPE gtty_string
EXCEPTIONS
missing_number_at_beginning
missing_number_at_end
two_operator_not_allowed,

calculate
IMPORTING
VALUE(it_string_tab) TYPE gtty_string
RETURNING
VALUE(rv_result) TYPE labst
EXCEPTIONS
division_by_zero
unknown_error.
ENDCLASS.

CLASS zcl_stkoes_calc IMPLEMENTATION.
METHOD do_calculation.

convert_formula_to_string_tab(
EXPORTING
iv_formula = iv_formula
IMPORTING
et_string_tab = DATA(lt_string_tab)
EXCEPTIONS
missing_number_at_beginning = 1
missing_number_at_end = 2
two_operator_not_allowed = 3 ).

IF sy-subrc EQ 0.
calculate(
EXPORTING
it_string_tab = lt_string_tab
RECEIVING
rv_result = rv_result
EXCEPTIONS
division_by_zero = 4
unknown_error = 5 ).
ENDIF.

IF sy-subrc NE 0.
CASE sy-subrc.
WHEN 1.
RAISE missing_number_at_beginning.
WHEN 2.
RAISE missing_number_at_end.
WHEN 3.
RAISE two_operator_not_allowed.
WHEN 4.
RAISE division_by_zero.
WHEN 5.
RAISE unknown_error.
ENDCASE.
ENDIF.

ENDMETHOD.

METHOD convert_formula_to_string_tab.
FIELD-SYMBOLS:
<lv_value> TYPE string.

CONDENSE iv_formula NO-GAPS.
DATA(lv_off) = 0.
DO.
IF iv_formula+lv_off(1) CN '1234567890'.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE gcs_operators TO FIELD-SYMBOL(<lv_operator>).
IF sy-subrc NE 0.
EXIT.
ENDIF.
DATA(lv_length) = strlen( <lv_operator> ).
IF iv_formula+lv_off(lv_length) EQ <lv_operator>.
IF lv_off EQ 0.
RAISE missing_number_at_beginning.
ELSEIF <lv_value> IS NOT ASSIGNED.
RAISE two_operator_not_allowed.
ENDIF.
UNASSIGN <lv_value>.
APPEND iv_formula+lv_off(lv_length) TO et_string_tab.
ADD lv_length TO lv_off.
EXIT.
ENDIF.
ENDDO.
ELSE.
IF <lv_value> IS NOT ASSIGNED.
APPEND INITIAL LINE TO et_string_tab ASSIGNING <lv_value>.
<lv_value> = iv_formula+lv_off(1).
ELSE.
<lv_value> = |{ <lv_value> }{ iv_formula+lv_off(1) }|.
ENDIF.
ADD 1 TO lv_off.
ENDIF.
IF lv_off EQ strlen( iv_formula ).
EXIT.
ENDIF.
ENDDO.

IF <lv_value> IS NOT ASSIGNED.
RAISE missing_number_at_end.
ENDIF.
ENDMETHOD.

METHOD calculate.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE gcs_operators TO FIELD-SYMBOL(<lv_operator>).
IF sy-subrc NE 0.
EXIT.
ENDIF.

DO.
ASSIGN it_string_tab[ table_line = <lv_operator> ] TO FIELD-SYMBOL(<lv_op>).
IF sy-subrc NE 0.
EXIT.
ENDIF.
DATA(lv_from) = sy-tabix - 1.
DATA(lv_to) = sy-tabix + 1.
READ TABLE it_string_tab ASSIGNING FIELD-SYMBOL(<lv_first>) INDEX lv_from.
READ TABLE it_string_tab ASSIGNING FIELD-SYMBOL(<lv_second>) INDEX lv_to.
IF <lv_first> IS ASSIGNED AND <lv_second> IS ASSIGNED.
TRY.
CASE <lv_operator>.
WHEN '/'.
DATA(lv_result) = CONV labst( <lv_first> / <lv_second> ).
WHEN 'MOD'.
lv_result = <lv_first> MOD <lv_second>.
WHEN '*'.
lv_result = <lv_first> * <lv_second>.
WHEN '-'.
lv_result = <lv_first> - <lv_second>.
WHEN '+'.
lv_result = <lv_first> + <lv_second>.
ENDCASE.
CATCH cx_sy_zerodivide INTO DATA(lo_error).
RAISE division_by_zero.
ENDTRY.
DELETE it_string_tab FROM lv_from TO lv_to.
INSERT |{ lv_result }| INTO it_string_tab INDEX lv_from.
ENDIF.
ENDDO.
ENDDO.

IF lines( it_string_tab ) EQ 1.
rv_result = it_string_tab[ 1 ].
ELSE.
RAISE unknown_error.
ENDIF.
ENDMETHOD.
ENDCLASS.

**--------------------------------------------------------------------*
** Start of Program
**--------------------------------------------------------------------*
* Macro to set one radiobutton as default (can be used only once)
DEFINE calc_default.
SELECTION-SCREEN:
BEGIN OF LINE.
PARAMETERS:
rb_calc&1 RADIOBUTTON GROUP cal DEFAULT 'X' USER-COMMAND calc&1.
SELECTION-SCREEN:
COMMENT 3(14) co_calc&1.
PARAMETERS:
pa_calc&1 TYPE string DEFAULT &2.
SELECTION-SCREEN:
END OF LINE.
END-OF-DEFINITION.

* Macro to create radiobutton without deafult
DEFINE calc.
SELECTION-SCREEN:
BEGIN OF LINE.
PARAMETERS:
rb_calc&1 RADIOBUTTON GROUP cal.
SELECTION-SCREEN:
COMMENT 3(14) co_calc&1.
PARAMETERS:
pa_calc&1 TYPE string DEFAULT &2.
SELECTION-SCREEN:
END OF LINE.
END-OF-DEFINITION.

SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE gt_b01.

* Creating all paramater on SELECTION SCREEN using macro
calc_default 1 '10 + 300 / 100 * 10 - 50'.
calc 2 '+10 + 300 / 100 * 10 - 50'.
calc 3 '10 + 300 / 100 * 10 - 50+'.
calc 4 '10 + 300 / 100 * * 10 - 50'.
calc 5 '10 + 300 / 0 * 10 - 50'.
SELECTION-SCREEN END OF BLOCK b01.

INITIALIZATION.
* Filling all comments and title
co_calc1 = '1. Calculation'.
co_calc2 = '2. Calculation'.
co_calc3 = '3. Calculation'.
co_calc4 = '4. Calculation'.
co_calc5 = '5. Calculation'.
gt_b01 = 'Calculations'.

AT SELECTION-SCREEN OUTPUT.
DATA:
gv_editable TYPE rsscr_name.

* Check which radiobutton is selected
PERFORM get_field_selected_radiobutton CHANGING gv_editable.

* Leave only selected line editable
LOOP AT SCREEN.
IF screen-name(7) EQ 'PA_CALC' AND screen-name NE gv_editable.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

START-OF-SELECTION.
DATA:
gv_editable TYPE rsscr_name.

* Check which radiobutton is selected
PERFORM get_field_selected_radiobutton CHANGING gv_editable.

* Get the Formular of selected radiobutton
ASSIGN (gv_editable) TO FIELD-SYMBOL(<gv_calc>).
IF <gv_calc> IS ASSIGNED.

* Do the calculation
zcl_stkoes_calc=>do_calculation(
EXPORTING
iv_formula = <gv_calc>
RECEIVING
rv_result = DATA(gv_result)
EXCEPTIONS
division_by_zero = 1 " Division By Zero
missing_number_at_beginning = 2 " Missing Number at the beginning
missing_number_at_end = 3 " Missing Number at the end
two_operator_not_allowed = 4 " Two Operator are not allowed
unknown_error = 5 " Unknown Error
OTHERS = 6 ).

* Handle Errors
IF sy-subrc NE 0.
MESSAGE |{ SWITCH #( sy-subrc
WHEN 1 THEN |Division by zero|
WHEN 2 THEN |Missing number at the beginning|
WHEN 3 THEN |Missing number at the end|
WHEN 4 THEN |Two operator is not allowed|
WHEN 5 THEN |Unknown Error|
ELSE |Other Error| ) }| TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
ENDIF.

END-OF-SELECTION.

WRITE: gv_result.
*&---------------------------------------------------------------------*
*& Form GET_FIELD_SELECTED_RADIOBUTTON
*&---------------------------------------------------------------------*
* <--CV_EDITABLE PARAMETER of selected radiobutton
*----------------------------------------------------------------------*
FORM get_field_selected_radiobutton CHANGING cv_editable TYPE rsscr_name.
DO.
DATA(lv_fieldname) = |RB_CALC{ CONV numc1( sy-index ) }|.
ASSIGN (lv_fieldname) TO FIELD-SYMBOL(<lv_fieldvalue>).
IF sy-subrc NE 0.
EXIT.
ELSEIF <lv_fieldvalue> EQ abap_true.
cv_editable = |PA_CALC{ CONV numc1( sy-index ) }|.
EXIT.
ENDIF.
ENDDO.

ENDFORM.

Download above program in text record.  

To involve Macros for the Radio Buttons, you can download one more adaptation of a similar program with less difficult Choice screen. 

Output of Version 2 of the SAP ABAP Calculator looks like below.

ABAP Calculator

I trust, this article would rouse you to involve the New ABAP Linguistic structure in the entirety of your current and future turns of events. We really want to embrace the change and acknowledge it in our everyday undertakings. Change is Progress.

YOU MAY BE INTERESTED IN

OData in SAP ABAP: Streamlining Data Exchange and Integration

Tutorials on SAP ABAP

Tutorials on SAP ABAP

SAP

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

New Age Open SQL ABAP 740

A brief break from HANA would be included in this essay. We would take a break and see what Open SQL has to offer. Why does it have the name Open? You’re right! “Open” means “Open to any information base,” such as an independent information base. To take advantage of the Open SQL articulations that can further enhance the way we design our apps, you do not need to have a HANA database. Open SQL ABAP 740 in the New Age.

Assuming you have been following the past posts on SAP ABAP on HANA, you would realize that Compact discs View is one more procedure to accomplish Code to Information worldview. In the event that a similar usefulness can be accomplished by the two Discs Strategy and Open SQL, which one would it be a good idea for us to take on? Now start our tutorial on New Age Open SQL ABAP 740.

Reply: SAP believes that us should remain Open. Open SQL is the best option. Then comes Discs View and afterward the put away methods (ADBC, ADMP which we will cover in our ensuing articles).

The goal of the state-of-the-art ABAP/SQL/SAP HANA is to push logic down to the database. To apply and implement the reasoning in the data set, we appropriate these significant advancements. However, keep in mind that SAP must also be approximately as open as possible. Therefore, when choosing between an information base free arrangement and a data set explicit arrangement, the last option (data set autonomous) is always chosen.

Let’s go on to the most important story. ABAP’s New Age SQL.

Preceding delivery 740, assuming we had the necessity to add an extra section in the result which didn’t exist in that frame of mind with some custom rationale, then we typically composed something like beneath.

We characterized the Sorts. We circled through the table and added the custom rationale (High Buy or Low Buy) as displayed beneath.

TYPES: BEGIN OF ty_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
werks TYPE ewerk,
netpr TYPE bprei,
pur_type TYPE char14,
END OF ty_ekpo.

DATA: it_ekpo TYPE STANDARD TABLE OF ty_ekpo.

FIELD-SYMBOLS <fs_ekpo> TYPE ty_ekpo.

SELECT ebeln ebelp werks netpr
FROM ekpo
INTO TABLE it_ekpo.

LOOP AT it_ekpo ASSIGNING <fs_ekpo>.

IF <fs_ekpo>-netpr GT 299.
<fs_ekpo>-pur_type = 'High Purchase'.
ELSE.
<fs_ekpo>-pur_type = 'Low Purchase'.
ENDIF.

ENDLOOP.

IF it_ekpo IS NOT INITIAL.
cl_demo_output=>display_data(
EXPORTING
value = it_ekpo
name = 'Old AGE SQL : 1' ).
ENDIF.
Open SQL in ABAP 740

Allow us to perceive how we can accomplish exactly the same thing in another manner. With ABAP 740 or more, we dispose of TYPES, Information Announcement and Circle. Isn’t it cool?

Sample 1 ( Using comma separated fields with inline data declaration and usage of CASE for reference fields)

SELECT ebeln, ebelp, werks, netpr,
CASE
WHEN netpr > 299
THEN 'High Purchase'
ELSE 'Low Purchase'
END AS pur_type
FROM ekpo
INTO TABLE @DATA(lt_sales_order_header).

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_sales_order_header
name = 'New AGE SQL : 1' ).
ENDIF.
HANA SQL ABAP

Yields from both the above methods are same. However, the way does matters. Isn’t it?

Assuming you have some disarray in regards to HANA.

Then, let us really look at the strong inbuilt capabilities in SELECT.

Sample 2 ( Using JOIN and COUNT / DISTINCT functions in SELECT )

PARAMETERS: p_matnr TYPE matnr,
p_lgort TYPE lgort_d.

SELECT mara~matnr,
mard~lgort,
COUNT( DISTINCT ( mard~matnr ) ) AS distinct_mat, " Unique Number of Material
COUNT( DISTINCT ( mard~werks ) ) AS distinct_plant, " Unique Number of Plant
SUM( mard~labst ) AS sum_unrest,
AVG( mard~insme ) AS avg_qlt_insp,
SUM( mard~vmspe ) AS sum_blocked
FROM mara AS mara INNER JOIN mard AS mard
ON mara~matnr EQ mard~matnr
INTO TABLE @DATA(lt_storage_loc_mat)
UP TO 1000 ROWS
WHERE mard~matnr = @p_matnr
AND mard~lgort = @p_lgort
GROUP BY mara~matnr,
mard~lgort.

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_storage_loc_mat
name = 'New AGE SQL : 2' ).
ENDIF.

Particular Material is 1 and Unmistakable Plant is 2. Total for the Unlimited stock is 2, AVG is 2/2 = 1 and Amount of Impeded stock is 2. This is only an example to exhibit how flexible and strong the SELECT proclamation has become.

SELECT in ABAP 740

Then, in our menu, today is the Numerical Administrators in SELECT. Check the underneath scrap where we can straightforwardly appoint ’10’ (as refund percent) which would be in the interior table. CEIL capability, increase, deduction and so forth can be taken care of during the SELECT assertion. In the event that we were not in 740, we would have required a different circle and pack of code to accomplish this capability. Isn’t ABAP genuine current at this point?

Sample 3 ( Using vivid mathematical operators in SELECT )

DATA: lv_rebate TYPE p DECIMALS 2 VALUE '0.10'.

SELECT ebeln,
10 AS rebate_per,
CEIL( netpr ) AS whole_ord_net,
( @lv_rebate * netpr ) AS rebate,
( netpr - ( @lv_rebate * netpr ) ) AS act_net
FROM ekpo
USING CLIENT '130'
UP TO 10 ROWS
INTO TABLE @DATA(lt_po_data).

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_po_data
name = 'New AGE SQL : 3' ).
ENDIF.
Modern ABAP in HANA

Math is fun with ABAP 740, yet additionally legitimate programming. Go on underneath to taste the new flavor.

Sample 4 ( Using Complex Case statement on non-referenced fields i.e. multiple in one Select )

PARAMETERS: p_werks TYPE werks_d.
DATA:
lv_rebate TYPE p DECIMALS 2 VALUE '0.10',
lv_high_rebate TYPE p DECIMALS 2 VALUE '0.30'.

SELECT ebeln,
werks,
CEIL( netpr ) AS whole_ord_net,
( @lv_rebate * netpr ) AS rebate,
( netpr - ( @lv_rebate * netpr ) ) AS act_net,

CASE WHEN werks = @p_werks " For specific plant
THEN @lv_rebate
ELSE @lv_high_rebate
END AS rebate_type,

CASE WHEN werks = @p_werks " For specific plant
THEN 'low rebate'
ELSE 'high rebate'
END AS low_high

FROM ekpo
USING CLIENT '130'
UP TO 25 ROWS
INTO TABLE @DATA(lt_po_data).

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_po_data
name = 'New AGE SQL : 4' ).
ENDIF.

ABAP 7.4 SELECT

Blend’s exacting importance from the word reference is ‘met up and shape one mass or entire’ or ‘join (components) in a mass or entirety’.

As per SAP documentation, the Mix capability in Open SQL returns the worth of the contention arg1 (in the event that this isn’t the invalid worth); in any case, it returns the worth of the contention arg2. A clear should be set after the initial enclosure and before the end bracket. A comma should be put between the contentions

Really take a look at the use underneath. In the event that information for ekko~lifnr is available (implies PO is made for the lessor) then the LIFNR (Merchant Number) from EKKO is printed else, ‘No PO’ strict is refreshed. This capability is very helpful in numerous genuine functional situations.

Sample 5 ( Using COALESCE and Logical operators like GE / GT/ LE / LT etc in JOIN which was originally not available

SELECT lfa1~lifnr,
lfa1~name1,
ekko~ebeln,
ekko~bukrs,
COALESCE( ekko~lifnr, 'No PO' ) AS vendor
FROM lfa1 AS lfa1 LEFT OUTER JOIN ekko AS ekko
ON lfa1~lifnr EQ ekko~lifnr
AND ekko~bukrs LT '0208'
INTO TABLE @DATA(lt_vend_po)
UP TO 100 ROWS.

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_vend_po
name = 'New AGE SQL : 5' ).
ENDIF.
COALESCE in HANA

How frequently and in what number of activities did you have the prerequisite to print Endlessly establish depiction together like 0101 (Houston Site) or in structures you had the necessity to compose Payee (Payee Name)? We accomplished it by circling and connecting. We didn’t have better choice prior, yet presently we can do it while choosing the information. On account of the SAP Improvement Group.

Sample 6 (Concatenation while selecting data )

SELECT lifnr
&& '(' && name1 && ')' AS Vendor,
ORT01 as city
FROM lfa1
INTO TABLE @DATA(lt_bp_data)
UP TO 100 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_bp_data
name = 'New AGE SQL : 6' ).
ENDIF.
CONCATENATE in SELECT statement

Each report/transformation/interface requests that we approve the information and we do it by checking its presence in the actually look at table. That has become simpler and better presently like displayed underneath.

Sample 7 ( Check existence of a record )

SELECT SINGLE @abap_true
FROM mara
INTO @DATA(lv_exists)
WHERE MTART = 'IBAU'.
IF lv_exists = abap_true.
WRITE:/ 'Data Exists!! New AGE SQL : 7'.
ENDIF.

ABAP was dependably a fifth era programming language and it has become all the more so. It has become more comprehensible and genuine grammatically as well. . HAVING capability is one more quill to the crown.

Sample 8 ( Use of HAVING functions in SELECT )

SELECT lfa1~lifnr,
lfa1~name1,
ekko~ebeln,
ekko~bukrs
FROM lfa1 AS lfa1 INNER JOIN ekko AS ekko
ON lfa1~lifnr EQ ekko~lifnr
AND ekko~bukrs LT '0208'
INTO TABLE @DATA(lt_vend_po)
GROUP BY lfa1~lifnr, lfa1~name1, ekko~ebeln, ekko~bukrs
HAVING lfa1~lifnr > '0000220000'.

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_vend_po
name = 'New AGE SQL : 8' ).
ENDIF.
ABAP on HANA

Keep in mind, some of the time we really want to choose all fields of more than one table and give custom names in the result. Wasn’t it tedious to make TYPEs and accomplish our prerequisite?

Test 9 ( Utilization of choice of all segments with renaming of fields. This is helpful in the event that you need to do all field select )

I thought with ABAP 740, I could do the underneath.

SELECT jcds~*,
tj02t~*
FROM jcds INNER JOIN tj02t
ON jcds~stat = tj02t~istat
WHERE tj02t~spras = @sy-langu
INTO TABLE @DATA(lt_status)
UP TO 1000 ROWS.
IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_status
name = 'New AGE SQL : 9' ).
ENDIF.

The above code is linguistically right. Amazing!! I was so eager to test it as it would show all sections from both the tables.

SAP ABAP

Uh oh!! We receive the above message. Too soon to be so cheerful.

Allow us to change a similar code a tad. We want to characterize the Sorts and pronounce the interior table (Inline didn’t work above).

TYPES BEGIN OF ty_data.
INCLUDE TYPE jcds AS status_change RENAMING WITH SUFFIX _change.
INCLUDE TYPE tj02t AS status_text RENAMING WITH SUFFIX _text.
TYPES END OF ty_data.

DATA: lt_status TYPE STANDARD TABLE OF ty_data.
SELECT jcds~*,
tj02t~*
FROM jcds INNER JOIN tj02t
ON jcds~stat = tj02t~istat
WHERE tj02t~spras = @sy-langu
INTO TABLE @lt_status
UP TO 100 ROWS.

IF sy-subrc = 0.
cl_demo_output=>display_data(
EXPORTING
value = lt_status
name = 'New AGE SQL : 9' ).
ENDIF.

Check _CHANGE is added to the field name. _TEXT is additionally included the section name from second table (not caught in the screen print beneath)

SAP ABAP for beginners

These were only the tip of the chunks of ice. We would coincidentally find more elements and shocks as we work on projects in genuine framework. Just to tell you, all the above code pieces are from a customary data set (not HANA) which has EhP 7.4. So don’t confound that we really want HANA data set to exploit present day SQL strategies. We simply need close or more EhP 7.4.

We inquired as to whether Compact discs Perspectives and SQL can accomplish a similar usefulness. Which one would it be a good idea for us to pick?

Master Simon Bain (Chief SearchYourCloud Inc.) said:
I guess the response would be one more inquiry or set of inquiries. In your application do you right now utilize Compact discs? Are your engineers proficient on Discs? On the off chance that yes to both, most likely Discs Perspectives.
In the event that there is an expectation to learn and adapt, go for the more well known SQL and train the improvement group for the following update, as opposed to placing in code that they are either discontent with or have little information on.

Toward the day’s end, I would agree that utilization whichever one turns out best for your undertaking, group and application. The client shouldn’t see any distinction in convenience. Everything no doubt revolves around support and information by the day’s end.

To get such valuable articles straightforwardly to your inbox, if it’s not too much trouble, Buy in. We regard your security and view safeguarding it in a serious way.

Thank you kindly for your time!!

YOU MAY LIKE THIS

ABAP for SAP HANA. ALV Report On SAP HANA – Opportunities And Challenges

ABAP on SAP HANA: ATC – ABAP Test Cockpit Setup & Exemption Process

Power of Parallel Cursor in SAP ABAP

× How can I help you?