09-08-2010 11:41 AM
Hi,
I concatenated 10 fields by using RESPECTING BLANK. I generated the file on the application server using this concatenated string. Now I need to read again that file for reference. Now I want to split that string into the 10 fields. How do i do that. Could anyone help me on this. (Other than OFFSET logic because sometimes I'll get 15 fields or 20 or 30 etc, I need to do it dynamically)
Regards,
Selva
09-08-2010 11:58 AM
So you have done it using space has seperator.
If its a single space then it will create problem because the data might also contain spaces.
If there is no space between the value, then try
data;itab type table of string.
split wa at ` ` into itab.
09-09-2010 6:20 AM
HI Keshav,
If we use RESPECTING BLANKS, it works like, For eg.
matnr mtart werks
56775 ZTRA 1000
For matnr 18 char, mtart 4 char and werks 4 char, here we got matnr as 5 char, so what it does,
56775 and it gives remaining 13 char as space and then mtart werks. but we don't get any spaces between mtart and werks.
if mtart value is 3 char then we get one char space. if mtart value is 2 char we get 2 char space between mtart and werks.
Regards,
Selva M
09-09-2010 6:27 AM
09-09-2010 12:16 PM
Hi Suhas,
I got ur point, if our structure is known then we can do it like ur method. But I want to do it dynamically. I'm not sure about the structure, each and every time I'll get different structure. I'm trying to create dynamic structure and check ur logic.
Thanks Suhas
Regards
selvaM
09-09-2010 12:23 PM
56775 and it gives remaining 13 char as space and then mtart werks. but we don't get any spaces between mtart and werks.
if mtart value is 3 char then we get one char space. if mtart value is 2 char we get 2 char space between mtart and werks.
CONDENSE after concatenate.
09-09-2010 1:20 PM
Hi keshav,
I think there is no meaning of using CONDENSE after the RESPECTING BLANKS. Condense will spoil the RESPECTING BLANKS character. So I'm not using CONDENSE.
Regards,
Selva M
09-09-2010 3:03 PM
Hi Selva,
You can modify the program that write the string? In this case you can use a separator between the fields and then split it while reading.
For example:
Write on dataset
concatenate mara-matnr '&' mara-mtart '&' makt-maktx into out_string respecting blank.
transfer out_string to out_file.
Reading data
read dataset in_file into in_string.
check sy-subrc eq 0.
do.
split in_string at '&' into t_table-fields in_string.
append t_table. clear t_table.
if not in_string ca '&'.
exit.
endif.
enddo.
I hope this can help you.
09-08-2010 11:59 AM
Hello Selva,
Check this code snippet:
DATA: v1 TYPE char2,
v2 TYPE numc10,
v3 TYPE char4,
v_res TYPE string.
DATA:
BEGIN OF struc,
f1 TYPE char2,
f2 TYPE numc10,
f3 TYPE char4,
END OF struc.
FIELD-SYMBOLS <val> TYPE ANY.
CONCATENATE v1 v2 v3 INTO v_res RESPECTING BLANKS.
WRITE / v_res.
struc = v_res.
Hope this gives you some idea.
BR,
Suhas
09-08-2010 12:01 PM
09-08-2010 12:09 PM
>
> he has to read it from server .
So, what difference does it make ?? My answer was just to give the OP a hint! This is the technique we use for transferring idoc data to structure(EDIDD-SDATA), correct!
We don't use SPLIT or any OFFSET techniques.
May this should make more sense:
TYPES:
BEGIN OF struc,
f1 TYPE char2,
f2 TYPE char10,
f3 TYPE char4,
END OF struc.
DATA: v1 TYPE char2,
v2 TYPE char10,
v3 TYPE char4,
v_res TYPE string,
itab TYPE STANDARD TABLE OF struc,
wa TYPE struc.
DATA: v_file TYPE fileintern VALUE './SDNtest.txt'.
FIELD-SYMBOLS <val> TYPE ANY.
CONCATENATE v1 v2 v3 INTO v_res RESPECTING BLANKS.
WRITE / v_res.
*---------------WRITE TO APP SERVER----------------*
OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
CHECK sy-subrc = 0.
TRANSFER v_res TO v_file.
CHECK sy-subrc = 0.
CLOSE DATASET v_file.
CHECK sy-subrc = 0.
*---------------READ FROM APP SERVER----------------*
OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
CHECK sy-subrc = 0.
DO.
READ DATASET v_file INTO wa.
IF sy-subrc = 0.
APPEND wa TO itab.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET v_file.
BR,
Suhas
Edited by: Suhas Saha on Sep 8, 2010 4:49 PM
09-08-2010 12:21 PM
Hi Suhas,
What i meant to say was that op has already downloaded the data which is seperated by blanks. His requirement is to read it in the program. may be i understood the question wrong
The problem is if a field contains a value like 'NAME1 NAME2' then how it would react . In this case offset will be the only solution.
READ DATASET v_file INTO wa.
IF sy-subrc = 0.
APPEND wa TO itab.
This will work fine if the itab structure is fixed.
09-13-2010 8:04 AM
Hi Suhas,
I think we can't assign a string directly to a structure (As you said above) of dynamic internal table because dynamic internal table uses field symbol. It is possible in normal format.
Thanks,
Selva M
09-08-2010 12:09 PM
Hi,
try this way...
data;begin of itab occurs 0 ,
char(1000),
End of itab.
OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
WRITE: 'Error opening :', dsn.
ENDIF.
LOOP AT it_doc INTO wa_doc.
TRANSFER wa_doc TO dsn.
IF sy-subrc <> 0.
WRITE /: 'Error writing'.
ELSE.
split wa_doc at ` ` into table itab. "Moving Unknnown rows into Internal
ENDIF.
ENDLOOP.
CLOSE DATASET dsn.
regards,
Prabhudas
09-08-2010 12:24 PM
after you open dataset, read the value into a long character string (type c up to 65535 characters long), do a condense to squeeze out extra spaces, unless you have spaces in texts, etc. Alternatively, describe a structure that matches the string and has the fields defined and read into that structure. The take the length of each field and move to another structure, if needed.