ABAP Select data from SAP table CNVMBTPROCTREE_STR 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 CNVMBTPROCTREE_STR 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 CNVMBTPROCTREE_STR. 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 CNVMBTPROCTREE_STR 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_CNVMBTPROCTREE_STR TYPE STANDARD TABLE OF CNVMBTPROCTREE_STR,
      WA_CNVMBTPROCTREE_STR TYPE CNVMBTPROCTREE_STR,
      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: <CNVMBTPROCTREE_STR> TYPE CNVMBTPROCTREE_STR.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CNVMBTPROCTREE_STR
*  INTO TABLE @DATA(IT_CNVMBTPROCTREE_STR2).
*--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_CNVMBTPROCTREE_STR INDEX 1 INTO DATA(WA_CNVMBTPROCTREE_STR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CNVMBTPROCTREE_STR ASSIGNING <CNVMBTPROCTREE_STR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CNVMBTPROCTREE_STR>-PHASE = 1.
<CNVMBTPROCTREE_STR>-ACTIVITY_ID = 1.
<CNVMBTPROCTREE_STR>-TLEVEL = 1.
<CNVMBTPROCTREE_STR>-PARENT_ID = 1.
<CNVMBTPROCTREE_STR>-NEXT_ID = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CNVMBTPROCTREE_STR-PROC_VIEW, sy-vline,
WA_CNVMBTPROCTREE_STR-OPTIONAL, sy-vline,
WA_CNVMBTPROCTREE_STR-USED_VARIANT, sy-vline,
WA_CNVMBTPROCTREE_STR-MANUAL_STS_ALLWD, sy-vline,
WA_CNVMBTPROCTREE_STR-ACTIVITY_TYPE, sy-vline,
WA_CNVMBTPROCTREE_STR-EXEC_TARGET, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CNVMBTPROCTREE_STR 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_CNVMBTPROCTREE_STR 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_CNVMBTPROCTREE_STR INTO WA_CNVMBTPROCTREE_STR. *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_CNVMBTPROCTREE_STR_STR,
PHASE TYPE STRING,
ACTIVITY_ID TYPE STRING,
TLEVEL TYPE STRING,
PARENT_ID TYPE STRING,
NEXT_ID TYPE STRING,
PROC_VIEW TYPE STRING,
OPTIONAL TYPE STRING,
USED_VARIANT TYPE STRING,
MANUAL_STS_ALLWD TYPE STRING,
ACTIVITY_TYPE TYPE STRING,
EXEC_TARGET TYPE STRING,
EXEC_TYPE TYPE STRING,
TCODE TYPE STRING,
PROGNAME TYPE STRING,
FUNCNAME TYPE STRING,
RERUN TYPE STRING,
NO_STATE_MNGMT TYPE STRING,
DOCU_TYPE TYPE STRING,
DOCUMENT_LINK TYPE STRING,
RESTART_ALLOWED TYPE STRING,
USER_DIALOG TYPE STRING,
RSFLAG1 TYPE STRING,
COMPONENT_NAME TYPE STRING,
APPLICATION_NAME TYPE STRING,
CHECK_FUNCNAME TYPE STRING,
NODE_TEXT TYPE STRING,
EXEC_NUM TYPE STRING,
STATE_TEC TYPE STRING,
STATE_LOG TYPE STRING,
ABORTED TYPE STRING,
RUNMODE TYPE STRING,
STARTTIME TYPE STRING,
ENDTIME TYPE STRING,
DURATION TYPE STRING,
DESTINATION TYPE STRING,
JOBNAME TYPE STRING,
JOBCOUNT TYPE STRING,
EXEC_SERVER TYPE STRING,
EXEC_PROCID TYPE STRING,
REC_SELECT TYPE STRING,
REC_RELEVANT TYPE STRING,
REC_READ TYPE STRING,
REC_CONV TYPE STRING,
REC_UPD TYPE STRING,
REC_INS TYPE STRING,
REC_TRANS TYPE STRING,
REC_SKIPPED TYPE STRING,
LOGNUMBER TYPE STRING,
SESSION_ID TYPE STRING,
LOGNUMBER_PCL TYPE STRING,
PROC_TOTAL TYPE STRING,
PROC_COMPL TYPE STRING,
PROGTYPE TYPE STRING,
STATUS_ICON TYPE STRING,
STATUS_ICON_NAME TYPE STRING,
SUBSTATE_EXIST TYPE STRING,
HAS_NOTE TYPE STRING,
HAS_ATTACHMENT TYPE STRING,
ACTIVITY_VARIANT TYPE STRING,
HOLD_UP TYPE STRING,
WDY_SHOW_AS TYPE STRING,
COT_ID TYPE STRING,END OF T_EKKO_STR. DATA: WA_CNVMBTPROCTREE_STR_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_CNVMBTPROCTREE_STR_STR-PHASE sy-vline
WA_CNVMBTPROCTREE_STR_STR-ACTIVITY_ID sy-vline
WA_CNVMBTPROCTREE_STR_STR-TLEVEL sy-vline
WA_CNVMBTPROCTREE_STR_STR-PARENT_ID sy-vline
WA_CNVMBTPROCTREE_STR_STR-NEXT_ID sy-vline
WA_CNVMBTPROCTREE_STR_STR-PROC_VIEW sy-vline
WA_CNVMBTPROCTREE_STR_STR-OPTIONAL sy-vline
WA_CNVMBTPROCTREE_STR_STR-USED_VARIANT sy-vline
WA_CNVMBTPROCTREE_STR_STR-MANUAL_STS_ALLWD sy-vline
WA_CNVMBTPROCTREE_STR_STR-ACTIVITY_TYPE sy-vline
WA_CNVMBTPROCTREE_STR_STR-EXEC_TARGET sy-vline
WA_CNVMBTPROCTREE_STR_STR-EXEC_TYPE sy-vline
WA_CNVMBTPROCTREE_STR_STR-TCODE sy-vline
WA_CNVMBTPROCTREE_STR_STR-PROGNAME sy-vline
WA_CNVMBTPROCTREE_STR_STR-FUNCNAME sy-vline
WA_CNVMBTPROCTREE_STR_STR-RERUN sy-vline
WA_CNVMBTPROCTREE_STR_STR-NO_STATE_MNGMT sy-vline
WA_CNVMBTPROCTREE_STR_STR-DOCU_TYPE sy-vline
WA_CNVMBTPROCTREE_STR_STR-DOCUMENT_LINK sy-vline
WA_CNVMBTPROCTREE_STR_STR-RESTART_ALLOWED sy-vline
WA_CNVMBTPROCTREE_STR_STR-USER_DIALOG sy-vline
WA_CNVMBTPROCTREE_STR_STR-RSFLAG1 sy-vline
WA_CNVMBTPROCTREE_STR_STR-COMPONENT_NAME sy-vline
WA_CNVMBTPROCTREE_STR_STR-APPLICATION_NAME sy-vline
WA_CNVMBTPROCTREE_STR_STR-CHECK_FUNCNAME sy-vline
WA_CNVMBTPROCTREE_STR_STR-NODE_TEXT sy-vline
WA_CNVMBTPROCTREE_STR_STR-EXEC_NUM sy-vline
WA_CNVMBTPROCTREE_STR_STR-STATE_TEC sy-vline
WA_CNVMBTPROCTREE_STR_STR-STATE_LOG sy-vline
WA_CNVMBTPROCTREE_STR_STR-ABORTED sy-vline
WA_CNVMBTPROCTREE_STR_STR-RUNMODE sy-vline
WA_CNVMBTPROCTREE_STR_STR-STARTTIME sy-vline
WA_CNVMBTPROCTREE_STR_STR-ENDTIME sy-vline
WA_CNVMBTPROCTREE_STR_STR-DURATION sy-vline
WA_CNVMBTPROCTREE_STR_STR-DESTINATION sy-vline
WA_CNVMBTPROCTREE_STR_STR-JOBNAME sy-vline
WA_CNVMBTPROCTREE_STR_STR-JOBCOUNT sy-vline
WA_CNVMBTPROCTREE_STR_STR-EXEC_SERVER sy-vline
WA_CNVMBTPROCTREE_STR_STR-EXEC_PROCID sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_SELECT sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_RELEVANT sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_READ sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_CONV sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_UPD sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_INS sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_TRANS sy-vline
WA_CNVMBTPROCTREE_STR_STR-REC_SKIPPED sy-vline
WA_CNVMBTPROCTREE_STR_STR-LOGNUMBER sy-vline
WA_CNVMBTPROCTREE_STR_STR-SESSION_ID sy-vline
WA_CNVMBTPROCTREE_STR_STR-LOGNUMBER_PCL sy-vline
WA_CNVMBTPROCTREE_STR_STR-PROC_TOTAL sy-vline
WA_CNVMBTPROCTREE_STR_STR-PROC_COMPL sy-vline
WA_CNVMBTPROCTREE_STR_STR-PROGTYPE sy-vline
WA_CNVMBTPROCTREE_STR_STR-STATUS_ICON sy-vline
WA_CNVMBTPROCTREE_STR_STR-STATUS_ICON_NAME sy-vline
WA_CNVMBTPROCTREE_STR_STR-SUBSTATE_EXIST sy-vline
WA_CNVMBTPROCTREE_STR_STR-HAS_NOTE sy-vline
WA_CNVMBTPROCTREE_STR_STR-HAS_ATTACHMENT sy-vline
WA_CNVMBTPROCTREE_STR_STR-ACTIVITY_VARIANT sy-vline
WA_CNVMBTPROCTREE_STR_STR-HOLD_UP sy-vline
WA_CNVMBTPROCTREE_STR_STR-WDY_SHOW_AS sy-vline
WA_CNVMBTPROCTREE_STR_STR-COT_ID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.