Application Development 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: 

How to use function modules that take data by tables with headers in OO context?

ghawsi1901_55
Explorer

Hello everyone,

I need to use some function modules related to the assessment cycles within the OO context. e.g. KGAL_CHANGE_CYCLE, KGAL_APPEND_SEGMENT...

These function modules take data by tables with a header, i.e. DATA: itab TYPE t811c OCCURS 0 WITH HEADER LINE. So if I feed them with such a table, it works fine. Here you can see that the "IT811C" has data on its header.


Here is the code for the above scenario:

And if I feed the function module with internal tables without a header, the data will not be reachable inside the function module.

Code for the above scenario:

but the problem is that tables with headers are not allowed to be used in classes.

Now my question is "How to use these function modules in OO context?".

Thanks in advance,

Mohammad Mansoor Ghawsi

25 REPLIES 25

turkaj
Active Participant

Hello Mohammad,

try this:

 CALL FUNCTION 'KGAL_CHANGE_CYCLE'
*      EXPORTING
* testrun = ' ' TABLES it811c = lt_t811c[] it811s = lt_t811s[] it811k = lt_t811k[]

The brackets create an empty header line. So you define your table without a header line and add the brackets when you call the function module.

--> Internal Tables with Header Line

Regards
Jim

Sandra_Rossi
Active Contributor
0 Kudos

It's not said very clearly.

Square brackets doesn't say anything about "creating", it means it's not passing the header line (if any). Inside function module, due to TABLES word, the table parameters have a header line.

In fact, the problem is not about the square brackets, it's how the internal tables are declared (DATA somewhere...)

Sorry if I'm not clear too.

0 Kudos

Sandra Rossi, you are right. I need to fill the header within the function module. As you can see, with the above solution it is still empty!

Sandra_Rossi
Active Contributor
0 Kudos

ghawsi1901_55 The problem is not in subroutines. Please show line 21 of your Z class, the one which has a syntax error.

0 Kudos

the problem is not on line 21, it was just a demonstration that tables with headers are not allowed in the OO context. The problem is How do I fill the header of the tables related to the function module within a class?

Sandra_Rossi
Active Contributor

Please show line 21

Tukutupap
Participant

Mohammad,

Pass tables with no headers to the Function module.

data: t811c type table of T811C,
t811s type table of t811s,
t811k type table of t811k,
error type table of BAPIRET2.

call function 'KGAL_CHANGE_CYCLE'
* EXPORTING
* TESTRUN = ' '
tables
it811c = t811c
it811s = t811s
it811k = t811k
* IT811F =
* IT811L =
error_log = error
.

0 Kudos

I mentioned this in the second scenario of my question. If I do so, the header of IT811c will be empty and therefore it will not work.

0 Kudos

This works for me, what am I missing.


data: t811cc type table of t811c,
t811ss type table of t811s,
t811kk type table of t811k,
error type table of bapiret2.


class myclass definition.
public section.
methods:
test.
endclass.

class myclass implementation.
method test.
data: t811cc type table of t811c,
t811ss type table of t811s,
t811kk type table of t811k,
error type table of bapiret2.

select * from t811c into table t811cc.

call function 'KGAL_CHANGE_CYCLE'
* EXPORTING
* TESTRUN = ' '
tables
it811c = t811cc
it811s = t811ss
it811k = t811kk
* IT811F =
* IT811L =
error_log = error.

endmethod.
endclass.

START-OF-SELECTION.
data: tst type ref to myclass.

create object tst.
tst->test( ).

0 Kudos

The question is not about valid syntax, the question is about executing the FM KGAL_CHANGE_CYCLE, functionally speaking the FM is using the data passed through the header line of the TABLES parameter IT811C, so did you run KGAL_CHANGE_CYCLE for real, and did it produce valid functional result?

The actual problem of the OP, is that "the data will not be reachable inside the function module." (whatever it means)

0 Kudos

I understand that.

These are the first 3 lines in KGAL_CHANGE_CYCLE. Note that I have tested this and verified that the header line is indeed populated within the FM regardless of what the initial value is. However I have not been able to verify that the FM works the way is supposed to.

   CLEAR :yt811s_cd, yt811c.
REFRESH: yt811s_cd, yt811c.

READ TABLE it811c INDEX 1.

So it doesn't really matter what the header line for it811c has, what matters is that the table contains at least 1 row. Now, there are many other tables that are also passed, but I have not found a place where a header line is used without first populating it. He mentioned other function modules that I have not checked or tested, I was just trying to point this out. These FMs were recently updated, so he could be missing something.

0 Kudos

