Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Transformations

Former Member
0 Likes
829

Hi,

I am loading a csv file from application server.

I have 15 columns.

<b>Column A</b>: I get values which may contain a "/" at the end. The character length is not fixed. But the object defined length is 6. <u>I need to remove "/".</u>

<b>Column B</b>: I get values which contain "/" in between. The number of characters before the "/" or after the "/" is not fixed. But the object defined length is 60. <u>I need to remove all the characters before "/" including "/".</u>

Can you please help me with the ABAP code for this?

Thanks

SAPBW

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
807

I assume that you are loading these values from the csv into an internal table in your program with specific fields, such as....

data: begin of itab occurs 0,
      columna(6) type c,
      columnb(60) type c,
      columnc(10) type c,
      ....
      end of itab.

So when filling the itab, you simply need to translate the slashes.

For column A, you only want to get rid of the one on the end. This code will get rid of the '/' on the end

Shift itab-columna right deleting trailing space.
Shift itab-columna right deleting trailing '/'.
Shift itab-columna left deleting leading space.

For column B, we need to get rid of all, in this case, we can use the TRANSLATE keyword. Here the literal after the USING part tells the system to get rid of the '/' and replace it with SPACE which is the second character in literal string below.

translate itab-columnb using '/ '.

Regards,

RIch Heilman

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
808

I assume that you are loading these values from the csv into an internal table in your program with specific fields, such as....

data: begin of itab occurs 0,
      columna(6) type c,
      columnb(60) type c,
      columnc(10) type c,
      ....
      end of itab.

So when filling the itab, you simply need to translate the slashes.

For column A, you only want to get rid of the one on the end. This code will get rid of the '/' on the end

Shift itab-columna right deleting trailing space.
Shift itab-columna right deleting trailing '/'.
Shift itab-columna left deleting leading space.

For column B, we need to get rid of all, in this case, we can use the TRANSLATE keyword. Here the literal after the USING part tells the system to get rid of the '/' and replace it with SPACE which is the second character in literal string below.

translate itab-columnb using '/ '.

Regards,

RIch Heilman

Read only

0 Likes
807

Hi Rich,

Do I need to define all the columns in Data:?

And in Column B I need to delete all charecters preceding "/" and also "/" itself.

Also, will there be any change if I am loading from client server?

Thanks

SAPBW

Read only

0 Likes
807

I think that it is a good idea to put the data into specific fields as it will be easier to work with. I must have misunderstood about column B.

You can find the first / using the search statement, sy-fdpos will have the value of the offset, then you can use the shift statement to shift to the left by x places.

search itab-columnb for '/'.
if sy-subrc = 0.
  shift itab-columnb left by sy-fdpos places.
endif.

Regards,

Rich Heilman

Read only

0 Likes
807

I got a short dump:

You attempted to change the internal table "???", but no valid cursor exists for the table.

1. The relavent ABAP/4 statement does not include the addition "....INDEX....", although the statement is not inside a "LOOP...ENDLOOP" loop processing this table.

2. The relavent ABAP/4 statement was called from within a "LOOP...ENDLOOP" loop after a delete "???"

I used the code as below.

data: begin of itab occurs 0,

/BIC/COLUMNA(000010) TYPE C,

/BIC/COLUMNB(000060) TYPE C,

.

.

.

.

end of itab.

Shift itab-/BIC/COLUMNA right deleting trailing space.

Shift itab-/BIC/COLUMNA right deleting trailing '/'.

Shift itab-/BIC/COLUMNA left deleting leading space.

search itab-/BIC/COLUMNB for '/'.

if sy-subrc = 0.

shift itab-/BIC/COLUMNB left by sy-fdpos places.

endif.

Modify itab.

Please let me know where I made a mistake.

Thanks

SAPBW

Read only

Former Member
0 Likes
807

Check if your itab is within a LOOP..Otherwise try to give INDEX for your modify statement..

Thanks,

Naren