Application Development and Automation 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: 
Read only

Dynamic table declaration in FM

Former Member
0 Likes
2,434

Hi Geeks,

I am calling a FM from a program where the FM should get the structure data and set that data into a single line with delimiters and send it out. The table structure can be anything. So how can I declare that table structure data (in tables tab in FM). Could somebody help me with this.

Thanks,

Kiran.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,883

Ok, so which approach did you try, what does the dump say, and you may want to post the code of the function module, and/or is interface definition.

Regards,

Rich Heilman

10 REPLIES 10
Read only

Former Member
0 Likes
1,883

Hi Kiran, try this code.

Try this piece of code:

REPORT YDEMO .

PARAMETERS: TBLNAME(50). "DEFAULT 'SPFLI'.

DATA: TOTAL_ROWS TYPE P.

SELECT COUNT(*) FROM (TBLNAME) INTO TOTAL_ROWS.

WRITE: / TBLNAME, TOTAL_ROWS.

cheers,

Hema.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,883

In the function module interface, do not assign a TYPE for the table if you are using a TABLES parameter. If you are passing the table in the IMPORTING and EXPORTING parameters, then you will want to type it as STANDARD TABLE. This allows you to pass a table with any structure. Once inside the function module you will then need to read this table using field symbols.

Regards,

Rich Heilman

Read only

0 Likes
1,883

Hi Rich,

I tried this but when calling this FM from a program its giving me a short dump.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,883

Just give the name of the internal table, don't give any type to this parameter.

Then in the source you will have to use dynamic assignment to access records and fields.

Regards

Read only

0 Likes
1,883

Hi Raymond,

Tried this as well..But still giving me a short dump..

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,883

So inside your function module then, you can read the importing table and then build the output table, maybe using comma as your delimiter. Here IM_TAB is the imcoming table. You can pass LT_DATA back out via an EXPORTING parameter or TABLES parameter



FIELD-SYMBOLS: <fs_im_tab> TYPE ANY,
               <fs_comp>   type any.

DATA: lt_data TYPE TABLE OF string.
DATA: ls_data TYPE string.


LOOP AT im_tab ASSIGNING <fs_im_tab> .
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE <fs_im_tab> TO <fs_comp>.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    IF sy-index = 1.
      ls_data = <fs_comp>.
    ELSE.
      CONCATENATE ls_data <fs_comp> INTO ls_data SEPARATED BY ','.
    ENDIF.
  ENDDO.
  APPEND ls_data TO lt_data.
ENDLOOP.


Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,884

Ok, so which approach did you try, what does the dump say, and you may want to post the code of the function module, and/or is interface definition.

Regards,

Rich Heilman

Read only

0 Likes
1,883

Hi Rich,

Thanks a lot for your help. Here is the code.

PARAMETERS p_delim TYPE sy-input OBLIGATORY DEFAULT '|'.

DATA: rec_hdr TYPE zwm_sch_waybill_fhdr.

DATA: rec_a01 TYPE zwm_sch_waybill_a01.

DATA: rec_a02 TYPE zwm_sch_waybill_a02.

DATA: rec_b01 TYPE zwm_sch_waybill_b01.

DATA: rec_b02 TYPE zwm_sch_waybill_b02.

DATA: rec_b03 TYPE zwm_sch_waybill_b03.

DATA: rec_b04 TYPE zwm_sch_waybill_b04.

DATA: rec_c01 TYPE zwm_sch_waybill_c01.

DATA: rec_c02 TYPE zwm_sch_waybill_c02.

DATA: rec_c03 TYPE zwm_sch_waybill_c03.

DATA: rec_d01 TYPE zwm_sch_waybill_d01.

DATA: rec_d02 TYPE zwm_sch_waybill_d02.

DATA: rec_d03 TYPE zwm_sch_waybill_d03.

DATA: rec_d04 TYPE zwm_sch_waybill_d04.

DATA: rec_e01 TYPE zwm_sch_waybill_e01.

DATA: rec_e02 TYPE zwm_sch_waybill_e02.

DATA: rec_e03 TYPE zwm_sch_waybill_e03.

DATA: rec_e04 TYPE zwm_sch_waybill_e04.

DATA: rec_f01 TYPE zwm_sch_waybill_f01.

DATA: rec_g01 TYPE zwm_sch_waybill_g01.

DATA: rec_ftr TYPE zwm_sch_waybill_fftr.

DATA: rec_fixed TYPE string.

DATA: rec_delimited TYPE string.

DATA: BEGIN OF rec_struc OCCURS 0.

INCLUDE STRUCTURE zfile_struc.

DATA: END OF rec_struc.

rec_hdr-rectype = 'FHDR' .

rec_hdr-filetype = 'LP' .

rec_hdr-fformat = 'DLM' .

rec_hdr-partenrid = 'SCEE' .

rec_hdr-testmode = 'T' .

rec_hdr-docver = 7 .

rec_hdr-ftimezone = 'GMT' .

rec_hdr-ftimestamp = 20081801110244 .

rec_hdr-dummy1 = '0000000000' .

rec_a01-rectype = 'A01' .

rec_a01-doctype = 'LP' .

rec_a01-waybno = 1234567890 .

rec_a01-clirefno1 = 'Sender ref 1' .

rec_a01-clirefno2 = 'Sender ref 2' .

rec_a01-clireftype = 5 .

rec_a01-msgfunc = 6 .

rec_a02-rectype = 'A02' .

rec_a02-clisendate = 20080118 .

rec_a02-clideliverdate = '' .

rec_a02-clisentime = '11:08' .

rec_a02-clidelivertime = '' .

rec_b01-rectype = 'B01' .

rec_b01-sendcc = 'PL' .

rec_b01-sendid = 1234567 .

rec_b01-sendsop = 9999999 .

rec_b02-rectype = 'B02' .

rec_b02-sendpost = '12-345' .

rec_b02-senddept = '' .

rec_b02-sendcity = '' .

rec_b02-sendstreet = 'Streetname' .

rec_ftr-rectype = 'FFTR' .

rec_ftr-filedocs = 99 .

PERFORM delimit USING rec_hdr.

PERFORM delimit USING rec_a01.

PERFORM delimit USING rec_a02.

PERFORM delimit USING rec_b01.

PERFORM delimit USING rec_b02.

PERFORM delimit USING rec_ftr.

FORM delimit USING inrec.

*----


data: v_length type sy-tleng.

CALL FUNCTION 'Z_FILENAME_CONTENT_SETUP'

EXPORTING

delimiter = p_delim

IMPORTING

delimited_data = rec_delimited

length = v_length

TABLES

struc = inrec

.

Importing declaration

rec_delimited type string

length type sy-tleng

exporting declaration

delimiter like sy-input

tables dec

struc type standard table

The data I am passing is a structure and not a table but in the FM we have to declare it as internal table.

Thanks,

Kiran.

Read only

0 Likes
1,883

You definitly have a few issues here my friend. First, if you have the structure INREC, you need to APPEND this line to an internal table in order to pass this via the TABLES parameter, trying to pass this INREC is probably producing your dump, you need to pass an internal table when using the TABLES parameters, otherwise you need to pass this via the IMPORTING parameters.

Regards,

Rich Heilman

Read only

0 Likes
1,883

Thanks a lot Rich. I will try to process it as an internal table because I have to use a delimiter between all the fields in the structure before outputting it.