2018 Nov 11 5:16 PM
Hi,
I wrote a report which I had to use the perform statement but I need now to move the code of that report into my class, unfortunately I just saw that you cannot implement a subroutine inside a method so what i did was to create a method to handle that.
The problem is that now the code is not working like it should work.
The report had to upload the file and parse the xml in it string by string.
I'll show you my program so maybe you can help me.
Here is the report:
perform upload_file. "It's for uploading the data from the xml to a string variable
perform parse_xml.
Form parse_xml.
CASE pnode->get_type( ).
WHEN if_ixml_node=>co_node_element.
string = pnode->get_name( ).
attribs = pnode->get_attributes( ).
CLEAR attrib_value.
CASE string.
*This is done for every string to get data from the xml.
WHEN 'identifier'.
CLEAR ss.
ss = pnode->get_value( ).
ls_context-identifier = ss.
APPEND ls_context TO lt_context.
endcase.
endcase.
pnode = pnode->get_first_child( ).
* then I am using while loop
WHILE NOT pnode IS INITIAL.
PERFORM parse_xml USING pnode.
pnode = pnode->get_next( ).
ENDWHILE.
endform.
This way it's working fine and not having any issues.
Now I have to move it to my class and that's where it becomes difficult since i cannot have a perform.
I used the same code calling the same method inside the method.
endcase
pnode = pnode->get_first_child( ).
WHILE NOT pnode IS INITIAL.
CALL METHOD zcl_xblr_dca=>parse_xml
EXPORTING
pnode = pnode
lv_output = lv_output
.
pnode = pnode->get_next( ).
ENDWHILE.
But it passes some xml tags.
Do you know any other ways to use a subroutine inside a class ?
2018 Nov 11 6:11 PM
Can you please copy and paste the complete code as that would be helpful for everyone. Apart from that I have few suggestions that might help you..
In the first piece of code you have subroutine parse_xml with no "using parameters" and then you are calling another subroutine by same name "parse_xml" with using parameter as "pnode". Both are different subroutines, hope you have created separate methods for them with meaningful different name.
And for the second piece of code, can you check if it's pass by reference or pass by value..?
2018 Nov 12 6:55 AM
You can call a subroutine from within a method by using the following statement:
PERFORM <subroutine> IN PROGRAM <program/include of subroutine>.