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

Using seperators

Former Member
0 Likes
854

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?

1 ACCEPTED SOLUTION
Read only

gopi_narendra
Active Contributor
0 Likes
828

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

7 REPLIES 7
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
828

Hi,

loop at itab.

...

If itab-f1 is initial.

*Here v1 is the variable which holds data

concatenate v1 '||' into v1.

else.

endif.

...

endloop.

Read only

Former Member
0 Likes
828

Ramana,

If you are putting '|' after every field, if a field does not have any value it will automatically have '||'.

Please confirm.

Thanks

Read only

gopi_narendra
Active Contributor
0 Likes
829

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

Read only

0 Likes
828

I am just adding 22 fields into the file...and I can't can't guess where there might be a miss of data.

Read only

0 Likes
828

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

Read only

0 Likes
828

Thanks then..I'll even try it.

Read only

0 Likes
828

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.