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 Internal Table with Dynamic Fields

Former Member
0 Likes
999

Hi all,

My scenario is fairly simple----

--> End user clicks a button on screen and he gets the list of HR tables.

--> Then selects a table and list of all the fields for that table gets displayed.

--> He/she selects the fields they want data to be retrieved for.

So, the requirement is, the dynamic internal table should get created with the fields selected.

The select statement should only retrieve fields which were selected by the end user

and from the table selected by the end user.

I believe the fields selected by end user can be passed by a variable of type string.

something like this---

select (fields)

from (p_table) " Table selected by end user

into dynamic internal table. " should contain columns selected by end user"

Appreciate your inputs and guidance.

Warm regards,

Hari Kiran

7 REPLIES 7
Read only

Former Member
0 Likes
953

Hi,

Use field symbols!!!

Regards,

Santhosh.

Read only

0 Likes
953

Hi Santosh,

I do know how to create a dynamic internal table using field symbols

based on the table name given as an input.

What I don't know is how to add the fields dynamically .

Say, for example for MARA table end user selects the fields --MATNR, MTART,MATKL,MBRSH.

So, the dynamic internal table should get created for the above table with those fields.

Next time if some other field combination is selected, then that kind of dynamic internal table

with those fields should get created.

Thank you for answering.

Warm regards,

Hari Kiran

Read only

Former Member
0 Likes
953
TYPE-POOLS :ABAP.
Parameters P_TAB      TYPE        DDOBJNAME.
DATA  : GO_LINE_TYPE  TYPE REF TO CL_ABAP_STRUCTDESCR,
        GO_TABLE_DESC TYPE REF TO CL_ABAP_TABLEDESCR,
        GS_COMPONENTS TYPE        ABAP_COMPONENTDESCR,
        GT_COMPONENTS TYPE        ABAP_COMPONENT_TAB,
        GR_TAB        TYPE REF TO DATA,
        GT_FIELDS  TYPE TABLE OF DFIES WITH HEADER LINE.
FIELD-SYMBOLS: <GT_TABLE> TYPE TABLE,
               <GS_TABLE> TYPE ANY,
               <GV_VALUE> TYPE ANY.


CALL FUNCTION 'DDIF_FIELDINFO_GET'
  EXPORTING
    TABNAME              = P_TAB
*   FIELDNAME            = ' '
*   LANGU                = SY-LANGU
*   LFIELDNAME           = ' '
*   ALL_TYPES            = ' '
*   GROUP_NAMES          = ' '
*   UCLEN                =
* IMPORTING
*   X030L_WA             =
*   DDOBJTYPE            =
*   DFIES_WA             =
*   LINES_DESCR          =
 TABLES
    DFIES_TAB            =  GT_FIELDS
*   FIXED_VALUES         =
 EXCEPTIONS
   NOT_FOUND            = 1
   INTERNAL_ERROR       = 2
   OTHERS               = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


LOOP AT GT_FIELDS.
  CLEAR GS_COMPONENTS.
  GS_COMPONENTS-NAME  = GT_FIELDS-FIELDNAME.
  GS_COMPONENTS-TYPE ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_NAME( GT_FIELDS-ROLLNAME ).
  APPEND GS_COMPONENTS TO GT_COMPONENTS.
ENDLOOP.

GO_LINE_TYPE  = CL_ABAP_STRUCTDESCR=>CREATE( GT_COMPONENTS ).
GO_TABLE_DESC = CL_ABAP_TABLEDESCR=>CREATE( GO_LINE_TYPE ).


CREATE DATA:  GR_TAB TYPE HANDLE GO_TABLE_DESC.

ASSIGN:  GR_TAB->* TO <GT_TABLE>.

SELECT * FROM (P_TAB) APPENDING CORRESPONDING FIELDS OF TABLE <GT_TABLE>.
LOOP AT <GT_TABLE> ASSIGNING <GS_TABLE>.
  NEW-LINE.
  DO.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE <GS_TABLE> TO <GV_VALUE>.
    IF SY-SUBRC NE '0'.
      EXIT.
    ENDIF.
    WRITE : <GV_VALUE>.
  ENDDO.
ENDLOOP.
Read only

0 Likes
953

Thank you Gtren..

I will go throught it.

I think this is what I want.

Thank you for replying.

Warm regards,

Hari Kiran

Read only

rainer_hbenthal
Active Contributor
0 Likes
953

Why do you want to reinvent SAP Queries? They are doing exactly what you want, and the best thing you dont need to check authoritation, cause thats handled by queries too. In your version every user can see everything - from authorization point of view catstrophic.

Use the built in features instead of reinventing the wheel.

Read only

0 Likes
953

Hi Rainer,

Basically, I am developing a custom BAPI and I will be exposing it

as a web service. Front end will be JAVA based.

so, user selects the table and the fields and

the connector then calls the custom BAPI.

The resultant data will then be FTPied using function

modules like FTP_COPY or other things can be done based on requirement.

The input for this custom BAPI therefore is the table name and the fields selected by the

end user.

Warm regards,

Hari Kiran

Read only

0 Likes
953

The Bigger Picture

Let's say there is a client who is using SAP HR for some years.

But they have not implemented ESS/MSS in their organisation.

Reasons for not using ESS/MSS are ---

1. They don't need to give too many people access to SAP.

2. They felt ESS/MSS was expensive- Each user ID will cost them.

But they would like their employees to see their Master data in a local intranet.

My code will help during initial field mapping stage.

What table data needs to be pushed out and what fields.

Entire table content will be/ can be pushed out to a third party database or

some other local database and displayed based on user account

in the local intranet.This way authorisation problem is also solved.

The program will be scheduled to run everyday.

This is totally based on client requirement.

This way its cheap.

Warm regards,

Hari Kiran

Edited by: HARI KIRAN REDDY on Jun 5, 2009 2:31 PM