With great respect, I want to say that if you put a break point at the " CALL FUNCTION 'KGAL_CHANGE_CYCLE' ", then proceed with single step or F5 (while the debugger reached the break point), then the program will reach the following form which takes IT811c as table.

After pressing F5 once again, the function module perform "delete_cycle_definition". Inside the form the IT811c table body has one record but the header is empty, here is the problem that it look through header data not table body.

0 Kudos

Alright I'm following your steps:

1. Breakpoint on delete_cycle_definition:

2. Inside the form

Not sure what the difference is, but here are my results and in my previous comment you can see how I have encapsulated the FM in a test class.

0 Kudos

You could be missing this note: 2813898

0 Kudos

Here is my code, kindly have a look. With the below code, the table header doesn't have data!

The problem has to be in the function module code, not your code. Please make sure you have note 2813898 installed.

0 Kudos

tukutufua Bravo. It's worth posting a distinct answer concerning this SAP note, I guess it's the best answer to the OP issue.

2813898 - Allocations: Error when deleting a cycle with RFC module - SAP for Me

ghawsi1901_55 You may ask to install this note specifically and your issue will drop.

Sandra_Rossi
Active Contributor

Got it. So your question is about a standard function module that you call from your Z class and which needs to receive a header line. EDIT: to receive a TABLES parameter with its header line filled.

(as you have confirmed here🙂

You're unlucky, that's very rare that function modules use header lines as input values... 😞

I would say, first of all, could you double check that these function modules use header lines as input values?

Second, they are probably not released, could you double check whether there are other more modern/more official APIs?

Third thing, too bad, you'll have to create dummy non-class stuff to initialize the header lines, e.g. copy the standard function modules to Z ones (Z_KGAL_CHANGE_CYCLE, Z_KGAL_APPEND_SEGMENT, etc.), add parameters dedicated to header lines.

FUNCTION Z_KGAL_CHANGE_CYCLE.
* IMPORTING
*   IS_T811C TYPE T811C <====== NEW PARAMETER
*   ...
* TABLES
*   IT811C STRUCTURE T811C
*   ...
  it811c = is_t811c.
  it811s = is_t811s.
  it811k = is_t811k.
  CALL FUNCTION 'KGAL_CHANGE_CYCLE'
    ...
    TABLES
      it811c = it811c
      it811s = it811s
      it811k = it811k
    ...

Now you may call it from your class and there is no syntax error:

CALL FUNCTION 'Z_KGAL_CHANGE_CYCLE'
  EXPORTING
    is_t811c = ... " <=== header line of parameter TABLES it811c
    ...
  TABLES
    it811c = ...
    ...

If you pass a table w/o header line to an FM that expects a table with a header line the header line will be added inside the function module. Or at least that has been my experience so far.

The key is whether the function module expects a value on the header line from the beginning or not. If yes, then unfortunately this approach is what's needed to make the code work.

In this case though, it looks like this FM reads row 1 of the table being passed and puts that record in the work area, so I don't think any of this is needed for this particular FM. As long as the table has 1 row this should work.

0 Kudos

tukutufua

I have edited my answer, including the actual OP question (obtained from one of OP comments).

The core of the question is "how to pass header line of TABLES parameter when calling function module or form from ABAP class".

I didn't look at this particular standard FM, I trust the OP assertion, I answered generically. As you have looked at this particular standard FM, you'd better move your comment into your own answer (just saying "do this it will work without any explanation why by doing this it will work" did not convince me), because if you're right, your answer will be more relevant than mine, concerning this particular standard FM.

0 Kudos

ghawsi1901_55

According to Vicente, your assumption is wrong, the function modules you are talking about don't need the header line. You should investigate more and discuss with Vicente to understand why you can't make it work without the header line but Vicente can.

0 Kudos

Sandra Rossi

I analyzed the function module through debugging a lot. The only thing that I need is to fill the header and we are good to go.

Why? because inside the function module the table name and the header are same. in some points it reads data from the header but in some other points it loops through the main content.

Here, if I change the IT811c-TAB value, the header data will change too, not the main content.

0 Kudos

At the attached screenshot you can see that, it cleared the header data on line 585. and in line 596 looped through main content of the table.

Sandra_Rossi
Active Contributor
0 Kudos

I don't understand "the data will not be reachable inside the function module."

Just to know if you are correct or not in thinking that these FMs need to receive values in header lines of tables, what is the real symptom of these FMs not receiving values in header lines of tables? How have you realized that something was wrong?

ghawsi1901_55
Explorer
0 Kudos

"The data will not be reachable inside the function module." accept my apologies that is was not much clear, I meant that the header will be empty not the table body. and because of the header usage inside the function module, it will not work fine.