· 

SAP BW Decode String during Import

In my current project I have a file to import, which only delivers me a string with a length of 1000. I also get a description what is in this file. Like the following points:

  • Customer from 1 to 10
  • City from 11 to 50

The file looks like: 0000123456London............................ So I have a file and a description how to decode this file. Now I need to find a way to separate this information into InfoObjects. I build a Z-Table which contains the decode information.

Z-Table to decode information
Z-Table to decode information

The content look like the following example.

Z-Table content
Z-Table content

After I filled all my necessary information into the table, I started to write my code in an expert routine. First I need some variables and internal tables.

1
2
3
4
5
6
7
DATA: lt_table0 TYPE TABLE OF z_dec,
      ls_table0 LIKE LINE OF lt_table0,
      lt_table1 TYPE TABLE OF z_dec,
      ls_table1 LIKE LINE OF lt_table1,
      lv_start  TYPE i.

FIELD-SYMBOLS: <fv_source> TYPE any.

After the variable declaration, we have to select our data and sort the internal tables.

 

1
2
3
4
5
SELECT * FROM z_dec INTO TABLE lt_table0 WHERE recordtype = 0.
SELECT * FROM z_dec INTO TABLE lt_table1 WHERE recordtype = 1.

SORT lt_table0 BY startfrom ASCENDING.
SORT lt_table1 BY startfrom ASCENDING.

Now we loop over the SOURCE_PACKAGE and loop over our internal table to assign all values.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
LOOP AT SOURCE_PACKAGE ASSIGNING <source_fields>.
  IF <source_fields>-field1(1) = 0.
   LOOP AT lt_table0 INTO ls_table0.
   "First I need to find the start of my information
     lv_start = ls_table0-startfrom - 1.
     "Now I assign the infoobject to my result structure
     ASSIGN COMPONENT ls_table0-infoobject OF STRUCTURE RESULT_FIELDS TO <fv_source>.
     "Here I write the value of string into the corresponding infoobject
     <fv_source> = <source_fields>-field1+lv_start(ls_table0-length).
   ENDLOOP.

   "Here we append the RESULT_FIELDS to the RESULT_PACKAGE.
   APPEND RESULT_FIELDS TO RESULT_PACKAGE.
  ELSEIF <source_fields>-field1(1) = 1.
    LOOP AT lt_table1 INTO ls_table1.
      "First I need to find the start of my information
      lv_start = ls_table1-startfrom - 1.
      "Now I assign the infoobject to my result structure
      ASSIGN COMPONENT ls_table1-infoobject OF STRUCTURE RESULT_FIELDS TO <fv_source>.
      "Here I write the value of string into the corresponding infoobject
      <fv_source> = <source_fields>-field1+lv_start(ls_table1-length).
    ENDLOOP.
    "Here we append the RESULT_FIELDS to the RESULT_PACKAGE.
    APPEND RESULT_FIELDS TO RESULT_PACKAGE.
  ENDIF.
ENDLOOP.

So when we now see the import file, which looks like the following.

Import File
Import File

The result looks like the a normal import.

Result after import
Result after import

You can download the whole source code from github. If you have questions, feel free to ask.

author.


I am Tobias, I write this blog since 2014, you can find me on twitter and youtube. If you want you can leave me a paypal coffee donation. You can also contact me directly if you want.

SAP Analysis for Office - The Comprehensive Guide
The book SAP Analysis for Office - The Comprehensive Guide by Tobias Meyer is a pdf book about SAP Analysis for Office. It is based on Analysis for Office 2.8 and contains 346 Pages.
45,00 €
SAP Analysis for Office - The Comprehensive Guide
SAP Analysis for Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis for Office. It is based on Analysis for Office 2.7 and contains 299 Pages.
37,00 €
SAP Analysis for Office - The Comprehensive Guide
SAP Analysis for Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis for Office. It is based on Analysis for Office 2.6 and contains 272 Pages.
27,00 €

Write a comment

Comments: 0