6/24/2023 0 Comments Abap 7.4 loop at itab( werks = substring_after( val = substring_before( val = ls_filename-filename sub = '_' occ = 2 ) sub = '_' occ = 1 ) ( filename = 'PM_CA02_0074203_C_HA.txt' ) ).ĭATA(it_vm_data_tab) = VALUE tt_vm_tab( FOR ls_filename IN it_fillename_data_tab * With this logic there is no need for usage of COND like in the first sample.ĭATA(it_fillename_data_tab) = VALUE tt_filename_tab( ( filename = 'VM_CA02_0074203_0000102207_H.txt' ) * My recommendation is to put an identifier at the beginning of the filename like in this sample. Tt_filename_tab TYPE TABLE OF ty_filename WITH EMPTY KEY. Tt_pm_tab TYPE TABLE OF ty_pm_file WITH EMPTY KEY, Tt_vm_tab TYPE TABLE OF ty_vm_file WITH EMPTY KEY, Also, the STRLEN check of each row is prevented along with COND #. He has used WHERE clause in the FOR Loop. Also, with his new solution logic there is no need to use COND.Ĭheck the solution above. Stephan recommended to put an identifier in the beginning of the data row for the file. And guess what? Stephan gave a flawless solution yet again!!Īlso Check – How I Created My First SAP OData Services Solution 2 from Stephan We achieved the business requirement, but we were still wondering if there is a better way to achieve it. Also, we had COND in the syntax which could be avoided. The above code also gave a blank line and we were forced to use the DELETE statement explicitly. The output for each result is “CD”, “CDEFGH”, “EFGH”, “AB”, and “ABCD” in the same order. The above snippet is from SAP Help to show the usage of SUB and different SUBSTRING functions. Sub looks for the characters in the string. If occ is positive value, the occurrences are counted from the left while if occ is a negative number, it is counted from the right side. You might see a negative number for occ = -1. Note: The key word occ is for Occurrence. The table types are declared like below.Īfter some research and with our new knowledge, we achieved the functionality using STRLEN, SUBSTRING_BEFORE, SUBSTRING_AFTER, sub, occ string functions along with the VALUE and FOR Loop and COND keywords. Do a F4 on each of these keywords and try to understand the concept.įor our case, we have know the TYPE, therefore they come after the VALUE operator. We have In-line data declaration, usage of VALUE, FOR Loop in internal table, SWITCH and #. We say, not only CDS, the new ABAP itself looks like super active ABAP.Ĭheck the above screenshot. txt.Īs author and ABAPer Paul Hardy says, CDS is ABAP in Steriods. ![]() Also, we do not need to show the extension. Row type one has 26 characters while row type two has 18 characters. We used SWITCH statement in new syntax and separated the rows based on the length of the data in the file (which is fixed). The idea is, all the data rows in the file for type first should go to one internal table and all rows like that of second type should go into another internal table. Similarly fourth field in green is a custom type in first row and some category in second row. But the third field in red is Vendor is first row and while it is an indicator in second row. For example, the first two fields (yellow and blue) in both the rows are Plant and Material. The data in the first row and second row are different. The data in the file would look like this: Sounds an easy requirement right? But can you do using the new ABAP Syntax?Īlso Take – Free Video Course on New Syntax in ABAP Existing Code for Fixed Length Data This delimiter can be anything viz comma(,), tilds (~), pipe (|) etc. They want to separate the data into columns at the delimiter underscore. ![]() But later on, the business decided to separate the data with underscore “_” and the file data is not fixed any more. One of our very active and helpful members, Wesley Massini had a program where he was reading data from a file with fixed length. This post is again the result of the question we had in our SAP Technical Telegram Group. In this article today, we would discuss one requirement which we can easily achieve in old ABAP, but needed some help for the new syntax. The lazy developers who were comfortable with traditional ABAP programming find it challenging to use the new syntax. Every developer has seen this syntax in some or other programming language: for (i=1 i<=3 i++).Why would ABAP stay behind?īut old habits die heard. FOR Loop is relatively new to ABAPers, though other programming language use it very commonly. SAP ABAP Developers are familiar with LOOP - ENDLOOP syntax.
0 Comments
Leave a Reply. |