Application Development 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: 

Radign a file into ITAB, Replacing # with NULL Value, From Application Serv

Former Member
0 Kudos
292

Hi,

I have to Read a file from Application Server and replace the # with NULL Value.

The Input Format: 5#2#0#0#T#E#X#A#S#B#B#B#B#B#B#B#B#B#B#D#I#R#E#C#T.

The expected format is : 5200TEXASBBBBBBBBBBDIRECT.

The output format is a "Fixed Length" TXT File. Here "B" is for Blank Space. Can you please suggest me a Soultion to this? The output file is to be read into an another internal table for further processing. So my objective it only to remove the # with a "No Space or NULL" value.

Can i have the Sample code to solve this issue please?

Thanks fo ryour Help in Advance.

KANNAN.SA

Message was edited by: Kannan SA

Message was edited by: Kannan SA

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
177

I think what you are seeing here is the actual "tabs" in between the fields. The "#" represents a "tab". Check out the following sample program, it will show you how to handle the "tab".



report zrich_0002 .

parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,      
field1(20) type c,      
field2(20) type c,    
  field3(20) type c,      
end of itab.
data: wa type string.

CONSTANTS: con_tab TYPE x VALUE '09'.

* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection. 

 open dataset d1 for input in text mode.  
if sy-subrc = 0.  
  do.     
 read dataset d1 into wa.     
 if sy-subrc <> 0.      
  exit.      endif.
* Here you are splitting at the hex value of "tab" not at* the # sign.       
 split wa at con_tab into itab-field1 itab-field2 itab-field3.    
  append itab.    
enddo. 
 endif.  
close dataset d1.


Regards,

Rich Heilman

8 REPLIES 8

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
178

I think what you are seeing here is the actual "tabs" in between the fields. The "#" represents a "tab". Check out the following sample program, it will show you how to handle the "tab".



report zrich_0002 .

parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,      
field1(20) type c,      
field2(20) type c,    
  field3(20) type c,      
end of itab.
data: wa type string.

CONSTANTS: con_tab TYPE x VALUE '09'.

* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection. 

 open dataset d1 for input in text mode.  
if sy-subrc = 0.  
  do.     
 read dataset d1 into wa.     
 if sy-subrc <> 0.      
  exit.      endif.
* Here you are splitting at the hex value of "tab" not at* the # sign.       
 split wa at con_tab into itab-field1 itab-field2 itab-field3.    
  append itab.    
enddo. 
 endif.  
close dataset d1.


Regards,

Rich Heilman

Former Member
0 Kudos
177

Hi Kannan,

For string operations just try this

data wa type string .

parameter pt(100) default '5#2#0#0#T#E#X#A#S# # #D#I#R#E#C#T' .

move pt to wa .

translate wa using ' B'.

translate wa using '# '.

clear pt.

move wa to pt.

condense pt no-gaps..

write 😕 pt.

( I have asumed that you file will have spaces instead of "B" . If not then you need not use the "translate wa using ' B'." statement.

Cheeers.

Dont forget to reward if answers were helpful.

Former Member
0 Kudos
177

My Input Data is: '5#2#0#0#T#E#X#A#S# # # # # # # # # # #D#I#R#E#C#T'.

Expected Output is :'5200TEXASBBBBBBBBBDIRECT'

It is a fixed length file. When data is not there, it needs to be of blank space for the relevant length. My requirement is only to replace # with a null value. I.e, the # needs to be removed when they appear betweeen digits. But when they appear between blank space, then delete the # and maintain the actual blank space. B-> Blank Space. I hope i made my objective clear. Please give me your suggestion.

Thanks in Advance

Kannan.SA

Message was edited by: Kannan SA

0 Kudos
177

Hi Kannan,

The "B" in outpput confused me. Ok try this.

data wa type string .

parameter pt(100) default '5#2#0#0#T#E#X#A#S# # # # # # # # # # #D#I#R#E#C#T' .

move pt to wa .

translate wa using ' &'.

translate wa using '# '.

clear pt.

move wa to pt.

condense pt no-gaps.

translate pt using '& '.

write 😕 pt.

( Instead of "&" you can use any character which is not expected in the input files ).

Cheers

0 Kudos
177

Hi, try that:

DATA trhex(4) TYPE x VALUE '0020'.
...
read dataset file into wa.
TRANSLATE wa  USING trhex.
...

regards Andreas

Former Member
0 Kudos
177

Hi,

I suppose that your file is in UTF-16 format. Am I right ?

Svetlin

0 Kudos
177

The File in Application Server is of code page 4103. This has to be read in to an Internal table for further processing. This file has # which is not a field seperator.

Thanks,

Kannan.SA

Message was edited by: Kannan SA

0 Kudos
177

This is a file created by the Payment Mediaum program. File is in the Application Server. Format Code Page:4103. This File from Application server to be read into an Internal Table for Further processing before it is send to Banks for payments.

Thanks,

Kannan.SA