‎2007 Feb 15 2:25 AM
Hi ,
I am sending all the fields of an ITAB into a unix file using Datasets.while doing this I must use the pipe symbol to seperate the fields( | ).for this I am using concatenate and putting all the fields into another ITAB with a single filed that can take the structure.
But my problem is ...
where there is no value in any field....I must put 2 pipe symbols ( || )as seperators.
How can I do this?
‎2007 Feb 15 3:04 AM
Hi Ramana...
The code which i gave previously. observe the one in the <b>BOLD</b> Which means that if there no value for that field it will just add a "|" Symbol to the internal table.
Hope this sovles, if u still need any clarification,do let us know
data : IT_STR type standard table of TY_STR,
IS_STR type TY_STR.
data : UNIX_FILE type RLGRAP-FILENAME.
IT_UNIX is the final internal table without seperators.
IT_STR is the internal table with seperators.
loop at it_unix into is_unix.
if not IS_UNIX-field1 is initial.
shift IS_UNIX-MO left deleting leading '0'.
concatenate IS_STR-STR IS_UNIX-field1 into IS_STR-STR.
<b>else.
concatenate IS_STR-STR IS_UNIX-field1 into IS_STR-STR.</b>
endif.
if not IS_UNIX-field2 is initial.
shift IS_UNIX-field2 left deleting leading '0'.
concatenate IS_STR-STR IS_UNIX-field2 into IS_STR-STR separated by '|'.
<b>else.
concatenate IS_STR-STR IS_UNIX-field2 into IS_STR-STR separated by '|'.</b>
endif.
clear : is_unix.
endloop.
Open Dataset
catch system-exceptions DATASET_CANT_OPEN = 8.
open dataset UNIX_FILE for output in text mode encoding default.
endcatch.
Write to Dataset
loop at IT_STR into IS_STR.
catch system-exceptions DATASET_NOT_OPEN = 0 .
transfer IS_STR-STR to UNIX_FILE.
endcatch.
clear : IS_STR.
endloop.
Close Dataset
close dataset UNIX_FILE.
Regards
Gopi
‎2007 Feb 15 2:29 AM
Hi,
loop at itab.
...
If itab-f1 is initial.
*Here v1 is the variable which holds data
concatenate v1 '||' into v1.
else.
endif.
...
endloop.
‎2007 Feb 15 2:34 AM
Ramana,
If you are putting '|' after every field, if a field does not have any value it will automatically have '||'.
Please confirm.
Thanks
‎2007 Feb 15 3:04 AM
Hi Ramana...
The code which i gave previously. observe the one in the <b>BOLD</b> Which means that if there no value for that field it will just add a "|" Symbol to the internal table.
Hope this sovles, if u still need any clarification,do let us know
data : IT_STR type standard table of TY_STR,
IS_STR type TY_STR.
data : UNIX_FILE type RLGRAP-FILENAME.
IT_UNIX is the final internal table without seperators.
IT_STR is the internal table with seperators.
loop at it_unix into is_unix.
if not IS_UNIX-field1 is initial.
shift IS_UNIX-MO left deleting leading '0'.
concatenate IS_STR-STR IS_UNIX-field1 into IS_STR-STR.
<b>else.
concatenate IS_STR-STR IS_UNIX-field1 into IS_STR-STR.</b>
endif.
if not IS_UNIX-field2 is initial.
shift IS_UNIX-field2 left deleting leading '0'.
concatenate IS_STR-STR IS_UNIX-field2 into IS_STR-STR separated by '|'.
<b>else.
concatenate IS_STR-STR IS_UNIX-field2 into IS_STR-STR separated by '|'.</b>
endif.
clear : is_unix.
endloop.
Open Dataset
catch system-exceptions DATASET_CANT_OPEN = 8.
open dataset UNIX_FILE for output in text mode encoding default.
endcatch.
Write to Dataset
loop at IT_STR into IS_STR.
catch system-exceptions DATASET_NOT_OPEN = 0 .
transfer IS_STR-STR to UNIX_FILE.
endcatch.
clear : IS_STR.
endloop.
Close Dataset
close dataset UNIX_FILE.
Regards
Gopi
‎2007 Feb 15 3:09 AM
I am just adding 22 fields into the file...and I can't can't guess where there might be a miss of data.
‎2007 Feb 15 3:12 AM
You can repeat doing it for all the 22 fields. I used the same kinda logic for around 56 fields. It works fine. Check thoroughly
Regards
Gopi
‎2007 Feb 15 3:13 AM
‎2007 Feb 15 3:15 AM
Hi,
If you are using concatenate to combine the fields,you will be using a variable to hold it.
If there is missing data,then there should be two pipe symbol continuosly in the variable.
concatenate f1 f2 f3 f4 into v1 separated by '|'.
If f2 is not having value and f1 = 'a' and f3 = 'b' and f4 = 'c',
then v1 = 'a||bc'.
Then in v1,you can search for two pipe symbols.