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.

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.

 

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.

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.

Analysis Office - The Comprehensive Guide 2nd edit
Analysis Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis Office. It is based on Analysis Office 2.4 and contains 243 pages.
39,99 €
Analysis Office - The Comprehensive Guide
Analysis Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis Office. It is based on Analysis Office 2.3 and contains 227 Pages.
29,99 €

Write a comment

Comments: 0