cancel
Showing results for 
Search instead for 
Did you mean: 

Forms in function module

Former Member
0 Kudos

Hello,

I am new to ABAP and i am trying to loop through one table and make another table if certain fields match. Here is my code. It does not work Any help would be greatly appreciated.

FUNCTION Z_ORGBUILDER_CONN.

*"----


""Local interface:

*" IMPORTING

*" VALUE(OTYPE) LIKE OBJEC-OTYPE

*" VALUE(OBJID) LIKE OBJEC-OBJID

*" VALUE(PATHID) LIKE GDSTR-WEGID

*" VALUE(PLVAR) LIKE OBJEC-PLVAR

*" EXPORTING

*" VALUE(RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2

*" TABLES

*" L_ZCONN_TAB TYPE ZCONN_TAB

*" RESULT_TAB STRUCTURE SWHACTOR OPTIONAL

*" RESULT_OBJEC STRUCTURE OBJEC OPTIONAL

*" RESULT_STRUC STRUCTURE STRUC OPTIONAL

*" L_ZCONN_TAB1 TYPE ZCONN_TAB

*"----


DATA: z_struc type zconn_struc.

DATA: OBJectID type struc-objid.

DATA: pointer type struc-pup.

CALL FUNCTION 'RH_STRUC_GET'

EXPORTING

act_otype = otype

act_objid = objid

act_plvar = plvar

act_wegid = pathid

TABLES

result_tab = result_tab

result_struc = result_struc

result_objec = result_objec

EXCEPTIONS

no_plvar_found = 1

no_entry_found = 2

OTHERS = 3.

IF sy-subrc <> 0.

RAISE no_roots_found.

ENDIF.

LOOP AT result_struc.

z_struc-objectID = result_struc-OBJID.

z_struc-pointer = result_struc-PUP.

Append z_struc to l_zconn_tab.

ENDLOOP.

LOOP AT l_zconn_tab.

objectid = l_zconn_tab-OBJectID.

pointer = l_zconn_tab-pointer.

PERFORM FIND_PARENT using objectID

pointer

changing l_zconn_tab1.

endloop.

ENDFUNCTION.

FORM FIND_PARENT using u_objectID like objectID

u_pointer like pointer

changing c_zconn_tab like l_zconn_tab1.

LOOP AT result_struc.

if result_struc-pup = u_pointer.

z_struc-objectID = u_objectID.

z_struc-parentID = result_struc-objid.

endif.

Append z_struc to l_zconn_tab.

ENDLOOP.

ENDFORM.

View Entire Topic
Former Member
0 Kudos

Mark,

I am not very clear what are you trying to do.

However in your code, you do have a problem.

In the loop of the internal table l_zconn_tab, you are calling form FIND_PARENT .

There are problems here.

1. You are passing a table l_zconn_tab1, which I can't find anywhere.

2. Inside the FORM you are appending rows to the same table l_zconn_tab, which is the same as the table which you are looping at. That means that you are appending rows to the same table which you looping at. That means if the rows are getting appended this loop will be infinite.

3. The actual parameter to the form c_zcomm_tab is not being utilized at all. Probably inside the form you might want to append rows to this table.

I am not sure if this solves your problem as I am not getting what you are trying to do.

Let me know if this helps,

Regards,

Ravi

NOte : Please reward points if this helps.

Former Member
0 Kudos

Hi Ravi,

Thanks for your reply. As I said I am very new to ABAP. Here is what I am trying to do. The function RH_STRUC_GET returns three tables. One of these tables "RESULT_STRUC" is basically TYPE STRUC. It contains fields such as SQNR, OBJID, PUP etc. PUP is the pointer which contains an integer which corresponds to SQNR which shows who the parent of the objid is.

So I am trying to create a new table that contains two fields, objid and its parent's objid. Since all the information is in one table i am not sure how to do it.

I hope I made myself clear :). Thanks for your help!!

Mark.

Former Member
0 Kudos

Mark,

I am not still clear about the logic.

Here is what I suggest. Use one single loop.

Loop at <Internal table> into workarea1.

process the data.

Read table <Internal table into workarea2 with key condition.

Process the data.

endloop.

I think this should suffice, try it out.

Regards,

Ravi

Former Member
0 Kudos

when I do read table, do I get the whole row or can I just take the columns that I am interested in? Like I am only interesed in OBJID.

Could you please show me an example of how would it work?

Thanks a lot!!

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I guess I might be missing something, all you need to do is read the table with a key into a different work area, then move the values in to your structure and append to new table.



FUNCTION Z_ORGBUILDER_CONN.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(OTYPE) LIKE OBJEC-OTYPE
*" VALUE(OBJID) LIKE OBJEC-OBJID
*" VALUE(PATHID) LIKE GDSTR-WEGID
*" VALUE(PLVAR) LIKE OBJEC-PLVAR
*" EXPORTING
*" VALUE(RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2
*" TABLES
*" L_ZCONN_TAB TYPE ZCONN_TAB
*" RESULT_TAB STRUCTURE SWHACTOR OPTIONAL
*" RESULT_OBJEC STRUCTURE OBJEC OPTIONAL
*" RESULT_STRUC STRUCTURE STRUC OPTIONAL
*" L_ZCONN_TAB1 TYPE ZCONN_TAB
*"----------------------------------------------------------------------

DATA: z_struc type zconn_struc.


DATA: OBJectID type struc-objid.
DATA: pointer type struc-pup.

CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = otype
act_objid = objid
act_plvar = plvar
act_wegid = pathid

TABLES
result_tab = result_tab
result_struc = result_struc
result_objec = result_objec
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.

IF sy-subrc <> 0.
RAISE no_roots_found.
ENDIF.

<b>LOOP AT result_struc into xresult_struc.

read table result_struc into yresult_struc
         with key pup = xresult_struc-pup.
if sy-subrc = 0.
z_struc-objectID = xresult_struc-OBJID.
z_struc-parentID = yresult_struc-objid.
endif.

Append z_struc to l_zconn_tab.

ENDLOOP.</b>

ENDFUNCTION.

Regards,

Rich Heilman

Former Member
0 Kudos

Mark,

You will have to read the entire row. consider this example.

Read table itab into workarea2 with key (condition)

If sy-subrc = 0.

Now you can process the field whichever you want from the workarea2.

You can address the field by workarea2-objid. Same will be applicable for other fields.

endif.

Regards,

Ravi

Former Member
0 Kudos

Rich,

Thanks, I tried this earlier with work areas but i keep getting this error that

"line of result_struc and Yresult_struc-objid are not mutually convertible in unicode program"

Mark

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Sorry, I had a typo.....




read table result_struc into <b>yresult_struc</b>
         with key pup = xresult_struc-pup.


Please make sure that you award points for the helpful answers.

Regards,

Rich Heilman

Former Member
0 Kudos

Mark,

I think it is because, looks like, you were tyring to pass a field to an entire structure.

result_struc is structure/table where yresult_struc-objid is a single field.

Regards,

Ravi

Former Member
0 Kudos

Thanks a lot Rich and Ravi. Your solutions did help. I will post more questions if I get stuck.

Former Member
0 Kudos

How do I award points? I dont see the radio buttons for rewards anymore!!!!

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

There should be some stars next to the posts. Please award points for all helpful answers. If you problem is solved, make sure to mark as "solved". Thanks.

Regards,

Rich Heilman

Former Member
0 Kudos

for some reason I dont see any stars...for the rewards. May be I will log out and try to log back in.

~Mark

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

That's weird. Try again later, then. Let us know if the solution works for you.

Regards,

Rich Heilman