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

Call transformation with dynamic table

Former Member
0 Likes
974

Hi

i have some xml file and they never have the same structure si is it possible to call transformation with dynamic table ?

thanks for your replies

serge

DATA : gv_read_xml TYPE string.

move '/tmp/xml/HLC5400409010.xml' to file.

  OPEN DATASET file FOR INPUT IN binary mode.

    READ DATASET file INTO gv_read_xml."WA_TX.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

  CLOSE DATASET filename.

call transformation ('ID') SOURCE XML gv_read_xml result tab = t[].

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
648

Hello,

U can try with this Code,

FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,

<FS_1> TYPE TABLE,

<FS_2> TYPE ANY,

<FS_3> TYPE ANY,

<FS_5> TYPE ANY.

DATA: NEW_LINE TYPE REF TO DATA.

DATA: LT_DATA TYPE REF TO DATA.

**dynamic table creation for data

ASSIGN LT_DATA TO <FS_DATA>.

  • Create a new Table

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = IT_FIELDCAT

IMPORTING

EP_TABLE = <FS_DATA>

EXCEPTIONS

GENERATE_SUBPOOL_DIR_FULL = 1

OTHERS = 2.

IF SY-SUBRC = 0.

ASSIGN <FS_DATA>->* TO <FS_1>.

CREATE DATA NEW_LINE LIKE LINE OF <FS_1>.

      • A field-symbol to access that work area

ASSIGN NEW_LINE->* TO <FS_2>.

**MOVE DATA

LOOP AT IT_OUTTAB INTO WA_OUTTAB.

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'

EXPORTING

INPUT = WA_OUTTAB-PSPID

IMPORTING

OUTPUT = WA_OUTTAB-PSPID.

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'

EXPORTING

INPUT = WA_OUTTAB-POSID

IMPORTING

OUTPUT = WA_OUTTAB-POSID.

LOOP AT G_T_FIELDCAT INTO G_R_FIELDCAT

WHERE NO_OUT IS INITIAL

AND TECH IS INITIAL.

ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE

WA_OUTTAB TO <FS_5>.

ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE

<FS_2> TO <FS_3>.

<FS_3> = <FS_5>.

ENDLOOP.

INSERT <FS_2> INTO TABLE <FS_1>.

ENDLOOP.

ELSE.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE.

IF SY-SUBRC EQ 0.

LOOP AT <FS_1> ASSIGNING <FS_2>.

TRANSFER <FS_2> TO P_FILE.

ENDLOOP.

ELSE.

MESSAGE E041(S9) WITH P_FILE.

ENDIF.

CLOSE DATASET P_FILE.

ENDFORM. " download_file

If useful reward the points.

Regards,

Vasanth

Hi

i have some xml file and they never have the same structure si is it possible to call transformation with dynamic table ?

thanks for your replies

serge

DATA : gv_read_xml TYPE string.

move '/tmp/xml/HLC5400409010.xml' to file.

  OPEN DATASET file FOR INPUT IN binary mode.

    READ DATASET file INTO gv_read_xml."WA_TX.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

  CLOSE DATASET filename.

call transformation ('ID') SOURCE XML gv_read_xml result tab = t[].

2 REPLIES 2
Read only

Former Member
0 Likes
649

Hello,

U can try with this Code,

FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,

<FS_1> TYPE TABLE,

<FS_2> TYPE ANY,

<FS_3> TYPE ANY,

<FS_5> TYPE ANY.

DATA: NEW_LINE TYPE REF TO DATA.

DATA: LT_DATA TYPE REF TO DATA.

**dynamic table creation for data

ASSIGN LT_DATA TO <FS_DATA>.

  • Create a new Table

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = IT_FIELDCAT

IMPORTING

EP_TABLE = <FS_DATA>

EXCEPTIONS

GENERATE_SUBPOOL_DIR_FULL = 1

OTHERS = 2.

IF SY-SUBRC = 0.

ASSIGN <FS_DATA>->* TO <FS_1>.

CREATE DATA NEW_LINE LIKE LINE OF <FS_1>.

      • A field-symbol to access that work area

ASSIGN NEW_LINE->* TO <FS_2>.

**MOVE DATA

LOOP AT IT_OUTTAB INTO WA_OUTTAB.

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'

EXPORTING

INPUT = WA_OUTTAB-PSPID

IMPORTING

OUTPUT = WA_OUTTAB-PSPID.

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'

EXPORTING

INPUT = WA_OUTTAB-POSID

IMPORTING

OUTPUT = WA_OUTTAB-POSID.

LOOP AT G_T_FIELDCAT INTO G_R_FIELDCAT

WHERE NO_OUT IS INITIAL

AND TECH IS INITIAL.

ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE

WA_OUTTAB TO <FS_5>.

ASSIGN COMPONENT G_R_FIELDCAT-FIELDNAME OF STRUCTURE

<FS_2> TO <FS_3>.

<FS_3> = <FS_5>.

ENDLOOP.

INSERT <FS_2> INTO TABLE <FS_1>.

ENDLOOP.

ELSE.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE.

IF SY-SUBRC EQ 0.

LOOP AT <FS_1> ASSIGNING <FS_2>.

TRANSFER <FS_2> TO P_FILE.

ENDLOOP.

ELSE.

MESSAGE E041(S9) WITH P_FILE.

ENDIF.

CLOSE DATASET P_FILE.

ENDFORM. " download_file

If useful reward the points.

Regards,

Vasanth

Read only

Former Member
0 Likes
648

Hi serge,

1. If that is the case,

then i think,

we should probably know on the first instance,

what will be the structure of the xml data.

2. If we know the structure,

then probably we can either HARDCODE

the different internal tables with different structures,

and accordingly use CALL TRANSFORMATION.

regards,

amit m.