2011 Oct 18 7:41 PM
Hi Guru's,
I want to write a subroutine where I have to pass a parameter and an internal table. But where it gets tricky is my internal table structure is not constant.
Perfrom subroutine_1 tables itab1 using p_file
Perfrom subroutine_1 tables itab2 using p_file
Perfrom subroutine_1 tables itab3 using p_file.
What I am trying to do is...I have 500 files hosted in my SAP Application Server and all these 500 files have different structure.
I have to get these files into my Program and place them in separate internal tables and then do some validations. I know how structure of each file will be. But I dont want to repeat the code for 500 times.!!!!!
So here is how my code looks
OPEN DATASET p_p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE
IF sy-subrc EQ 0.
DO.
READ DATASET p_p_file INTO wa_result.
IF sy-subrc = 0.
APPEND wa_result TO it_result.
CLEAR wa_result.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
I want to put this in a subroutine as I dont want to write same code for 500 files. The structure of these 500 files is different and each time in my subroutine i have to pass an internal table with different structure. How can I achieve it? My it_result structure will be different for each file..500 diffrent structures.
The input to this routine should be file name and out put should be an internal table with file contents and each time the structure of the internal table will be different.
Any code snippets will be of great help. I serached SDN but not of much help addresisng my issue.
Edited by: jessica sam on Oct 18, 2011 9:42 PM
Edited by: jessica sam on Oct 18, 2011 9:44 PM
Hi Guru's,
I want to write a subroutine where I have to pass a parameter and an internal table. But where it gets tricky is my internal table structure is not constant.
Perfrom subroutine_1 tables itab1 using p_file
Perfrom subroutine_1 tables itab2 using p_file
Perfrom subroutine_1 tables itab3 using p_file.
What I am trying to do is...I have 500 files hosted in my SAP Application Server and all these 500 files have different structure.
I have to get these files into my Program and place them in separate internal tables and then do some validations. I know how structure of each file will be. But I dont want to repeat the code for 500 times.!!!!!
So here is how my code looks
OPEN DATASET p_p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE
IF sy-subrc EQ 0.
DO.
READ DATASET p_p_file INTO wa_result.
IF sy-subrc = 0.
APPEND wa_result TO it_result.
CLEAR wa_result.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
I want to put this in a subroutine as I dont want to write same code for 500 files. The structure of these 500 files is different and each time in my subroutine i have to pass an internal table with different structure. How can I achieve it? My it_result structure will be different for each file..500 diffrent structures.
The input to this routine should be file name and out put should be an internal table with file contents and each time the structure of the internal table will be different.
Any code snippets will be of great help. I serached SDN but not of much help addresisng my issue.
Edited by: jessica sam on Oct 18, 2011 9:42 PM
Edited by: jessica sam on Oct 18, 2011 9:44 PM
2011 Oct 18 8:43 PM
HI Jessica.
It could be something like this:
DATA: t_1 TYPE TABLE OF pa0001,
t_2 TYPE TABLE OF pa0002,
t_3 TYPE TABLE OF pa0003.
PERFORM test: TABLES t_1 USING p_file,
TABLES t_2 USING p_file,
TABLES t_3 USING p_file.
*&---------------------------------------------------------------------*
*& Form test
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->T_TABLE text
* -->P_P_FILE text
*----------------------------------------------------------------------*
FORM test TABLES t_table
USING p_p_file.
DATA: line TYPE REF TO data.
FIELD-SYMBOLS: <wa>.
CREATE DATA line LIKE LINE OF t_table.
ASSIGN line->* TO <wa>.
OPEN DATASET p_p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT message.
IF sy-subrc EQ 0.
DO.
READ DATASET p_p_file INTO <wa>.
IF sy-subrc = 0.
APPEND <wa> TO t_table.
CLEAR <wa>.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
ENDFORM. "test
2011 Oct 18 9:01 PM
Each time my P-file value will also change. If is say follwing it dumps
PERFORM transfer: TABLES it_atc USING 'file1.txt',
TABLES it_crp USING 'file2.txt',
TABLES it_frm USING 'file3.txt''.
FORM transfer TABLES t_table
USING p_p_file.
DATA: l_message(30) TYPE c.
DATA: line TYPE REF TO data.
FIELD-SYMBOLS: <wa>.
CREATE DATA line LIKE LINE OF t_table.
ASSIGN line->* TO <wa>.
CONCATENATE sap_loc p_p_file INTO p_p_file.
OPEN DATASET p_p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT
MESSAGE l_message.
IF sy-subrc EQ 0.
DO.
READ DATASET p_p_file INTO <wa>.
IF sy-subrc = 0.
APPEND <wa> TO t_table.
CLEAR <wa>.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
break abcdef.
ENDFORM.
Edited by: jessica sam on Oct 18, 2011 11:02 PM
2011 Oct 18 9:05 PM
Could you let us know what the dump is?
You do have one too many quotes in the code you posted.
Rob
2011 Oct 18 9:11 PM
Your file names look as if they are coming from the local PC, not the ap server. Are they?
Rob
2011 Oct 18 9:12 PM
I got rid of the run time error and it works
Edited by: jessica sam on Oct 18, 2011 11:19 PM
2011 Oct 18 9:33 PM
If your question is answered, please mark it as such. It looks like the answer from Jose solved it.
Rob
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |