3
votes

I'm working on an Enhancement Implantation on ZXMBCU10 which is called in a custom program couple of levels down the execution path. Inside ZXMBCU10 I want to access the a table in the parent program, which I do in the following method;

  1. Declare the parent program name;

    DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.

  2. Getting the value through field symbol assignment.

    FIELD-SYMBOLS: <fs> TYPE any.

    ASSIGN (ex_tbl_name) TO <fs>.

Then I check for successful assignment (which is true).

IF <fs> IS ASSIGNED.

Accessing parent table

Problem I have is how to read the data in the <fs> field symbol.

I've tried LOOP and READ TABLE, but getting the following;

Loop and Read table sample

Both Read Table and Loop is added here just to get the syntax checks

LOOP;

Internal table "<FS>" has no header line - one of the additions "INTO wa", "ASSIGNING", "REFERENCE INTO", "TRANSPORTING NO FIELDS" required. required.

READ TABLE;

You cannot use explicit or implicit index operations on tables with types "HASHED TABLE" or "ANY TABLE". "<FS>" has the type "ANY TABLE". It is possible that the "TABLE" addition was not specified before "<FS>".

2
Based on your description, it's impossible to get the message you show for LOOP AT. Could you provide a compilable code so that your issue can be reproduced. Thank you. (PS: the message you get for READ TABLE corresponds to your description) - Sandra Rossi
I agree with @SandraRossi. There is not enough information on the question to derive the solution. - Umar Abdullah
@SandraRossi and Umar Abdullah i've updated the question. Hope that it's more clearer now. - Isuru
@isuru Thanks. What I meant is just a copy/paste of your LOOP AT code to help others reproduce the problem. Sorry to have said "compilable" because it's not relevant in your case, so help us reproduce the syntax error. - Sandra Rossi
@SandraRossi added the rest of the code. I've written both the Read table and the loops, just to get the syntax error thrown. Thanks a bunch for the continued interest :) - Isuru

2 Answers

3
votes

LOOP AT

The error about LOOP AT (Internal table "<FS>" has no header line - one of the additions "INTO wa", "ASSIGNING", "REFERENCE INTO", "TRANSPORTING NO FIELDS" required), is that you don't indicate the "result" part of LOOP AT i.e. ASSIGNING, REFERENCE INTO... (as said in the message).

For a field symbol, LOOP AT alone is always invalid, and if it's a variable instead of a field symbol it's obsolete because that would imply the use of a header line.

LOOP AT <fs>. " always invalid !

A valid syntax could be as follows: you must declare the field symbol as being an internal table (with at least the word TABLE, or refer to a "Table Type"), any category of internal table is supported for LOOP AT (hashed, sorted, standard), so you can use TYPE ANY TABLE :

DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.
FIELD-SYMBOLS: <fs> TYPE ANY TABLE.

ASSIGN (ex_tbl_name) TO <fs>.
LOOP AT <fs> ASSIGNING FIELD-SYMBOL(<line>).
ENDLOOP.

READ TABLE

The error about READ TABLE (You cannot use explicit or implicit index operations on tables with types "HASHED TABLE" or "ANY TABLE". "<FS>" has the type "ANY TABLE". It is possible that the "TABLE" addition was not specified before "<FS>") is that you used READ TABLE ... INDEX ... whose INDEX means that it can only be used with an internal table with category SORTED or STANDARD.

The next code is invalid because of the combination of ANY TABLE and READ TABLE INDEX, because <FS> could eventually be a hashed internal table (who knows), then READ TABLE INDEX would fail, hence the compiler error:

DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.
FIELD-SYMBOLS: <fs> TYPE ANY TABLE. " <=== impossible with READ TABLE INDEX !

ASSIGN (ex_tbl_name) TO <fs>.
READ TABLE <fs> ASSIGNING FIELD-SYMBOL(<line>) INDEX 1. " <=== impossible with ANY TABLE !

Solution: to use READ TABLE <fs> INDEX ... you may declare the field-symbol as SORTED, STANDARD, or INDEX (the latter is a generic name corresponding to SORTED and STANDARD).

This code is valid:

DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.
FIELD-SYMBOLS: <fs> TYPE INDEX TABLE.

ASSIGN (ex_tbl_name) TO <fs>.
READ TABLE <fs> ASSIGNING FIELD-SYMBOL(<line>) INDEX 1.

Of course, it's assumed that G_TAB is an "index" table, not a hashed table!

PS: in your code you used INTO DATA(lv_fs) but usually if you have a generic internal table ASSIGNING is preferred.

2
votes

change field symbol type to

any table.

instead of:

any.