ABAP Select data from SAP table TPDA_SCRIPT_ORIGIN into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP TPDA_SCRIPT_ORIGIN table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to TPDA_SCRIPT_ORIGIN. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the TPDA_SCRIPT_ORIGIN table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_TPDA_SCRIPT_ORIGIN TYPE STANDARD TABLE OF TPDA_SCRIPT_ORIGIN,
      WA_TPDA_SCRIPT_ORIGIN TYPE TPDA_SCRIPT_ORIGIN,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: <TPDA_SCRIPT_ORIGIN> TYPE TPDA_SCRIPT_ORIGIN.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_TPDA_SCRIPT_ORIGIN.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM TPDA_SCRIPT_ORIGIN
  INTO TABLE IT_TPDA_SCRIPT_ORIGIN.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM TPDA_SCRIPT_ORIGIN
*  INTO TABLE @DATA(IT_TPDA_SCRIPT_ORIGIN2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_TPDA_SCRIPT_ORIGIN INDEX 1 INTO DATA(WA_TPDA_SCRIPT_ORIGIN2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_TPDA_SCRIPT_ORIGIN ASSIGNING <TPDA_SCRIPT_ORIGIN>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<TPDA_SCRIPT_ORIGIN>-FILE_NAME = 1.
<TPDA_SCRIPT_ORIGIN>-CUSER = 1.
<TPDA_SCRIPT_ORIGIN>-CDATE = 1.
<TPDA_SCRIPT_ORIGIN>-CTIME = 1.
<TPDA_SCRIPT_ORIGIN>-SCRIPT_CLASS = 1.
ENDLOOP.

LOOP AT IT_TPDA_SCRIPT_ORIGIN INTO WA_TPDA_SCRIPT_ORIGIN.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_TPDA_SCRIPT_ORIGIN-SCRIPT_COMMENT, sy-vline,
WA_TPDA_SCRIPT_ORIGIN-WRITES_TRACE, sy-vline,
WA_TPDA_SCRIPT_ORIGIN-NO_BREAK, sy-vline,
WA_TPDA_SCRIPT_ORIGIN-BP_REACHED, sy-vline,
WA_TPDA_SCRIPT_ORIGIN-WP_REACHED, sy-vline,
WA_TPDA_SCRIPT_ORIGIN-SINGLE_STEP, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TPDA_SCRIPT_ORIGIN you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_TPDA_SCRIPT_ORIGIN TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_TPDA_SCRIPT_ORIGIN INTO WA_TPDA_SCRIPT_ORIGIN. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_TPDA_SCRIPT_ORIGIN_STR,
FILE_NAME TYPE STRING,
CUSER TYPE STRING,
CDATE TYPE STRING,
CTIME TYPE STRING,
SCRIPT_CLASS TYPE STRING,
SCRIPT_COMMENT TYPE STRING,
WRITES_TRACE TYPE STRING,
NO_BREAK TYPE STRING,
BP_REACHED TYPE STRING,
WP_REACHED TYPE STRING,
SINGLE_STEP TYPE STRING,
NEW_ROLLAREA TYPE STRING,
SINGLE_RUN TYPE STRING,
SYSTDBG TYPE STRING,
CLOSEDEBF8 TYPE STRING,
SYNCBPS TYPE STRING,
EXCCREATEOBJECT TYPE STRING,
UPDATEDEBUG TYPE STRING,
BTCDEBUG TYPE STRING,
EMODESTACK TYPE STRING,
ESI TYPE STRING,
ACFLUSH TYPE STRING,
SOAAC TYPE STRING,
CHECKREADBINARY TYPE STRING,
LAYERCONTROL TYPE STRING,
OBJECT_NAME TYPE STRING,
DATATEMPERATURE TYPE STRING,END OF T_EKKO_STR. DATA: WA_TPDA_SCRIPT_ORIGIN_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-FILE_NAME sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-CUSER sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-CDATE sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-CTIME sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-SCRIPT_CLASS sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-SCRIPT_COMMENT sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-WRITES_TRACE sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-NO_BREAK sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-BP_REACHED sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-WP_REACHED sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-SINGLE_STEP sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-NEW_ROLLAREA sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-SINGLE_RUN sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-SYSTDBG sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-CLOSEDEBF8 sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-SYNCBPS sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-EXCCREATEOBJECT sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-UPDATEDEBUG sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-BTCDEBUG sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-EMODESTACK sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-ESI sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-ACFLUSH sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-SOAAC sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-CHECKREADBINARY sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-LAYERCONTROL sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-OBJECT_NAME sy-vline
WA_TPDA_SCRIPT_ORIGIN_STR-DATATEMPERATURE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.